shares.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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. {{end}}
  22. {{define "page_body"}}
  23. <div id="errorMsg" class="alert alert-warning alert-dismissible fade show" style="display: none;" role="alert">
  24. <span id="errorTxt"></span>
  25. <button type="button" class="close" data-dismiss="alert" aria-label="Close">
  26. <span aria-hidden="true">&times;</span>
  27. </button>
  28. </div>
  29. <div class="card shadow mb-4">
  30. <div class="card-header py-3">
  31. <h6 class="m-0 font-weight-bold text-primary">View and manage shares</h6>
  32. </div>
  33. <div class="card-body">
  34. <div class="table-responsive">
  35. <table class="table table-hover nowrap" id="dataTable" width="100%" cellspacing="0">
  36. <thead>
  37. <tr>
  38. <th>ID</th>
  39. <th>Name</th>
  40. <th>Scope</th>
  41. <th>Info</th>
  42. <th></th>
  43. </tr>
  44. </thead>
  45. <tbody>
  46. {{range .Shares}}
  47. <tr>
  48. <td>{{.ShareID}}</td>
  49. <td>{{.Name}}</td>
  50. <td>{{.GetScopeAsString}}</td>
  51. <td>{{.GetInfoString}}</td>
  52. <td>{{if .IsExpired}}1{{else}}0{{end}}</td>
  53. </tr>
  54. {{end}}
  55. </tbody>
  56. </table>
  57. </div>
  58. </div>
  59. </div>
  60. {{end}}
  61. {{define "dialog"}}
  62. <div class="modal fade" id="deleteModal" tabindex="-1" role="dialog" aria-labelledby="deleteModalLabel"
  63. aria-hidden="true">
  64. <div class="modal-dialog" role="document">
  65. <div class="modal-content">
  66. <div class="modal-header">
  67. <h5 class="modal-title" id="deleteModalLabel">
  68. Confirmation required
  69. </h5>
  70. <button class="close" type="button" data-dismiss="modal" aria-label="Close">
  71. <span aria-hidden="true">&times;</span>
  72. </button>
  73. </div>
  74. <div class="modal-body">Do you want to delete the selected share?</div>
  75. <div class="modal-footer">
  76. <button class="btn btn-secondary" type="button" data-dismiss="modal">
  77. Cancel
  78. </button>
  79. <a class="btn btn-warning" href="#" onclick="deleteAction()">
  80. Delete
  81. </a>
  82. </div>
  83. </div>
  84. </div>
  85. </div>
  86. <div class="modal fade" id="linkModal" tabindex="-1" role="dialog" aria-labelledby="linkModalLabel"
  87. aria-hidden="true">
  88. <div class="modal-dialog" role="document">
  89. <div class="modal-content">
  90. <div class="modal-header">
  91. <h5 class="modal-title" id="linkModalLabel">
  92. Share access links
  93. </h5>
  94. <button class="close" type="button" data-dismiss="modal" aria-label="Close">
  95. <span aria-hidden="true">&times;</span>
  96. </button>
  97. </div>
  98. <div class="modal-body">
  99. <div id="readShare">
  100. <p>You can download the shared contents, as single zip file, using this <a id="readLink" href="#" target="_blank">link</a>.</p>
  101. <p>If the share consists of a single directory you can browse and download files using this <a id="readBrowseLink" href="#" target="_blank">page</a>.</p>
  102. <p>If the share consists of a single file you can download it uncompressed using this <a id="readUncompressedLink" href="#" target="_blank">link</a>.</p>
  103. </div>
  104. <div id="writeShare">
  105. <p>You can upload one or more files to the shared directory using this <a id="writePageLink" href="#" target="_blank">page</a></p>
  106. </div>
  107. <div id="expiredShare">
  108. This share is no longer accessible because it has expired
  109. </div>
  110. </div>
  111. <div class="modal-footer">
  112. <button class="btn btn-primary" type="button" data-dismiss="modal">
  113. OK
  114. </button>
  115. </div>
  116. </div>
  117. </div>
  118. </div>
  119. {{end}}
  120. {{define "extra_js"}}
  121. <script src="{{.StaticURL}}/vendor/datatables/jquery.dataTables.min.js"></script>
  122. <script src="{{.StaticURL}}/vendor/datatables/dataTables.bootstrap4.min.js"></script>
  123. <script src="{{.StaticURL}}/vendor/datatables/dataTables.buttons.min.js"></script>
  124. <script src="{{.StaticURL}}/vendor/datatables/buttons.bootstrap4.min.js"></script>
  125. <script src="{{.StaticURL}}/vendor/datatables/dataTables.fixedHeader.min.js"></script>
  126. <script src="{{.StaticURL}}/vendor/datatables/dataTables.responsive.min.js"></script>
  127. <script src="{{.StaticURL}}/vendor/datatables/responsive.bootstrap4.min.js"></script>
  128. <script src="{{.StaticURL}}/vendor/datatables/dataTables.select.min.js"></script>
  129. <script type="text/javascript">
  130. function deleteAction() {
  131. let table = $('#dataTable').DataTable();
  132. table.button('delete:name').enable(false);
  133. let shareID = table.row({ selected: true }).data()[0];
  134. let path = '{{.ShareURL}}' + "/" + fixedEncodeURIComponent(shareID);
  135. $('#deleteModal').modal('hide');
  136. $('#errorMsg').hide();
  137. $.ajax({
  138. url: path,
  139. type: 'DELETE',
  140. dataType: 'json',
  141. headers: {'X-CSRF-TOKEN' : '{{.CSRFToken}}'},
  142. timeout: 15000,
  143. success: function (result) {
  144. window.location.href = '{{.SharesURL}}';
  145. },
  146. error: function ($xhr, textStatus, errorThrown) {
  147. let txt = "Unable to delete the selected share";
  148. if ($xhr) {
  149. let json = $xhr.responseJSON;
  150. if (json) {
  151. if (json.message){
  152. txt += ": " + json.message;
  153. } else {
  154. txt += ": " + json.error;
  155. }
  156. }
  157. }
  158. $('#errorTxt').text(txt);
  159. $('#errorMsg').show();
  160. }
  161. });
  162. }
  163. $(document).ready(function () {
  164. $.fn.dataTable.ext.buttons.add = {
  165. text: '<i class="fas fa-plus"></i>',
  166. name: 'add',
  167. titleAttr: "Add",
  168. action: function (e, dt, node, config) {
  169. window.location.href = '{{.ShareURL}}';
  170. }
  171. };
  172. $.fn.dataTable.ext.buttons.edit = {
  173. text: '<i class="fas fa-pen"></i>',
  174. name: 'edit',
  175. titleAttr: "Edit",
  176. action: function (e, dt, node, config) {
  177. var shareID = dt.row({ selected: true }).data()[0];
  178. var path = '{{.ShareURL}}' + "/" + fixedEncodeURIComponent(shareID);
  179. window.location.href = path;
  180. },
  181. enabled: false
  182. };
  183. $.fn.dataTable.ext.buttons.delete = {
  184. text: '<i class="fas fa-trash"></i>',
  185. name: 'delete',
  186. titleAttr: "Delete",
  187. action: function (e, dt, node, config) {
  188. $('#deleteModal').modal('show');
  189. },
  190. enabled: false
  191. };
  192. $.fn.dataTable.ext.buttons.link = {
  193. text: '<i class="fas fa-link"></i>',
  194. name: 'link',
  195. titleAttr: "Link",
  196. action: function (e, dt, node, config) {
  197. var shareData = dt.row({ selected: true }).data();
  198. var shareID = shareData[0];
  199. var shareScope = shareData[2];
  200. var isExpired = shareData[4];
  201. if (isExpired == "1"){
  202. $('#expiredShare').show();
  203. $('#writeShare').hide();
  204. $('#readShare').hide();
  205. } else {
  206. var shareURL = '{{.BasePublicSharesURL}}' + "/" + fixedEncodeURIComponent(shareID);
  207. if (shareScope == 'Read'){
  208. $('#expiredShare').hide();
  209. $('#writeShare').hide();
  210. $('#readShare').show();
  211. $('#readLink').attr("href", shareURL);
  212. $('#readLink').attr("title", shareURL);
  213. $('#readUncompressedLink').attr("href", shareURL+"?compress=false");
  214. $('#readUncompressedLink').attr("title", shareURL+"?compress=false");
  215. $('#readBrowseLink').attr("href", shareURL+"/browse");
  216. $('#readBrowseLink').attr("title", shareURL+"/browse");
  217. } else {
  218. $('#expiredShare').hide();
  219. $('#writeShare').show();
  220. $('#readShare').hide();
  221. $('#writePageLink').attr("href", shareURL+"/upload");
  222. $('#writePageLink').attr("title", shareURL+"/upload");
  223. }
  224. }
  225. $('#linkModal').modal('show');
  226. },
  227. enabled: false
  228. };
  229. var table = $('#dataTable').DataTable({
  230. "select": {
  231. "style": "single",
  232. "blurable": true
  233. },
  234. "stateSave": true,
  235. "stateDuration": 0,
  236. "buttons": [],
  237. "columnDefs": [
  238. {
  239. "targets": [0, 4],
  240. "visible": false,
  241. "searchable": false
  242. }
  243. ],
  244. "scrollX": false,
  245. "scrollY": false,
  246. "responsive": true,
  247. "language": {
  248. "emptyTable": "No share defined"
  249. },
  250. "order": [[1, 'asc']]
  251. });
  252. new $.fn.dataTable.FixedHeader( table );
  253. table.button().add(0,'link');
  254. table.button().add(0,'delete');
  255. table.button().add(0,'edit');
  256. table.button().add(0,'add');
  257. table.buttons().container().appendTo('.col-md-6:eq(0)', table.table().container());
  258. table.on('select deselect', function () {
  259. var selectedRows = table.rows({ selected: true }).count();
  260. table.button('edit:name').enable(selectedRows == 1);
  261. table.button('clone:name').enable(selectedRows == 1);
  262. table.button('delete:name').enable(selectedRows == 1);
  263. table.button('link:name').enable(selectedRows == 1);
  264. });
  265. });
  266. </script>
  267. {{end}}