PermissionsWidget.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /*##############################################################################
  2. # HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. ############################################################################## */
  16. define([
  17. "dojo/_base/declare",
  18. "dojo/_base/lang",
  19. "dojo/i18n",
  20. "dojo/i18n!./nls/hpcc",
  21. "dijit/registry",
  22. "dgrid/OnDemandGrid",
  23. "dgrid/Keyboard",
  24. "dgrid/Selection",
  25. "dgrid/tree",
  26. "dgrid/editor",
  27. "dgrid/extensions/ColumnResizer",
  28. "dgrid/extensions/DijitRegistry",
  29. "hpcc/GridDetailsWidget",
  30. "hpcc/ws_access",
  31. "hpcc/ESPUtil"
  32. ], function (declare, lang, i18n, nlsHPCC,
  33. registry,
  34. OnDemandGrid, Keyboard, Selection, tree, editor, ColumnResizer, DijitRegistry,
  35. GridDetailsWidget, WsAccess, ESPUtil) {
  36. return declare("PermissionsWidget", [GridDetailsWidget], {
  37. i18n: nlsHPCC,
  38. gridTitle: nlsHPCC.title_UserPermissions,
  39. idProperty: "__hpcc_id",
  40. // Hitched Actions ---
  41. _onRefresh: function (args) {
  42. this.grid.refresh();
  43. },
  44. // Implementation ---
  45. init: function (params) {
  46. if (this.inherited(arguments))
  47. return;
  48. this.store = WsAccess.CreatePermissionsStore(params.groupname, params.username);
  49. this.grid.setStore(this.store);
  50. this._refreshActionState();
  51. },
  52. createGrid: function (domID) {
  53. var context = this;
  54. var retVal = new declare([OnDemandGrid, Keyboard, Selection, ColumnResizer, DijitRegistry, ESPUtil.GridHelper])({
  55. store: this.store,
  56. columns: {
  57. DisplayName: tree({
  58. label: this.i18n.Resource,
  59. formatter: function (_name, row) {
  60. return _name;
  61. }
  62. }),
  63. allow_access: editor({
  64. width: 54,
  65. editor: "checkbox",
  66. autoSave: true,
  67. canEdit: function (object, value) { return object.__hpcc_type != "Permission"; },
  68. renderHeaderCell: function (node) {
  69. node.innerHTML = context.i18n.AllowAccess;
  70. }
  71. }),
  72. allow_read: editor({
  73. width: 54,
  74. editor: "checkbox",
  75. autoSave: true,
  76. canEdit: function (object, value) { return object.__hpcc_type != "Permission"; },
  77. renderHeaderCell: function (node) {
  78. node.innerHTML = context.i18n.AllowRead;
  79. }
  80. }),
  81. allow_write: editor({
  82. width: 54,
  83. editor: "checkbox",
  84. autoSave: true,
  85. canEdit: function (object, value) { return object.__hpcc_type != "Permission"; },
  86. renderHeaderCell: function (node) {
  87. node.innerHTML = context.i18n.AllowWrite;
  88. }
  89. }),
  90. allow_full: editor({
  91. width: 54,
  92. editor: "checkbox",
  93. autoSave: true,
  94. canEdit: function (object, value) { return object.__hpcc_type != "Permission"; },
  95. renderHeaderCell: function (node) {
  96. node.innerHTML = context.i18n.AllowFull;
  97. }
  98. }),
  99. padding: {
  100. width:20,
  101. label: " "
  102. },
  103. deny_access: editor({
  104. width: 54,
  105. editor: "checkbox",
  106. autoSave: true,
  107. canEdit: function (object, value) { return object.__hpcc_type != "Permission"; },
  108. renderHeaderCell: function (node) {
  109. node.innerHTML = context.i18n.DenyAccess
  110. }
  111. }),
  112. deny_read: editor({
  113. width: 54,
  114. editor: "checkbox",
  115. autoSave: true,
  116. canEdit: function (object, value) { return object.__hpcc_type != "Permission"; },
  117. renderHeaderCell: function (node) {
  118. node.innerHTML = context.i18n.DenyRead
  119. }
  120. }),
  121. deny_write: editor({
  122. width: 54,
  123. editor: "checkbox",
  124. autoSave: true,
  125. canEdit: function (object, value) { return object.__hpcc_type != "Permission"; },
  126. renderHeaderCell: function (node) {
  127. node.innerHTML = context.i18n.DenyWrite
  128. }
  129. }),
  130. deny_full: editor({
  131. width: 54,
  132. editor: "checkbox",
  133. autoSave: true,
  134. canEdit: function (object, value) { return object.__hpcc_type != "Permission"; },
  135. renderHeaderCell: function (node) {
  136. node.innerHTML = context.i18n.DenyFull
  137. }
  138. }),
  139. }
  140. }, domID);
  141. retVal.on("dgrid-datachange", function (evt) {
  142. evt.preventDefault();
  143. context.calcPermissionState(evt.cell.column.field, evt.value, evt.cell.row.data);
  144. evt.grid.store.putChild(evt.cell.row.data);
  145. });
  146. return retVal;
  147. },
  148. calcPermissionState: function(field, value, row) {
  149. switch (field) {
  150. case "allow_access":
  151. row.allow_full = value && row.allow_read && row.allow_write;
  152. if (value)
  153. this.calcPermissionState("deny_access", false, row);
  154. break;
  155. case "allow_read":
  156. row.allow_full = row.allow_access && value && row.allow_write;
  157. if (value)
  158. this.calcPermissionState("deny_read", false, row);
  159. break;
  160. case "allow_write":
  161. row.allow_full = row.allow_access && row.allow_read && value;
  162. if (value)
  163. this.calcPermissionState("deny_write", false, row);
  164. break;
  165. case "allow_full":
  166. row.allow_access = value;
  167. row.allow_read = value;
  168. row.allow_write = value;
  169. if (value)
  170. this.calcPermissionState("deny_full", false, row);
  171. break;
  172. case "deny_access":
  173. row.deny_full = value && row.deny_read && row.deny_write;
  174. if (value)
  175. this.calcPermissionState("allow_access", false, row);
  176. break;
  177. case "deny_read":
  178. row.deny_full = row.deny_access && value && row.deny_write;
  179. if (value)
  180. this.calcPermissionState("allow_read", false, row);
  181. break;
  182. case "deny_write":
  183. row.deny_full = row.deny_access && row.deny_read && value;
  184. if (value)
  185. this.calcPermissionState("allow_write", false, row);
  186. break;
  187. case "deny_full":
  188. row.deny_access = value;
  189. row.deny_read = value;
  190. row.deny_write = value;
  191. if (value)
  192. this.calcPermissionState("allow_full", false, row);
  193. break;
  194. }
  195. row[field] = value;
  196. },
  197. refreshActionState: function (selection) {
  198. registry.byId(this.id + "Open").set("disabled", true);
  199. }
  200. });
  201. });