folders.html 13 KB

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