modx.panel.fcset.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  1. /**
  2. * @class MODx.panel.FCSet
  3. * @extends MODx.FormPanel
  4. * @param {Object} config An object of configuration properties
  5. * @xtype modx-panel-fc-set
  6. */
  7. MODx.panel.FCSet = function(config) {
  8. config = config || {};
  9. Ext.applyIf(config,{
  10. url: MODx.config.connector_url
  11. ,baseParams: {
  12. action: 'security/forms/set/update'
  13. }
  14. ,id: 'modx-panel-fc-set'
  15. ,class_key: 'modFormCustomizationSet'
  16. ,cls: 'container'
  17. ,items: [{
  18. html: _('set_edit')
  19. ,id: 'modx-fcs-header'
  20. ,xtype: 'modx-header'
  21. },MODx.getPageStructure([{
  22. title: _('set_and_fields')
  23. ,xtype: 'panel'
  24. ,border: false
  25. ,defaults: { border: false }
  26. ,items: [{
  27. html: '<p>'+_('set_msg')+'</p>'
  28. ,id: 'modx-fcs-msg'
  29. ,xtype: 'modx-description'
  30. },{
  31. layout: 'form'
  32. ,id: 'modx-fcs-form'
  33. ,msgTarget: 'side'
  34. ,cls: 'main-wrapper'
  35. ,labelWidth: 150
  36. ,items: [{
  37. xtype: 'hidden'
  38. ,name: 'id'
  39. ,id: 'modx-fcs-id'
  40. ,value: config.record.id || MODx.request.id
  41. },{
  42. xtype: 'modx-combo-fc-action'
  43. ,fieldLabel: _('action')
  44. ,name: 'action_id'
  45. ,hiddenName: 'action_id'
  46. ,id: 'modx-fcs-action'
  47. ,anchor: '100%'
  48. ,allowBlank: false
  49. ,value: config.record.action
  50. ,listeners: {
  51. 'select': {scope:this,fn:function(f,e) {
  52. Ext.getCmp('modx-fcs-header').getEl().update(_('set')+': '+f.getRawValue());
  53. }}
  54. }
  55. },{
  56. xtype: 'modx-combo-template'
  57. ,fieldLabel: _('template')
  58. ,description: _('set_template_desc')
  59. ,name: 'template'
  60. ,hiddenName: 'template'
  61. ,value: config.record.template || 0
  62. ,anchor: '100%'
  63. ,allowBlank: true
  64. ,lazyInit: false
  65. ,lazyRender: false
  66. ,baseParams: {
  67. action: 'element/template/getList'
  68. ,combo: true
  69. }
  70. ,listeners: {
  71. 'select': {fn:this.changeTemplate,scope:this}
  72. }
  73. },{
  74. xtype: 'textarea'
  75. ,fieldLabel: _('description')
  76. ,name: 'description'
  77. ,id: 'modx-fcs-description'
  78. ,anchor: '100%'
  79. ,maxLength: 255
  80. ,grow: false
  81. ,value: config.record.description
  82. },{
  83. xtype: 'hidden'
  84. ,fieldLabel: _('constraint_class')
  85. ,name: 'constraint_class'
  86. ,value: 'modResource'
  87. ,anchor: '100%'
  88. ,allowBlank: true
  89. },{
  90. xtype: 'textfield'
  91. ,fieldLabel: _('constraint_field')
  92. ,description: _('set_constraint_field_desc')
  93. ,name: 'constraint_field'
  94. ,value: config.record.constraint_field
  95. ,anchor: '100%'
  96. ,allowBlank: true
  97. },{
  98. xtype: 'textfield'
  99. ,fieldLabel: _('constraint')
  100. ,description: _('set_constraint_desc')
  101. ,name: 'constraint'
  102. ,value: config.record.constraint
  103. ,anchor: '100%'
  104. ,allowBlank: true
  105. },{
  106. xtype: 'xcheckbox'
  107. ,fieldLabel: _('active')
  108. ,name: 'active'
  109. ,inputValue: true
  110. ,value: config.record.active ? true : false
  111. ,anchor: '100%'
  112. ,allowBlank: true
  113. }]
  114. },{
  115. html: '<p>'+_('set_fields_msg')+'</p>'
  116. ,xtype: 'modx-description'
  117. },{
  118. id: 'modx-fcs-fields-form'
  119. ,msgTarget: 'side'
  120. ,cls: 'main-wrapper'
  121. ,layout: 'anchor'
  122. ,items: [{
  123. xtype: 'modx-grid-fc-set-fields'
  124. ,data: config.record.fields || []
  125. ,preventRender: true
  126. }]
  127. }]
  128. },{
  129. title: _('regions')
  130. ,border: false
  131. ,layout: 'anchor'
  132. ,items: [{
  133. html: '<p>'+_('set_tabs_msg')+'</p>'
  134. ,xtype: 'modx-description'
  135. },{
  136. xtype: 'modx-grid-fc-set-tabs'
  137. ,cls: 'main-wrapper'
  138. ,data: config.record.tabs || []
  139. ,preventRender: true
  140. }]
  141. },{
  142. title: _('tvs')
  143. ,border: false
  144. ,layout: 'anchor'
  145. ,items: [{
  146. html: '<p>'+_('set_tvs_msg')+'</p>'
  147. ,xtype: 'modx-description'
  148. },{
  149. xtype: 'modx-grid-fc-set-tvs'
  150. ,cls: 'main-wrapper'
  151. ,data: config.record.tvs || []
  152. ,preventRender: true
  153. }]
  154. }],{
  155. id: 'modx-fc-set-tabs'
  156. })]
  157. ,listeners: {
  158. 'setup': {fn:this.setup,scope:this}
  159. ,'success': {fn:this.success,scope:this}
  160. ,'beforeSubmit': {fn:this.beforeSubmit,scope:this}
  161. }
  162. });
  163. MODx.panel.FCSet.superclass.constructor.call(this,config);
  164. };
  165. Ext.extend(MODx.panel.FCSet,MODx.FormPanel,{
  166. initialized: false
  167. ,setup: function() {
  168. if (!this.initialized) {this.getForm().setValues(this.config.record);}
  169. if (!Ext.isEmpty(this.config.record.controller)) {
  170. Ext.getCmp('modx-fcs-header').update(_('set')+': '+this.config.record.controller);
  171. }
  172. this.fireEvent('ready',this.config.record);
  173. this.clearDirty();
  174. this.initialized = true;
  175. MODx.fireEvent('ready');
  176. return true;
  177. }
  178. ,beforeSubmit: function(o) {
  179. Ext.apply(o.form.baseParams,{
  180. fields: Ext.getCmp('modx-grid-fc-set-fields').encode()
  181. ,tabs: Ext.getCmp('modx-grid-fc-set-tabs').encode()
  182. ,tvs: Ext.getCmp('modx-grid-fc-set-tvs').encode()
  183. });
  184. return this.fireEvent('save',{
  185. values: this.getForm().getValues()
  186. });
  187. }
  188. ,success: function(r) {
  189. this.getForm().setValues(r.result.object);
  190. Ext.getCmp('modx-grid-fc-set-fields').getStore().commitChanges();
  191. Ext.getCmp('modx-grid-fc-set-tabs').getStore().commitChanges();
  192. Ext.getCmp('modx-grid-fc-set-tvs').getStore().commitChanges();
  193. }
  194. ,changeTemplate: function(cb) {
  195. if (cb.getValue() != this.config.record.template) {
  196. Ext.Msg.confirm(_('set_change_template'),_('set_change_template_confirm'),function(e) {
  197. if (e == 'yes') {
  198. this.on('success',function() {
  199. location.href = location.href;
  200. },this);
  201. this.submit();
  202. } else {
  203. cb.setValue(this.config.record.template);
  204. }
  205. },this);
  206. }
  207. return false;
  208. }
  209. });
  210. Ext.reg('modx-panel-fc-set',MODx.panel.FCSet);
  211. MODx.grid.FCSetFields = function(config) {
  212. config = config || {};
  213. this.vcb = new Ext.ux.grid.CheckColumn({
  214. header: _('visible')
  215. ,dataIndex: 'visible'
  216. ,width: 40
  217. ,sortable: false
  218. });
  219. Ext.applyIf(config,{
  220. id: 'modx-grid-fc-set-fields'
  221. ,fields: ['id','action','name','tab','tab_rank','other','rank','visible','label','default_value']
  222. ,autoHeight: true
  223. ,grouping: true
  224. ,groupBy: 'tab'
  225. ,plugins: [this.vcb]
  226. ,stateful: false
  227. ,remoteSort: false
  228. ,sortBy: 'rank'
  229. ,sortDir: 'ASC'
  230. ,hideGroupedColumn: true
  231. ,groupTextTpl: '{group} ({[values.rs.length]} {[values.rs.length > 1 ? "'+_('fields')+'" : "'+_('field')+'"]})'
  232. ,columns: [{
  233. header: _('name')
  234. ,dataIndex: 'name'
  235. ,width: 200
  236. },{
  237. header: _('region')
  238. ,dataIndex: 'tab'
  239. ,width: 100
  240. },this.vcb,{
  241. header: _('label')
  242. ,dataIndex: 'label'
  243. ,editor: { xtype: 'textfield' }
  244. ,renderer: function(v,md) {
  245. return Ext.util.Format.htmlEncode(v);
  246. }
  247. },{
  248. header: _('default_value')
  249. ,dataIndex: 'default_value'
  250. ,editor: { xtype: 'textfield' }
  251. ,renderer: function(v,md) {
  252. return Ext.util.Format.htmlEncode(v);
  253. }
  254. }]
  255. ,viewConfig: {
  256. forceFit:true
  257. ,enableRowBody:true
  258. ,scrollOffset: 0
  259. ,autoFill: true
  260. ,showPreview: true
  261. ,getRowClass : function(rec, ri, p){
  262. return rec.data.visible ? 'grid-row-active' : 'grid-row-inactive';
  263. }
  264. }
  265. });
  266. MODx.grid.FCSetFields.superclass.constructor.call(this,config);
  267. this.propRecord = Ext.data.Record.create(config.fields);
  268. };
  269. Ext.extend(MODx.grid.FCSetFields,MODx.grid.LocalGrid);
  270. Ext.reg('modx-grid-fc-set-fields',MODx.grid.FCSetFields);
  271. MODx.grid.FCSetTabs = function(config) {
  272. config = config || {};
  273. this.vcb = new Ext.ux.grid.CheckColumn({
  274. header: _('visible')
  275. ,dataIndex: 'visible'
  276. ,width: 40
  277. ,sortable: false
  278. });
  279. Ext.applyIf(config,{
  280. id: 'modx-grid-fc-set-tabs'
  281. ,fields: ['id','action','name','form','other','rank','visible','label','type']
  282. ,autoHeight: true
  283. ,plugins: [this.vcb]
  284. ,stateful: false
  285. ,columns: [{
  286. header: _('tab_id')
  287. ,dataIndex: 'name'
  288. ,width: 200
  289. },this.vcb,{
  290. header: _('tab_title')
  291. ,dataIndex: 'label'
  292. ,editor: { xtype: 'textfield' }
  293. }]
  294. ,viewConfig: {
  295. forceFit:true
  296. ,enableRowBody:true
  297. ,scrollOffset: 0
  298. ,autoFill: true
  299. ,showPreview: true
  300. ,getRowClass : function(rec, ri, p){
  301. return rec.data.visible ? 'grid-row-active' : 'grid-row-inactive';
  302. }
  303. }
  304. ,tbar: [{
  305. text: _('tab_create')
  306. ,cls: 'primary-button'
  307. ,handler: this.createTab
  308. ,scope: this
  309. }]
  310. });
  311. MODx.grid.FCSetTabs.superclass.constructor.call(this,config);
  312. this.propRecord = Ext.data.Record.create(config.fields);
  313. };
  314. Ext.extend(MODx.grid.FCSetTabs,MODx.grid.LocalGrid,{
  315. createTab: function(btn,e) {
  316. if (!this.windows.ctab) {
  317. this.windows.ctab = MODx.load({
  318. xtype: 'modx-window-fc-set-add-tab'
  319. ,listeners: {
  320. 'success': {fn:function(r) {
  321. var s = this.getStore();
  322. var rec = new this.propRecord(r);
  323. s.add(rec);
  324. },scope:this}
  325. }
  326. });
  327. }
  328. this.windows.ctab.reset();
  329. this.windows.ctab.show(e.target);
  330. }
  331. ,getMenu: function(g,ri) {
  332. var rec = this.getStore().getAt(ri);
  333. if (rec.data.type == 'new') {
  334. return [{
  335. text: _('tab_remove')
  336. ,handler: this.removeTab
  337. ,scope: this
  338. }];
  339. }
  340. return [];
  341. }
  342. ,removeTab: function(btn,e) {
  343. var rec = this.getSelectionModel().getSelected();
  344. Ext.Msg.confirm(_('tab_remove'),_('tab_remove_confirm'),function(e) {
  345. if (e == 'yes') {
  346. this.getStore().remove(rec);
  347. }
  348. },this);
  349. }
  350. });
  351. Ext.reg('modx-grid-fc-set-tabs',MODx.grid.FCSetTabs);
  352. MODx.window.AddTabToSet = function(config) {
  353. config = config || {};
  354. Ext.applyIf(config,{
  355. title: _('tab_create')
  356. // ,height: 150
  357. // ,width: 375
  358. ,fields: [{
  359. xtype: 'hidden'
  360. ,name: 'container'
  361. ,value: 'modx-resource-tabs'
  362. },{
  363. xtype: 'hidden'
  364. ,name: 'visible'
  365. ,value: true
  366. },{
  367. xtype: 'hidden'
  368. ,name: 'type'
  369. ,value: 'new'
  370. },{
  371. xtype: 'textfield'
  372. ,name: 'name'
  373. ,fieldLabel: _('tab_id')
  374. ,id: 'modx-fcatab-id'
  375. ,allowBlank: false
  376. ,anchor: '100%'
  377. },{
  378. xtype: 'textfield'
  379. ,fieldLabel: _('tab_title')
  380. ,name: 'value'
  381. ,id: 'modx-fcatab-name'
  382. ,allowBlank: false
  383. ,anchor: '100%'
  384. }]
  385. });
  386. MODx.window.AddTabToSet.superclass.constructor.call(this,config);
  387. };
  388. Ext.extend(MODx.window.AddTabToSet,MODx.Window,{
  389. submit: function() {
  390. var rec = this.fp.getForm().getValues();
  391. var g = Ext.getCmp('modx-grid-fc-set-tabs');
  392. var s = g.getStore();
  393. var v = s.query('name',rec.name).items;
  394. if (v.length > 0) {
  395. MODx.msg.alert(_('error'),_('set_tab_err_ae'));
  396. return false;
  397. }
  398. rec.label = rec.value;
  399. rec.visible = true;
  400. rec.type = 'new';
  401. this.fireEvent('success',rec);
  402. this.hide();
  403. return false;
  404. }
  405. });
  406. Ext.reg('modx-window-fc-set-add-tab',MODx.window.AddTabToSet);
  407. MODx.grid.FCSetTVs = function(config) {
  408. config = config || {};
  409. this.vcb = new Ext.ux.grid.CheckColumn({
  410. header: _('visible')
  411. ,dataIndex: 'visible'
  412. ,width: 40
  413. ,sortable: false
  414. });
  415. Ext.applyIf(config,{
  416. id: 'modx-grid-fc-set-tvs'
  417. ,fields: ['id','name','tab','rank','visible','label','default_value','category','default_text']
  418. ,autoHeight: true
  419. ,grouping: true
  420. ,groupBy: 'category'
  421. ,sortBy: 'rank'
  422. ,sortDir: 'ASC'
  423. ,stateful: false
  424. ,groupTextTpl: '{group} ({[values.rs.length]} {[values.rs.length > 1 ? "'+_('tvs')+'" : "'+_('tv')+'"]})'
  425. ,plugins: [this.vcb]
  426. ,hideGroupedColumn: true
  427. ,columns: [{
  428. header: _('category')
  429. ,dataIndex: 'category'
  430. },{
  431. header: _('tv_name')
  432. ,dataIndex: 'name'
  433. ,width: 200
  434. },this.vcb,{
  435. header: _('label')
  436. ,dataIndex: 'label'
  437. ,editor: { xtype: 'textfield' }
  438. },{
  439. header: _('default_value')
  440. ,dataIndex: 'default_value'
  441. ,editor: { xtype: 'textfield' }
  442. ,renderer: function(v) { return Ext.util.Format.htmlEncode(v); }
  443. },{
  444. header: _('original_value')
  445. ,dataIndex: 'default_text'
  446. ,editable: false
  447. },{
  448. header: _('region')
  449. ,dataIndex: 'tab'
  450. ,width: 100
  451. ,editor: { xtype: 'textfield' }
  452. },{
  453. header: _('tab_rank')
  454. ,dataIndex: 'rank'
  455. ,width: 70
  456. ,editor: { xtype: 'textfield' }
  457. }]
  458. ,viewConfig: {
  459. forceFit:true
  460. ,enableRowBody:true
  461. ,scrollOffset: 0
  462. ,autoFill: true
  463. ,showPreview: true
  464. ,getRowClass : function(rec, ri, p){
  465. return rec.data.visible ? 'grid-row-active' : 'grid-row-inactive';
  466. }
  467. }
  468. });
  469. MODx.grid.FCSetTVs.superclass.constructor.call(this,config);
  470. this.propRecord = Ext.data.Record.create(config.fields);
  471. };
  472. Ext.extend(MODx.grid.FCSetTVs,MODx.grid.LocalGrid,{
  473. });
  474. Ext.reg('modx-grid-fc-set-tvs',MODx.grid.FCSetTVs);