//jumpserver 自定义js 2015-01-29 //此函数用于checkbox的全选和反选 var checked=false; function check_all(form) { var checkboxes = document.getElementById(form); if (checked === false) { checked = true; } else { checked = false; } for (var i = 0; i < checkboxes.elements.length; i++) { if (checkboxes.elements[i].type == "checkbox") { checkboxes.elements[i].checked = checked; } } } function checkAll(id, name){ var checklist = document.getElementsByName(name); if(document.getElementById(id).checked) { for(var i=0;i{}}, ...], // uc_html: 'header button', // op_html: 'div.btn-group?' // } var ele = options.ele || $('.dataTable'); var columnDefs = [ { targets: 0, orderable: false, createdCell: function(td, cellData) { $(td).html(''.replace('99991937', cellData)); }}, {className: 'text-center', targets: '_all'} ]; columnDefs = options.columnDefs ? options.columnDefs.concat(columnDefs) : columnDefs; var table = ele.DataTable({ pageLength: options.pageLength || 15, dom: options.dom || '<"#uc.pull-left">flt<"row m-t"<"col-md-8"<"#op.col-md-6"><"col-md-6 text-center"i>><"col-md-4"p>>', language: { url: options.i18n_url || "/static/js/plugins/dataTables/i18n/zh-hans.json" }, order: options.order || [[ 1, 'asc' ]], select: options.select || 'multi', buttons: [], columnDefs: columnDefs, ajax: { url: options.ajax_url , dataSrc: "" }, columns: options.columns || [], lengthMenu: [[15, 25, 50, -1], [15, 25, 50, "All"]] }); 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$(); $node.find('input.ipt_check').prop('checked', false); jumpserver.selected[$node.find('input.ipt_check').prop('id')] = false }).on('draw', function(){ $('#op').html(options.op_html || ''); $('#uc').html(options.uc_html || ''); }); $('.ipt_check_all').on('click', function() { if (!jumpserver.checked) { $(this).closest('table').find('.ipt_check').prop('checked', true); jumpserver.checked = true; table.rows().select(); } else { $(this).closest('table').find('.ipt_check').prop('checked', false); jumpserver.checked = false; table.rows().deselect(); } }); return table; }; /** * 替换所有匹配exp的字符串为指定字符串 * @param exp 被替换部分的正则 * @param newStr 替换成的字符串 */ String.prototype.replaceAll = function (exp, newStr) { return this.replace(new RegExp(exp, "gm"), newStr); }; /** * 原型:字符串格式化 * @param args 格式化参数值 */ String.prototype.format = function(args) { var result = this; if (arguments.length < 1) { return result; } var data = arguments; if (arguments.length == 1 && typeof (args) == "object") { data = args; } for ( var key in data) { var value = data[key]; if (undefined != value) { result = result.replaceAll("\\{" + key + "\\}", value); } } return result; }