mirror of https://github.com/jumpserver/jumpserver
修复idc_list删除时重新加载table
parent
e0179ea332
commit
9de2ff2052
|
@ -51,8 +51,8 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="hr-line-dashed"></div>
|
<div class="hr-line-dashed"></div>
|
||||||
<h3 class="widget-head-color-box">资产用户</h3>
|
{# <h3 class="widget-head-color-box">资产用户</h3>#}
|
||||||
{{ form.system_users|bootstrap_horizontal }}
|
{# {{ form.system_users|bootstrap_horizontal }}#}
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<div class="col-sm-4 col-sm-offset-5">
|
<div class="col-sm-4 col-sm-offset-5">
|
||||||
<button class="btn btn-white" type="reset"> 重置 </button>
|
<button class="btn btn-white" type="reset"> 重置 </button>
|
||||||
|
|
|
@ -101,42 +101,6 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="panel panel-info">
|
|
||||||
<div class="panel-heading">
|
|
||||||
<i class="fa fa-info-circle"></i> {% trans 'Associate system user' %}
|
|
||||||
</div>
|
|
||||||
<div class="panel-body">
|
|
||||||
<table class="table system-user-table">
|
|
||||||
<tbody>
|
|
||||||
<form>
|
|
||||||
<tr class="no-borders-tr">
|
|
||||||
<td colspan="2">
|
|
||||||
<select data-placeholder="{% trans 'Select system user' %}" class="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.name }}</option>
|
|
||||||
{% endfor %}
|
|
||||||
</select>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr class="no-borders-tr">
|
|
||||||
<td colspan="2">
|
|
||||||
<button type="button" class="btn btn-info btn-sm btn-asset-add-groups-system-users">{% trans 'Associate' %}</button>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</form>
|
|
||||||
{% for system_user in system_users %}
|
|
||||||
<tr>
|
|
||||||
<td ><b class="bdg_system_user" data-sid={{ system_user.id }}>{{ system_user.name }}</b></td>
|
|
||||||
<td>
|
|
||||||
<button class="btn btn-danger btn-xs pull-right btn_leave_asset_group" type="button" style="float: right;"><i class="fa fa-minus"></i></button>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
{% endfor %}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -71,7 +71,7 @@
|
||||||
<option value="delete">{% trans 'Delete selected' %}</option>
|
<option value="delete">{% trans 'Delete selected' %}</option>
|
||||||
<option value="update">{% trans 'Update selected' %}</option>
|
<option value="update">{% trans 'Update selected' %}</option>
|
||||||
<option value="deactive">{% trans 'Deactive selected' %}</option>
|
<option value="deactive">{% trans 'Deactive selected' %}</option>
|
||||||
<option value="active">{% trans 'Active' %}</option>
|
<option value="active">{% trans 'Active' %}</option>
|
||||||
</select>
|
</select>
|
||||||
<div class="input-group-btn pull-left" style="padding-left: 5px;">
|
<div class="input-group-btn pull-left" style="padding-left: 5px;">
|
||||||
<button id='btn_bulk_update' style="height: 32px;" class="btn btn-sm btn-primary">
|
<button id='btn_bulk_update' style="height: 32px;" class="btn btn-sm btn-primary">
|
||||||
|
@ -96,12 +96,12 @@ window.onload = function (){
|
||||||
};
|
};
|
||||||
|
|
||||||
function tagShow() {
|
function tagShow() {
|
||||||
var oDiv = document.getElementById("ydxbd");
|
var oDiv = document.getElementById("ydxbd");
|
||||||
if (oDiv.style.display == 'none'){
|
if (oDiv.style.display == 'none'){
|
||||||
oDiv.style.display = "block";
|
oDiv.style.display = "block";
|
||||||
}else{
|
}else{
|
||||||
oDiv.style.display = "none";
|
oDiv.style.display = "none";
|
||||||
}
|
}
|
||||||
} //onload;
|
} //onload;
|
||||||
|
|
||||||
function objDelete(obj, name, url) {
|
function objDelete(obj, name, url) {
|
||||||
|
@ -137,98 +137,98 @@ function objDelete(obj, name, url) {
|
||||||
}
|
}
|
||||||
|
|
||||||
$(document).ready(function(){
|
$(document).ready(function(){
|
||||||
var options = {
|
var options = {
|
||||||
ele: $('#asset_list_table'),
|
ele: $('#asset_list_table'),
|
||||||
columnDefs: [
|
columnDefs: [
|
||||||
{targets: 1, createdCell: function (td, cellData, rowData) {
|
{targets: 1, createdCell: function (td, cellData, rowData) {
|
||||||
var detail_btn = '<a href="{% url "assets:asset-detail" pk=99991937 %}">' + cellData + '</a>';
|
var detail_btn = '<a href="{% url "assets:asset-detail" pk=99991937 %}">' + cellData + '</a>';
|
||||||
$(td).html(detail_btn.replace('99991937', rowData.id));
|
$(td).html(detail_btn.replace('99991937', rowData.id));
|
||||||
}},
|
}},
|
||||||
{targets: 7, createdCell: function (td, cellData) {
|
{targets: 7, createdCell: function (td, cellData) {
|
||||||
if (!cellData) {
|
if (!cellData) {
|
||||||
$(td).html('<i class="fa fa-times text-danger"></i>')
|
$(td).html('<i class="fa fa-times text-danger"></i>')
|
||||||
} else {
|
} else {
|
||||||
$(td).html('<i class="fa fa-check text-navy"></i>')
|
$(td).html('<i class="fa fa-check text-navy"></i>')
|
||||||
}
|
}
|
||||||
}},
|
}},
|
||||||
{targets: 8, createdCell: function (td, cellData) {
|
{targets: 8, createdCell: function (td, cellData) {
|
||||||
if (!cellData) {
|
if (!cellData) {
|
||||||
$(td).html('<i class="fa fa-circle text-danger"></i>')
|
$(td).html('<i class="fa fa-circle text-danger"></i>')
|
||||||
} else {
|
} else {
|
||||||
$(td).html('<i class="fa fa-circle text-navy"></i>')
|
$(td).html('<i class="fa fa-circle text-navy"></i>')
|
||||||
}
|
}
|
||||||
}},
|
}},
|
||||||
{targets: 9, createdCell: function (td, cellData, rowData) {
|
{targets: 9, createdCell: function (td, cellData, rowData) {
|
||||||
var update_btn = '<a href="{% url "assets:asset-update" pk=99991937 %}" class="btn btn-xs btn-info">{% trans "Update" %}</a>'.replace('99991937', cellData);
|
var update_btn = '<a href="{% url "assets:asset-update" pk=99991937 %}" class="btn btn-xs btn-info">{% trans "Update" %}</a>'.replace('99991937', cellData);
|
||||||
var del_btn = '<a class="btn btn-xs btn-danger m-l-xs btn_asset_delete" data-uid="99991937">{% trans "Delete" %}</a>'.replace('99991937', cellData);
|
var del_btn = '<a class="btn btn-xs btn-danger m-l-xs btn_asset_delete" data-uid="99991937">{% trans "Delete" %}</a>'.replace('99991937', cellData);
|
||||||
$(td).html(update_btn + del_btn)
|
$(td).html(update_btn + del_btn)
|
||||||
}}
|
}}
|
||||||
],
|
],
|
||||||
ajax_url: '{% url "api-assets:asset-list" %}',
|
ajax_url: '{% url "api-assets:asset-list" %}',
|
||||||
columns: [{data: "id"}, {data: "hostname" }, {data: "ip" }, {data: "port" },
|
columns: [{data: "id"}, {data: "hostname" }, {data: "ip" }, {data: "port" },
|
||||||
{data: "get_type_display" }, {data: "get_env_display"}, {data: "hardware"},
|
{data: "get_type_display" }, {data: "get_env_display"}, {data: "hardware"},
|
||||||
{data: "is_active" }, {data: "is_active"}, {data: "id" }],
|
{data: "is_active" }, {data: "is_active"}, {data: "id" }],
|
||||||
op_html: $('#actions').html()
|
op_html: $('#actions').html()
|
||||||
};
|
};
|
||||||
var table = jumpserver.initDataTable(options);
|
var table = jumpserver.initDataTable(options);
|
||||||
$('.btn_export').click(function () {
|
$('.btn_export').click(function () {
|
||||||
var assets = [];
|
var assets = [];
|
||||||
var rows = table.rows('.selected').data();
|
var rows = table.rows('.selected').data();
|
||||||
$.each(rows, function (index, obj) {
|
$.each(rows, function (index, obj) {
|
||||||
assets.push(obj.id)
|
assets.push(obj.id)
|
||||||
});
|
});
|
||||||
console.log(assets);
|
console.log(assets);
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "{% url "assets:asset-export" %}",
|
url: "{% url "assets:asset-export" %}",
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
data: JSON.stringify({assets_id: assets}),
|
data: JSON.stringify({assets_id: assets}),
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
success: function (data, textStatus) {
|
success: function (data, textStatus) {
|
||||||
window.open(data.redirect)
|
window.open(data.redirect)
|
||||||
},
|
},
|
||||||
error: function () {
|
error: function () {
|
||||||
toastr.error('Export failed');
|
toastr.error('Export failed');
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
$('#btn_asset_import').click(function() {
|
$('#btn_asset_import').click(function() {
|
||||||
var $form = $('#fm_asset_import');
|
var $form = $('#fm_asset_import');
|
||||||
$form.find('.help-block').remove();
|
$form.find('.help-block').remove();
|
||||||
function success (data) {
|
function success (data) {
|
||||||
if (data.valid === false) {
|
if (data.valid === false) {
|
||||||
$('<span />', {class: 'help-block text-danger'}).html(data.msg).insertAfter($('#id_assets'));
|
$('<span />', {class: 'help-block text-danger'}).html(data.msg).insertAfter($('#id_assets'));
|
||||||
} else {
|
} else {
|
||||||
$('#id_created').html(data.created_info);
|
$('#id_created').html(data.created_info);
|
||||||
$('#id_created_detail').html(data.created.join(', '));
|
$('#id_created_detail').html(data.created.join(', '));
|
||||||
$('#id_updated').html(data.updated_info);
|
$('#id_updated').html(data.updated_info);
|
||||||
$('#id_updated_detail').html(data.updated.join(', '));
|
$('#id_updated_detail').html(data.updated.join(', '));
|
||||||
$('#id_failed').html(data.failed_info);
|
$('#id_failed').html(data.failed_info);
|
||||||
$('#id_failed_detail').html(data.failed.join(', '));
|
$('#id_failed_detail').html(data.failed.join(', '));
|
||||||
var $data_table = $('#asset_list_table').DataTable();
|
var $data_table = $('#asset_list_table').DataTable();
|
||||||
$data_table.ajax.reload();
|
$data_table.ajax.reload();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$form.ajaxSubmit({success: success});
|
$form.ajaxSubmit({success: success});
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
.on('click', '.btn_asset_delete', function () {
|
.on('click', '.btn_asset_delete', function () {
|
||||||
var $this = $(this);
|
var $this = $(this);
|
||||||
var $data_table = $("#asset_list_table").DataTable();
|
var $data_table = $("#asset_list_table").DataTable();
|
||||||
var name = $(this).closest("tr").find(":nth-child(2)").children('a').html();
|
var name = $(this).closest("tr").find(":nth-child(2)").children('a').html();
|
||||||
var uid = $this.data('uid');
|
var uid = $this.data('uid');
|
||||||
var the_url = '{% url "api-assets:asset-detail" pk=99991937 %}'.replace('99991937', uid);
|
var the_url = '{% url "api-assets:asset-detail" pk=99991937 %}'.replace('99991937', uid);
|
||||||
console.log(the_url);
|
console.log(the_url);
|
||||||
objDelete($this, name, the_url);
|
objDelete($this, name, the_url);
|
||||||
setTimeout( function () {
|
setTimeout( function () {
|
||||||
$data_table.ajax.reload();
|
$data_table.ajax.reload();
|
||||||
}, 3000);
|
}, 3000);
|
||||||
})
|
})
|
||||||
|
|
||||||
.on('click', '#btn_bulk_update', function () {
|
.on('click', '#btn_bulk_update', function () {
|
||||||
var action = $('#slct_bulk_update').val();
|
var action = $('#slct_bulk_update').val();
|
||||||
var $data_table = $('#asset_list_table').DataTable();
|
var $data_table = $('#asset_list_table').DataTable();
|
||||||
var id_list = [];
|
var id_list = [];
|
||||||
var plain_id_list = [];
|
var plain_id_list = [];
|
||||||
$data_table.rows({selected: true}).every(function(){
|
$data_table.rows({selected: true}).every(function(){
|
||||||
id_list.push({id: this.data().id});
|
id_list.push({id: this.data().id});
|
||||||
|
@ -301,8 +301,8 @@ $(document).ready(function(){
|
||||||
})
|
})
|
||||||
|
|
||||||
.on('click', '#btn_asset_bulk_update', function () {
|
.on('click', '#btn_asset_bulk_update', function () {
|
||||||
var json_data = $("#fm_asset_bulk_update").serializeObject();
|
var json_data = $("#fm_asset_bulk_update").serializeObject();
|
||||||
var body = {};
|
var body = {};
|
||||||
body.enable_otp = (json_data.enable_otp === 'on')? true: false;
|
body.enable_otp = (json_data.enable_otp === 'on')? true: false;
|
||||||
if (json_data.type != '') {
|
if (json_data.type != '') {
|
||||||
body.type = json_data.type;
|
body.type = json_data.type;
|
||||||
|
@ -318,23 +318,23 @@ $(document).ready(function(){
|
||||||
}
|
}
|
||||||
|
|
||||||
if (json_data.system_users != undefined) {
|
if (json_data.system_users != undefined) {
|
||||||
body.system_users = json_data.system_users;
|
body.system_users = json_data.system_users;
|
||||||
}
|
}
|
||||||
if (typeof body.system_users === 'string') {
|
if (typeof body.system_users === 'string') {
|
||||||
body.system_users = [parseInt(body.system_users)]
|
body.system_users = [parseInt(body.system_users)]
|
||||||
} else if(typeof body.system_users === 'array') {
|
} else if(typeof body.system_users === 'array') {
|
||||||
var new_users = body.system_users.map(Number);
|
var new_users = body.system_users.map(Number);
|
||||||
body.system_users = new_users;
|
body.system_users = new_users;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (json_data.tags != undefined) {
|
if (json_data.tags != undefined) {
|
||||||
body.tags = json_data.tags;
|
body.tags = json_data.tags;
|
||||||
}
|
}
|
||||||
if (typeof body.tags == 'string') {
|
if (typeof body.tags == 'string') {
|
||||||
body.tags = [parseInt(body.tags)];
|
body.tags = [parseInt(body.tags)];
|
||||||
} else if (typeof body.tags === 'array') {
|
} else if (typeof body.tags === 'array') {
|
||||||
var new_tags = body.tags.map(Number);
|
var new_tags = body.tags.map(Number);
|
||||||
body.tags = new_tags;
|
body.tags = new_tags;
|
||||||
}
|
}
|
||||||
|
|
||||||
var $data_table = $('#asset_list_table').DataTable();
|
var $data_table = $('#asset_list_table').DataTable();
|
||||||
|
|
|
@ -27,16 +27,16 @@
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<div id="actions" class="hide">
|
<div id="actions" class="hide">
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<select class="form-control m-b" style="width: auto" id="slct_bulk_update">
|
<select class="form-control m-b" style="width: auto" id="slct_bulk_update">
|
||||||
<option value="delete">{% trans 'Delete selected' %}</option>
|
<option value="delete">{% trans 'Delete selected' %}</option>
|
||||||
</select>
|
</select>
|
||||||
<div class="input-group-btn pull-left" style="padding-left: 5px;">
|
<div class="input-group-btn pull-left" style="padding-left: 5px;">
|
||||||
<button id='btn_bulk_update' style="height: 32px;" class="btn btn-sm btn-primary">
|
<button id='btn_bulk_update' style="height: 32px;" class="btn btn-sm btn-primary">
|
||||||
{% trans 'Submit' %}
|
{% trans 'Submit' %}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block content_bottom_left %}{% endblock %}
|
{% block content_bottom_left %}{% endblock %}
|
||||||
|
@ -65,19 +65,20 @@ $(document).ready(function(){
|
||||||
})
|
})
|
||||||
|
|
||||||
.on('click', '.btn_idc_delete', function () {
|
.on('click', '.btn_idc_delete', function () {
|
||||||
var $this = $(this);
|
var $this = $(this);
|
||||||
var $data_table = $('#idc_list_table').DataTable();
|
var $data_table = $('#idc_list_table').DataTable();
|
||||||
var name = $(this).closest("tr").find(":nth-child(2)").children('a').html();
|
var name = $(this).closest("tr").find(":nth-child(2)").children('a').html();
|
||||||
var uid = $this.data('uid');
|
var uid = $this.data('uid');
|
||||||
var the_url = '{% url "api-assets:idc-detail" pk=99991937 %}'.replace('99991937', uid);
|
var the_url = '{% url "api-assets:idc-detail" pk=99991937 %}'.replace('99991937', uid);
|
||||||
objectDelete($this, name, the_url);
|
objectDelete($this, name, the_url);
|
||||||
$data_table.ajax.reload();
|
setTimeout( function () {
|
||||||
{# TODO: reload the tale #}
|
$data_table.ajax.reload();
|
||||||
|
}, 3000);
|
||||||
})
|
})
|
||||||
|
|
||||||
.on('click', '#btn_bulk_update', function () {
|
.on('click', '#btn_bulk_update', function () {
|
||||||
var action = $('#slct_bulk_update').val();
|
var action = $('#slct_bulk_update').val();
|
||||||
var $data_table = $('#idc_list_table').DataTable();
|
var $data_table = $('#idc_list_table').DataTable();
|
||||||
var id_list = [];
|
var id_list = [];
|
||||||
var plain_id_list = [];
|
var plain_id_list = [];
|
||||||
$data_table.rows({selected: true}).every(function(){
|
$data_table.rows({selected: true}).every(function(){
|
||||||
|
@ -113,13 +114,13 @@ $(document).ready(function(){
|
||||||
jumpserver.checked = false;
|
jumpserver.checked = false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case 'delete':
|
case 'delete':
|
||||||
doDelete();
|
doDelete();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
Loading…
Reference in New Issue