modx.panel.property.set.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. /**
  2. * @class MODx.panel.PropertySet
  3. * @extends MODx.Panel
  4. * @param {Object} config An object of config properties
  5. * @xtype modx-panel-property-sets
  6. */
  7. MODx.panel.PropertySet = function(config) {
  8. config = config || {};
  9. Ext.applyIf(config,{
  10. id: 'modx-panel-property-sets'
  11. ,cls: 'container'
  12. ,items: [{
  13. html: _('propertysets')
  14. ,xtype: 'modx-header'
  15. },{
  16. layout: 'form'
  17. ,id: 'modx-property-set-form'
  18. ,border: true
  19. ,items: [{
  20. html: '<p>'+_('propertysets_desc')+'</p>'
  21. ,id: 'modx-property-set-msg'
  22. ,xtype: 'modx-description'
  23. },{
  24. layout: 'column'
  25. ,border: false
  26. ,cls: 'main-wrapper'
  27. ,items: [{
  28. columnWidth: .3
  29. ,cls: 'left-col'
  30. ,border: false
  31. ,layout: 'anchor'
  32. ,items: [{
  33. xtype: 'modx-tree-property-sets'
  34. ,preventRender: true
  35. ,anchor: '100%'
  36. }]
  37. },{
  38. columnWidth: .7
  39. ,layout: 'form'
  40. ,border: false
  41. ,autoHeight: true
  42. ,id: 'right-column'
  43. ,items: []
  44. }]
  45. }]
  46. }]
  47. });
  48. MODx.panel.PropertySet.superclass.constructor.call(this,config);
  49. /* load after b/c of safari/ie focus bug */
  50. (function() {
  51. Ext.getCmp('right-column').add({
  52. xtype: 'modx-grid-property-set-properties'
  53. ,id: 'modx-grid-element-properties'
  54. });
  55. }).defer(50, this);
  56. };
  57. Ext.extend(MODx.panel.PropertySet,MODx.FormPanel);
  58. Ext.reg('modx-panel-property-sets',MODx.panel.PropertySet);
  59. /**
  60. * @class MODx.grid.PropertySetProperties
  61. * @extends MODx.grid.ElementProperties
  62. * @param {Object} config An object of config properties
  63. * @xtype modx-grid-property-set-properties
  64. */
  65. MODx.grid.PropertySetProperties = function(config) {
  66. config = config || {};
  67. Ext.applyIf(config,{
  68. autoHeight: true
  69. ,lockProperties: false
  70. ,tbar: [{
  71. xtype: 'modx-combo-property-set'
  72. ,id: 'modx-combo-property-set'
  73. ,baseParams: {
  74. action: 'element/propertyset/getList'
  75. }
  76. ,listeners: {
  77. 'select': {fn:function(cb) { Ext.getCmp('modx-grid-element-properties').changePropertySet(cb); },scope:this}
  78. }
  79. ,value: ''
  80. },{
  81. text: _('property_create')
  82. ,handler: function(btn,e) {
  83. if (Ext.getCmp('modx-combo-property-set').value != '') {
  84. Ext.getCmp('modx-grid-element-properties').create(btn,e);
  85. } else {
  86. MODx.msg.alert('', _('propertyset_err_ns'));
  87. }
  88. }
  89. ,scope: this
  90. },'->',{
  91. text: _('propertyset_save')
  92. ,cls: 'primary-button'
  93. ,handler: function() { Ext.getCmp('modx-grid-element-properties').save(); }
  94. ,scope: this
  95. }]
  96. });
  97. MODx.grid.PropertySetProperties.superclass.constructor.call(this,config);
  98. };
  99. Ext.extend(MODx.grid.PropertySetProperties,MODx.grid.ElementProperties);
  100. Ext.reg('modx-grid-property-set-properties',MODx.grid.PropertySetProperties);
  101. /**
  102. * @class MODx.tree.PropertySets
  103. * @extends MODx.tree.Tree
  104. * @param {Object} config An object of config properties
  105. * @xtype modx-tree-property-sets
  106. */
  107. MODx.tree.PropertySets = function(config) {
  108. config = config || {};
  109. Ext.applyIf(config,{
  110. rootVisible: false
  111. ,enableDD: false
  112. ,title: ''
  113. ,url: MODx.config.connector_url
  114. ,action: 'element/propertyset/getNodes'
  115. ,tbar: ['->', {
  116. text: _('propertyset_new')
  117. ,cls: 'primary-button'
  118. ,handler: this.createSet
  119. ,scope: this
  120. }]
  121. ,useDefaultToolbar: true
  122. });
  123. MODx.tree.PropertySets.superclass.constructor.call(this,config);
  124. this.on('click',this.loadGrid,this);
  125. };
  126. Ext.extend(MODx.tree.PropertySets,MODx.tree.Tree,{
  127. loadGrid: function(n,e) {
  128. var ar = n.id.split('_');
  129. if (ar[0] == 'ps') {
  130. MODx.Ajax.request({
  131. url: MODx.config.connector_url
  132. ,params: {
  133. action: 'element/propertyset/getProperties'
  134. ,id: ar[1]
  135. }
  136. ,listeners: {
  137. 'success': {fn:function(r) {
  138. var d = r.object;
  139. var g = Ext.getCmp('modx-grid-element-properties');
  140. var s = g.getStore();
  141. g.defaultProperties = d;
  142. delete g.config.elementId;
  143. delete g.config.elementType;
  144. s.removeAll();
  145. s.loadData(d);
  146. Ext.getCmp('modx-combo-property-set').setValue(ar[1]);
  147. },scope:this}
  148. }
  149. });
  150. } else if (ar[0] == 'el' && ar[2] && ar[3]) {
  151. MODx.Ajax.request({
  152. url: MODx.config.connector_url
  153. ,params: {
  154. action: 'element/propertyset/getProperties'
  155. ,id: ar[1]
  156. ,element: ar[2]
  157. ,element_class: ar[3]
  158. }
  159. ,listeners: {
  160. 'success': {fn:function(r) {
  161. var d = r.object;
  162. var g = Ext.getCmp('modx-grid-element-properties');
  163. var s = g.getStore();
  164. g.defaultProperties = d;
  165. g.config.elementId = ar[2];
  166. g.config.elementType = ar[3];
  167. s.removeAll();
  168. s.loadData(d);
  169. Ext.getCmp('modx-combo-property-set').setValue(ar[1]);
  170. },scope:this}
  171. }
  172. });
  173. }
  174. }
  175. ,createSet: function(btn,e) {
  176. if (!this.winCreateSet) {
  177. this.winCreateSet = MODx.load({
  178. xtype: 'modx-window-property-set-create'
  179. ,listeners: {
  180. 'success':{fn:function() {
  181. this.refresh();
  182. Ext.getCmp('modx-combo-property-set').store.reload();
  183. },scope:this}
  184. }
  185. });
  186. }
  187. this.winCreateSet.reset();
  188. this.winCreateSet.show(e.target);
  189. }
  190. ,duplicateSet: function(btn,e) {
  191. var id = this.cm.activeNode.id.split('_');
  192. var r = this.cm.activeNode.attributes.data;
  193. r.id = id[1];
  194. r.new_name = _('duplicate_of',{name:r.name});
  195. if (!this.winDupeSet) {
  196. this.winDupeSet = MODx.load({
  197. xtype: 'modx-window-property-set-duplicate'
  198. ,record: r
  199. ,listeners: {
  200. 'success':{fn:function() {
  201. this.refresh();
  202. Ext.getCmp('modx-combo-property-set').store.reload();
  203. },scope:this}
  204. }
  205. });
  206. }
  207. this.winDupeSet.setValues(r);
  208. this.winDupeSet.show(e.target);
  209. }
  210. ,updateSet: function(btn,e) {
  211. var id = this.cm.activeNode.id.split('_');
  212. var r = this.cm.activeNode.attributes.data;
  213. r.id = id[1];
  214. if (!this.winUpdateSet) {
  215. this.winUpdateSet = MODx.load({
  216. xtype: 'modx-window-property-set-update'
  217. ,record: r
  218. ,listeners: {
  219. 'success':{fn:function() {
  220. this.refresh();
  221. Ext.getCmp('modx-combo-property-set').store.reload();
  222. },scope:this}
  223. }
  224. });
  225. }
  226. this.winUpdateSet.setValues(r);
  227. this.winUpdateSet.show(e.target);
  228. }
  229. ,removeSet: function(btn,e) {
  230. var id = this.cm.activeNode.id.split('_');
  231. id = id[1];
  232. MODx.msg.confirm({
  233. text: _('propertyset_remove_confirm')
  234. ,url: MODx.config.connector_url
  235. ,params: {
  236. action: 'element/propertyset/remove'
  237. ,id: id
  238. }
  239. ,listeners: {
  240. 'success': {fn:function() {
  241. this.refreshNode(this.cm.activeNode.id);
  242. var g = Ext.getCmp('modx-grid-element-properties');
  243. g.getStore().removeAll();
  244. g.defaultProperties = [];
  245. Ext.getCmp('modx-combo-property-set').setValue('');
  246. },scope:this}
  247. }
  248. });
  249. }
  250. ,addElement: function(btn,e) {
  251. var id = this.cm.activeNode.id.split('_'); id = id[1];
  252. var t = this.cm.activeNode.text;
  253. var r = {
  254. propertysetName: this.cm.activeNode.text
  255. ,propertyset: id
  256. };
  257. if (!this.winPSEA) {
  258. this.winPSEA = MODx.load({
  259. xtype: 'modx-window-propertyset-element-add'
  260. ,record: r
  261. ,listeners: {
  262. 'success':{fn:function() { this.refreshNode(this.cm.activeNode.id,true); },scope:this}
  263. }
  264. });
  265. }
  266. this.winPSEA.fp.getForm().reset();
  267. this.winPSEA.fp.getForm().setValues(r);
  268. this.winPSEA.show(e.target);
  269. }
  270. ,removeElement: function(btn,e) {
  271. var d = this.cm.activeNode.attributes;
  272. MODx.msg.confirm({
  273. text: _('propertyset_element_remove_confirm')
  274. ,url: MODx.config.connector_url
  275. ,params: {
  276. action: 'element/propertyset/removeElement'
  277. ,element: d.pk
  278. ,element_class: d.element_class
  279. ,propertyset: d.propertyset
  280. }
  281. ,listeners: {
  282. 'success': {fn:function() { this.refreshNode(this.cm.activeNode.id); },scope:this}
  283. }
  284. });
  285. }
  286. });
  287. Ext.reg('modx-tree-property-sets',MODx.tree.PropertySets);
  288. /**
  289. * @class MODx.window.AddElementToPropertySet
  290. * @extends MODx.Window
  291. * @param {Object} config An object of configuration properties
  292. * @xtype modx-window-propertyset-element-add
  293. */
  294. MODx.window.AddElementToPropertySet = function(config) {
  295. config = config || {};
  296. Ext.applyIf(config,{
  297. title: _('propertyset_element_add')
  298. ,url: MODx.config.connector_url
  299. ,baseParams: {
  300. action: 'element/propertyset/addElement'
  301. }
  302. // ,width: 400
  303. ,fields: [{
  304. xtype: 'hidden'
  305. ,name: 'propertyset'
  306. },{
  307. xtype: 'statictextfield'
  308. ,fieldLabel: _('propertyset')
  309. ,name: 'propertysetName'
  310. ,anchor: '100%'
  311. },{
  312. xtype: 'modx-combo-element-class'
  313. ,fieldLabel: _('class_name')
  314. ,name: 'element_class'
  315. ,id: 'modx-combo-element-class'
  316. ,anchor: '100%'
  317. ,listeners: {
  318. 'select': {fn:this.onClassSelect,scope:this}
  319. }
  320. },{
  321. xtype: 'modx-combo-elements'
  322. ,fieldLabel: _('element')
  323. ,name: 'element'
  324. ,id: 'modx-combo-elements'
  325. ,anchor: '100%'
  326. ,listeners: {
  327. 'select': {fn:this.onElementSelect,scope:this}
  328. }
  329. }]
  330. });
  331. MODx.window.AddElementToPropertySet.superclass.constructor.call(this,config);
  332. };
  333. Ext.extend(MODx.window.AddElementToPropertySet,MODx.Window,{
  334. onClassSelect: function(cb) {
  335. var e = Ext.getCmp('modx-combo-elements');
  336. var s = e.store;
  337. s.baseParams.element_class = cb.getValue();
  338. s.load();
  339. e.setValue('');
  340. }
  341. ,onElementSelect: function(cb) {
  342. var ec = Ext.getCmp('modx-combo-element-class');
  343. if (ec.getValue() == '') {
  344. ec.setValue('modSnippet');
  345. }
  346. }
  347. });
  348. Ext.reg('modx-window-propertyset-element-add',MODx.window.AddElementToPropertySet);
  349. /**
  350. * @class MODx.combo.ElementClass
  351. * @extends MODx.combo.ComboBox
  352. * @param {Object} config An object of configuration properties
  353. * @xtype modx-combo-element-class
  354. */
  355. MODx.combo.ElementClass = function(config) {
  356. config = config || {};
  357. Ext.applyIf(config,{
  358. name: 'element_class'
  359. ,hiddenName: 'element_class'
  360. ,displayField: 'name'
  361. ,valueField: 'name'
  362. ,fields: ['name']
  363. // ,listWidth: 300
  364. ,pageSize: 20
  365. ,editable: false
  366. ,url: MODx.config.connector_url
  367. ,baseParams: {
  368. action: 'element/getClasses'
  369. }
  370. });
  371. MODx.combo.ElementClass.superclass.constructor.call(this,config);
  372. };
  373. Ext.extend(MODx.combo.ElementClass,MODx.combo.ComboBox);
  374. Ext.reg('modx-combo-element-class',MODx.combo.ElementClass);
  375. /**
  376. * @class MODx.combo.Elements
  377. * @extends MODx.combo.ComboBox
  378. * @param {Object} config An object of configuration properties
  379. * @xtype modx-combo-elements
  380. */
  381. MODx.combo.Elements = function(config) {
  382. config = config || {};
  383. Ext.applyIf(config,{
  384. name: 'element'
  385. ,hiddenName: 'element'
  386. ,displayField: 'name'
  387. ,valueField: 'id'
  388. ,fields: ['id','name']
  389. // ,listWidth: 300
  390. ,pageSize: 20
  391. ,editable: false
  392. ,url: MODx.config.connector_url
  393. ,baseParams: {
  394. action: 'element/getListByClass'
  395. ,element_class: 'modSnippet'
  396. }
  397. });
  398. MODx.combo.Elements.superclass.constructor.call(this,config);
  399. };
  400. Ext.extend(MODx.combo.Elements,MODx.combo.ComboBox);
  401. Ext.reg('modx-combo-elements',MODx.combo.Elements);
  402. /**
  403. * @class MODx.window.CreatePropertySet
  404. * @extends MODx.Window
  405. * @param {Object} config An object of configuration properties
  406. * @xtype modx-window-property-set-create
  407. */
  408. MODx.window.CreatePropertySet = function(config) {
  409. config = config || {};
  410. Ext.applyIf(config,{
  411. title: _('propertyset_create')
  412. ,url: MODx.config.connector_url
  413. ,baseParams: {
  414. action: 'element/propertyset/create'
  415. }
  416. ,autoHeight: true
  417. // ,width: 550
  418. ,fields: [{
  419. xtype: 'hidden'
  420. ,name: 'id'
  421. },{
  422. xtype: 'textfield'
  423. ,fieldLabel: _('name')
  424. ,name: 'name'
  425. ,anchor: '100%'
  426. ,allowBlank: false
  427. ,maxLength: 50
  428. },{
  429. xtype: 'modx-combo-category'
  430. ,fieldLabel: _('category')
  431. ,name: 'category'
  432. ,anchor: '100%'
  433. ,allowBlank: true
  434. },{
  435. xtype: 'textarea'
  436. ,fieldLabel: _('description')
  437. ,name: 'description'
  438. ,anchor: '100%'
  439. ,grow: true
  440. ,maxLength: 255
  441. }]
  442. ,keys: []
  443. });
  444. MODx.window.CreatePropertySet.superclass.constructor.call(this,config);
  445. };
  446. Ext.extend(MODx.window.CreatePropertySet,MODx.Window);
  447. Ext.reg('modx-window-property-set-create',MODx.window.CreatePropertySet);
  448. /**
  449. * @class MODx.window.UpdatePropertySet
  450. * @extends MODx.Window
  451. * @param {Object} config An object of configuration properties
  452. * @xtype modx-window-property-set-update
  453. */
  454. MODx.window.UpdatePropertySet = function(config) {
  455. config = config || {};
  456. Ext.applyIf(config,{
  457. title: _('propertyset_update')
  458. ,baseParams: {
  459. action: 'element/propertyset/update'
  460. }
  461. ,autoHeight: true
  462. });
  463. MODx.window.UpdatePropertySet.superclass.constructor.call(this,config);
  464. };
  465. Ext.extend(MODx.window.UpdatePropertySet,MODx.window.CreatePropertySet);
  466. Ext.reg('modx-window-property-set-update',MODx.window.UpdatePropertySet);
  467. /**
  468. * @class MODx.window.DuplicatePropertySet
  469. * @extends MODx.Window
  470. * @param {Object} config An object of configuration properties
  471. * @xtype modx-window-property-set-duplicate
  472. */
  473. MODx.window.DuplicatePropertySet = function(config) {
  474. config = config || {};
  475. Ext.applyIf(config,{
  476. title: _('propertyset_duplicate')
  477. ,url: MODx.config.connector_url
  478. ,baseParams: {
  479. action: 'element/propertyset/duplicate'
  480. }
  481. ,autoHeight: true
  482. // ,width: 550
  483. ,fields: [{
  484. xtype: 'hidden'
  485. ,name: 'id'
  486. ,id: 'modx-dpropset-id'
  487. },{
  488. xtype: 'textfield'
  489. ,fieldLabel: _('new_name')
  490. ,name: 'name'
  491. ,anchor: '100%'
  492. ,value: _('duplicate_of',{name:config.record.name})
  493. ,maxLength: 50
  494. },{
  495. xtype: 'xcheckbox'
  496. ,boxLabel: _('propertyset_duplicate_copyels')
  497. // ,labelSeparator: ''
  498. ,hideLabel: true
  499. ,name: 'copyels'
  500. ,id: 'modx-dpropset-copyels'
  501. ,checked: true
  502. }]
  503. });
  504. MODx.window.DuplicatePropertySet.superclass.constructor.call(this,config);
  505. };
  506. Ext.extend(MODx.window.DuplicatePropertySet,MODx.Window);
  507. Ext.reg('modx-window-property-set-duplicate',MODx.window.DuplicatePropertySet);