mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-09-06 18:00:57 +00:00
[Update] 修改asset modal table
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
//jumpserver 自定义js 2015-01-29
|
||||
|
||||
//此函数用于checkbox的全选和反选
|
||||
var checked=false;
|
||||
var checked = false;
|
||||
|
||||
function check_all(form) {
|
||||
var checkboxes = document.getElementById(form);
|
||||
if (checked === false) {
|
||||
@@ -16,26 +17,23 @@ function check_all(form) {
|
||||
}
|
||||
}
|
||||
|
||||
function checkAll(id, name){
|
||||
function checkAll(id, name) {
|
||||
var checklist = document.getElementsByName(name);
|
||||
if(document.getElementById(id).checked)
|
||||
{
|
||||
for(var i=0;i<checklist.length;i++)
|
||||
{
|
||||
checklist[i].checked = 1;
|
||||
if (document.getElementById(id).checked) {
|
||||
for (var i = 0; i < checklist.length; i++) {
|
||||
checklist[i].checked = 1;
|
||||
}
|
||||
}else{
|
||||
for(var j=0;j<checklist.length;j++)
|
||||
{
|
||||
checklist[j].checked = 0;
|
||||
} else {
|
||||
for (var j = 0; j < checklist.length; j++) {
|
||||
checklist[j].checked = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//提取指定行的数据,JSON格式
|
||||
function GetRowData(row){
|
||||
function GetRowData(row) {
|
||||
var rowData = {};
|
||||
for(var j=0;j<row.cells.length; j++) {
|
||||
for (var j = 0; j < row.cells.length; j++) {
|
||||
name = row.parentNode.rows[0].cells[j].getAttribute("Name");
|
||||
if (name) {
|
||||
var value = row.cells[j].getAttribute("Value");
|
||||
@@ -56,16 +54,16 @@ function GetTableDataBox() {
|
||||
var checkboxes = document.getElementById("contents_form");
|
||||
var id_list = [];
|
||||
len = checkboxes.elements.length;
|
||||
for (var i=0; i < len; i++) {
|
||||
for (var i = 0; i < len; i++) {
|
||||
if (checkboxes.elements[i].type == "checkbox" && checkboxes.elements[i].checked === true && checkboxes.elements[i].value != "checkall") {
|
||||
id_list.push(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (i in id_list) {
|
||||
tableData.push(GetRowData(tabProduct.rows[id_list[i]]));
|
||||
}
|
||||
|
||||
if (id_list.length === 0){
|
||||
if (id_list.length === 0) {
|
||||
alert('请至少选择一行!');
|
||||
}
|
||||
returnData.push(tableData);
|
||||
@@ -77,8 +75,8 @@ function move(from, to, from_o, to_o) {
|
||||
$("#" + from + " option").each(function () {
|
||||
if ($(this).prop("selected") === true) {
|
||||
$("#" + to).append(this);
|
||||
if( typeof from_o !== 'undefined'){
|
||||
$("#"+to_o).append($("#"+from_o +" option[value='"+this.value+"']"));
|
||||
if (typeof from_o !== 'undefined') {
|
||||
$("#" + to_o).append($("#" + from_o + " option[value='" + this.value + "']"));
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -88,18 +86,18 @@ function move_left(from, to, from_o, to_o) {
|
||||
$("#" + from + " option").each(function () {
|
||||
if ($(this).prop("selected") === true) {
|
||||
$("#" + to).append(this);
|
||||
if( typeof from_o !== 'undefined'){
|
||||
$("#"+to_o).append($("#"+from_o +" option[value='"+this.value+"']"));
|
||||
if (typeof from_o !== 'undefined') {
|
||||
$("#" + to_o).append($("#" + from_o + " option[value='" + this.value + "']"));
|
||||
}
|
||||
}
|
||||
$(this).attr("selected",'true');
|
||||
$(this).attr("selected", 'true');
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function selectAll(){
|
||||
function selectAll() {
|
||||
// Select all check box
|
||||
$('option').each(function(){
|
||||
$('option').each(function () {
|
||||
$(this).attr('selected', true);
|
||||
});
|
||||
}
|
||||
@@ -131,7 +129,7 @@ function setAjaxCSRFToken() {
|
||||
var sessionid = getCookie('sessionid');
|
||||
|
||||
$.ajaxSetup({
|
||||
beforeSend: function(xhr, settings) {
|
||||
beforeSend: function (xhr, settings) {
|
||||
if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
|
||||
xhr.setRequestHeader("X-CSRFToken", csrftoken);
|
||||
}
|
||||
@@ -143,19 +141,16 @@ function activeNav() {
|
||||
var url_array = document.location.pathname.split("/");
|
||||
var app = url_array[1];
|
||||
var resource = url_array[2];
|
||||
if (app === ''){
|
||||
if (app === '') {
|
||||
$('#index').addClass('active');
|
||||
}
|
||||
else if (app === 'xpack' && resource === 'cloud') {
|
||||
} else if (app === 'xpack' && resource === 'cloud') {
|
||||
var item = url_array[3];
|
||||
$("#" + app).addClass('active');
|
||||
$('#' + app + ' #' + resource).addClass('active');
|
||||
$('#' + app + ' #' + resource + ' #' + item + ' a').css('color', '#ffffff');
|
||||
}
|
||||
else if (app === 'settings'){
|
||||
} else if (app === 'settings') {
|
||||
$("#" + app).addClass('active');
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$("#" + app).addClass('active');
|
||||
$('#' + app + ' #' + resource).addClass('active');
|
||||
}
|
||||
@@ -186,14 +181,14 @@ function formSubmit(props) {
|
||||
}).done(function (data, textState, jqXHR) {
|
||||
if (redirect_to) {
|
||||
if (props.message) {
|
||||
var messages="ed65330a45559c87345a0eb6ac7812d18d0d8976$[[\"__json_message\"\0540\05425\054\"asdfasdf \\u521b\\u5efa\\u6210\\u529f\"]]"
|
||||
var messages = "ed65330a45559c87345a0eb6ac7812d18d0d8976$[[\"__json_message\"\0540\05425\054\"asdfasdf \\u521b\\u5efa\\u6210\\u529f\"]]"
|
||||
setCookie("messages", messages)
|
||||
}
|
||||
location.href = redirect_to;
|
||||
} else if (typeof props.success === 'function') {
|
||||
return props.success(data, textState, jqXHR);
|
||||
}
|
||||
}).fail(function(jqXHR, textStatus, errorThrown) {
|
||||
}).fail(function (jqXHR, textStatus, errorThrown) {
|
||||
if (typeof props.error === 'function') {
|
||||
return props.error(jqXHR, textStatus, errorThrown)
|
||||
}
|
||||
@@ -233,7 +228,7 @@ function formSubmit(props) {
|
||||
}
|
||||
if (fieldRef.length === 1 && formGroupRef.length === 1) {
|
||||
formGroupRef.addClass('has-error');
|
||||
var help_msg = v.join("<br/>") ;
|
||||
var help_msg = v.join("<br/>");
|
||||
helpBlockRef.html(help_msg);
|
||||
} else {
|
||||
$.each(v, function (kk, vv) {
|
||||
@@ -241,7 +236,7 @@ function formSubmit(props) {
|
||||
$.each(vv, function (kkk, vvv) {
|
||||
noneFieldErrorMsg += " " + vvv + '<br/>';
|
||||
})
|
||||
} else{
|
||||
} else {
|
||||
noneFieldErrorMsg += vv + '<br/>';
|
||||
}
|
||||
})
|
||||
@@ -264,7 +259,7 @@ function requestApi(props) {
|
||||
var user_fail_message = props.fail_message;
|
||||
var default_failed_message = gettext('An unknown error occurred while updating..');
|
||||
var flash_message = props.flash_message || true;
|
||||
if (props.flash_message === false){
|
||||
if (props.flash_message === false) {
|
||||
flash_message = false;
|
||||
}
|
||||
|
||||
@@ -274,7 +269,7 @@ function requestApi(props) {
|
||||
data: props.body,
|
||||
contentType: props.content_type || "application/json; charset=utf-8",
|
||||
dataType: props.data_type || "json"
|
||||
}).done(function(data, textStatue, jqXHR) {
|
||||
}).done(function (data, textStatue, jqXHR) {
|
||||
if (flash_message) {
|
||||
var msg = "";
|
||||
if (user_success_message) {
|
||||
@@ -287,7 +282,7 @@ function requestApi(props) {
|
||||
if (typeof props.success === 'function') {
|
||||
return props.success(data);
|
||||
}
|
||||
}).fail(function(jqXHR, textStatus, errorThrown) {
|
||||
}).fail(function (jqXHR, textStatus, errorThrown) {
|
||||
if (flash_message) {
|
||||
var msg = "";
|
||||
if (user_fail_message) {
|
||||
@@ -308,24 +303,24 @@ function requestApi(props) {
|
||||
return props.error(jqXHR.responseText, jqXHR.status);
|
||||
}
|
||||
});
|
||||
// return true;
|
||||
// return true;
|
||||
}
|
||||
|
||||
// Sweet Alert for Delete
|
||||
function objectDelete(obj, name, url, redirectTo) {
|
||||
function doDelete() {
|
||||
var body = {};
|
||||
var success = function() {
|
||||
var success = function () {
|
||||
// swal('Deleted!', "[ "+name+"]"+" has been deleted ", "success");
|
||||
if (!redirectTo) {
|
||||
$(obj).parent().parent().remove();
|
||||
} else {
|
||||
window.location.href=redirectTo;
|
||||
window.location.href = redirectTo;
|
||||
}
|
||||
};
|
||||
var fail = function() {
|
||||
var fail = function () {
|
||||
// swal("错误", "删除"+"[ "+name+" ]"+"遇到错误", "error");
|
||||
swal(gettext('Error'), "[ "+name+" ]" + gettext("Being used by the asset, please unbind the asset first."), "error");
|
||||
swal(gettext('Error'), "[ " + name + " ]" + gettext("Being used by the asset, please unbind the asset first."), "error");
|
||||
};
|
||||
requestApi({
|
||||
url: url,
|
||||
@@ -336,6 +331,7 @@ function objectDelete(obj, name, url, redirectTo) {
|
||||
error: fail
|
||||
});
|
||||
}
|
||||
|
||||
swal({
|
||||
title: gettext('Are you sure about deleting it?'),
|
||||
text: " [" + name + "] ",
|
||||
@@ -350,22 +346,21 @@ function objectDelete(obj, name, url, redirectTo) {
|
||||
});
|
||||
}
|
||||
|
||||
function orgDelete(obj, name, url, redirectTo){
|
||||
function orgDelete(obj, name, url, redirectTo) {
|
||||
function doDelete() {
|
||||
var body = {};
|
||||
var success = function() {
|
||||
var success = function () {
|
||||
if (!redirectTo) {
|
||||
$(obj).parent().parent().remove();
|
||||
} else {
|
||||
window.location.href=redirectTo;
|
||||
window.location.href = redirectTo;
|
||||
}
|
||||
};
|
||||
var fail = function(responseText, status) {
|
||||
if (status === 400){
|
||||
swal(gettext("Error"), "[ " + name + " ] " + gettext("The organization contains undeleted information. Please try again after deleting"), "error");
|
||||
}
|
||||
else if (status === 405){
|
||||
swal(gettext("Error"), " [ "+ name + " ] " + gettext("Do not perform this operation under this organization. Try again after switching to another organization"), "error");
|
||||
var fail = function (responseText, status) {
|
||||
if (status === 400) {
|
||||
swal(gettext("Error"), "[ " + name + " ] " + gettext("The organization contains undeleted information. Please try again after deleting"), "error");
|
||||
} else if (status === 405) {
|
||||
swal(gettext("Error"), " [ " + name + " ] " + gettext("Do not perform this operation under this organization. Try again after switching to another organization"), "error");
|
||||
}
|
||||
};
|
||||
requestApi({
|
||||
@@ -377,6 +372,7 @@ function orgDelete(obj, name, url, redirectTo){
|
||||
error: fail
|
||||
});
|
||||
}
|
||||
|
||||
swal({
|
||||
title: gettext("Please ensure that the following information in the organization has been deleted"),
|
||||
text: gettext("User list、User group、Asset list、Domain list、Admin user、System user、Labels、Asset permission"),
|
||||
@@ -391,11 +387,10 @@ function orgDelete(obj, name, url, redirectTo){
|
||||
});
|
||||
}
|
||||
|
||||
$.fn.serializeObject = function()
|
||||
{
|
||||
$.fn.serializeObject = function () {
|
||||
var o = {};
|
||||
var a = this.serializeArray();
|
||||
$.each(a, function() {
|
||||
$.each(a, function () {
|
||||
if (o[this.name] !== undefined) {
|
||||
if (!o[this.name].push) {
|
||||
o[this.name] = [o[this.name]];
|
||||
@@ -413,7 +408,6 @@ function makeLabel(data) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
var jumpserver = {};
|
||||
jumpserver.checked = false;
|
||||
jumpserver.selected = {};
|
||||
@@ -422,7 +416,7 @@ jumpserver.language = {
|
||||
search: gettext('Search'),
|
||||
select: {
|
||||
rows: {
|
||||
_: gettext("Selected item %d"),
|
||||
_: gettext("Selected item %d"),
|
||||
0: ""
|
||||
}
|
||||
},
|
||||
@@ -440,36 +434,40 @@ jumpserver.language = {
|
||||
}
|
||||
};
|
||||
jumpserver.initDataTable = function (options) {
|
||||
// options = {
|
||||
// ele *: $('#dataTable_id'),
|
||||
// ajax_url *: '{% url 'users:user-list-api' %}',
|
||||
// columns *: [{data: ''}, ....],
|
||||
// dom: 'fltip',
|
||||
// i18n_url: '{% static "js/...../en-us.json" %}',
|
||||
// order: [[1, 'asc'], [2, 'asc'], ...],
|
||||
// buttons: ['excel', 'pdf', 'print'],
|
||||
// columnDefs: [{target: 0, createdCell: ()=>{}}, ...],
|
||||
// uc_html: '<a>header button</a>',
|
||||
// op_html: 'div.btn-group?',
|
||||
// paging: true
|
||||
// }
|
||||
var ele = options.ele || $('.dataTable');
|
||||
var columnDefs = [
|
||||
{
|
||||
targets: 0,
|
||||
orderable: false,
|
||||
createdCell: function (td, cellData) {
|
||||
$(td).html('<input type="checkbox" class="text-center ipt_check" id=99991937>'.replace('99991937', cellData));
|
||||
}
|
||||
},
|
||||
{className: 'text-center', render: $.fn.dataTable.render.text(), targets: '_all'}
|
||||
];
|
||||
columnDefs = options.columnDefs ? options.columnDefs.concat(columnDefs) : columnDefs;
|
||||
var select = {
|
||||
style: 'multi',
|
||||
selector: 'td:first-child'
|
||||
};
|
||||
var table = ele.DataTable({
|
||||
// options = {
|
||||
// ele *: $('#dataTable_id'),
|
||||
// ajax_url *: '{% url 'users:user-list-api' %}',
|
||||
// columns *: [{data: ''}, ....],
|
||||
// dom: 'fltip',
|
||||
// i18n_url: '{% static "js/...../en-us.json" %}',
|
||||
// order: [[1, 'asc'], [2, 'asc'], ...],
|
||||
// buttons: ['excel', 'pdf', 'print'],
|
||||
// columnDefs: [{target: 0, createdCell: ()=>{}}, ...],
|
||||
// uc_html: '<a>header button</a>',
|
||||
// op_html: 'div.btn-group?',
|
||||
// paging: true
|
||||
// }
|
||||
var ele = options.ele || $('.dataTable');
|
||||
var columnDefs = [
|
||||
{
|
||||
targets: 0,
|
||||
orderable: false,
|
||||
createdCell: function (td, cellData) {
|
||||
$(td).html('<input type="checkbox" class="text-center ipt_check" id=99991937>'.replace('99991937', cellData));
|
||||
}
|
||||
},
|
||||
{
|
||||
className: 'text-center',
|
||||
render: $.fn.dataTable.render.text(),
|
||||
targets: '_all'
|
||||
}
|
||||
];
|
||||
columnDefs = options.columnDefs ? options.columnDefs.concat(columnDefs) : columnDefs;
|
||||
var select = {
|
||||
style: 'multi',
|
||||
selector: 'td:first-child'
|
||||
};
|
||||
var table = ele.DataTable({
|
||||
pageLength: options.pageLength || 15,
|
||||
dom: options.dom || '<"#uc.pull-left"><"pull-right"<"inline"l><"#fb.inline"><"inline"f><"#fa.inline">>tr<"row m-t"<"col-md-8"<"#op.col-md-6"><"col-md-6 text-center"i>><"col-md-4"p>>',
|
||||
order: options.order || [],
|
||||
@@ -486,15 +484,15 @@ jumpserver.initDataTable = function (options) {
|
||||
language: jumpserver.language,
|
||||
lengthMenu: [[10, 15, 25, 50, -1], [10, 15, 25, 50, "All"]]
|
||||
});
|
||||
table.on('select', function(e, dt, type, indexes) {
|
||||
var $node = table[ type ]( indexes ).nodes().to$();
|
||||
table.on('select', function (e, dt, type, indexes) {
|
||||
var $node = table[type](indexes).nodes().to$();
|
||||
$node.find('input.ipt_check').prop('checked', true);
|
||||
jumpserver.selected[$node.find('input.ipt_check').prop('id')] = true
|
||||
}).on('deselect', function(e, dt, type, indexes) {
|
||||
var $node = table[ type ]( indexes ).nodes().to$();
|
||||
}).on('deselect', function (e, dt, type, indexes) {
|
||||
var $node = table[type](indexes).nodes().to$();
|
||||
$node.find('input.ipt_check').prop('checked', false);
|
||||
jumpserver.selected[$node.find('input.ipt_check').prop('id')] = false
|
||||
}).on('draw', function(){
|
||||
}).on('draw', function () {
|
||||
$('#op').html(options.op_html || '');
|
||||
$('#uc').html(options.uc_html || '');
|
||||
$('[data-toggle="popover"]').popover({
|
||||
@@ -506,16 +504,16 @@ jumpserver.initDataTable = function (options) {
|
||||
$('[data-toggle="popover"]').not(this).popover('hide');
|
||||
});
|
||||
});
|
||||
$('.ipt_check_all').on('click', function() {
|
||||
if ($(this).prop("checked")) {
|
||||
$(this).closest('table').find('.ipt_check').prop('checked', true);
|
||||
jumpserver.checked = true;
|
||||
table.rows({search:'applied', page:'current'}).select();
|
||||
} else {
|
||||
$(this).closest('table').find('.ipt_check').prop('checked', false);
|
||||
jumpserver.checked = false;
|
||||
table.rows({search:'applied', page:'current'}).deselect();
|
||||
}
|
||||
$('.ipt_check_all').on('click', function () {
|
||||
if ($(this).prop("checked")) {
|
||||
$(this).closest('table').find('.ipt_check').prop('checked', true);
|
||||
jumpserver.checked = true;
|
||||
table.rows({search: 'applied', page: 'current'}).select();
|
||||
} else {
|
||||
$(this).closest('table').find('.ipt_check').prop('checked', false);
|
||||
jumpserver.checked = false;
|
||||
table.rows({search: 'applied', page: 'current'}).deselect();
|
||||
}
|
||||
});
|
||||
|
||||
return table;
|
||||
@@ -532,40 +530,42 @@ jumpserver.initStaticTable = function (selector) {
|
||||
};
|
||||
|
||||
jumpserver.initServerSideDataTable = function (options) {
|
||||
// options = {
|
||||
// ele *: $('#dataTable_id'),
|
||||
// ajax_url *: '{% url 'users:user-list-api' %}',
|
||||
// columns *: [{data: ''}, ....],
|
||||
// dom: 'fltip',
|
||||
// i18n_url: '{% static "js/...../en-us.json" %}',
|
||||
// order: [[1, 'asc'], [2, 'asc'], ...],
|
||||
// buttons: ['excel', 'pdf', 'print'],
|
||||
// columnDefs: [{target: 0, createdCell: ()=>{}}, ...],
|
||||
// uc_html: '<a>header button</a>',
|
||||
// op_html: 'div.btn-group?',
|
||||
// paging: true
|
||||
// }
|
||||
var ele = options.ele || $('.dataTable');
|
||||
var columnDefs = [
|
||||
{
|
||||
targets: 0,
|
||||
orderable: false,
|
||||
createdCell: function (td, cellData) {
|
||||
$(td).html('<input type="checkbox" class="text-center ipt_check" id=99991937>'.replace('99991937', cellData));
|
||||
}
|
||||
},
|
||||
{
|
||||
targets: '_all',
|
||||
className: 'text-center',
|
||||
render: $.fn.dataTable.render.text()
|
||||
}
|
||||
];
|
||||
columnDefs = options.columnDefs ? options.columnDefs.concat(columnDefs) : columnDefs;
|
||||
var select = {
|
||||
style: 'multi',
|
||||
selector: 'td:first-child'
|
||||
};
|
||||
var table = ele.DataTable({
|
||||
// options = {
|
||||
// ele *: $('#dataTable_id'),
|
||||
// ajax_url *: '{% url 'users:user-list-api' %}',
|
||||
// select_style: 'multi',
|
||||
// columns *: [{data: ''}, ....],
|
||||
// dom: 'fltip',
|
||||
// i18n_url: '{% static "js/...../en-us.json" %}',
|
||||
// order: [[1, 'asc'], [2, 'asc'], ...],
|
||||
// buttons: ['excel', 'pdf', 'print'],
|
||||
// columnDefs: [{target: 0, createdCell: ()=>{}}, ...],
|
||||
// uc_html: '<a>header button</a>',
|
||||
// op_html: 'div.btn-group?',
|
||||
// paging: true
|
||||
// }
|
||||
var ele = options.ele || $('.dataTable');
|
||||
var columnDefs = [
|
||||
{
|
||||
targets: 0,
|
||||
orderable: false,
|
||||
createdCell: function (td, cellData) {
|
||||
$(td).html('<input type="checkbox" class="text-center ipt_check" id=99991937>'.replace('99991937', cellData));
|
||||
}
|
||||
},
|
||||
{
|
||||
targets: '_all',
|
||||
className: 'text-center',
|
||||
render: $.fn.dataTable.render.text()
|
||||
}
|
||||
];
|
||||
var select_style = options.select_style || 'multi';
|
||||
columnDefs = options.columnDefs ? options.columnDefs.concat(columnDefs) : columnDefs;
|
||||
var select = {
|
||||
style: select_style,
|
||||
selector: 'td:first-child'
|
||||
};
|
||||
var table = ele.DataTable({
|
||||
pageLength: options.pageLength || 15,
|
||||
// dom: options.dom || '<"#uc.pull-left">fltr<"row m-t"<"col-md-8"<"#op.col-md-6"><"col-md-6 text-center"i>><"col-md-4"p>>',
|
||||
dom: options.dom || '<"#uc.pull-left"><"pull-right"<"inline"l><"#fb.inline"><"inline"f><"#fa.inline">>tr<"row m-t"<"col-md-8"<"#op.col-md-6"><"col-md-6 text-center"i>><"col-md-4"p>>',
|
||||
@@ -576,8 +576,8 @@ jumpserver.initServerSideDataTable = function (options) {
|
||||
processing: true,
|
||||
searchDelay: 800,
|
||||
ajax: {
|
||||
url: options.ajax_url ,
|
||||
error: function(jqXHR, textStatus, errorThrown) {
|
||||
url: options.ajax_url,
|
||||
error: function (jqXHR, textStatus, errorThrown) {
|
||||
var msg = gettext("Unknown error occur");
|
||||
if (jqXHR.responseJSON) {
|
||||
if (jqXHR.responseJSON.error) {
|
||||
@@ -590,7 +590,7 @@ jumpserver.initServerSideDataTable = function (options) {
|
||||
},
|
||||
data: function (data) {
|
||||
delete data.columns;
|
||||
if (data.length !== null){
|
||||
if (data.length !== null) {
|
||||
data.limit = data.length;
|
||||
delete data.length;
|
||||
}
|
||||
@@ -605,15 +605,15 @@ jumpserver.initServerSideDataTable = function (options) {
|
||||
var search_raw = [];
|
||||
|
||||
search_list.map(function (val, index) {
|
||||
var kv = val.split(":");
|
||||
if (kv.length === 2) {
|
||||
var value = kv[1];
|
||||
var key = kv[0].trim();
|
||||
value = value.replace("+", " ").trim();
|
||||
search_attr[key] = value
|
||||
} else {
|
||||
search_raw.push(kv)
|
||||
}
|
||||
var kv = val.split(":");
|
||||
if (kv.length === 2) {
|
||||
var value = kv[1];
|
||||
var key = kv[0].trim();
|
||||
value = value.replace("+", " ").trim();
|
||||
search_attr[key] = value
|
||||
} else {
|
||||
search_raw.push(kv)
|
||||
}
|
||||
});
|
||||
data.search = search_raw.join("");
|
||||
$.each(search_attr, function (k, v) {
|
||||
@@ -629,8 +629,8 @@ jumpserver.initServerSideDataTable = function (options) {
|
||||
data.order = order;
|
||||
}
|
||||
},
|
||||
dataFilter: function(data){
|
||||
var json = jQuery.parseJSON( data );
|
||||
dataFilter: function (data) {
|
||||
var json = jQuery.parseJSON(data);
|
||||
json.recordsTotal = json.count;
|
||||
json.recordsFiltered = json.count;
|
||||
return JSON.stringify(json); // return JSON string
|
||||
@@ -644,35 +644,36 @@ jumpserver.initServerSideDataTable = function (options) {
|
||||
});
|
||||
table.selected = [];
|
||||
table.selected_rows = [];
|
||||
table.on('select', function(e, dt, type, indexes) {
|
||||
var $node = table[ type ]( indexes ).nodes().to$();
|
||||
table.on('select', function (e, dt, type, indexes) {
|
||||
var $node = table[type](indexes).nodes().to$();
|
||||
$node.find('input.ipt_check').prop('checked', true);
|
||||
jumpserver.selected[$node.find('input.ipt_check').prop('id')] = true;
|
||||
if (type === 'row') {
|
||||
var rows = table.rows(indexes).data();
|
||||
$.each(rows, function (id, row) {
|
||||
table.selected_rows.push(row);
|
||||
if (row.id && $.inArray(row.id, table.selected) === -1){
|
||||
table.selected.push(row.id)
|
||||
if (row.id && $.inArray(row.id, table.selected) === -1) {
|
||||
table.selected.push(row.id);
|
||||
table.selected_rows.push(row);
|
||||
}
|
||||
})
|
||||
}
|
||||
}).on('deselect', function(e, dt, type, indexes) {
|
||||
var $node = table[ type ]( indexes ).nodes().to$();
|
||||
}).on('deselect', function (e, dt, type, indexes) {
|
||||
var $node = table[type](indexes).nodes().to$();
|
||||
$node.find('input.ipt_check').prop('checked', false);
|
||||
jumpserver.selected[$node.find('input.ipt_check').prop('id')] = false;
|
||||
if (type === 'row') {
|
||||
var rows = table.rows(indexes).data();
|
||||
$.each(rows, function (id, row) {
|
||||
if (row.id){
|
||||
if (row.id) {
|
||||
var index = table.selected.indexOf(row.id);
|
||||
if (index > -1){
|
||||
table.selected.splice(index, 1)
|
||||
if (index > -1) {
|
||||
table.selected.splice(index, 1);
|
||||
table.selected_rows.splice(index, 1);
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}).on('draw', function(){
|
||||
}).on('draw', function () {
|
||||
$('[data-toggle="popover"]').popover({
|
||||
html: true,
|
||||
placement: 'bottom',
|
||||
@@ -690,7 +691,7 @@ jumpserver.initServerSideDataTable = function (options) {
|
||||
|
||||
$.each(table.selected, function (id, data) {
|
||||
var index = table_data.indexOf(data);
|
||||
if (index > -1){
|
||||
if (index > -1) {
|
||||
table.rows(index).select()
|
||||
}
|
||||
});
|
||||
@@ -701,13 +702,16 @@ jumpserver.initServerSideDataTable = function (options) {
|
||||
$('#fa').html(options.fa_html || '');
|
||||
});
|
||||
var table_id = table.settings()[0].sTableId;
|
||||
$('#' + table_id + ' .ipt_check_all').on('click', function() {
|
||||
$('#' + table_id + ' .ipt_check_all').on('click', function () {
|
||||
if (select_style !== 'multi') {
|
||||
return
|
||||
}
|
||||
if ($(this).prop("checked")) {
|
||||
$(this).closest('table').find('.ipt_check').prop('checked', true);
|
||||
table.rows({search:'applied', page:'current'}).select();
|
||||
table.rows({search: 'applied', page: 'current'}).select();
|
||||
} else {
|
||||
$(this).closest('table').find('.ipt_check').prop('checked', false);
|
||||
table.rows({search:'applied', page:'current'}).deselect();
|
||||
table.rows({search: 'applied', page: 'current'}).deselect();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -728,7 +732,7 @@ String.prototype.replaceAll = function (exp, newStr) {
|
||||
* 原型:字符串格式化
|
||||
* @param args 格式化参数值
|
||||
*/
|
||||
String.prototype.format = function(args) {
|
||||
String.prototype.format = function (args) {
|
||||
var result = this;
|
||||
if (arguments.length < 1) {
|
||||
return result;
|
||||
@@ -738,7 +742,7 @@ String.prototype.format = function(args) {
|
||||
if (arguments.length == 1 && typeof (args) == "object") {
|
||||
data = args;
|
||||
}
|
||||
for ( var key in data) {
|
||||
for (var key in data) {
|
||||
var value = data[key];
|
||||
if (undefined != value) {
|
||||
result = result.replaceAll("\\{" + key + "\\}", value);
|
||||
@@ -750,7 +754,7 @@ String.prototype.format = function(args) {
|
||||
function setCookie(key, value, time) {
|
||||
var expires = new Date();
|
||||
if (!time) {
|
||||
time = expires.getTime() + (24 * 60 * 60 * 1000);
|
||||
time = expires.getTime() + (24 * 60 * 60 * 1000);
|
||||
}
|
||||
expires.setTime(time);
|
||||
document.cookie = key + '=' + value + ';expires=' + expires.toUTCString() + ';path=/';
|
||||
@@ -767,7 +771,7 @@ function delCookie(key) {
|
||||
}
|
||||
|
||||
function createPopover(dataset, title, callback) {
|
||||
if (callback !== undefined){
|
||||
if (callback !== undefined) {
|
||||
var new_dataset = [];
|
||||
$.each(dataset, function (index, value) {
|
||||
new_dataset.push(callback(value))
|
||||
@@ -780,12 +784,13 @@ function createPopover(dataset, title, callback) {
|
||||
}
|
||||
|
||||
|
||||
$(function () {
|
||||
$(function () {
|
||||
(function ($) {
|
||||
$.getUrlParam = function (name) {
|
||||
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
|
||||
var r = window.location.search.substr(1).match(reg);
|
||||
if (r != null) return unescape(r[2]); return null;
|
||||
if (r != null) return unescape(r[2]);
|
||||
return null;
|
||||
}
|
||||
})(jQuery);
|
||||
});
|
||||
@@ -793,12 +798,13 @@ function createPopover(dataset, title, callback) {
|
||||
function getUrlParam(name) {
|
||||
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
|
||||
var r = window.location.search.substr(1).match(reg);
|
||||
if (r != null) return unescape(r[2]); return null;
|
||||
if (r != null) return unescape(r[2]);
|
||||
return null;
|
||||
}
|
||||
|
||||
function setUrlParam(url, name, value) {
|
||||
var urlArray = url.split("?");
|
||||
if (urlArray.length===1){
|
||||
if (urlArray.length === 1) {
|
||||
url += "?" + name + "=" + value;
|
||||
} else {
|
||||
var oriParam = urlArray[1].split("&");
|
||||
@@ -835,12 +841,11 @@ var rules_id_map_label = {
|
||||
'id_security_password_special_char': gettext('Must contain special characters')
|
||||
};
|
||||
|
||||
function getRuleLabel(rule){
|
||||
function getRuleLabel(rule) {
|
||||
var label = '';
|
||||
if (rule.key === rules_short_map_id['min']){
|
||||
if (rule.key === rules_short_map_id['min']) {
|
||||
label = rules_id_map_label[rule.key].replace('{N}', rule.value)
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
label = rules_id_map_label[rule.key]
|
||||
}
|
||||
return label
|
||||
@@ -849,38 +854,33 @@ function getRuleLabel(rule){
|
||||
// 校验密码-改变规则颜色
|
||||
function checkPasswordRules(password, minLength) {
|
||||
if (wordMinLength(password, minLength)) {
|
||||
$('#'+rules_short_map_id['min']).css('color', 'green')
|
||||
}
|
||||
else {
|
||||
$('#'+rules_short_map_id['min']).css('color', '#908a8a')
|
||||
$('#' + rules_short_map_id['min']).css('color', 'green')
|
||||
} else {
|
||||
$('#' + rules_short_map_id['min']).css('color', '#908a8a')
|
||||
}
|
||||
|
||||
if (wordUpperCase(password)) {
|
||||
$('#'+rules_short_map_id['upper']).css('color', 'green')
|
||||
}
|
||||
else {
|
||||
$('#'+rules_short_map_id['upper']).css('color', '#908a8a')
|
||||
$('#' + rules_short_map_id['upper']).css('color', 'green')
|
||||
} else {
|
||||
$('#' + rules_short_map_id['upper']).css('color', '#908a8a')
|
||||
}
|
||||
|
||||
if (wordLowerCase(password)) {
|
||||
$('#'+rules_short_map_id['lower']).css('color', 'green')
|
||||
}
|
||||
else {
|
||||
$('#'+rules_short_map_id['lower']).css('color', '#908a8a')
|
||||
$('#' + rules_short_map_id['lower']).css('color', 'green')
|
||||
} else {
|
||||
$('#' + rules_short_map_id['lower']).css('color', '#908a8a')
|
||||
}
|
||||
|
||||
if (wordNumber(password)) {
|
||||
$('#'+rules_short_map_id['number']).css('color', 'green')
|
||||
}
|
||||
else {
|
||||
$('#'+rules_short_map_id['number']).css('color', '#908a8a')
|
||||
$('#' + rules_short_map_id['number']).css('color', 'green')
|
||||
} else {
|
||||
$('#' + rules_short_map_id['number']).css('color', '#908a8a')
|
||||
}
|
||||
|
||||
if (wordSpecialChar(password)) {
|
||||
$('#'+rules_short_map_id['special']).css('color', 'green')
|
||||
}
|
||||
else {
|
||||
$('#'+rules_short_map_id['special']).css('color', '#908a8a')
|
||||
$('#' + rules_short_map_id['special']).css('color', 'green')
|
||||
} else {
|
||||
$('#' + rules_short_map_id['special']).css('color', '#908a8a')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -890,18 +890,22 @@ function wordMinLength(word, minLength) {
|
||||
var re = new RegExp("^(.{" + minLength + ",})$");
|
||||
return word.match(re)
|
||||
}
|
||||
|
||||
// 大写字母
|
||||
function wordUpperCase(word) {
|
||||
return word.match(/([A-Z]+)/)
|
||||
}
|
||||
|
||||
// 小写字母
|
||||
function wordLowerCase(word) {
|
||||
return word.match(/([a-z]+)/)
|
||||
}
|
||||
|
||||
// 数字字符
|
||||
function wordNumber(word) {
|
||||
return word.match(/([\d]+)/)
|
||||
}
|
||||
|
||||
// 特殊字符
|
||||
function wordSpecialChar(word) {
|
||||
return word.match(/[`,~,!,@,#,\$,%,\^,&,\*,\(,\),\-,_,=,\+,\{,\},\[,\],\|,\\,;,',:,",\,,\.,<,>,\/,\?]+/)
|
||||
@@ -919,7 +923,7 @@ function popoverPasswordRules(password_check_rules, $el) {
|
||||
}
|
||||
|
||||
// 初始化弹窗popover
|
||||
function initPopover($container, $progress, $idPassword, $el, password_check_rules, i18n_fallback){
|
||||
function initPopover($container, $progress, $idPassword, $el, password_check_rules, i18n_fallback) {
|
||||
options = {};
|
||||
// User Interface
|
||||
options.ui = {
|
||||
@@ -943,37 +947,6 @@ function initPopover($container, $progress, $idPassword, $el, password_check_rul
|
||||
popoverPasswordRules(password_check_rules, $el);
|
||||
}
|
||||
|
||||
// 解决input框中的资产和弹出表格中资产的显示不一致
|
||||
function initSelectedAssets2Table(id){
|
||||
if (!id) {
|
||||
id = "#id_assets"
|
||||
}
|
||||
var inputAssets = $(id).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');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function rootNodeAddDom(ztree, callback) {
|
||||
@@ -1001,7 +974,7 @@ function APIExportData(props) {
|
||||
var params = props.params || {};
|
||||
params['format'] = props.format;
|
||||
params['spm'] = data.spm;
|
||||
for (var k in params){
|
||||
for (var k in params) {
|
||||
export_url = setUrlParam(export_url, k, params[k])
|
||||
}
|
||||
window.open(export_url);
|
||||
@@ -1012,7 +985,7 @@ function APIExportData(props) {
|
||||
})
|
||||
}
|
||||
|
||||
function APIImportData(props){
|
||||
function APIImportData(props) {
|
||||
props = props || {};
|
||||
$.ajax({
|
||||
url: props.url,
|
||||
@@ -1021,12 +994,12 @@ function APIImportData(props){
|
||||
data: props.body,
|
||||
contentType: props.content_type || 'text/csv',
|
||||
success: function (data) {
|
||||
if(props.method === 'POST'){
|
||||
if (props.method === 'POST') {
|
||||
$('#created_failed').html('');
|
||||
$('#created_failed_detail').html('');
|
||||
$('#success_created').html(gettext("Import Success"));
|
||||
$('#success_created_detail').html("Count" + ": " + data.length);
|
||||
}else{
|
||||
} else {
|
||||
$('#updated_failed').html('');
|
||||
$('#updated_failed_detail').html('');
|
||||
$('#success_updated').html(gettext("Update Success"));
|
||||
@@ -1037,11 +1010,11 @@ function APIImportData(props){
|
||||
},
|
||||
error: function (error) {
|
||||
var data = error.responseJSON;
|
||||
if (data instanceof Array){
|
||||
if (data instanceof Array) {
|
||||
var html = '';
|
||||
var li = '';
|
||||
var err = '';
|
||||
$.each(data, function (index, item){
|
||||
$.each(data, function (index, item) {
|
||||
err = '';
|
||||
for (var prop in item) {
|
||||
err += prop + ": " + item[prop][0] + " "
|
||||
@@ -1052,16 +1025,15 @@ function APIImportData(props){
|
||||
}
|
||||
});
|
||||
html = "<ul>" + html + "</ul>"
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
html = error.responseText
|
||||
}
|
||||
if(props.method === 'POST'){
|
||||
if (props.method === 'POST') {
|
||||
$('#success_created').html('');
|
||||
$('#success_created_detail').html('');
|
||||
$('#created_failed').html(gettext("Import failed"));
|
||||
$('#created_failed_detail').html(html);
|
||||
}else{
|
||||
} else {
|
||||
$('#success_updated').html('');
|
||||
$('#success_updated_detail').html('');
|
||||
$('#updated_failed').html(gettext("Update failed"));
|
||||
@@ -1072,7 +1044,7 @@ function APIImportData(props){
|
||||
}
|
||||
|
||||
|
||||
function htmlEscape ( d ) {
|
||||
function htmlEscape(d) {
|
||||
return typeof d === 'string' ?
|
||||
d.replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"') :
|
||||
d;
|
||||
@@ -1080,10 +1052,9 @@ function htmlEscape ( d ) {
|
||||
|
||||
function objectAttrsIsList(obj, attrs) {
|
||||
attrs.forEach(function (attr) {
|
||||
if (!obj[attr]){
|
||||
if (!obj[attr]) {
|
||||
obj[attr] = []
|
||||
}
|
||||
else if (obj[attr] && !(obj[attr] instanceof Array)){
|
||||
} else if (obj[attr] && !(obj[attr] instanceof Array)) {
|
||||
obj[attr] = [obj[attr]]
|
||||
}
|
||||
})
|
||||
@@ -1106,8 +1077,8 @@ function objectAttrsIsBool(obj, attrs) {
|
||||
}
|
||||
|
||||
function cleanDateStr(d) {
|
||||
for (var i=0;i<3;i++) {
|
||||
if (!isNaN(Date.parse(d))){
|
||||
for (var i = 0; i < 3; i++) {
|
||||
if (!isNaN(Date.parse(d))) {
|
||||
return d;
|
||||
}
|
||||
if (!isNaN(Number(d))) {
|
||||
@@ -1144,7 +1115,7 @@ function toSafeLocalDateStr(d) {
|
||||
function getUrlParams(url) {
|
||||
url = url.split("?");
|
||||
var params = "";
|
||||
if (url.length === 2){
|
||||
if (url.length === 2) {
|
||||
params = url[1];
|
||||
}
|
||||
return params
|
||||
@@ -1166,7 +1137,7 @@ function getTimeUnits(u) {
|
||||
function timeOffset(a, b) {
|
||||
var start = safeDate(a);
|
||||
var end = safeDate(b);
|
||||
var offset = (end - start)/1000;
|
||||
var offset = (end - start) / 1000;
|
||||
|
||||
var days = offset / 3600 / 24;
|
||||
var hours = offset / 3600;
|
||||
@@ -1191,7 +1162,7 @@ function readFile(ref) {
|
||||
if (hasFile) {
|
||||
var reader = new FileReader();//新建一个FileReader
|
||||
reader.readAsText(files[0], "UTF-8");//读取文件
|
||||
reader.onload = function(evt){ //读取完文件之后会回来这里
|
||||
reader.onload = function (evt) { //读取完文件之后会回来这里
|
||||
ref.trigger("onload", evt.target.result);
|
||||
};
|
||||
} else {
|
||||
@@ -1209,9 +1180,9 @@ function nodesSelect2Init(selector, url) {
|
||||
data: function (params) {
|
||||
var page = params.page || 1;
|
||||
var query = {
|
||||
search: params.term,
|
||||
offset: (page -1) * 10,
|
||||
limit: 10
|
||||
search: params.term,
|
||||
offset: (page - 1) * 10,
|
||||
limit: 10
|
||||
};
|
||||
return query
|
||||
},
|
||||
@@ -1220,7 +1191,7 @@ function nodesSelect2Init(selector, url) {
|
||||
return {id: v.id, text: v.full_value}
|
||||
});
|
||||
var more = !!data.next;
|
||||
return {results: results, pagination: {"more": more }}
|
||||
return {results: results, pagination: {"more": more}}
|
||||
}
|
||||
},
|
||||
})
|
||||
|
Reference in New Issue
Block a user