editgroup.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. <html>
  2. <head>
  3. <title>Edit Group</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.css">
  7. <link rel="stylesheet" href="../../script/ao.css">
  8. <script type="text/javascript" src="../../script/jquery.min.js"></script>
  9. <script type="text/javascript" src="../../script/semantic/semantic.js"></script>
  10. <script type="text/javascript" src="../../script/ao_module.js"></script>
  11. <style>
  12. body{
  13. background-color:white;
  14. }
  15. .themebackground{
  16. background-color:#588ce0 !important;
  17. color:white !important;
  18. background-image: url("/img/public/slate.png") !important;
  19. background-repeat: no-repeat !important;
  20. background-attachment: fixed !important;
  21. }
  22. .ui.padded.slate{
  23. width: 100%;
  24. display: flex;
  25. flex-direction: column;
  26. padding: 4em;
  27. }
  28. .ui.heading.slate{
  29. align-items: flex-start;
  30. }
  31. .ui.slate .header:not(.ui):not(.sub):not(.item){
  32. font-size: 1.6em;
  33. line-height: 1.42857em;
  34. font-weight: 500;
  35. display: block;
  36. }
  37. .required{
  38. color:red;
  39. }
  40. .actionbtns{
  41. text-align:right;
  42. }
  43. </style>
  44. </head>
  45. <body>
  46. <div class="ui heading fluid padded slate themebackground" >
  47. <span class="header">
  48. <i class="users icon"></i> Edit Users Group</span>
  49. <span class="description">Fill in the following group information to proceed.</span>
  50. </div>
  51. <br>
  52. <div class="ui container">
  53. <div id="confirmUpdate" class="ui green inverted segment" style="display:none; margin-top:12px;">
  54. <i class="checkmark icon"></i> Group Permissions Updated
  55. </div>
  56. <div class="ui horizontal form">
  57. <div class="field">
  58. <label>Group Name <span class="required">(READ ONLY)</span></label>
  59. <input id="groupname" class="disabled" type="text" readonly="true">
  60. </div>
  61. <div class="two fields">
  62. <div class="field">
  63. <label>Default Storage Quota <span class="required">*</span></label>
  64. <input id="quota" type="text" value="15">
  65. </div>
  66. <div class="field">
  67. <label>Unit <span class="required">*</span></label>
  68. <select class="ui fluid search dropdown" id="unit">
  69. <option value="1">Bytes</option>
  70. <option value="1024">KB</option>
  71. <option value="1048576">MB</option>
  72. <option value="1073741824">GB</option>
  73. <option value="1099511627776">TB</option>
  74. <option value="1125899906842624">PB</option>
  75. </select>
  76. </div>
  77. </div>
  78. <div class="field">
  79. <label>Default Interface Module <span class="required">*</span></label>
  80. <div class="ui fluid selection dropdown">
  81. <input type="hidden" name="dim">
  82. <i class="dropdown icon"></i>
  83. <div class="default text">Select Interface Module</div>
  84. <div class="menu" id="interfaceModuleList">
  85. </div>
  86. </div>
  87. <small>The module that the user land once they logged in. Default Desktop</small>
  88. </div>
  89. <div class="field">
  90. <label>Allow Access <span class="required">*</span></label>
  91. <select id="allowAccessList" multiple="" class="ui fluid dropdown">
  92. </select>
  93. <small>Allow this user group to access the selected modules and their APIs.</small>
  94. </div>
  95. <div class="field">
  96. <div class="ui checkbox">
  97. <input id="setAsAdmin" type="checkbox" tabindex="0" class="">
  98. <label>Assign Administrator Privileges to Group</label>
  99. </div>
  100. </div>
  101. <div class="ui divider"></div>
  102. <table class="ui celled striped unstackable table">
  103. <thead>
  104. <tr>
  105. <th >#</th>
  106. <th>Module Name</th>
  107. </tr>
  108. </thead>
  109. <tbody id="selectedModuleList">
  110. </tbody>
  111. </table>
  112. <div class="ui divider"></div>
  113. <div align="right">
  114. <button class="ui primary button" onclick="updateGroup();">Update</button>
  115. <button id="cancelbtn" class="ui button" onclick="cancel();">Close</button>
  116. </div>
  117. <div id="errorbox" class="ui inverted red segment" style="display:none;">
  118. <p><i class="remove icon"></i><span class="errormessage"></span></p>
  119. </div>
  120. </div>
  121. <br><br>
  122. </div>
  123. <script>
  124. var selectedModules = [];
  125. var moduleList = [];
  126. if (window.location.hash.length == 0){
  127. //Invalid use of editor
  128. window.location.href = "../closeTabInsturction.html";
  129. }
  130. var targetUserGroup = window.location.hash.substr(1);
  131. targetUserGroup = JSON.parse(decodeURIComponent(targetUserGroup));
  132. var originalGroupData;
  133. function bytesToSize(bytes) {
  134. var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB'];
  135. if (bytes == 0) return '0 Byte';
  136. var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
  137. return [bytes / Math.pow(1024, i), sizes[i]];
  138. }
  139. //Init functions
  140. initModuleList(function(){
  141. //Set the contents of the selector to the current group one
  142. $('.ui.checkbox').checkbox();
  143. $.ajax({
  144. url: "../../system/permission/editgroup?list=true",
  145. data: {groupname: targetUserGroup},
  146. success: function(data){
  147. console.log(data);
  148. originalGroupData = data;
  149. if (data.error !== undefined){
  150. alert(data.error);
  151. }else{
  152. $("#groupname").val(data.Name);
  153. $("#interfaceModuleList").parent().dropdown("set selected",data.DefaultInterfaceModule);
  154. //Set accessable module list
  155. if (data.AccessibleModules.length > 0 && data.AccessibleModules[0] == "*"){
  156. $("#allowAccessList").parent().hide();
  157. $("#allowAccessList").parent().after("<p>This account has been set to have all permissions to all modules</p>");
  158. selectedModules = moduleList;
  159. renderSelectedModuleList();
  160. }else{
  161. $("#allowAccessList").dropdown("set selected",data.AccessibleModules);
  162. }
  163. //Set storage quota
  164. var defaultStorage = bytesToSize(data.DefaultStorageQuota);
  165. if (data.DefaultStorageQuota == -1){
  166. defaultStorage[0] = -1;
  167. }
  168. if (data.Quota == -1){
  169. $("#quota").val(-1);
  170. }else{
  171. $("#quota").val(defaultStorage[0]);
  172. $("#unit").dropdown("set selected",defaultStorage[1])
  173. }
  174. //Check admin checkbox
  175. if (data.IsAdmin == true){
  176. $("#setAsAdmin").parent().checkbox("check");
  177. }else{
  178. $("#setAsAdmin").parent().checkbox("uncheck");
  179. }
  180. }
  181. }
  182. })
  183. });
  184. $(".ui.dropdown").dropdown();
  185. $("#unit").dropdown("set selected","GB");
  186. function updateGroup(){
  187. var groupname = originalGroupData.Name;
  188. //Continue to create usergroup
  189. targetModuleList = [];
  190. if (originalGroupData.AccessibleModules[0] == "*"){
  191. //Continue to use * as the accessable modules
  192. targetModuleList = originalGroupData.AccessibleModules;
  193. }else{
  194. for (var i =0; i < selectedModules.length; i++){
  195. targetModuleList.push(selectedModules[i].Name);
  196. }
  197. }
  198. var defaultStorageSize = parseFloat($("#quota").val()) * $("#unit").val();
  199. if (isNaN(defaultStorageSize)){
  200. $("#quota").parent().addClass("error");
  201. return
  202. }else{
  203. $("#quota").parent().removeClass("error");
  204. }
  205. if ($("#quota").val() == -1){
  206. defaultStorageSize = -1;
  207. }
  208. var interfaceModule = $("#interfaceModuleList").parent().dropdown("get value");
  209. if (interfaceModule == ""){
  210. interfaceModule = "Desktop";
  211. }
  212. //Send Request to server side
  213. $.ajax({
  214. url: "../../system/permission/editgroup",
  215. data: {
  216. "groupname": groupname,
  217. "permission": JSON.stringify(targetModuleList),
  218. "isAdmin": $("#setAsAdmin").is(":checked"),
  219. "defaultQuota": defaultStorageSize,
  220. "interfaceModule": interfaceModule,
  221. },
  222. traditional: true,
  223. method: "POST",
  224. success: function(data){
  225. if (data.error !== undefined){
  226. $("#errorbox").slideDown("fast");
  227. $("#errorbox").find(".errormessage").text(data.error);
  228. }else{
  229. $("#confirmUpdate").stop().finish().slideDown("fast").delay(3000).slideUp("fast");
  230. ao_module_parentCallback(true);
  231. window.scrollTo(0,0);
  232. //ao_module_close();
  233. }
  234. }
  235. })
  236. }
  237. function initModuleList(callback=undefined){
  238. $("#interfaceModuleList").html("");
  239. var firstInterfaceModule = null;
  240. $.get("../../system/modules/list",function(data){
  241. if (data.error !== undefined){
  242. alert(data.error);
  243. }else{
  244. for (var i =0; i < data.length; i++){
  245. if (data[i].StartDir !== "" && data[i].Group != "Interface Module"){
  246. $("#allowAccessList").append(`<option value="${data[i].Name}" icon="${data[i].IconPath}">${data[i].Name}</option>`);
  247. }else if (data[i].Group == "Interface Module"){
  248. //Add to interface module list
  249. $("#interfaceModuleList").append(`
  250. <div class="item" data-value="${data[i].Name}">
  251. <img class="ui mini avatar image" style="border-radius: 0px !important;" src="../../${data[i].IconPath}">
  252. ${data[i].Name}
  253. </div>
  254. `);
  255. if (firstInterfaceModule == null){
  256. firstInterfaceModule = data[i].Name;
  257. }
  258. }else{
  259. //Utlities modules. Always allow access
  260. }
  261. }
  262. //Select the first interface modules
  263. $("#interfaceModuleList").parent().dropdown();
  264. $("#interfaceModuleList").parent().dropdown("set selected",firstInterfaceModule);
  265. moduleList = data;
  266. if (callback !== undefined){
  267. //Handle callback events
  268. callback();
  269. }
  270. }
  271. });
  272. $("#allowAccessList").on("change", function(e){
  273. var currentSelected = $(this).val();
  274. selectedModules = [];
  275. moduleList.forEach(mod => {
  276. if (currentSelected.includes(mod.Name)){
  277. selectedModules.push(mod);
  278. }
  279. });
  280. renderSelectedModuleList();
  281. });
  282. }
  283. renderSelectedModuleList();
  284. function renderSelectedModuleList(){
  285. $("#selectedModuleList").html("");
  286. for (var i = 0; i < selectedModules.length; i++){
  287. $("#selectedModuleList").append(`<tr>
  288. <td class="collapsing"><img class="ui mini image" src="../../${selectedModules[i].IconPath}"/></td>
  289. <td>${selectedModules[i].Name}</td>
  290. </tr>`);
  291. }
  292. if (selectedModules.length == 0){
  293. $("#selectedModuleList").append(`<tr>
  294. <td class="collapsing"><img class="ui mini image" src="img/nomodule.png"></img></td>
  295. <td>No Module Selected</td>
  296. </tr>`);
  297. }
  298. }
  299. function cancel(){
  300. ao_module_close();
  301. }
  302. </script>
  303. </body>
  304. </html>