diff --git a/apps/static/css/jumpserver.css b/apps/static/css/jumpserver.css index da3354188..c3459298f 100644 --- a/apps/static/css/jumpserver.css +++ b/apps/static/css/jumpserver.css @@ -78,4 +78,25 @@ th a { border-top: none !important; } +table.dataTable tbody > tr.selected, table.dataTable tbody > tr > .selected { + background-color: #1ab394; +} +table.dataTable tbody tr.selected a, +table.dataTable tbody th.selected a, +table.dataTable tbody td.selected a, +table.dataTable tbody tr.selected td i.text-navy, +table.dataTable tbody th.selected td i.text-navy, +table.dataTable tbody td.selected td i.text-navy +{ + color: white; +} + +div.dataTables_wrapper div.dataTables_filter, +.dataTables_length { + float: right !important; +} + +div.dataTables_wrapper div.dataTables_filter { + margin-left: 15px; +} diff --git a/apps/static/js/jumpserver.js b/apps/static/js/jumpserver.js index 9f664fb51..9a26a5607 100644 --- a/apps/static/js/jumpserver.js +++ b/apps/static/js/jumpserver.js @@ -240,7 +240,6 @@ function objectDelete(obj, name, url){ }); } -var jumpserver = {}; $.fn.serializeObject = function() { var o = {}; @@ -257,3 +256,80 @@ $.fn.serializeObject = function() }); return o; }; +var jumpserver = {}; +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: 'header button', + // op_html: 'div.btn-group?' + // } + var ele = options.ele || $('.dataTable'); + var columnDefs = [ + { + targets: 0, orderable: false, + createdCell: function(td) { + $(td).html('
'); + } + }, + {className: 'text-center', targets: '_all'}, + ]; + columnDefs = options.columnDefs ? options.columnDefs.concat(columnDefs) : columnDefs; + var table = ele.DataTable({ + pageLength: options.pageLength || 25, + dom: options.dom || '<"#uc.pull-left"><"html5buttons"B>flti<"row m-t"<"#op.col-md-6"><"col-md-6"p>>', + language: { + url: options.i18n_url || "/static/js/plugins/dataTables/i18n/zh-hans.json" + }, + order: options.order || [[ 1, 'asc' ]], + buttons: options.buttons || [ + {extend: 'excel', + exportOptions: { + modifier: { + selected: true + } + } + }, + {extend: 'pdf', + exportOptions: { + modifier: { + selected: true + } + } + }, + {extend: 'print', + customize: function (win){ + $(win.document.body).addClass('white-bg'); + $(win.document.body).css('font-size', '10px'); + $(win.document.body).find('table') + .addClass('compact') + .css('font-size', 'inherit'); + } + } + ], + columnDefs: columnDefs, + select: options.select || {style: 'multi'}, + ajax: { + url: options.ajax_url , + dataSrc: "" + }, + columns: options.columns || [] + }); + table.on('select', function(e, dt, type, indexes) { + var $node = table[ type ]( indexes ).nodes().to$(); + $node.find('input.ipt_check').prop('checked', true); + }).on('deselect', function(e, dt, type, indexes) { + var $node = table[ type ]( indexes ).nodes().to$(); + $node.find('input.ipt_check').prop('checked', false); + }).on('draw', function(){ + $('#op').html(options.op_html || ''); + $('#uc').html(options.uc_html || ''); + }); + return table; +} diff --git a/apps/templates/_head_css_js.html b/apps/templates/_head_css_js.html index 0fc1ac92c..4bb984ae3 100644 --- a/apps/templates/_head_css_js.html +++ b/apps/templates/_head_css_js.html @@ -7,17 +7,9 @@ - - - - - - - - diff --git a/apps/users/templates/users/user_list.html b/apps/users/templates/users/user_list.html index a1369ee73..d712a28bc 100644 --- a/apps/users/templates/users/user_list.html +++ b/apps/users/templates/users/user_list.html @@ -2,16 +2,14 @@ {% load i18n static %} {% get_current_language as LANGUAGE_CODE %} {% load common_tags %} -{% block content_left_head %} - {% trans "Create user" %} -{% endblock %} {% block table_search %}{% endblock %} {% block table_container %} +- + | {% trans 'Name' %} | {% trans 'Username' %} | @@ -25,66 +23,43 @@
---|