|
64 | 64 | <script src="{% static 'js/jquery.form.min.js' %}"></script> |
65 | 65 | <script type="text/javascript"> |
66 | 66 |
|
67 | | - |
68 | | -$(document).ready(function(){ |
| 67 | +function initTable() { |
69 | 68 | var options = { |
70 | 69 | ele: $('#asset_list_table'), |
71 | 70 | columnDefs: [ |
|
103 | 102 | {data: "is_active" }, {data: "is_connective"}, {data: "id" }], |
104 | 103 | op_html: $('#actions').html() |
105 | 104 | }; |
106 | | - var table = jumpserver.initDataTable(options); |
| 105 | + return jumpserver.initDataTable(options); |
| 106 | +} |
107 | 107 |
|
108 | | - $('.btn_export').click(function () { |
109 | | - var assets = []; |
110 | | - var rows = table.rows('.selected').data(); |
111 | | - $.each(rows, function (index, obj) { |
112 | | - assets.push(obj.id) |
113 | | - }); |
114 | | - console.log(assets); |
115 | | - $.ajax({ |
116 | | - url: "{% url "assets:asset-export" %}", |
117 | | - method: 'POST', |
118 | | - data: JSON.stringify({assets_id: assets}), |
119 | | - dataType: "json", |
120 | | - success: function (data, textStatus) { |
121 | | - window.open(data.redirect) |
122 | | - }, |
123 | | - error: function () { |
124 | | - toastr.error('Export failed'); |
125 | | - } |
126 | | - }) |
| 108 | +$(document).ready(function(){ |
| 109 | + initTable(); |
| 110 | +}) |
| 111 | +.on('click', '#btn_export', function () { |
| 112 | + var $data_table = $('#asset_list_table').DataTable(); |
| 113 | + var rows = $data_table.rows('.selected').data(); |
| 114 | + var assets = []; |
| 115 | + $.each(rows, function (index, obj) { |
| 116 | + assets.push(obj.id) |
127 | 117 | }); |
128 | | - $('#btn_asset_import').click(function() { |
129 | | - var $form = $('#fm_asset_import'); |
130 | | - $form.find('.help-block').remove(); |
131 | | - function success (data) { |
132 | | - if (data.valid === false) { |
133 | | - $('<span />', {class: 'help-block text-danger'}).html(data.msg).insertAfter($('#id_assets')); |
134 | | - } else { |
135 | | - $('#id_created').html(data.created_info); |
136 | | - $('#id_created_detail').html(data.created.join(', ')); |
137 | | - $('#id_updated').html(data.updated_info); |
138 | | - $('#id_updated_detail').html(data.updated.join(', ')); |
139 | | - $('#id_failed').html(data.failed_info); |
140 | | - $('#id_failed_detail').html(data.failed.join(', ')); |
141 | | - var $data_table = $('#asset_list_table').DataTable(); |
142 | | - $data_table.ajax.reload(); |
143 | | - } |
| 118 | + $.ajax({ |
| 119 | + url: "{% url "assets:asset-export" %}", |
| 120 | + method: 'POST', |
| 121 | + data: JSON.stringify({assets_id: assets}), |
| 122 | + dataType: "json", |
| 123 | + success: function (data, textStatus) { |
| 124 | + window.open(data.redirect) |
| 125 | + }, |
| 126 | + error: function () { |
| 127 | + toastr.error('Export failed'); |
144 | 128 | } |
145 | | - $form.ajaxSubmit({success: success}); |
146 | 129 | }) |
147 | 130 | }) |
| 131 | +.on('click', '#btn_import', function () { |
| 132 | + var $form = $('#fm_asset_import'); |
| 133 | + $form.find('.help-block').remove(); |
| 134 | + function success (data) { |
| 135 | + if (data.valid === false) { |
| 136 | + $('<span />', {class: 'help-block text-danger'}).html(data.msg).insertAfter($('#id_assets')); |
| 137 | + } else { |
| 138 | + $('#id_created').html(data.created_info); |
| 139 | + $('#id_created_detail').html(data.created.join(', ')); |
| 140 | + $('#id_updated').html(data.updated_info); |
| 141 | + $('#id_updated_detail').html(data.updated.join(', ')); |
| 142 | + $('#id_failed').html(data.failed_info); |
| 143 | + $('#id_failed_detail').html(data.failed.join(', ')); |
| 144 | + var $data_table = $('#asset_list_table').DataTable(); |
| 145 | + $data_table.ajax.reload(); |
| 146 | + } |
| 147 | + } |
| 148 | + $form.ajaxSubmit({success: success}); |
| 149 | +}) |
148 | 150 |
|
149 | 151 | .on('click', '.btn_asset_delete', function () { |
150 | 152 | var $this = $(this); |
|
0 commit comments