modx.tree.resource.group.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. /**
  2. * Generates the Resource Group Tree in Ext
  3. *
  4. * @class MODx.tree.ResourceGroup
  5. * @extends MODx.tree.Tree
  6. * @param {Object} config An object of options.
  7. * @xtype modx-tree-resourcegroup
  8. */
  9. MODx.tree.ResourceGroup = function(config) {
  10. config = config || {};
  11. Ext.applyIf(config,{
  12. title: _('resource_groups')
  13. ,url: MODx.config.connector_url
  14. ,action: 'security/resourcegroup/getnodes'
  15. ,root_id: '0'
  16. ,root_name: _('resource_groups')
  17. ,enableDrag: false
  18. ,enableDrop: true
  19. ,ddAppendOnly: true
  20. ,useDefaultToolbar: true
  21. ,baseParams: {
  22. limit: 0
  23. }
  24. ,tbar: ['->', {
  25. text: _('resource_group_create')
  26. ,cls: 'primary-button'
  27. ,scope: this
  28. ,handler: this.createResourceGroup
  29. }]
  30. });
  31. MODx.tree.ResourceGroup.superclass.constructor.call(this,config);
  32. };
  33. Ext.extend(MODx.tree.ResourceGroup,MODx.tree.Tree,{
  34. forms: {}
  35. ,windows: {}
  36. ,stores: {}
  37. ,getMenu: function() {
  38. var n = this.cm.activeNode;
  39. var m = [];
  40. if (n.attributes.type == 'modResourceGroup') {
  41. m.push({
  42. text: _('resource_group_create')
  43. ,handler: this.createResourceGroup
  44. });
  45. m.push('-');
  46. m.push({
  47. text: _('resource_group_update')
  48. ,handler: this.updateResourceGroup
  49. });
  50. m.push('-');
  51. m.push({
  52. text: _('resource_group_remove')
  53. ,handler: this.removeResourceGroup
  54. });
  55. } else if (n.attributes.type == 'modResource' || n.attributes.type == 'modDocument') {
  56. m.push({
  57. text: _('resource_group_access_remove')
  58. ,handler: this.removeResource
  59. });
  60. }
  61. return m;
  62. }
  63. ,updateResourceGroup: function(itm,e) {
  64. var r = this.cm.activeNode.attributes.data;
  65. if (!this.windows.updateResourceGroup) {
  66. this.windows.updateResourceGroup = MODx.load({
  67. xtype: 'modx-window-resourcegroup-update'
  68. ,record: r
  69. ,listeners: {
  70. 'success': {fn:this.refresh,scope:this}
  71. }
  72. });
  73. }
  74. this.windows.updateResourceGroup.reset();
  75. this.windows.updateResourceGroup.setValues(r);
  76. this.windows.updateResourceGroup.show(e.target);
  77. }
  78. ,removeResource: function(item,e) {
  79. var n = this.cm.activeNode;
  80. var resourceId = n.id.split('_'); resourceId = resourceId[1];
  81. var resourceGroupId = n.parentNode.id.substr(2).split('_'); resourceGroupId = resourceGroupId[1];
  82. MODx.msg.confirm({
  83. text: _('resource_group_access_remove_confirm')
  84. ,url: this.config.url
  85. ,params: {
  86. action: 'security/resourcegroup/removeResource'
  87. ,resource: resourceId
  88. ,resourceGroup: resourceGroupId
  89. }
  90. ,listeners: {
  91. 'success': {fn:this.refresh,scope:this}
  92. }
  93. });
  94. }
  95. ,removeResourceGroup: function(item,e) {
  96. var n = this.cm.activeNode;
  97. var id = n.id.substr(2).split('_'); id = id[1];
  98. MODx.msg.confirm({
  99. text: _('resource_group_remove_confirm')
  100. ,url: this.config.url
  101. ,params: {
  102. action: 'security/resourcegroup/remove'
  103. ,id: id
  104. }
  105. ,listeners: {
  106. 'success': {fn:this.refresh,scope:this}
  107. }
  108. });
  109. }
  110. ,createResourceGroup: function(itm,e) {
  111. if (!this.windows.create) {
  112. this.windows.create = MODx.load({
  113. xtype: 'modx-window-resourcegroup-create'
  114. ,listeners: {
  115. 'success': {fn:this.refresh,scope:this}
  116. }
  117. });
  118. }
  119. this.windows.create.show(e.target);
  120. }
  121. ,_handleDrop: function(e){
  122. var n = e.dropNode;
  123. if(this.isDocCopy(e,n)) {
  124. var copy = new Ext.tree.TreeNode(
  125. Ext.apply({leaf: true,allowDelete:true,expanded:true}, n.attributes)
  126. );
  127. copy.loader = undefined;
  128. if(e.target.attributes.options){
  129. e.target = this.createDGD(e.target, copy.text);
  130. }
  131. e.dropNode = copy;
  132. return true;
  133. }
  134. return false;
  135. }
  136. ,isDocCopy: function(e, n) {
  137. var a = e.target.attributes;
  138. var docid = n.attributes.id.split('_'); docid = 'n_'+docid[1];
  139. if (e.target.findChild('id',docid) !== null) { return false; }
  140. if (n.attributes.type != 'modResource' && n.attributes.type != 'modDocument') { return false; }
  141. if (e.point != 'append') { return false; }
  142. if (a.type != 'modResourceGroup') { return false; }
  143. return a.leaf !== true;
  144. }
  145. ,createDGD: function(n, text){
  146. var cnode = this.getNodeById(n.attributes.cmpId);
  147. var node = new Ext.tree.TreeNode({
  148. text: text
  149. ,cmpId:cnode.id
  150. ,leaf: true
  151. ,allowDelete:true
  152. ,allowEdit:true
  153. ,id:this._guid('o-')
  154. });
  155. cnode.childNodes[2].appendChild(node);
  156. cnode.childNodes[2].expand(false, false);
  157. return node;
  158. }
  159. ,_handleDrag: function(dropEvent) {
  160. Ext.Msg.show({
  161. title: _('please_wait')
  162. ,msg: _('saving')
  163. ,width: 240
  164. ,progress:true
  165. ,closable:false
  166. });
  167. MODx.util.Progress.reset();
  168. for(var i = 1; i < 20; i++) {
  169. setTimeout('MODx.util.Progress.time('+i+','+MODx.util.Progress.id+')',i*1000);
  170. }
  171. MODx.Ajax.request({
  172. url: this.config.url
  173. ,scope: this
  174. ,params: {
  175. resource: dropEvent.dropNode.attributes.id
  176. ,resourceGroup: dropEvent.target.attributes.id
  177. ,action: 'security/resourcegroup/updateResourcesIn'
  178. }
  179. ,listeners: {
  180. 'success': {fn: function(r,o) {
  181. MODx.util.Progress.reset();
  182. Ext.Msg.hide();
  183. if (!r.success) {
  184. Ext.Msg.alert(_('error'),r.message);
  185. return false;
  186. }
  187. this.refresh();
  188. return true;
  189. },scope:this}
  190. }
  191. });
  192. }
  193. });
  194. Ext.reg('modx-tree-resource-group',MODx.tree.ResourceGroup);
  195. MODx.window.CreateResourceGroup = function(config) {
  196. config = config || {};
  197. this.ident = config.ident || 'modx-crgrp'+Ext.id();
  198. Ext.applyIf(config,{
  199. title: _('resource_group_create')
  200. ,id: this.ident
  201. // ,height: 150
  202. ,width: 600
  203. ,stateful: false
  204. ,url: MODx.config.connector_url
  205. ,action: 'security/resourcegroup/create'
  206. ,fields: [{
  207. fieldLabel: _('name')
  208. ,name: 'name'
  209. ,id: 'modx-'+this.ident+'-name'
  210. ,xtype: 'textfield'
  211. ,anchor: '100%'
  212. },{
  213. xtype: 'fieldset'
  214. ,collapsible: true
  215. ,collapsed: false
  216. ,title: _('resource_group_automatic_access')
  217. ,items: [{
  218. html: '<br /><p>'+_('resource_group_automatic_access_desc')+'</p>'
  219. ,cls: 'desc-under'
  220. },{
  221. xtype: 'textfield'
  222. ,name: 'access_contexts'
  223. ,fieldLabel: _('contexts')
  224. ,description: MODx.expandHelp ? '' : _('resource_group_access_contexts')
  225. ,id: this.ident+'-access-contexts'
  226. ,anchor: '100%'
  227. ,value: 'web'
  228. },{
  229. xtype: MODx.expandHelp ? 'label' : 'hidden'
  230. ,forId: this.ident+'-access-contexts'
  231. ,html: _('resource_group_access_contexts')
  232. ,cls: 'desc-under'
  233. },{
  234. layout: 'column'
  235. ,border: false
  236. ,defaults: {
  237. layout: 'form'
  238. ,labelAlign: 'top'
  239. ,anchor: '100%'
  240. ,border: false
  241. }
  242. ,items: [{
  243. columnWidth: .5
  244. ,items: [{
  245. boxLabel: _('resource_group_access_admin')
  246. ,description: _('resource_group_access_admin_desc')
  247. ,name: 'access_admin'
  248. ,id: this.ident+'-access-admin'
  249. ,xtype: 'checkbox'
  250. ,checked: false
  251. ,inputValue: 1
  252. ,anchor: '100%'
  253. },{
  254. xtype: MODx.expandHelp ? 'label' : 'hidden'
  255. ,forId: this.ident+'-access-admin'
  256. ,html: _('resource_group_access_admin_desc')
  257. ,cls: 'desc-under'
  258. },{
  259. boxLabel: _('resource_group_access_anon')
  260. ,description: _('resource_group_access_anon_desc')
  261. ,name: 'access_anon'
  262. ,id: this.ident+'-access-anon'
  263. ,xtype: 'checkbox'
  264. ,checked: false
  265. ,inputValue: 1
  266. ,anchor: '100%'
  267. },{
  268. xtype: MODx.expandHelp ? 'label' : 'hidden'
  269. ,forId: this.ident+'-access-anon'
  270. ,html: _('resource_group_access_anon_desc')
  271. ,cls: 'desc-under'
  272. }]
  273. },{
  274. columnWidth: .5
  275. ,items: [{
  276. boxLabel: _('resource_group_access_parallel')
  277. ,description: _('resource_group_access_parallel_desc')
  278. ,name: 'access_parallel'
  279. ,id: this.ident+'-access-parallel'
  280. ,xtype: 'checkbox'
  281. ,checked: false
  282. ,inputValue: 1
  283. ,anchor: '100%'
  284. },{
  285. xtype: MODx.expandHelp ? 'label' : 'hidden'
  286. ,forId: this.ident+'-access-parallel'
  287. ,html: _('resource_group_access_parallel_desc')
  288. ,cls: 'desc-under'
  289. },{
  290. fieldLabel: _('resource_group_access_ugs')
  291. ,description: _('resource_group_access_ugs_desc')
  292. ,name: 'access_usergroups'
  293. ,id: this.ident+'-access-usergroups'
  294. ,xtype: 'textfield'
  295. ,value: ''
  296. ,anchor: '100%'
  297. },{
  298. xtype: MODx.expandHelp ? 'label' : 'hidden'
  299. ,forId: this.ident+'-access-usergroups'
  300. ,html: _('resource_group_access_ugs_desc')
  301. ,cls: 'desc-under'
  302. }]
  303. }]
  304. }]
  305. }]
  306. });
  307. MODx.window.CreateResourceGroup.superclass.constructor.call(this,config);
  308. };
  309. Ext.extend(MODx.window.CreateResourceGroup,MODx.Window);
  310. Ext.reg('modx-window-resourcegroup-create',MODx.window.CreateResourceGroup);
  311. MODx.window.UpdateResourceGroup = function(config) {
  312. config = config || {};
  313. this.ident = config.ident || 'urgrp'+Ext.id();
  314. Ext.applyIf(config,{
  315. title: _('resource_group_update')
  316. ,id: this.ident
  317. // ,height: 150
  318. // ,width: 350
  319. ,url: MODx.config.connector_url
  320. ,action: 'security/resourcegroup/update'
  321. ,fields: [{
  322. name: 'id'
  323. ,xtype: 'hidden'
  324. ,id: 'modx-'+this.ident+'-id'
  325. },{
  326. fieldLabel: _('name')
  327. ,name: 'name'
  328. ,id: 'modx-'+this.ident+'-name'
  329. ,xtype: 'textfield'
  330. ,anchor: '100%'
  331. }]
  332. });
  333. MODx.window.UpdateResourceGroup.superclass.constructor.call(this,config);
  334. };
  335. Ext.extend(MODx.window.UpdateResourceGroup,MODx.Window);
  336. Ext.reg('modx-window-resourcegroup-update',MODx.window.UpdateResourceGroup);