group.html 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <html>
  2. <head>
  3. <title>Group List</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. <!-- <script type="text/javascript" src="../../script/ao_module.js"></script> -->
  10. </head>
  11. <body>
  12. <div class="ui container">
  13. <div class="ui basic segment">
  14. <div class="ui header">
  15. <i class="users icon"></i>
  16. <div class="content">
  17. Group Permissions
  18. <div class="sub header">Manage group permission and access right</div>
  19. </div>
  20. </div>
  21. <button class="ui primary small button" onclick="newgroupInterface();">
  22. <i class="add icon"></i>New Group
  23. </button>
  24. <button id="editGroupButton" class="ui small disabled button" onclick="openEditWindow();">
  25. Edit
  26. </button>
  27. <button id="removeGroupButton" class="ui small negative disabled right floated button" onclick="removeGroup();">
  28. Remove
  29. </button>
  30. </div>
  31. <table class="ui very basic celled table">
  32. <thead>
  33. <tr>
  34. <th>Group Name</th>
  35. <th>Access Permission</th>
  36. <th>Admin Privileges</th>
  37. <th>Default Storage Quota</th>
  38. <th>Select</th>
  39. </tr>
  40. </thead>
  41. <tbody id="groupList" >
  42. <tr>
  43. <td>administrator</td>
  44. <td>All Modules (Administrator)</td>
  45. <td>
  46. <div class="ui checkbox">
  47. <input type="radio" name="selectUser" onchange="enableEdit(this);">
  48. <label></label>
  49. </div>
  50. </td>
  51. </tr>
  52. </tbody>
  53. </table>
  54. </div>
  55. <script>
  56. var groupPermissionInfo = [];
  57. var currentSelectedGroup = "";
  58. loadGroupList();
  59. function loadGroupList(){
  60. $.get("../../system/permission/listgroup?showper=true",function(data){
  61. $("#groupList").html("");
  62. $("#editGroupButton").addClass("disabled");
  63. $("#removeGroupButton").addClass('disabled');
  64. if (data.error !== undefined){
  65. alert(data.error);
  66. }else{
  67. for (const [key, value] of Object.entries(data)) {
  68. //Check for module list
  69. var accessPermission = "No Module Accessible";
  70. if (value[0].includes("*")){
  71. accessPermission = "All Modules (Administrator)";
  72. }else{
  73. accessPermission = '<div class="ui bulleted list">';
  74. for (var i =0; i < value[0].length; i++){
  75. accessPermission += '<div class="item">' + value[0][i] + '</div>';
  76. }
  77. accessPermission += '</div>'
  78. }
  79. //Check for admin permission
  80. var isAdminIcon = "<i class='red remove icon'></i>"
  81. if (value[1] == true){
  82. isAdminIcon = "<i class='green checkmark icon'></i>"
  83. }
  84. //Check for storage quota
  85. var quota = bytesToSize(value[2]);
  86. if (value[2] == 0){
  87. quota = "Read Only";
  88. }else if (value[2] == -1){
  89. quota = "Unlimited";
  90. }
  91. $("#groupList").append(`
  92. <tr>
  93. <td>${key}</td>
  94. <td>${accessPermission}</td>
  95. <td>${isAdminIcon}</td>
  96. <td>${quota}</td>
  97. <td>
  98. <div class="ui checkbox">
  99. <input type="radio" name="selectUser" value="${key}" onchange="enableEdit(this);">
  100. <label></label>
  101. </div>
  102. </td>
  103. </tr>
  104. `);
  105. }
  106. groupPermissionInfo = data;
  107. }
  108. });
  109. }
  110. function openEditWindow(){
  111. ao_module_newfw({
  112. url: "SystemAO/users/editgroup.html#" + encodeURIComponent(JSON.stringify(currentSelectedGroup)),
  113. width: 560,
  114. height: 768,
  115. appicon: "SystemAO/users/img/users-white.svg",
  116. title: "Edit User Group",
  117. parent: ao_module_windowID,
  118. callback: "confirmCreateHandler"
  119. });
  120. }
  121. function bytesToSize(bytes) {
  122. var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
  123. if (bytes == 0) return '0 Byte';
  124. var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
  125. return Math.round(bytes / Math.pow(1024, i), 2) + ' ' + sizes[i];
  126. }
  127. function enableEdit(obj){
  128. //console.log($(obj).val());
  129. $("#editGroupButton").removeClass('disabled');
  130. if ($(obj).val() != "administrator"){
  131. $("#removeGroupButton").removeClass('disabled');
  132. }else{
  133. $("#removeGroupButton").addClass('disabled');
  134. }
  135. currentSelectedGroup = $(obj).val();
  136. }
  137. function newgroupInterface(){
  138. ao_module_newfw({
  139. url: "SystemAO/users/newgroup.html",
  140. width: 560,
  141. height: 768,
  142. appicon: "SystemAO/users/img/users-white.svg",
  143. title: "Create User Group",
  144. parent: ao_module_windowID,
  145. callback: "confirmCreateHandler"
  146. });
  147. }
  148. //Finished adding group. Update grouplist
  149. function confirmCreateHandler(data){
  150. if (data){
  151. loadGroupList();
  152. }
  153. }
  154. //Remove the selected group
  155. function removeGroup(){
  156. if (currentSelectedGroup == "administrator"){
  157. //This group cannot be removed
  158. alert("You cannot remove the administrator group.")
  159. }else{
  160. //Remove the selected group
  161. if (confirm("Confirm removing group: " + currentSelectedGroup + " ?")){
  162. $.ajax({
  163. url: "../../system/permission/delgroup",
  164. data: {groupname: currentSelectedGroup},
  165. method: "GET",
  166. success: function(data){
  167. if (data.error !== undefined){
  168. alert(data.error);
  169. }else{
  170. //Remove succeed. refresh list
  171. loadGroupList();
  172. }
  173. }
  174. })
  175. }
  176. }
  177. }
  178. </script>
  179. </body>
  180. </html>