[Bugfix] 修复 资产授权/标签 选择资产时,input框内的资产和弹出资产tabl显示不一致的bug (#2205)

* [Bugfix] 修复授权规则,选择资产时,输入框资产和弹出表格中资产显示不一致

* [Bugfix] 修复创建/更新资产标签,选择资产时,输入框资产和弹出表格中资产显示不一致的bug

* [Update] 修复标签/授权选择资产时, 2次初始化table的bug;资产input和弹出table统一的代码逻辑移到js中;
pull/2208/head
BaiJiangJie 2018-12-18 18:50:02 +08:00 committed by 老广
parent a609f17078
commit fb44ef0986
4 changed files with 35 additions and 0 deletions

View File

@ -57,6 +57,10 @@
<script>
var zTree2, asset_table2 = 0;
function initTable2() {
if(asset_table2){
return
}
var options = {
ele: $('#asset_list_modal_table'),
ajax_url: '{% url "api-assets:asset-list" %}?show_current_asset=1',

View File

@ -32,6 +32,7 @@ $(document).ready(function () {
}).on('click', '.select2-selection__rendered', function (e) {
e.preventDefault();
$("#asset_list_modal").modal();
initSelectedAssets2Table();
})
.on('click', '#btn_asset_modal_confirm', function () {
var assets = asset_table2.selected;

View File

@ -113,6 +113,7 @@ $(document).ready(function () {
e.preventDefault();
e.stopPropagation();
$("#asset_list_modal").modal();
initSelectedAssets2Table();
}
})
})

View File

@ -812,3 +812,32 @@ function initPopover($container, $progress, $idPassword, $el, password_check_rul
$idPassword.pwstrength(options);
popoverPasswordRules(password_check_rules, $el);
}
// 解决input框中的资产和弹出表格中资产的显示不一致
function initSelectedAssets2Table(){
var inputAssets = $('#id_assets').val();
var selectedAssets = asset_table2.selected.concat();
// input assets无table assets选中则取消勾选(再次click)
if (selectedAssets.length !== 0){
$.each(selectedAssets, function (index, assetId){
if ($.inArray(assetId, inputAssets) === -1){
$('#'+assetId).trigger('click'); // 取消勾选
}
});
}
// input assets有table assets没选则选中(click)
if (inputAssets !== null){
asset_table2.selected = inputAssets;
$.each(inputAssets, function(index, assetId){
var dom = document.getElementById(assetId);
if (dom !== null){
var selected = dom.parentElement.parentElement.className.indexOf('selected')
}
if (selected === -1){
$('#'+assetId).trigger('click');
}
});
}
}