From 3ccd54680ed8d56685dc6603f409c52af4845e5f Mon Sep 17 00:00:00 2001 From: ibuler Date: Sat, 14 Apr 2018 12:18:15 +0800 Subject: [PATCH] =?UTF-8?q?[Bugfix]=20=E4=BF=AE=E6=94=B9=E6=8E=88=E6=9D=83?= =?UTF-8?q?=E8=AF=A6=E6=83=85=E5=BF=AB=E9=80=9FNode=E6=9B=B4=E6=94=B9?= =?UTF-8?q?=E5=A4=B1=E6=95=88=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../templates/assets/system_user_detail.html | 4 +- apps/jumpserver/urls.py | 6 +- .../perms/asset_permission_asset.html | 89 ++++++++----------- .../perms/asset_permission_detail.html | 4 +- .../perms/asset_permission_user.html | 6 +- 5 files changed, 47 insertions(+), 62 deletions(-) diff --git a/apps/assets/templates/assets/system_user_detail.html b/apps/assets/templates/assets/system_user_detail.html index 3572cfd3d..a02bf1e44 100644 --- a/apps/assets/templates/assets/system_user_detail.html +++ b/apps/assets/templates/assets/system_user_detail.html @@ -173,7 +173,7 @@ @@ -187,7 +187,7 @@ {% for node in system_user.nodes.all %} - {{ node.name }} + {{ node }} diff --git a/apps/jumpserver/urls.py b/apps/jumpserver/urls.py index e8a490bf3..8300ebe06 100644 --- a/apps/jumpserver/urls.py +++ b/apps/jumpserver/urls.py @@ -36,12 +36,10 @@ urlpatterns = [ url(r'^captcha/', include('captcha.urls')), ] -urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) +urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) \ + + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) if settings.DEBUG: urlpatterns += [ url(r'^docs/', schema_view, name="docs"), ] - -if not settings.DEBUG: - urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) diff --git a/apps/perms/templates/perms/asset_permission_asset.html b/apps/perms/templates/perms/asset_permission_asset.html index fa50b4eb9..364d7e60f 100644 --- a/apps/perms/templates/perms/asset_permission_asset.html +++ b/apps/perms/templates/perms/asset_permission_asset.html @@ -85,9 +85,9 @@
- {% for asset in assets_remain %} - + {% endfor %} @@ -113,9 +113,9 @@ - {% for node in nodes_remain %} - + {% endfor %} @@ -129,9 +129,9 @@ {% for node in asset_permission.nodes.all %} - {{ node.value }} + {{ node }} - + {% 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( - '' + - '' + group_name + '' + - '' + - '' - ) - }); - - 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( + '' + + '' + name + '' + + '' + + '' + ) + }); + }; + 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); }) {% endblock %} diff --git a/apps/perms/templates/perms/asset_permission_detail.html b/apps/perms/templates/perms/asset_permission_detail.html index 4cfa48de4..3996cb274 100644 --- a/apps/perms/templates/perms/asset_permission_detail.html +++ b/apps/perms/templates/perms/asset_permission_detail.html @@ -147,7 +147,7 @@ @@ -161,7 +161,7 @@ {% for system_user in object.system_users.all %} - {{ system_user.name }} + {{ system_user }} diff --git a/apps/perms/templates/perms/asset_permission_user.html b/apps/perms/templates/perms/asset_permission_user.html index b5542707c..5d490bc28 100644 --- a/apps/perms/templates/perms/asset_permission_user.html +++ b/apps/perms/templates/perms/asset_permission_user.html @@ -87,7 +87,7 @@ @@ -115,7 +115,7 @@ @@ -129,7 +129,7 @@ {% for user_group in asset_permission.user_groups.all %} - {{ user_group.name }} + {{ user_group }}