2016-09-13 17:08:26 +00:00
{% extends 'base.html' %}
{% load static %}
{% load i18n %}
{% block content %}
< div class = "wrapper wrapper-content animated fadeInRight" >
< div class = "row" >
< div class = "col-sm-12" >
< div class = "ibox float-e-margins" >
< div class = "panel-options" >
< ul class = "nav nav-tabs" >
< li >
< a href = "{% url 'perms:asset-permission-detail' pk=asset_permission.id %}" class = "text-center" >
< i class = "fa fa-laptop" > < / i > {% trans 'Detail' %} < / a >
< / li >
< li >
< a href = "{% url 'perms:asset-permission-user-list' pk=asset_permission.id %}" class = "text-center" >
2019-07-18 03:01:28 +00:00
< i class = "fa fa-group" > < / i > {% trans 'Users and user groups' %}
2016-09-13 17:08:26 +00:00
< / a >
< / li >
< li class = "active" >
< a href = "{% url 'perms:asset-permission-asset-list' pk=asset_permission.id %}" class = "text-center" >
2019-07-18 03:01:28 +00:00
< i class = "fa fa-inbox" > < / i > {% trans 'Assets and node' %}< / a >
2016-09-13 17:08:26 +00:00
< / li >
< / ul >
< / div >
< div class = "tab-content" >
2019-07-18 03:01:28 +00:00
< div class = "col-sm-8" style = "padding-left: 0;" >
2016-09-13 17:08:26 +00:00
< div class = "ibox float-e-margins" >
< div class = "ibox-title" >
< span style = "float: left" > {% trans 'Asset list of ' %} < b > {{ asset_permission.name }}< / b > < / span >
< div class = "ibox-tools" >
< a class = "collapse-link" >
< i class = "fa fa-chevron-up" > < / i >
< / a >
< a class = "dropdown-toggle" data-toggle = "dropdown" href = "#" >
< i class = "fa fa-wrench" > < / i >
< / a >
< ul class = "dropdown-menu dropdown-user" >
< / ul >
< a class = "close-link" >
< i class = "fa fa-times" > < / i >
< / a >
< / div >
< / div >
< div class = "ibox-content" >
2019-07-12 10:31:14 +00:00
< table class = "table table-striped table-bordered table-hover" id = "asset_list_table" style = "width: 100%" >
2016-09-13 17:08:26 +00:00
< thead >
2019-07-12 10:31:14 +00:00
< tr >
< th class = "text-center" >
< input type = "checkbox" id = "check_all" class = "ipt_check_all" >
< / th >
2019-12-05 07:09:25 +00:00
< th class = "text-center" > {% trans 'Asset' %}< / th >
< th class = "text-center" > {% trans 'Action' %}< / th >
2019-07-12 10:31:14 +00:00
< / tr >
2016-09-13 17:08:26 +00:00
< / thead >
< tbody >
< / tbody >
< / table >
< / div >
< / div >
< / div >
2019-07-18 03:01:28 +00:00
< div class = "col-sm-4" style = "padding-left: 0;padding-right: 0" >
2016-09-13 17:08:26 +00:00
< div class = "panel panel-primary" >
< div class = "panel-heading" >
2016-09-14 15:29:39 +00:00
< i class = "fa fa-info-circle" > < / i > {% trans 'Add asset to this permission' %}
2016-09-13 17:08:26 +00:00
< / div >
< div class = "panel-body" >
< table class = "table" >
< tbody >
< form >
< tr class = "no-borders-tr" >
< td colspan = "2" >
2019-12-05 07:09:25 +00:00
< select data-placeholder = "{% trans 'Select assets' %}" class = "select2 assets-select2" id = "id_assets" style = "width: 100%" multiple = "" tabindex = "4" >
2016-09-13 17:08:26 +00:00
< / select >
< / td >
< / tr >
< tr class = "no-borders-tr" >
< td colspan = "2" >
2017-12-19 11:38:09 +00:00
< button type = "button" class = "btn btn-primary btn-sm btn-add-assets" > {% trans 'Add' %}< / button >
2016-09-13 17:08:26 +00:00
< / td >
< / tr >
< / form >
< / tbody >
< / table >
< / div >
< / div >
< div class = "panel panel-info" >
< div class = "panel-heading" >
2018-04-11 07:24:12 +00:00
< i class = "fa fa-info-circle" > < / i > {% trans 'Add node to this permission' %}
2016-09-13 17:08:26 +00:00
< / div >
< div class = "panel-body" >
< table class = "table group_edit" >
< tbody >
< form >
< tr >
< td colspan = "2" class = "no-borders" >
2019-09-12 09:58:52 +00:00
< select data-placeholder = "{% trans 'Select nodes' %}" class = "nodes-select2" id = "nodes_select2" style = "width: 100%" multiple = "" tabindex = "4" >
2016-09-13 17:08:26 +00:00
< / select >
< / td >
< / tr >
< tr >
< td colspan = "2" class = "no-borders" >
2018-04-11 07:24:12 +00:00
< button type = "button" class = "btn btn-info btn-sm" id = "btn-add-node" > {% trans 'Join' %}< / button >
2016-09-13 17:08:26 +00:00
< / td >
< / tr >
< / form >
2018-04-11 07:24:12 +00:00
{% for node in asset_permission.nodes.all %}
2019-12-05 07:09:25 +00:00
< tr { % if forloop . counter = = 1 % } class = "no-borders-tr" { % endif % } >
2019-08-21 12:27:21 +00:00
< td > < b class = "bdg_group" data-gid = {{ node . id } } > {{ node.full_value }}< / b > < / td >
2016-09-13 17:08:26 +00:00
< td >
2019-12-05 07:09:25 +00:00
< button class = "btn btn-danger btn-xs btn-remove-node" type = "button" data-uid = "{{ node.id }}" style = "float: right;" > < i class = "fa fa-minus" > < / i > < / button >
< / td >
< / tr >
{% endfor %}
< / tbody >
< / table >
< / div >
< / div >
< div class = "panel panel-warning" >
< div class = "panel-heading" >
< i class = "fa fa-info-circle" > < / i > {% trans 'System user' %}
< / div >
< div class = "panel-body" >
< table class = "table" id = "system-user-table" >
< tbody >
< form >
< tr class = "no-borders-tr" >
< td colspan = "2" >
< select data-placeholder = "{% trans 'Select system users' %}" class = "select2 system-users" id = "system_users_select2" style = "width: 100%" multiple = "" tabindex = "4" >
{% for system_user in system_users_remain %}
< option value = "{{ system_user.id }}" id = "opt_{{ system_user.id }}" > {{ system_user }}< / option >
{% endfor %}
< / select >
< / td >
< / tr >
< tr class = "no-borders-tr" >
< td colspan = "2" >
< button type = "button" class = "btn btn-warning btn-sm" id = "btn-add-system-user" > {% trans 'Add' %}< / button >
< / td >
< / tr >
< / form >
{% for system_user in object.system_users.all %}
< tr { % if forloop . counter = = 1 % } class = "no-borders-tr" { % endif % } >
< td > < b class = "bdg-system-user" data-uid = {{ system_user . id } } > {{ system_user|truncatechars:21}}< / b > < / td >
< td >
< button class = "btn btn-danger btn-xs btn-remove-sys-user" data-uid = "{{ system_user.id }}" type = "button" style = "float: right;" > < i class = "fa fa-minus" > < / i > < / button >
2016-09-13 17:08:26 +00:00
< / td >
< / tr >
{% endfor %}
< / tbody >
< / table >
< / div >
< / div >
< / div >
< / div >
< / div >
< / div >
< / div >
< / div >
2019-07-12 10:31:14 +00:00
{% include 'assets/_asset_list_modal.html' %}
2016-09-13 17:08:26 +00:00
{% endblock %}
{% block custom_foot_js %}
2017-12-19 11:38:09 +00:00
< script >
2019-12-05 07:09:25 +00:00
var assetsRelationUrl = "{% url 'api-perms:asset-permissions-assets-relation-list' %}";
var nodesRelationUrl = "{% url 'api-perms:asset-permissions-nodes-relation-list' %}";
var systemUsersRelationUrl = "{% url 'api-perms:asset-permissions-system-users-relation-list' %}";
function getRelationUrl(type) {
var theUrl = "";
switch (type) {
case "asset":
theUrl = assetsRelationUrl;
break;
case "node":
theUrl = nodesRelationUrl;
break;
case "systemuser":
theUrl = systemUsersRelationUrl;
break;
}
return theUrl;
}
function addObjects(objectsId, type) {
if (!objectsId || objectsId.length === 0) {
return
}
var theUrl = getRelationUrl(type);
var body = [];
objectsId.forEach(function (v) {
var data = {assetpermission: "{{ object.id }}"};
data[type] = v;
body.push(data)
});
2019-07-12 10:31:55 +00:00
requestApi({
2019-12-05 07:09:25 +00:00
url: theUrl,
2017-12-19 11:38:09 +00:00
body: JSON.stringify(body),
2019-12-05 07:09:25 +00:00
method: "POST",
success: reloadPage
2017-12-19 11:38:09 +00:00
});
}
2019-12-05 07:09:25 +00:00
function removeObject(objectId, type) {
if (!objectId) {
return
}
var theUrl = getRelationUrl(type);
theUrl = setUrlParam(theUrl, 'assetpermission', "{{ object.id }}");
theUrl = setUrlParam(theUrl, type, objectId);
2019-07-12 10:31:55 +00:00
requestApi({
2019-12-05 07:09:25 +00:00
url: theUrl,
method: "DELETE",
success: reloadPage
2017-12-19 11:38:09 +00:00
});
}
2019-12-05 07:09:25 +00:00
2019-07-12 10:31:14 +00:00
var table;
function initAssetTable() {
var options = {
ele: $('#asset_list_table'),
toggle: true,
columnDefs: [
2019-12-05 07:09:25 +00:00
{targets: 2, createdCell: function (td, cellData, rowData) {
var removeBtn = '< a class = "btn btn-xs btn-danger m-l-xs btn-remove-asset" disabled data-uid = "{{ DEFAULT_PK }}" > < i class = "fa fa-minus" > < / i > < / a > '
.replace('{{ DEFAULT_PK }}', cellData);
if (assetDirectRelated.indexOf(cellData) !== -1) {
removeBtn = removeBtn.replace('disabled', '')
}
$(td).html(removeBtn);
}}
2019-07-12 10:31:14 +00:00
],
2019-12-05 07:09:25 +00:00
ajax_url: "{% url 'api-perms:asset-permission-all-assets' pk=object.id %}",
2019-07-12 10:31:14 +00:00
columns: [
2019-12-05 07:09:25 +00:00
{data: "asset"}, {data: "asset_display"}, {data: "asset", width: "30px"}
2019-07-12 10:31:14 +00:00
],
op_html: $('#actions').html()
};
table = jumpserver.initServerSideDataTable(options);
return table
}
2017-12-19 11:38:09 +00:00
2019-12-05 07:09:25 +00:00
var assetDirectRelated = {{ assets | safe }};
2019-09-12 09:58:52 +00:00
2017-12-19 11:38:09 +00:00
$(document).ready(function () {
2019-07-12 10:31:14 +00:00
$('.select2').select2();
2019-09-27 06:18:51 +00:00
nodesSelect2Init(".nodes-select2");
2019-12-05 07:09:25 +00:00
initAssetTable();
initAssetTreeModel('#id_assets');
2019-07-12 10:31:14 +00:00
})
2017-12-19 11:38:09 +00:00
.on('click', '.btn-add-assets', function () {
2019-12-05 07:09:25 +00:00
var assetsId = $("#id_assets").val();
addObjects(assetsId, "asset");
2017-12-19 11:38:09 +00:00
})
.on('click', '.btn-remove-asset', function () {
2019-12-05 07:09:25 +00:00
var assetId = $(this).data("uid");
removeObject(assetId, "asset")
2017-12-19 11:38:09 +00:00
})
2018-04-11 07:24:12 +00:00
.on('click', '#btn-add-node', function () {
2019-12-05 07:09:25 +00:00
var nodesId = $("#nodes_select2").val();
addObjects(nodesId, "node");
})
2018-04-11 07:24:12 +00:00
.on('click', '.btn-remove-node', function () {
2019-12-05 07:09:25 +00:00
var nodeId = $(this).data("uid");
removeObject(nodeId, "node")
})
.on('click', '#btn-add-system-user', function () {
var systemUsersId = $("#system_users_select2").val();
addObjects(systemUsersId, "systemuser");
})
.on('click', '.btn-remove-sys-user', function () {
var systemUserId = $(this).data("uid");
removeObject(systemUserId, "systemuser")
2017-12-19 11:38:09 +00:00
})
< / script >
2017-01-26 12:24:50 +00:00
{% endblock %}