modx.panel.context.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /**
  2. * @class MODx.panel.Context
  3. * @extends MODx.FormPanel
  4. * @param {Object} config An object of config properties
  5. * @xtype modx-panel-context
  6. */
  7. MODx.panel.Context = function(config) {
  8. config = config || {};
  9. Ext.applyIf(config,{
  10. url: MODx.config.connector_url
  11. ,baseParams: {
  12. action: 'context/get'
  13. }
  14. ,id: 'modx-panel-context'
  15. ,cls: 'container'
  16. ,class_key: 'modContext'
  17. ,plugin: ''
  18. ,bodyStyle: ''
  19. ,items: [{
  20. html: _('context')+': '+config.context
  21. ,id: 'modx-context-name'
  22. ,xtype: 'modx-header'
  23. },MODx.getPageStructure([{
  24. title: _('general_information')
  25. ,autoHeight: true
  26. ,layout: 'form'
  27. ,defaults: { border: false ,msgTarget: 'side' }
  28. ,items:[{
  29. xtype: 'panel'
  30. ,border: false
  31. ,cls:'main-wrapper'
  32. ,layout: 'form'
  33. ,items: [{
  34. xtype: 'statictextfield'
  35. ,fieldLabel: _('key')
  36. ,name: 'key'
  37. ,width: 300
  38. ,maxLength: 100
  39. ,enableKeyEvents: true
  40. ,allowBlank: true
  41. ,value: config.context
  42. ,submitValue: true
  43. },{
  44. xtype: 'textfield'
  45. ,fieldLabel: _('name')
  46. ,name: 'name'
  47. ,width: 300
  48. ,maxLength: 255
  49. ,renderer: Ext.util.Format.htmlEncode
  50. },{
  51. xtype: 'textarea'
  52. ,fieldLabel: _('description')
  53. ,name: 'description'
  54. ,width: 300
  55. ,grow: true
  56. ,renderer: Ext.util.Format.htmlEncode
  57. },{
  58. xtype: 'numberfield'
  59. ,fieldLabel: _('rank')
  60. ,name: 'rank'
  61. ,allowBlank: true
  62. ,width: 300
  63. },{
  64. html: MODx.onContextFormRender
  65. ,border: false
  66. }]
  67. }]
  68. },{
  69. title: _('context_settings')
  70. ,autoHeight: true
  71. ,layout: 'form'
  72. ,items: [{
  73. html: '<p>'+_('context_settings_desc')+'</p>'
  74. ,id: 'modx-context-settings-desc'
  75. ,xtype: 'modx-description'
  76. },{
  77. xtype: 'modx-grid-context-settings'
  78. ,cls:'main-wrapper'
  79. ,title: ''
  80. ,preventRender: true
  81. ,context_key: config.context
  82. ,listeners: {
  83. 'afteredit': {fn:function() { this.markDirty(); },scope:this}
  84. }
  85. }]
  86. },{
  87. title: _('access_permissions')
  88. ,autoHeight: true
  89. ,items:[{
  90. xtype: 'modx-grid-access-context'
  91. ,cls:'main-wrapper'
  92. ,title: ''
  93. ,preventRender: true
  94. ,context_key: config.context
  95. ,listeners: {
  96. 'afteredit': {fn:function() { this.markDirty(); },scope:this}
  97. }
  98. }]
  99. }],{
  100. id: 'modx-context-tabs'
  101. })]
  102. ,useLoadingMask: true
  103. ,listeners: {
  104. 'setup': {fn:this.setup,scope:this}
  105. ,'success': {fn:this.success,scope:this}
  106. ,'beforeSubmit': {fn:this.beforeSubmit,scope:this}
  107. }
  108. });
  109. MODx.panel.Context.superclass.constructor.call(this,config);
  110. };
  111. Ext.extend(MODx.panel.Context,MODx.FormPanel,{
  112. initialized: false
  113. ,setup: function() {
  114. if (this.initialized || (this.config.context === '' || this.config.context === 0)) {
  115. this.fireEvent('ready');
  116. return false;
  117. }
  118. MODx.Ajax.request({
  119. url: this.config.url
  120. ,params: {
  121. action: 'context/get'
  122. ,key: this.config.context
  123. }
  124. ,listeners: {
  125. 'success': {fn:function(r) {
  126. this.getForm().setValues(r.object);
  127. var el = Ext.getCmp('modx-context-name');
  128. if (el) { el.getEl().update(_('context')+': '+r.object.key); }
  129. this.fireEvent('ready');
  130. MODx.fireEvent('ready');
  131. this.initialized = true;
  132. },scope:this}
  133. }
  134. });
  135. }
  136. ,beforeSubmit: function(o) {
  137. var r = {};
  138. var g = Ext.getCmp('modx-grid-context-settings');
  139. if (g) { r.settings = g.encodeModified(); }
  140. Ext.apply(o.form.baseParams,r);
  141. }
  142. ,success: function(o) {
  143. var g = Ext.getCmp('modx-grid-context-settings');
  144. if (g) { g.getStore().commitChanges(); }
  145. var t = parent.Ext.getCmp('modx-resource-tree');
  146. if (t) { t.refresh(); }
  147. }
  148. });
  149. Ext.reg('modx-panel-context',MODx.panel.Context);