folders.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. <!--
  2. Copyright (C) 2019-2022 Nicola Murino
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Affero General Public License as published
  5. by the Free Software Foundation, version 3.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU Affero General Public License for more details.
  10. You should have received a copy of the GNU Affero General Public License
  11. along with this program. If not, see <https://www.gnu.org/licenses/>.
  12. -->
  13. {{template "base" .}}
  14. {{define "title"}}{{.Title}}{{end}}
  15. {{define "extra_css"}}
  16. <link href="{{.StaticURL}}/vendor/datatables/dataTables.bootstrap4.min.css" rel="stylesheet">
  17. <link href="{{.StaticURL}}/vendor/datatables/buttons.bootstrap4.min.css" rel="stylesheet">
  18. <link href="{{.StaticURL}}/vendor/datatables/fixedHeader.bootstrap4.min.css" rel="stylesheet">
  19. <link href="{{.StaticURL}}/vendor/datatables/responsive.bootstrap4.min.css" rel="stylesheet">
  20. <link href="{{.StaticURL}}/vendor/datatables/select.bootstrap4.min.css" rel="stylesheet">
  21. <link href="{{.StaticURL}}/vendor/datatables/colReorder.bootstrap4.min.css" rel="stylesheet">
  22. {{end}}
  23. {{define "page_body"}}
  24. <div id="errorMsg" class="card mb-4 border-left-warning" style="display: none;">
  25. <div id="errorTxt" class="card-body text-form-error"></div>
  26. </div>
  27. <div id="successMsg" class="card mb-4 border-left-success" style="display: none;">
  28. <div id="successTxt" class="card-body"></div>
  29. </div>
  30. <div class="card shadow mb-4">
  31. <div class="card-header py-3">
  32. <h6 class="m-0 font-weight-bold text-primary">View and manage folders</h6>
  33. </div>
  34. <div class="card-body">
  35. <div class="table-responsive">
  36. <table class="table table-hover nowrap" id="dataTable" width="100%" cellspacing="0">
  37. <thead>
  38. <tr>
  39. <th></th>
  40. <th>Name</th>
  41. <th>Storage</th>
  42. <th>Description</th>
  43. <th>Associated users</th>
  44. <th>Associated groups</th>
  45. <th>Quota</th>
  46. </tr>
  47. </thead>
  48. <tbody>
  49. {{range .Folders}}
  50. <tr>
  51. <td>{{.GetLastQuotaUpdateAsString}}</td>
  52. <td>{{.Name}}</td>
  53. <td>{{.GetStorageDescrition}}</td>
  54. <td>{{.Description}}</td>
  55. <td>{{.GetUsersAsString}}</td>
  56. <td>{{.GetGroupsAsString}}</td>
  57. <td>{{.GetQuotaSummary}}</td>
  58. </tr>
  59. {{end}}
  60. </tbody>
  61. </table>
  62. </div>
  63. </div>
  64. </div>
  65. {{end}}
  66. {{define "dialog"}}
  67. <div class="modal fade" id="deleteModal" tabindex="-1" role="dialog" aria-labelledby="deleteModalLabel"
  68. aria-hidden="true">
  69. <div class="modal-dialog" role="document">
  70. <div class="modal-content">
  71. <div class="modal-header">
  72. <h5 class="modal-title" id="deleteModalLabel">
  73. Confirmation required
  74. </h5>
  75. <button class="close" type="button" data-dismiss="modal" aria-label="Close">
  76. <span aria-hidden="true">&times;</span>
  77. </button>
  78. </div>
  79. <div class="modal-body">Do you want to delete the selected virtual folder and any users mapping?</div>
  80. <div class="modal-footer">
  81. <button class="btn btn-secondary" type="button" data-dismiss="modal">
  82. Cancel
  83. </button>
  84. <a class="btn btn-warning" href="#" onclick="deleteAction()">
  85. Delete
  86. </a>
  87. </div>
  88. </div>
  89. </div>
  90. </div>
  91. {{end}}
  92. {{define "extra_js"}}
  93. <script src="{{.StaticURL}}/vendor/datatables/jquery.dataTables.min.js"></script>
  94. <script src="{{.StaticURL}}/vendor/datatables/dataTables.bootstrap4.min.js"></script>
  95. <script src="{{.StaticURL}}/vendor/datatables/dataTables.buttons.min.js"></script>
  96. <script src="{{.StaticURL}}/vendor/datatables/buttons.bootstrap4.min.js"></script>
  97. <script src="{{.StaticURL}}/vendor/datatables/buttons.colVis.min.js"></script>
  98. <script src="{{.StaticURL}}/vendor/datatables/dataTables.fixedHeader.min.js"></script>
  99. <script src="{{.StaticURL}}/vendor/datatables/dataTables.responsive.min.js"></script>
  100. <script src="{{.StaticURL}}/vendor/datatables/responsive.bootstrap4.min.js"></script>
  101. <script src="{{.StaticURL}}/vendor/datatables/dataTables.select.min.js"></script>
  102. <script src="{{.StaticURL}}/vendor/datatables/ellipsis.js"></script>
  103. <script src="{{.StaticURL}}/vendor/datatables/dataTables.colReorder.min.js"></script>
  104. <script type="text/javascript">
  105. function deleteAction() {
  106. var table = $('#dataTable').DataTable();
  107. table.button('delete:name').enable(false);
  108. var folderName = table.row({ selected: true }).data()[1];
  109. var path = '{{.FolderURL}}' + "/" + fixedEncodeURIComponent(folderName);
  110. $('#deleteModal').modal('hide');
  111. $.ajax({
  112. url: path,
  113. type: 'DELETE',
  114. dataType: 'json',
  115. headers: {'X-CSRF-TOKEN' : '{{.CSRFToken}}'},
  116. timeout: 15000,
  117. success: function (result) {
  118. window.location.href = '{{.FoldersURL}}';
  119. },
  120. error: function ($xhr, textStatus, errorThrown) {
  121. var txt = "Unable to delete the selected folder";
  122. if ($xhr) {
  123. var json = $xhr.responseJSON;
  124. if (json) {
  125. if (json.message){
  126. txt += ": " + json.message;
  127. } else {
  128. txt += ": " + json.error;
  129. }
  130. }
  131. }
  132. $('#errorTxt').text(txt);
  133. $('#errorMsg').show();
  134. setTimeout(function () {
  135. $('#errorMsg').hide();
  136. }, 5000);
  137. }
  138. });
  139. }
  140. $(document).ready(function () {
  141. $.fn.dataTable.ext.buttons.add = {
  142. text: '<i class="fas fa-plus"></i>',
  143. name: 'add',
  144. titleAttr: "Add",
  145. action: function (e, dt, node, config) {
  146. window.location.href = '{{.FolderURL}}';
  147. }
  148. };
  149. $.fn.dataTable.ext.buttons.edit = {
  150. text: '<i class="fas fa-pen"></i>',
  151. name: 'edit',
  152. titleAttr: "Edit",
  153. action: function (e, dt, node, config) {
  154. var folderName = table.row({ selected: true }).data()[1];
  155. var path = '{{.FolderURL}}' + "/" + fixedEncodeURIComponent(folderName);
  156. window.location.href = path;
  157. },
  158. enabled: false
  159. };
  160. $.fn.dataTable.ext.buttons.template = {
  161. text: '<i class="fas fa-clone"></i>',
  162. name: 'template',
  163. titleAttr: "Template",
  164. action: function (e, dt, node, config) {
  165. var selectedRows = table.rows({ selected: true }).count();
  166. if (selectedRows == 1){
  167. var folderName = table.row({ selected: true }).data()[1];
  168. var path = '{{.FolderTemplateURL}}' + "?from=" + encodeURIComponent(folderName);
  169. window.location.href = path;
  170. } else {
  171. window.location.href = '{{.FolderTemplateURL}}';
  172. }
  173. }
  174. };
  175. $.fn.dataTable.ext.buttons.delete = {
  176. text: '<i class="fas fa-trash"></i>',
  177. name: 'delete',
  178. titleAttr: "Delete",
  179. action: function (e, dt, node, config) {
  180. $('#deleteModal').modal('show');
  181. },
  182. enabled: false
  183. };
  184. $.fn.dataTable.ext.buttons.quota_scan = {
  185. text: '<i class="fas fa-redo-alt"></i>',
  186. name: 'quota_scan',
  187. titleAttr: 'Quota Scan',
  188. action: function (e, dt, node, config) {
  189. dt.button('quota_scan:name').enable(false);
  190. var folderName = dt.row({ selected: true }).data()[1];
  191. var path = '{{.FolderQuotaScanURL}}'+ "/" + fixedEncodeURIComponent(folderName);
  192. $.ajax({
  193. url: path,
  194. type: 'POST',
  195. headers: {'X-CSRF-TOKEN' : '{{.CSRFToken}}'},
  196. timeout: 15000,
  197. success: function (result) {
  198. dt.button('quota_scan:name').enable(true);
  199. $('#successTxt').text("Quota scan started for the selected folder. Please reload the folders page to check when the scan ends");
  200. $('#successMsg').show();
  201. setTimeout(function () {
  202. $('#successMsg').hide();
  203. }, 5000);
  204. },
  205. error: function ($xhr, textStatus, errorThrown) {
  206. dt.button('quota_scan:name').enable(true);
  207. var txt = "Unable to update quota for the selected folder";
  208. if ($xhr) {
  209. var json = $xhr.responseJSON;
  210. if (json) {
  211. if (json.message) {
  212. txt += ": " + json.message;
  213. } else if (json.error) {
  214. txt += ": " + json.error;
  215. }
  216. }
  217. }
  218. $('#errorTxt').text(txt);
  219. $('#errorMsg').show();
  220. setTimeout(function () {
  221. $('#errorMsg').hide();
  222. }, 5000);
  223. }
  224. });
  225. },
  226. enabled: false
  227. };
  228. let dateFn = $.fn.dataTable.render.datetime();
  229. let table = $('#dataTable').DataTable({
  230. "select": {
  231. "style": "single",
  232. "blurable": true
  233. },
  234. "colReorder": {
  235. "enable": true,
  236. "fixedColumnsLeft": 2
  237. },
  238. "stateSave": true,
  239. "stateDuration": 0,
  240. "buttons": [
  241. {
  242. "text": "Column visibility",
  243. "extend": "colvis",
  244. "columns": ":not(.noVis)"
  245. }
  246. ],
  247. "columnDefs": [
  248. {
  249. "targets": [0],
  250. "visible": false,
  251. "className": "noVis"
  252. },
  253. {
  254. "targets": [1],
  255. "className": "noVis"
  256. },
  257. {
  258. "targets": [2],
  259. "render": $.fn.dataTable.render.ellipsis(50, true)
  260. },
  261. {
  262. "targets": [3],
  263. "visible": false
  264. },
  265. {
  266. "targets": [4],
  267. "render": $.fn.dataTable.render.ellipsis(40, true)
  268. },
  269. {
  270. "targets": [5],
  271. "visible": false,
  272. "render": $.fn.dataTable.render.ellipsis(40, true)
  273. },
  274. {
  275. "targets": [6],
  276. "visible": false,
  277. "render": function ( data, type, row, meta ) {
  278. if (type !== 'display') {
  279. return data;
  280. }
  281. if (row[0] !== ""){
  282. let formattedDate = dateFn(row[0], type);
  283. data = `${data}. Updated at: ${formattedDate}`;
  284. }
  285. let ellipsisFn = $.fn.dataTable.render.ellipsis(60, true);
  286. return ellipsisFn(data, type);
  287. }
  288. }
  289. ],
  290. "scrollX": false,
  291. "scrollY": false,
  292. "responsive": true,
  293. "language": {
  294. "emptyTable": "No folder defined"
  295. },
  296. "order": [[1, 'asc']]
  297. });
  298. new $.fn.dataTable.FixedHeader( table );
  299. {{if .LoggedAdmin.HasPermission "quota_scans"}}
  300. table.button().add(0,'quota_scan');
  301. {{end}}
  302. {{if .LoggedAdmin.HasPermission "del_users"}}
  303. table.button().add(0,'delete');
  304. {{end}}
  305. {{if .LoggedAdmin.HasPermission "add_users"}}
  306. table.button().add(0,'template');
  307. {{end}}
  308. {{if .LoggedAdmin.HasPermission "edit_users"}}
  309. table.button().add(0,'edit');
  310. {{end}}
  311. {{if .LoggedAdmin.HasPermission "add_users"}}
  312. table.button().add(0,'add');
  313. {{end}}
  314. table.buttons().container().appendTo('.col-md-6:eq(0)', table.table().container());
  315. table.on('select deselect', function () {
  316. var selectedRows = table.rows({ selected: true }).count();
  317. {{if .LoggedAdmin.HasPermission "del_users"}}
  318. table.button('delete:name').enable(selectedRows == 1);
  319. {{end}}
  320. {{if .LoggedAdmin.HasPermission "edit_users"}}
  321. table.button('edit:name').enable(selectedRows == 1);
  322. {{end}}
  323. {{if .LoggedAdmin.HasPermission "quota_scans"}}
  324. table.button('quota_scan:name').enable(selectedRows == 1);
  325. {{end}}
  326. });
  327. });
  328. </script>
  329. {{end}}