newgroup.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. <html>
  2. <head>
  3. <title>Create 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> Create 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 class="ui horizontal form">
  54. <div class="field">
  55. <label>Group Name <span class="required">*</span></label>
  56. <input id="groupname" type="text">
  57. </div>
  58. <div class="two fields">
  59. <div class="field">
  60. <label>Default Storage Quota <span class="required">*</span></label>
  61. <input id="quota" type="text" value="15">
  62. </div>
  63. <div class="field">
  64. <label>Unit <span class="required">*</span></label>
  65. <select class="ui fluid search dropdown" id="unit">
  66. <option value="1">Bytes</option>
  67. <option value="1024">KB</option>
  68. <option value="1048576">MB</option>
  69. <option value="1073741824">GB</option>
  70. <option value="1099511627776">TB</option>
  71. <option value="1125899906842624">PB</option>
  72. </select>
  73. </div>
  74. </div>
  75. <div class="field">
  76. <label>Default Interface Module <span class="required">*</span></label>
  77. <div class="ui fluid selection dropdown">
  78. <input type="hidden" name="dim">
  79. <i class="dropdown icon"></i>
  80. <div class="default text">Select Interface Module</div>
  81. <div class="menu" id="interfaceModuleList">
  82. </div>
  83. </div>
  84. <small>The module that the user land once they logged in. Default Desktop</small>
  85. </div>
  86. <div class="field">
  87. <label>Allow Access <span class="required">*</span></label>
  88. <select id="allowAccessList" multiple="" class="ui fluid dropdown">
  89. </select>
  90. <small>Allow this user group to access the selected modules and their APIs.</small>
  91. </div>
  92. <div class="field">
  93. <div class="ui checkbox">
  94. <input id="setAsAdmin" type="checkbox" tabindex="0" class="">
  95. <label>Assign Administrator Privileges to Group</label>
  96. </div>
  97. </div>
  98. <div class="ui divider"></div>
  99. <table class="ui celled striped compact unstackable table">
  100. <thead>
  101. <tr>
  102. <th >#</th>
  103. <th>Module Name</th>
  104. </tr>
  105. </thead>
  106. <tbody id="selectedModuleList">
  107. </tbody>
  108. </table>
  109. <div class="ui divider"></div>
  110. <div align="right">
  111. <button class="ui primary button" onclick="createGroup();">Create</button>
  112. <button id="cancelbtn" class="ui button" onclick="cancel();">Cancel</button>
  113. </div>
  114. <div id="errorbox" class="ui inverted red segment" style="display:none;">
  115. <p><i class="remove icon"></i><span class="errormessage"></span></p>
  116. </div>
  117. </div>
  118. <br><br>
  119. </div>
  120. <script>
  121. var selectedModules = [];
  122. var moduleList = [];
  123. //Init functions
  124. initModuleList();
  125. $(".ui.dropdown").dropdown();
  126. $("#unit").dropdown("set selected","GB");
  127. function createGroup(){
  128. var groupname = $("#groupname").val();
  129. if (groupname == ""){
  130. $("#groupname").parent().removeClass("success").addClass("error");
  131. return
  132. }else{
  133. $("#groupname").parent().removeClass("error").addClass("success");
  134. }
  135. //Continue to create usergroup
  136. targetModuleList = [];
  137. for (var i =0; i < selectedModules.length; i++){
  138. targetModuleList.push(selectedModules[i].Name);
  139. }
  140. var defaultStorageSize = parseFloat($("#quota").val()) * $("#unit").val();
  141. if (isNaN(defaultStorageSize)){
  142. $("#quota").parent().addClass("error");
  143. return
  144. }else{
  145. $("#quota").parent().removeClass("error");
  146. }
  147. var interfaceModule = $("#interfaceModuleList").parent().dropdown("get value");
  148. if (interfaceModule == ""){
  149. interfaceModule = "Desktop";
  150. }
  151. //Send Request to server side
  152. $.ajax({
  153. url: "../../system/permission/newgroup",
  154. data: {
  155. "groupname": groupname,
  156. "permission": JSON.stringify(targetModuleList),
  157. "isAdmin": $("#setAsAdmin").is(":checked"),
  158. "defaultQuota": defaultStorageSize,
  159. "interfaceModule": interfaceModule,
  160. },
  161. traditional: true,
  162. method: "POST",
  163. success: function(data){
  164. if (data.error !== undefined){
  165. $("#errorbox").slideDown("fast");
  166. $("#errorbox").find(".errormessage").text(data.error);
  167. }else{
  168. ao_module_parentCallback(true);
  169. ao_module_close();
  170. }
  171. }
  172. })
  173. }
  174. function initModuleList(){
  175. $("#interfaceModuleList").html("");
  176. var firstInterfaceModule = null;
  177. $.get("../../system/modules/list",function(data){
  178. if (data.error !== undefined){
  179. alert(data.error);
  180. }else{
  181. for (var i =0; i < data.length; i++){
  182. if (data[i].StartDir !== "" && data[i].Group != "Interface Module"){
  183. $("#allowAccessList").append(`<option value="${data[i].Name}" icon="${data[i].IconPath}">${data[i].Name}</option>`);
  184. }else if (data[i].Group == "Interface Module"){
  185. //Add to interface module list
  186. $("#interfaceModuleList").append(`
  187. <div class="item" data-value="${data[i].Name}">
  188. <img class="ui mini avatar image" style="border-radius: 0px !important;" src="../../${data[i].IconPath}">
  189. ${data[i].Name}
  190. </div>
  191. `);
  192. if (firstInterfaceModule == null){
  193. firstInterfaceModule = data[i].Name;
  194. }
  195. }else{
  196. //Utlities modules. Always allow access
  197. }
  198. }
  199. //Select the first interface modules
  200. $("#interfaceModuleList").parent().dropdown();
  201. $("#interfaceModuleList").parent().dropdown("set selected",firstInterfaceModule);
  202. moduleList = data;
  203. }
  204. });
  205. $("#allowAccessList").on("change", function(e){
  206. var currentSelected = $(this).val();
  207. selectedModules = [];
  208. moduleList.forEach(mod => {
  209. if (currentSelected.includes(mod.Name)){
  210. selectedModules.push(mod);
  211. }
  212. });
  213. renderSelectedModuleList();
  214. });
  215. }
  216. renderSelectedModuleList();
  217. function renderSelectedModuleList(){
  218. $("#selectedModuleList").html("");
  219. for (var i = 0; i < selectedModules.length; i++){
  220. $("#selectedModuleList").append(`<tr>
  221. <td class="collapsing"><img class="ui mini image" src="../../${selectedModules[i].IconPath}"/></td>
  222. <td>${selectedModules[i].Name}</td>
  223. </tr>`);
  224. }
  225. if (selectedModules.length == 0){
  226. $("#selectedModuleList").append(`<tr>
  227. <td class="collapsing"><img class="ui mini image" src="img/nomodule.png"></img></td>
  228. <td>No Module Selected</td>
  229. </tr>`);
  230. }
  231. }
  232. function cancel(){
  233. ao_module_close();
  234. }
  235. </script>
  236. </body>
  237. </html>