|
|
|
@ -85,9 +85,9 @@
|
|
|
|
|
<form>
|
|
|
|
|
<tr class="no-borders-tr">
|
|
|
|
|
<td colspan="2">
|
|
|
|
|
<select data-placeholder="{% trans 'Select assets' %}" class="select2 asset" style="width: 100%" multiple="" tabindex="4">
|
|
|
|
|
<select data-placeholder="{% trans 'Select assets' %}" class="select2" id="asset_select2" style="width: 100%" multiple="" tabindex="4">
|
|
|
|
|
{% for asset in assets_remain %}
|
|
|
|
|
<option value="{{ asset.id }}">{{ asset.hostname }}</option>
|
|
|
|
|
<option value="{{ asset.id }}">{{ asset }}</option>
|
|
|
|
|
{% endfor %}
|
|
|
|
|
</select>
|
|
|
|
|
</td>
|
|
|
|
@ -113,9 +113,9 @@
|
|
|
|
|
<form>
|
|
|
|
|
<tr>
|
|
|
|
|
<td colspan="2" class="no-borders">
|
|
|
|
|
<select data-placeholder="{% trans 'Select nodes' %}" class="select2 group" style="width: 100%" multiple="" tabindex="4">
|
|
|
|
|
<select data-placeholder="{% trans 'Select nodes' %}" class="select2" id="node_select2" style="width: 100%" multiple="" tabindex="4">
|
|
|
|
|
{% for node in nodes_remain %}
|
|
|
|
|
<option value="{{ node.id }}" id="opt_{{ node.id }}">{{ node.value }}</option>
|
|
|
|
|
<option value="{{ node.id }}" id="opt_{{ node.id }}">{{ node }}</option>
|
|
|
|
|
{% endfor %}
|
|
|
|
|
</select>
|
|
|
|
|
</td>
|
|
|
|
@ -129,9 +129,9 @@
|
|
|
|
|
|
|
|
|
|
{% for node in asset_permission.nodes.all %}
|
|
|
|
|
<tr>
|
|
|
|
|
<td ><b class="bdg_user_group" data-gid={{ node.id }}>{{ node.value }}</b></td>
|
|
|
|
|
<td ><b class="bdg_group" data-gid={{ node.id }}>{{ node }}</b></td>
|
|
|
|
|
<td>
|
|
|
|
|
<button class="btn btn-danger btn-xs btn-remove-node" type="button" style="float: right;"><i class="fa fa-minus"></i></button>
|
|
|
|
|
<button class="btn btn-danger btn-xs btn-remove-node" type="button" data-gid="{{ node.id }}" style="float: right;"><i class="fa fa-minus"></i></button>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
{% endfor %}
|
|
|
|
@ -179,49 +179,30 @@ function removeAssets(assets) {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function updateNodes(nodes) {
|
|
|
|
|
function updateNodes(nodes, success) {
|
|
|
|
|
var the_url = "{% url 'api-perms:asset-permission-detail' pk=asset_permission.id %}";
|
|
|
|
|
var body = {
|
|
|
|
|
nodes: nodes
|
|
|
|
|
};
|
|
|
|
|
APIUpdateAttr({
|
|
|
|
|
url: the_url,
|
|
|
|
|
body: JSON.stringify(body)
|
|
|
|
|
body: JSON.stringify(body),
|
|
|
|
|
success: success
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
jumpserver.assets_selected = {};
|
|
|
|
|
jumpserver.nodes_selected = {};
|
|
|
|
|
|
|
|
|
|
$(document).ready(function () {
|
|
|
|
|
$('.select2.asset').select2()
|
|
|
|
|
.on('select2:select', function(evt) {
|
|
|
|
|
var data = evt.params.data;
|
|
|
|
|
jumpserver.assets_selected[data.id] = data.text;
|
|
|
|
|
})
|
|
|
|
|
.on('select2:unselect', function(evt) {
|
|
|
|
|
var data = evt.params.data;
|
|
|
|
|
delete jumpserver.assets_selected[data.id]
|
|
|
|
|
});
|
|
|
|
|
$('.select2.group').select2()
|
|
|
|
|
.on('select2:select', function(evt) {
|
|
|
|
|
var data = evt.params.data;
|
|
|
|
|
jumpserver.nodes_selected[data.id] = data.text;
|
|
|
|
|
})
|
|
|
|
|
.on('select2:unselect', function(evt) {
|
|
|
|
|
var data = evt.params.data;
|
|
|
|
|
delete jumpserver.nodes_selected[data.id]
|
|
|
|
|
})
|
|
|
|
|
$('.select2').select2();
|
|
|
|
|
})
|
|
|
|
|
.on('click', '.btn-add-assets', function () {
|
|
|
|
|
if (Object.keys(jumpserver.assets_selected).length === 0) {
|
|
|
|
|
var assets_selected = $("#asset_select2 option:selected").map(function () {
|
|
|
|
|
return $(this).attr('value');
|
|
|
|
|
}).get();
|
|
|
|
|
if (assets_selected.length === 0) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
var assets = [];
|
|
|
|
|
$.map(jumpserver.assets_selected, function(value, index) {
|
|
|
|
|
assets.push(index);
|
|
|
|
|
});
|
|
|
|
|
addAssets(assets);
|
|
|
|
|
addAssets(assets_selected);
|
|
|
|
|
})
|
|
|
|
|
.on('click', '.btn-remove-asset', function () {
|
|
|
|
|
var asset_id = $(this).data("gid");
|
|
|
|
@ -232,26 +213,30 @@ $(document).ready(function () {
|
|
|
|
|
removeAssets(assets)
|
|
|
|
|
})
|
|
|
|
|
.on('click', '#btn-add-node', function () {
|
|
|
|
|
if (Object.keys(jumpserver.nodes_selected).length === 0) {
|
|
|
|
|
var nodes_selected = {};
|
|
|
|
|
$("#node_select2 option:selected").each(function (i, data) {
|
|
|
|
|
nodes_selected[$(data).attr('value')] = $(data).text();
|
|
|
|
|
});
|
|
|
|
|
if (Object.keys(nodes_selected).length === 0) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var nodes = $('.bdg_group').map(function() {
|
|
|
|
|
var nodes_origin = $('.bdg_group').map(function() {
|
|
|
|
|
return $(this).data('gid');
|
|
|
|
|
}).get();
|
|
|
|
|
|
|
|
|
|
$.map(jumpserver.nodes_selected, function(group_name, index) {
|
|
|
|
|
nodes.push(index);
|
|
|
|
|
$('#opt_' + index).remove();
|
|
|
|
|
$('.group_edit tbody').append(
|
|
|
|
|
'<tr>' +
|
|
|
|
|
'<td><b class="bdg_group" data-gid="' + index + '">' + group_name + '</b></td>' +
|
|
|
|
|
'<td><button class="btn btn-danger btn-xs pull-right btn-leave-group" type="button"><i class="fa fa-minus"></i></button></td>' +
|
|
|
|
|
'</tr>'
|
|
|
|
|
)
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
updateNodes(nodes);
|
|
|
|
|
var nodes = nodes_origin.concat(Object.keys(nodes_selected));
|
|
|
|
|
var success = function () {
|
|
|
|
|
$.map(nodes_selected, function(name, id) {
|
|
|
|
|
$('#opt_' + id).remove();
|
|
|
|
|
$('.group_edit tbody').append(
|
|
|
|
|
'<tr>' +
|
|
|
|
|
'<td><b class="bdg_group" data-gid="' + id + '">' + name + '</b></td>' +
|
|
|
|
|
'<td><button class="btn btn-danger btn-xs pull-right btn-leave-group" type="button"><i class="fa fa-minus"></i></button></td>' +
|
|
|
|
|
'</tr>'
|
|
|
|
|
)
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
updateNodes(nodes, success);
|
|
|
|
|
})
|
|
|
|
|
.on('click', '.btn-remove-node', function () {
|
|
|
|
|
var $this = $(this);
|
|
|
|
@ -261,8 +246,10 @@ $(document).ready(function () {
|
|
|
|
|
return $(this).data('gid');
|
|
|
|
|
}
|
|
|
|
|
}).get();
|
|
|
|
|
updateNodes(nodes);
|
|
|
|
|
$tr.remove()
|
|
|
|
|
var success = function () {
|
|
|
|
|
$tr.remove()
|
|
|
|
|
};
|
|
|
|
|
updateNodes(nodes, success);
|
|
|
|
|
})
|
|
|
|
|
</script>
|
|
|
|
|
{% endblock %}
|
|
|
|
|