modx.grid.source.access.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /**
  2. * Loads a grid of modAccessContexts.
  3. *
  4. * @class MODx.grid.AccessContext
  5. * @extends MODx.grid.Grid
  6. * @param {Object} config An object of options.
  7. * @xtype modx-grid-access-context
  8. */
  9. MODx.grid.MediaSourceAccess = function(config) {
  10. config = config || {};
  11. Ext.applyIf(config,{
  12. id: 'modx-grid-source-access'
  13. ,fields: ['id','target','target_name','principal_class','principal','principal_name','authority','authority_name','policy','policy_name','context_key']
  14. ,type: 'modAccessMediaSource'
  15. ,paging: true
  16. ,columns: [
  17. { header: _('user_group') ,dataIndex: 'principal_name' ,width: 120 }
  18. ,{ header: _('minimum_role') ,dataIndex: 'authority_name' ,width: 50 }
  19. ,{ header: _('policy') ,dataIndex: 'policy_name' ,width: 175 }
  20. ]
  21. ,tbar: [{
  22. text: _('source_access_add')
  23. ,cls: 'primary-button'
  24. ,scope: this
  25. ,handler: this.createAcl
  26. }]
  27. });
  28. MODx.grid.MediaSourceAccess.superclass.constructor.call(this,config);
  29. this.propRecord = Ext.data.Record.create(config.fields);
  30. };
  31. Ext.extend(MODx.grid.MediaSourceAccess,MODx.grid.LocalGrid,{
  32. combos: {}
  33. ,windows: {}
  34. ,createAcl: function(itm,e) {
  35. var r = {
  36. target: this.config.source
  37. ,principal_class: 'modUserGroup'
  38. };
  39. if (!this.windows.access_add) {
  40. this.windows.access_add = MODx.load({
  41. xtype: 'modx-window-source-access-create'
  42. ,record: r
  43. ,listeners: {
  44. 'success': {fn:function(vs) {
  45. var rec = new this.propRecord(vs);
  46. this.getStore().add(rec);
  47. },scope:this}
  48. }
  49. });
  50. }
  51. this.windows.access_add.fp.getForm().reset();
  52. this.windows.access_add.setValues(r);
  53. this.windows.access_add.show(e.target);
  54. }
  55. ,editAcl: function(itm,e) {
  56. var r = this.menu.record;
  57. Ext.applyIf(r,{
  58. source: r.target
  59. ,user_group: r.principal
  60. });
  61. if (!this.windows.update_acl) {
  62. this.windows.update_acl = MODx.load({
  63. xtype: 'modx-window-source-access-update'
  64. ,acl: r.id
  65. ,record: r
  66. ,listeners: {
  67. 'success': {fn:function(vs) {
  68. var s = this.getStore();
  69. var rec;
  70. try {
  71. rec = s.getAt(s.find('id',vs.id));
  72. } catch(e) {}
  73. if (rec) {
  74. for (var k in vs) {
  75. rec.set(k,vs[k]);
  76. }
  77. rec.commit();
  78. }
  79. },scope:this}
  80. }
  81. });
  82. }
  83. this.windows.update_acl.setValues(r);
  84. this.windows.update_acl.show(e.target);
  85. }
  86. ,removeAcl: function(itm,e) {
  87. MODx.msg.confirm({
  88. title: _('source_access_remove')
  89. ,text: _('source_access_remove_confirm')
  90. ,url: this.config.url
  91. ,params: {
  92. action: 'security/access/removeAcl'
  93. ,id: this.menu.record.id
  94. ,type: this.config.type || 'modAccessMediaSource'
  95. }
  96. ,listeners: {
  97. 'success': {fn:this.refresh,scope:this}
  98. }
  99. });
  100. }
  101. ,getMenu: function() {
  102. var menu = [];
  103. if (this.menu.record.id) {
  104. menu.push({
  105. text: _('source_access_update')
  106. ,handler: this.editAcl
  107. });
  108. }
  109. menu.push({
  110. text: _('source_access_remove')
  111. ,handler: this.remove.createDelegate(this,[{
  112. title: _('source_access_remove')
  113. ,text: _('source_access_remove_confirm')
  114. }])
  115. });
  116. return menu;
  117. }
  118. });
  119. Ext.reg('modx-grid-source-access',MODx.grid.MediaSourceAccess);
  120. MODx.window.CreateSourceAccess = function(config) {
  121. config = config || {};
  122. var r = config.record;
  123. Ext.applyIf(config,{
  124. title: _('source_access_add')
  125. // ,height: 250
  126. // ,width: 350
  127. ,type: 'modAccessMediaSource'
  128. ,acl: 0
  129. ,fields: [{
  130. xtype: 'hidden'
  131. ,name: 'id'
  132. ,value: r.id || ''
  133. },{
  134. xtype: 'hidden'
  135. ,name: 'target'
  136. ,value: config.target || 0
  137. },{
  138. xtype: 'hidden'
  139. ,name: 'principal_class'
  140. ,value: 'modUserGroup'
  141. },{
  142. xtype: 'hidden'
  143. ,name: 'context_key'
  144. ,hiddenName: 'context_key'
  145. ,value: 'mgr'
  146. },{
  147. xtype: 'modx-combo-usergroup'
  148. ,fieldLabel: _('user_group')
  149. ,name: 'principal'
  150. ,hiddenName: 'principal'
  151. ,value: r.principal || ''
  152. ,baseParams: {
  153. action: 'security/group/getList'
  154. ,combo: '1'
  155. }
  156. ,anchor: '100%'
  157. },{
  158. xtype: 'modx-combo-authority'
  159. ,fieldLabel: _('minimum_role')
  160. ,name: 'authority'
  161. ,hiddenName: 'authority'
  162. ,value: r.authority || 9999
  163. ,anchor: '100%'
  164. },{
  165. xtype: 'modx-combo-policy'
  166. ,fieldLabel: _('policy')
  167. ,name: 'policy'
  168. ,hiddenName: 'policy'
  169. ,value: r.policy || ''
  170. ,baseParams: {
  171. action: 'security/access/policy/getList'
  172. ,group: 'MediaSource'
  173. }
  174. ,anchor: '100%'
  175. }]
  176. });
  177. MODx.window.CreateSourceAccess.superclass.constructor.call(this,config);
  178. };
  179. Ext.extend(MODx.window.CreateSourceAccess,MODx.Window,{
  180. submit: function() {
  181. var f = this.fp.getForm();
  182. var prf = f.findField('principal');
  183. var pof = f.findField('policy');
  184. var auf = f.findField('authority');
  185. var r = f.getValues();
  186. if (prf) { r.principal_name = prf.getRawValue(); }
  187. if (pof) { r.policy_name = pof.getRawValue(); }
  188. if (auf) { r.authority_name = auf.getRawValue(); }
  189. if (this.fp.getForm().isValid()) {
  190. if (this.fireEvent('success',r)) {
  191. this.fp.getForm().reset();
  192. this.hide();
  193. return true;
  194. }
  195. }
  196. return true;
  197. }
  198. });
  199. Ext.reg('modx-window-source-access-create',MODx.window.CreateSourceAccess);
  200. MODx.window.UpdateSourceAccess = function(config) {
  201. config = config || {};
  202. var r = config.record;
  203. Ext.applyIf(config,{
  204. title: _('source_access_update')
  205. });
  206. MODx.window.UpdateSourceAccess.superclass.constructor.call(this,config);
  207. };
  208. Ext.extend(MODx.window.UpdateSourceAccess,MODx.window.CreateSourceAccess,{});
  209. Ext.reg('modx-window-source-access-update',MODx.window.UpdateSourceAccess);