manage.html 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <html>
  2. <head>
  3. <title>Manage Storage Quota</title>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0 user-scalable=no">
  6. <link rel="stylesheet" href="../../../script/semantic/semantic.min.css">
  7. <script type="text/javascript" src="../../../script/jquery.min.js"></script>
  8. <script type="text/javascript" src="../../../script/semantic/semantic.min.js"></script>
  9. <style>
  10. </style>
  11. </head>
  12. <body>
  13. <div class="ui container">
  14. <div class="ui basic segment">
  15. <div class="ui header">
  16. <i class="hdd icon"></i>
  17. <div class="content">
  18. Storage Quota Settings
  19. <div class="sub header">Limit each user groups storage quota</div>
  20. </div>
  21. </div>
  22. </div>
  23. <div id="oprsucc" style="display:none;" class="ui green inverted segment"><i class="checkmark icon"></i> Quota Updated</div>
  24. <div id="oprfailed" style="display:none;" class="ui red inverted segment"><i class="remove icon"></i> Error occured while tring to update storage quota</div>
  25. <div id="updateQuotaInterface" class="ui segment" style="display:none;">
  26. <p>Group to be Updated: </p>
  27. <div class="ui fluid tiny input">
  28. <input id="editingGroup" type="text" readonly="true" value="">
  29. </div>
  30. <br>
  31. <p>New Quota: </p>
  32. <div class="ui tiny input">
  33. <input id="newQuotaValue" type="number" value="15">
  34. </div>
  35. <div class="ui selection tiny dropdown">
  36. <input id="newquota" type="hidden" name="size">
  37. <i class="dropdown icon"></i>
  38. <div class="default text" >GB</div>
  39. <div class="menu">
  40. <div class="item" data-value="1">MB</div>
  41. <div class="item" data-value="1024">GB</div>
  42. <div class="item" data-value="1048576">TB</div>
  43. </div>
  44. </div>
  45. <div class="ui divider"></div>
  46. <div style="width:100%;" align="right">
  47. <button class="ui button" onclick="$('#updateQuotaInterface').transition('fade down');">Cancel</button>
  48. <button class="ui primary button" onclick="confirmUpdate();"><i class="checkmark icon"></i> Confirm</button>
  49. </div>
  50. </div>
  51. <table class="ui celled striped table">
  52. <thead>
  53. <tr>
  54. <th colspan="3">
  55. Current Storage Quota
  56. </th>
  57. </tr>
  58. <tr>
  59. <th>User Group</th>
  60. <th>Storage Quota</th>
  61. <th>Edit Quota</th>
  62. </tr>
  63. </thead>
  64. <tbody id="quotaTable">
  65. <tr>
  66. <td colspan="3">Initializing Storage Quota Table</td>
  67. </tr>
  68. </tbody>
  69. </table>
  70. <p><i class="info circle icon"></i> All users in the given group will have the same storage quota. If you want to create a special storage quota for a given user, please create a new group.</p>
  71. </div>
  72. <script>
  73. var usergroup = "";
  74. $('.ui.dropdown').dropdown();
  75. initQuotaTable();
  76. function initQuotaTable(){
  77. $("#quotaTable").html("Loading...");
  78. $.get("../../system/disk/quota/listQuota",function(data){
  79. $("#quotaTable").html("");
  80. if (data.error !== undefined){
  81. alert(data.error);
  82. }else{
  83. for (const [key, value] of Object.entries(data)) {
  84. var quota = "Read Only";
  85. if (value == -1){
  86. quota = "Unlimited";
  87. }else if (value > 0){
  88. quota = formatBytes(value);
  89. }
  90. var updateButton = `<button class="ui teal tiny button" group="${key}" onclick="updateGroupQuota(this);">Update</button>`;
  91. if (key == "administrator"){
  92. updateButton = "";
  93. }
  94. $("#quotaTable").append(`<tr>
  95. <td class="collapsing">
  96. <i class="user icon"></i> ${key}
  97. </td>
  98. <td>${quota}</td>
  99. <td class="right aligned collapsing">${updateButton}</td>
  100. </tr>`);
  101. }
  102. }
  103. });
  104. }
  105. function confirmUpdate(){
  106. var targetUsergroup = usergroup;
  107. var quotaMultipler = $("#newquota").val();
  108. if (quotaMultipler == ""){
  109. quotaMultipler = 1024;
  110. }
  111. var quotaNumeric = $("#newQuotaValue").val();
  112. var actualQuota = quotaNumeric * quotaMultipler;
  113. $.ajax({
  114. url: "../../../system/disk/quota/setQuota",
  115. data: {"groupname": targetUsergroup, "quota":actualQuota},
  116. method: "POST",
  117. success: function(data){
  118. $('#updateQuotaInterface').transition('fade down');
  119. if (data.error !== undefined){
  120. $("#oprfailed").text(data.error);
  121. $("#oprfailed").slideDown("fast").delay(3000).slideUp("fast");
  122. }else{
  123. initQuotaTable();
  124. $("#oprsucc").slideDown("fast").delay(3000).slideUp("fast");
  125. }
  126. }
  127. });
  128. }
  129. function updateGroupQuota(object){
  130. var groupname = $(object).attr("group");
  131. $("#editingGroup").val(groupname);
  132. usergroup = groupname;
  133. if ($("#updateQuotaInterface").is(":hidden")){
  134. $("#updateQuotaInterface").transition('fade down');
  135. }
  136. }
  137. function formatBytes(bytes, decimals = 2) {
  138. if (bytes === 0) return '0 Bytes';
  139. const k = 1024;
  140. const dm = decimals < 0 ? 0 : decimals;
  141. const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
  142. const i = Math.floor(Math.log(bytes) / Math.log(k));
  143. return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
  144. }
  145. </script>
  146. </body>
  147. </html>