/manager/assets/modext/widgets/resource/modx.tree.resource.js

https://bitbucket.org/Fosil/modx-revolution-standard-distribution-upstream · JavaScript · 1187 lines · 1126 code · 48 blank · 13 comment · 117 complexity · b3d8a04f5eb6964ac879c81f11f7dadd MD5 · raw file

  1. /**
  2. * Generates the Resource Tree in Ext
  3. *
  4. * @class MODx.tree.Resource
  5. * @extends MODx.tree.Tree
  6. * @param {Object} config An object of options.
  7. * @xtype modx-tree-resource
  8. */
  9. MODx.tree.Resource = function(config) {
  10. config = config || {};
  11. Ext.applyIf(config,{
  12. url: MODx.config.connectors_url+'resource/index.php'
  13. ,title: ''
  14. ,rootVisible: false
  15. ,expandFirst: true
  16. ,enableDD: (MODx.config.enable_dragdrop != '0') ? true : false
  17. ,ddGroup: 'modx-treedrop-dd'
  18. ,remoteToolbar: true
  19. ,sortBy: this.getDefaultSortBy(config)
  20. ,tbarCfg: {
  21. id: config.id ? config.id+'-tbar' : 'modx-tree-resource-tbar'
  22. }
  23. ,baseParams: {
  24. action: 'getNodes'
  25. ,sortBy: this.getDefaultSortBy(config)
  26. ,currentResource: MODx.request.id || 0
  27. ,currentAction: MODx.request.a || 0
  28. }
  29. });
  30. MODx.tree.Resource.superclass.constructor.call(this,config);
  31. this.on('render',function() {
  32. var el = Ext.get('modx-resource-tree');
  33. el.createChild({tag: 'div', id: 'modx-resource-tree_tb'});
  34. el.createChild({tag: 'div', id: 'modx-resource-tree_filter'});
  35. },this);
  36. this.addEvents('loadCreateMenus');
  37. this.on('afterSort',this._handleAfterDrop,this);
  38. this.addSearchToolbar();
  39. };
  40. Ext.extend(MODx.tree.Resource,MODx.tree.Tree,{
  41. forms: {}
  42. ,windows: {}
  43. ,stores: {}
  44. ,_initExpand: function() {
  45. var treeState = Ext.state.Manager.get(this.treestate_id);
  46. if ((Ext.isString(treeState) || Ext.isEmpty(treeState)) && this.root) {
  47. if (this.root) {this.root.expand();}
  48. var wn = this.getNodeById('web_0');
  49. if (wn && this.config.expandFirst) {
  50. wn.select();
  51. wn.expand();
  52. }
  53. } else {
  54. for (var i=0;i<treeState.length;i++) {
  55. this.expandPath(treeState[i]);
  56. }
  57. }
  58. }
  59. ,addSearchToolbar: function() {
  60. var t = Ext.get(this.config.id+'-tbar');
  61. var fbd = t.createChild({tag: 'div' ,cls: 'modx-formpanel' ,autoHeight: true, id: 'modx-resource-searchbar'});
  62. var tb = new Ext.Toolbar({
  63. applyTo: fbd
  64. ,autoHeight: true
  65. ,width: '100%'
  66. });
  67. var tf = new Ext.form.TextField({
  68. name: 'search'
  69. ,value: ''
  70. ,ctCls: 'modx-leftbar-second-tb'
  71. ,width: Ext.getCmp('modx-resource-tree').getWidth() - 12
  72. ,emptyText: _('search_ellipsis')
  73. ,listeners: {
  74. 'change': {fn: this.search,scope:this}
  75. ,'render': {fn: function(cmp) {
  76. new Ext.KeyMap(cmp.getEl(), {
  77. key: Ext.EventObject.ENTER
  78. ,fn: function() {
  79. this.fireEvent('change',this.getValue());
  80. this.blur();
  81. return true;}
  82. ,scope: cmp
  83. });
  84. },scope:this}
  85. }
  86. });
  87. tb.add(tf);
  88. tb.doLayout();
  89. this.searchBar = tb;
  90. }
  91. ,search: function(nv) {
  92. Ext.state.Manager.set(this.treestate_id+'-search',nv);
  93. this.config.search = nv;
  94. this.getLoader().baseParams = {
  95. action: this.config.action
  96. ,search: this.config.search
  97. };
  98. this.refresh();
  99. }
  100. /**
  101. * Shows the current context menu.
  102. * @param {Ext.tree.TreeNode} n The current node
  103. * @param {Ext.EventObject} e The event object run.
  104. */
  105. ,_showContextMenu: function(n,e) {
  106. n.select();
  107. this.cm.activeNode = n;
  108. this.cm.removeAll();
  109. if (n.attributes.menu && n.attributes.menu.items) {
  110. this.addContextMenuItem(n.attributes.menu.items);
  111. this.cm.show(n.getUI().getEl(),'t?');
  112. } else {
  113. var m = [];
  114. switch (n.attributes.type) {
  115. case 'modResource':
  116. case 'modDocument':
  117. m = this._getModResourceMenu(n);
  118. break;
  119. case 'modContext':
  120. m = this._getModContextMenu(n);
  121. break;
  122. }
  123. this.addContextMenuItem(m);
  124. this.cm.showAt(e.xy);
  125. }
  126. e.stopEvent();
  127. }
  128. ,duplicateResource: function(item,e) {
  129. var node = this.cm.activeNode;
  130. var id = node.id.split('_');id = id[1];
  131. var r = {
  132. resource: id
  133. ,is_folder: node.getUI().hasClass('folder')
  134. };
  135. var w = MODx.load({
  136. xtype: 'modx-window-resource-duplicate'
  137. ,resource: id
  138. ,hasChildren: node.attributes.hasChildren
  139. ,listeners: {
  140. 'success': {fn:function() {this.refreshNode(node.id);},scope:this}
  141. }
  142. });
  143. w.config.hasChildren = node.attributes.hasChildren;
  144. w.setValues(r);
  145. w.show(e.target);
  146. }
  147. ,duplicateContext: function(itm,e) {
  148. var node = this.cm.activeNode;
  149. var key = node.attributes.pk;
  150. var r = {
  151. key: key
  152. ,newkey: ''
  153. };
  154. var w = MODx.load({
  155. xtype: 'modx-window-context-duplicate'
  156. ,record: r
  157. ,listeners: {
  158. 'success': {fn:function() {this.refresh();},scope:this}
  159. }
  160. });
  161. w.show(e.target);
  162. }
  163. ,removeContext: function(itm,e) {
  164. var node = this.cm.activeNode;
  165. var key = node.attributes.pk;
  166. MODx.msg.confirm({
  167. title: _('context_remove')
  168. ,text: _('context_remove_confirm')
  169. ,url: MODx.config.connectors_url+'context/index.php'
  170. ,params: {
  171. action: 'remove'
  172. ,key: key
  173. }
  174. ,listeners: {
  175. 'success': {fn:function() {this.refresh();},scope:this}
  176. }
  177. });
  178. }
  179. ,preview: function() {
  180. window.open(this.cm.activeNode.attributes.preview_url);
  181. }
  182. ,deleteDocument: function(itm,e) {
  183. var node = this.cm.activeNode;
  184. var id = node.id.split('_');id = id[1];
  185. MODx.msg.confirm({
  186. title: _('resource_delete')
  187. ,text: _('resource_delete_confirm')
  188. ,url: MODx.config.connectors_url+'resource/index.php'
  189. ,params: {
  190. action: 'delete'
  191. ,id: id
  192. }
  193. ,listeners: {
  194. 'success': {fn:function() {
  195. var n = this.cm.activeNode;
  196. var ui = n.getUI();
  197. ui.addClass('deleted');
  198. n.cascade(function(nd) {
  199. nd.getUI().addClass('deleted');
  200. },this);
  201. Ext.get(ui.getEl()).frame();
  202. },scope:this}
  203. }
  204. });
  205. }
  206. ,undeleteDocument: function(itm,e) {
  207. var node = this.cm.activeNode;
  208. var id = node.id.split('_');id = id[1];
  209. MODx.Ajax.request({
  210. url: MODx.config.connectors_url+'resource/index.php'
  211. ,params: {
  212. action: 'undelete'
  213. ,id: id
  214. }
  215. ,listeners: {
  216. 'success': {fn:function() {
  217. var n = this.cm.activeNode;
  218. var ui = n.getUI();
  219. ui.removeClass('deleted');
  220. n.cascade(function(nd) {
  221. nd.getUI().removeClass('deleted');
  222. },this);
  223. Ext.get(ui.getEl()).frame();
  224. },scope:this}
  225. }
  226. });
  227. }
  228. ,publishDocument: function(itm,e) {
  229. var node = this.cm.activeNode;
  230. var id = node.id.split('_');id = id[1];
  231. MODx.msg.confirm({
  232. title: _('resource_publish')
  233. ,text: _('resource_publish_confirm')
  234. ,url: MODx.config.connectors_url+'resource/index.php'
  235. ,params: {
  236. action: 'publish'
  237. ,id: id
  238. }
  239. ,listeners: {
  240. 'success': {fn:function() {
  241. var ui = this.cm.activeNode.getUI();
  242. ui.removeClass('unpublished');
  243. Ext.get(ui.getEl()).frame();
  244. },scope:this}
  245. }
  246. });
  247. }
  248. ,unpublishDocument: function(itm,e) {
  249. var node = this.cm.activeNode;
  250. var id = node.id.split('_');id = id[1];
  251. MODx.msg.confirm({
  252. title: _('resource_unpublish')
  253. ,text: _('resource_unpublish_confirm')
  254. ,url: MODx.config.connectors_url+'resource/index.php'
  255. ,params: {
  256. action: 'unpublish'
  257. ,id: id
  258. }
  259. ,listeners: {
  260. 'success': {fn:function() {
  261. var ui = this.cm.activeNode.getUI();
  262. ui.addClass('unpublished');
  263. Ext.get(ui.getEl()).frame();
  264. },scope:this}
  265. }
  266. });
  267. }
  268. ,emptyRecycleBin: function() {
  269. MODx.msg.confirm({
  270. title: _('empty_recycle_bin')
  271. ,text: _('empty_recycle_bin_confirm')
  272. ,url: MODx.config.connectors_url+'resource/index.php'
  273. ,params: {
  274. action: 'emptyRecycleBin'
  275. }
  276. ,listeners: {
  277. 'success':{fn:function() {
  278. Ext.select('div.deleted',this.getRootNode()).remove();
  279. MODx.msg.status({
  280. title: _('success')
  281. ,message: _('empty_recycle_bin_emptied')
  282. })
  283. },scope:this}
  284. }
  285. });
  286. }
  287. ,showFilter: function(itm,e) {
  288. if (this._filterVisible) {return false;}
  289. var t = Ext.get(this.config.id+'-tbar');
  290. var fbd = t.createChild({tag: 'div' ,cls: 'modx-formpanel' ,autoHeight: true});
  291. var tb = new Ext.Toolbar({
  292. applyTo: fbd
  293. ,autoHeight: true
  294. ,width: '100%'
  295. });
  296. var cb = new Ext.form.ComboBox({
  297. store: new Ext.data.SimpleStore({
  298. fields: ['name','value']
  299. ,data: [
  300. [_('menu_order'),'menuindex']
  301. ,[_('page_title'),'pagetitle']
  302. ,[_('publish_date'),'pub_date']
  303. ,[_('unpublish_date'),'unpub_date']
  304. ,[_('createdon'),'createdon']
  305. ,[_('editedon'),'editedon']
  306. ,[_('publishedon'),'publishedon']
  307. ,[_('alias'),'alias']
  308. ]
  309. })
  310. ,displayField: 'name'
  311. ,valueField: 'value'
  312. ,forceSelection: false
  313. ,editable: true
  314. ,mode: 'local'
  315. ,id: 'modx-resource-tree-sortby'
  316. ,triggerAction: 'all'
  317. ,selectOnFocus: false
  318. ,width: 100
  319. ,value: this.getDefaultSortBy(this.config)
  320. ,listeners: {
  321. 'select': {fn:this.filterSort,scope:this}
  322. ,'change': {fn:this.filterSort,scope:this}
  323. }
  324. });
  325. tb.add(_('sort_by')+':');
  326. tb.addField(cb);
  327. tb.add('-',{
  328. scope: this
  329. ,cls: 'x-btn-text'
  330. ,text: _('close')
  331. ,handler: this.hideFilter
  332. });
  333. tb.doLayout();
  334. this.filterBar = tb;
  335. this._filterVisible = true;
  336. return true;
  337. }
  338. ,getDefaultSortBy: function(config) {
  339. var v = 'menuindex';
  340. if (!Ext.isEmpty(config) && !Ext.isEmpty(config.sortBy)) {
  341. v = config.sortBy;
  342. } else {
  343. var d = Ext.state.Manager.get(this.treestate_id+'-sort-default');
  344. if (d != MODx.config.tree_default_sort) {
  345. v = MODx.config.tree_default_sort;
  346. Ext.state.Manager.set(this.treestate_id+'-sort-default',v);
  347. Ext.state.Manager.set(this.treestate_id+'-sort',v);
  348. } else {
  349. v = Ext.state.Manager.get(this.treestate_id+'-sort') || MODx.config.tree_default_sort;
  350. }
  351. }
  352. return v;
  353. }
  354. ,filterSort: function(cb,r,i) {
  355. Ext.state.Manager.set(this.treestate_id+'-sort',cb.getValue());
  356. this.config.sortBy = cb.getValue();
  357. this.getLoader().baseParams = {
  358. action: this.config.action
  359. ,sortBy: this.config.sortBy
  360. };
  361. this.refresh();
  362. }
  363. ,hideFilter: function(itm,e) {
  364. this.filterBar.destroy();
  365. this._filterVisible = false;
  366. }
  367. ,_handleAfterDrop: function(o,r) {
  368. var targetNode = o.event.target;
  369. if (o.event.point == 'append' && targetNode) {
  370. var ui = targetNode.getUI();
  371. ui.addClass('haschildren');
  372. ui.removeClass('icon-resource');
  373. }
  374. }
  375. ,_handleDrop: function(e){
  376. var dropNode = e.dropNode;
  377. var targetParent = e.target;
  378. if (targetParent.findChild('id',dropNode.attributes.id) !== null) {return false;}
  379. if (dropNode.attributes.type == 'modContext' && (targetParent.getDepth() > 1 || (targetParent.attributes.id == targetParent.attributes.pk + '_0' && e.point == 'append'))) {
  380. return false;
  381. }
  382. if (dropNode.attributes.type !== 'modContext' && targetParent.getDepth() <= 1 && e.point !== 'append') {
  383. return false;
  384. }
  385. if (targetParent.attributes.hide_children_in_tree) { return false; }
  386. return dropNode.attributes.text != 'root' && dropNode.attributes.text !== ''
  387. && targetParent.attributes.text != 'root' && targetParent.attributes.text !== '';
  388. }
  389. ,getContextSettingForNode: function(node,ctx,setting,dv) {
  390. var val = dv || null;
  391. if (node.attributes.type != 'modContext') {
  392. var t = node.getOwnerTree();
  393. var rn = t.getRootNode();
  394. var cn = rn.findChild('ctx',ctx,false);
  395. if (cn) {
  396. val = cn.attributes.settings[setting];
  397. }
  398. } else {
  399. val = node.attributes.settings[setting];
  400. }
  401. return val;
  402. }
  403. ,quickCreate: function(itm,e,cls,ctx,p) {
  404. cls = cls || 'modDocument';
  405. var r = {
  406. class_key: cls
  407. ,context_key: ctx || 'web'
  408. ,'parent': p || 0
  409. ,'template': parseInt(this.getContextSettingForNode(this.cm.activeNode,ctx,'default_template',MODx.config.default_template))
  410. ,'richtext': parseInt(this.getContextSettingForNode(this.cm.activeNode,ctx,'richtext_default',MODx.config.richtext_default))
  411. ,'hidemenu': parseInt(this.getContextSettingForNode(this.cm.activeNode,ctx,'hidemenu_default',MODx.config.hidemenu_default))
  412. ,'searchable': parseInt(this.getContextSettingForNode(this.cm.activeNode,ctx,'search_default',MODx.config.search_default))
  413. ,'cacheable': parseInt(this.getContextSettingForNode(this.cm.activeNode,ctx,'cache_default',MODx.config.cache_default))
  414. ,'published': parseInt(this.getContextSettingForNode(this.cm.activeNode,ctx,'publish_default',MODx.config.publish_default))
  415. ,'content_type': parseInt(this.getContextSettingForNode(this.cm.activeNode,ctx,'default_content_type',MODx.config.default_content_type))
  416. };
  417. if (this.cm.activeNode.attributes.type != 'modContext') {
  418. var t = this.cm.activeNode.getOwnerTree();
  419. var rn = t.getRootNode();
  420. var cn = rn.findChild('ctx',ctx,false);
  421. if (cn) {
  422. r['template'] = cn.attributes.settings.default_template;
  423. }
  424. } else {
  425. r['template'] = this.cm.activeNode.attributes.settings.default_template;
  426. }
  427. var w = MODx.load({
  428. xtype: 'modx-window-quick-create-modResource'
  429. ,record: r
  430. ,listeners: {
  431. 'success':{fn:function() {
  432. var node = this.getNodeById(this.cm.activeNode.id);
  433. if (node) {
  434. var n = node.parentNode ? node.parentNode : node;
  435. this.getLoader().load(n,function() {
  436. n.expand();
  437. },this);
  438. }
  439. },scope:this}
  440. ,'hide':{fn:function() {this.destroy();}}
  441. ,'show':{fn:function() {this.center();}}
  442. }
  443. });
  444. w.setValues(r);
  445. w.show(e.target,function() {
  446. Ext.isSafari ? w.setPosition(null,30) : w.center();
  447. },this);
  448. }
  449. ,quickUpdate: function(itm,e,cls) {
  450. MODx.Ajax.request({
  451. url: MODx.config.connectors_url+'resource/index.php'
  452. ,params: {
  453. action: 'get'
  454. ,id: this.cm.activeNode.attributes.pk
  455. }
  456. ,listeners: {
  457. 'success': {fn:function(r) {
  458. var pr = r.object;
  459. pr.class_key = cls;
  460. var w = MODx.load({
  461. xtype: 'modx-window-quick-update-modResource'
  462. ,record: pr
  463. ,listeners: {
  464. 'success':{fn:function() {
  465. this.refreshNode(this.cm.activeNode.id);
  466. },scope:this}
  467. ,'hide':{fn:function() {this.destroy();}}
  468. }
  469. });
  470. w.setValues(r.object);
  471. w.show(e.target,function() {
  472. Ext.isSafari ? w.setPosition(null,30) : w.center();
  473. },this);
  474. },scope:this}
  475. }
  476. });
  477. }
  478. ,_getModContextMenu: function(n) {
  479. var a = n.attributes;
  480. var ui = n.getUI();
  481. var m = [];
  482. m.push({
  483. text: '<b>'+a.text+'</b>'
  484. ,handler: function() {return false;}
  485. ,header: true
  486. });
  487. m.push('-');
  488. if (ui.hasClass('pedit')) {
  489. m.push({
  490. text: _('edit_context')
  491. ,handler: function() {
  492. var at = this.cm.activeNode.attributes;
  493. this.loadAction('a='+MODx.action['context/update']+'&key='+at.pk);
  494. }
  495. });
  496. }
  497. m.push({
  498. text: _('context_refresh')
  499. ,handler: function() {
  500. this.refreshNode(this.cm.activeNode.id,true);
  501. }
  502. });
  503. if (ui.hasClass('pnewdoc')) {
  504. m.push('-');
  505. this._getCreateMenus(m,'0',ui);
  506. }
  507. if (ui.hasClass('pnew')) {
  508. m.push({
  509. text: _('context_duplicate')
  510. ,handler: this.duplicateContext
  511. });
  512. }
  513. if (ui.hasClass('pdelete')) {
  514. m.push('-');
  515. m.push({
  516. text: _('context_remove')
  517. ,handler: this.removeContext
  518. });
  519. }
  520. return m;
  521. }
  522. ,overviewResource: function() {this.loadAction('a='+MODx.action['resource/data'])}
  523. ,quickUpdateResource: function(itm,e) {
  524. Ext.getCmp("modx-resource-tree").quickUpdate(itm,e,itm.classKey);
  525. }
  526. ,editResource: function() {this.loadAction('a='+MODx.action['resource/update']);}
  527. ,_getModResourceMenu: function(n) {
  528. var a = n.attributes;
  529. var ui = n.getUI();
  530. var m = [];
  531. m.push({
  532. text: '<b>'+a.text+'</b>'
  533. ,handler: function() {return false;}
  534. ,header: true
  535. });
  536. m.push('-');
  537. if (ui.hasClass('pview')) {
  538. m.push({
  539. text: _('resource_overview')
  540. ,handler: this.overviewResource
  541. });
  542. }
  543. if (ui.hasClass('pedit')) {
  544. m.push({
  545. text: _('resource_edit')
  546. ,handler: this.editResource
  547. });
  548. }
  549. if (ui.hasClass('pqupdate')) {
  550. m.push({
  551. text: _('quick_update_resource')
  552. ,classKey: a.classKey
  553. ,handler: this.quickUpdateResource
  554. });
  555. }
  556. if (ui.hasClass('pduplicate')) {
  557. m.push({
  558. text: _('resource_duplicate')
  559. ,handler: this.duplicateResource
  560. });
  561. }
  562. m.push({
  563. text: _('resource_refresh')
  564. ,handler: this.refreshResource
  565. ,scope: this
  566. });
  567. if (ui.hasClass('pnew')) {
  568. m.push('-');
  569. this._getCreateMenus(m,null,ui);
  570. }
  571. if (ui.hasClass('psave')) {
  572. m.push('-');
  573. if (ui.hasClass('ppublish') && ui.hasClass('unpublished')) {
  574. m.push({
  575. text: _('resource_publish')
  576. ,handler: this.publishDocument
  577. });
  578. } else if (ui.hasClass('punpublish')) {
  579. m.push({
  580. text: _('resource_unpublish')
  581. ,handler: this.unpublishDocument
  582. });
  583. }
  584. if (ui.hasClass('pundelete') && ui.hasClass('deleted')) {
  585. m.push({
  586. text: _('resource_undelete')
  587. ,handler: this.undeleteDocument
  588. });
  589. } else if (ui.hasClass('pdelete') && !ui.hasClass('deleted')) {
  590. m.push({
  591. text: _('resource_delete')
  592. ,handler: this.deleteDocument
  593. });
  594. }
  595. }
  596. if (ui.hasClass('pview')) {
  597. m.push('-');
  598. m.push({
  599. text: _('resource_view')
  600. ,handler: this.preview
  601. });
  602. }
  603. return m;
  604. }
  605. ,refreshResource: function() {
  606. this.refreshNode(this.cm.activeNode.id);
  607. }
  608. ,createResourceHere: function(itm) {
  609. var at = this.cm.activeNode.attributes;
  610. var p = itm.usePk ? itm.usePk : at.pk;
  611. Ext.getCmp('modx-resource-tree').loadAction(
  612. 'a='+MODx.action['resource/create']
  613. + '&class_key='+itm.classKey
  614. + '&parent='+p
  615. + (at.ctx ? '&context_key='+at.ctx : '')
  616. );
  617. }
  618. ,createResource: function(itm,e) {
  619. var at = this.cm.activeNode.attributes;
  620. var p = itm.usePk ? itm.usePk : at.pk;
  621. Ext.getCmp('modx-resource-tree').quickCreate(itm,e,itm.classKey,at.ctx,p);
  622. }
  623. ,_getCreateMenus: function(m,pk,ui) {
  624. var types = MODx.config.resource_classes;
  625. var o = this.fireEvent('loadCreateMenus',types);
  626. if (Ext.isObject(o)) {
  627. Ext.apply(types,o);
  628. }
  629. var coreTypes = ['modDocument','modWebLink','modSymLink','modStaticResource'];
  630. var ct = [];
  631. var qct = [];
  632. for (var k in types) {
  633. if (coreTypes.indexOf(k) != -1) {
  634. if (!ui.hasClass('pnew_'+k)) {
  635. continue;
  636. }
  637. }
  638. ct.push({
  639. text: types[k]['text_create_here']
  640. ,classKey: k
  641. ,usePk: pk ? pk : false
  642. ,handler: this.createResourceHere
  643. ,scope: this
  644. });
  645. if (ui && ui.hasClass('pqcreate')) {
  646. qct.push({
  647. text: types[k]['text_create']
  648. ,classKey: k
  649. ,handler: this.createResource
  650. ,scope: this
  651. });
  652. }
  653. }
  654. m.push({
  655. text: _('create')
  656. ,handler: Ext.emptyFn
  657. ,menu: {items: ct}
  658. });
  659. if (ui && ui.hasClass('pqcreate')) {
  660. m.push({
  661. text: _('quick_create')
  662. ,handler: Ext.emptyFn
  663. ,menu: {items: qct}
  664. });
  665. }
  666. return m;
  667. }
  668. });
  669. Ext.reg('modx-tree-resource',MODx.tree.Resource);
  670. MODx.window.QuickCreateResource = function(config) {
  671. config = config || {};
  672. this.ident = config.ident || 'qcr'+Ext.id();
  673. Ext.applyIf(config,{
  674. title: _('quick_create_resource')
  675. ,id: this.ident
  676. ,width: 700
  677. ,height: ['modSymLink', 'modWebLink', 'modStaticResource'].indexOf(config.record.class_key) == -1 ? 640 : 498
  678. ,autoHeight: false
  679. ,layout: 'anchor'
  680. ,url: MODx.config.connectors_url+'resource/index.php'
  681. ,action: 'create'
  682. ,shadow: false
  683. ,fields: [{
  684. xtype: 'modx-tabs'
  685. ,bodyStyle: { background: 'transparent' }
  686. ,border: true
  687. ,deferredRender: false
  688. ,autoHeight: false
  689. ,autoScroll: false
  690. ,anchor: '100% 100%'
  691. ,items: [{
  692. title: _('resource')
  693. ,layout: 'form'
  694. ,cls: 'modx-panel'
  695. ,bodyStyle: { background: 'transparent', padding: '10px' }
  696. ,autoHeight: false
  697. ,anchor: '100% 100%'
  698. ,labelWidth: 100
  699. ,items: [{
  700. layout: 'column'
  701. ,border: false
  702. ,items: [{
  703. columnWidth: .6
  704. ,border: false
  705. ,layout: 'form'
  706. ,items: [{
  707. xtype: 'textfield'
  708. ,name: 'pagetitle'
  709. ,id: 'modx-'+this.ident+'-pagetitle'
  710. ,fieldLabel: _('pagetitle')
  711. ,anchor: '100%'
  712. },{
  713. xtype: 'textfield'
  714. ,name: 'longtitle'
  715. ,id: 'modx-'+this.ident+'-longtitle'
  716. ,fieldLabel: _('long_title')
  717. ,anchor: '100%'
  718. },{
  719. xtype: 'textarea'
  720. ,name: 'description'
  721. ,id: 'modx-'+this.ident+'-description'
  722. ,fieldLabel: _('description')
  723. ,anchor: '100%'
  724. ,grow: false
  725. ,height: 50
  726. },{
  727. xtype: 'textarea'
  728. ,name: 'introtext'
  729. ,id: 'modx-'+this.ident+'-introtext'
  730. ,fieldLabel: _('introtext')
  731. ,anchor: '100%'
  732. ,height: 50
  733. }]
  734. },{
  735. columnWidth: .4
  736. ,border: false
  737. ,layout: 'form'
  738. ,items: [{
  739. xtype: 'modx-combo-template'
  740. ,name: 'template'
  741. ,id: 'modx-'+this.ident+'-template'
  742. ,fieldLabel: _('template')
  743. ,editable: false
  744. ,anchor: '100%'
  745. ,baseParams: {
  746. action: 'getList'
  747. ,combo: '1'
  748. ,limit: 0
  749. }
  750. ,value: MODx.config.default_template
  751. },{
  752. xtype: 'textfield'
  753. ,name: 'alias'
  754. ,id: 'modx-'+this.ident+'-alias'
  755. ,fieldLabel: _('alias')
  756. ,anchor: '100%'
  757. },{
  758. xtype: 'textfield'
  759. ,name: 'menutitle'
  760. ,id: 'modx-'+this.ident+'-menutitle'
  761. ,fieldLabel: _('resource_menutitle')
  762. ,anchor: '100%'
  763. },{
  764. xtype: 'xcheckbox'
  765. ,boxLabel: _('resource_hide_from_menus')
  766. ,description: _('resource_hide_from_menus_help')
  767. ,name: 'hidemenu'
  768. ,id: 'modx-'+this.ident+'-hidemenu'
  769. ,inputValue: 1
  770. ,checked: MODx.config.hidemenu_default == '1' ? 1 : 0
  771. },{
  772. xtype: 'xcheckbox'
  773. ,name: 'published'
  774. ,id: 'modx-'+this.ident+'-published'
  775. ,boxLabel: _('resource_published')
  776. ,description: _('resource_published_help')
  777. ,inputValue: 1
  778. ,checked: MODx.config.publish_default == '1' ? 1 : 0
  779. }]
  780. }]
  781. },MODx.getQRContentField(this.ident,config.record.class_key)]
  782. },{
  783. id: 'modx-'+this.ident+'-settings'
  784. ,title: _('settings')
  785. ,layout: 'form'
  786. ,cls: 'modx-panel'
  787. ,autoHeight: true
  788. ,forceLayout: true
  789. ,labelWidth: 100
  790. ,defaults: {autoHeight: true ,border: false}
  791. ,style: 'background: transparent;'
  792. ,bodyStyle: { background: 'transparent', padding: '10px' }
  793. ,items: MODx.getQRSettings(this.ident,config.record)
  794. }]
  795. }]
  796. ,keys: [{
  797. key: Ext.EventObject.ENTER
  798. ,shift: true
  799. ,fn: this.submit
  800. ,scope: this
  801. }]
  802. });
  803. MODx.window.QuickCreateResource.superclass.constructor.call(this,config);
  804. };
  805. Ext.extend(MODx.window.QuickCreateResource,MODx.Window);
  806. Ext.reg('modx-window-quick-create-modResource',MODx.window.QuickCreateResource);
  807. MODx.window.QuickUpdateResource = function(config) {
  808. config = config || {};
  809. this.ident = config.ident || 'qur'+Ext.id();
  810. Ext.applyIf(config,{
  811. title: _('quick_update_resource')
  812. ,id: this.ident
  813. ,width: 700
  814. ,height: ['modSymLink', 'modWebLink', 'modStaticResource'].indexOf(config.record.class_key) == -1 ? 640 : 498
  815. ,autoHeight: false
  816. ,layout: 'anchor'
  817. ,url: MODx.config.connectors_url+'resource/index.php'
  818. ,action: 'update'
  819. ,shadow: false
  820. ,fields: [{
  821. xtype: 'modx-tabs'
  822. ,bodyStyle: { background: 'transparent' }
  823. ,border: true
  824. ,autoHeight: false
  825. ,autoScroll: false
  826. ,anchor: '100% 100%'
  827. ,deferredRender: false
  828. ,items: [{
  829. title: _('resource')
  830. ,layout: 'form'
  831. ,cls: 'modx-panel'
  832. ,bodyStyle: { background: 'transparent', padding: '10px', overflow: 'hidden' }
  833. ,autoHeight: false
  834. ,anchor: '100% 100%'
  835. ,labelWidth: 100
  836. ,items: [{
  837. xtype: 'hidden'
  838. ,name: 'id'
  839. ,id: 'modx-'+this.ident+'-id'
  840. },{
  841. layout: 'column'
  842. ,border: false
  843. ,items: [{
  844. columnWidth: .6
  845. ,border: false
  846. ,layout: 'form'
  847. ,items: [{
  848. xtype: 'textfield'
  849. ,name: 'pagetitle'
  850. ,id: 'modx-'+this.ident+'-pagetitle'
  851. ,fieldLabel: _('pagetitle')
  852. ,anchor: '100%'
  853. },{
  854. xtype: 'textfield'
  855. ,name: 'longtitle'
  856. ,id: 'modx-'+this.ident+'-longtitle'
  857. ,fieldLabel: _('long_title')
  858. ,anchor: '100%'
  859. },{
  860. xtype: 'textarea'
  861. ,name: 'description'
  862. ,id: 'modx-'+this.ident+'-description'
  863. ,fieldLabel: _('description')
  864. ,anchor: '100%'
  865. ,grow: false
  866. ,height: 50
  867. },{
  868. xtype: 'textarea'
  869. ,name: 'introtext'
  870. ,id: 'modx-'+this.ident+'-introtext'
  871. ,fieldLabel: _('introtext')
  872. ,anchor: '100%'
  873. ,height: 50
  874. }]
  875. },{
  876. columnWidth: .4
  877. ,border: false
  878. ,layout: 'form'
  879. ,items: [{
  880. xtype: 'modx-combo-template'
  881. ,name: 'template'
  882. ,id: 'modx-'+this.ident+'-template'
  883. ,fieldLabel: _('template')
  884. ,editable: false
  885. ,anchor: '100%'
  886. ,baseParams: {
  887. action: 'getList'
  888. ,combo: '1'
  889. ,limit: 0
  890. }
  891. },{
  892. xtype: 'textfield'
  893. ,name: 'alias'
  894. ,id: 'modx-'+this.ident+'-alias'
  895. ,fieldLabel: _('alias')
  896. ,anchor: '100%'
  897. },{
  898. xtype: 'textfield'
  899. ,name: 'menutitle'
  900. ,id: 'modx-'+this.ident+'-menutitle'
  901. ,fieldLabel: _('resource_menutitle')
  902. ,anchor: '100%'
  903. },{
  904. xtype: 'xcheckbox'
  905. ,boxLabel: _('resource_hide_from_menus')
  906. ,description: _('resource_hide_from_menus_help')
  907. ,name: 'hidemenu'
  908. ,id: 'modx-'+this.ident+'-hidemenu'
  909. ,inputValue: 1
  910. },{
  911. xtype: 'xcheckbox'
  912. ,name: 'published'
  913. ,id: 'modx-'+this.ident+'-published'
  914. ,boxLabel: _('resource_published')
  915. ,description: _('resource_published_help')
  916. ,inputValue: 1
  917. }]
  918. }]
  919. },MODx.getQRContentField(this.ident,config.record.class_key)]
  920. },{
  921. id: 'modx-'+this.ident+'-settings'
  922. ,title: _('settings'),layout: 'form'
  923. ,cls: 'modx-panel'
  924. ,autoHeight: true
  925. ,forceLayout: true
  926. ,labelWidth: 100
  927. ,defaults: {autoHeight: true ,border: false}
  928. ,style: 'background: transparent;'
  929. ,bodyStyle: { background: 'transparent', padding: '10px' }
  930. ,items: MODx.getQRSettings(this.ident,config.record)
  931. }]
  932. }]
  933. ,keys: [{
  934. key: Ext.EventObject.ENTER
  935. ,shift: true
  936. ,fn: this.submit
  937. ,scope: this
  938. }]
  939. ,buttons: [{
  940. text: config.cancelBtnText || _('cancel')
  941. ,scope: this
  942. ,handler: function() { this.hide(); }
  943. },{
  944. text: config.saveBtnText || _('save')
  945. ,scope: this
  946. ,handler: function() { this.submit(false); }
  947. },{
  948. text: config.saveBtnText || _('save_and_close')
  949. ,scope: this
  950. ,handler: this.submit
  951. }]
  952. });
  953. MODx.window.QuickUpdateResource.superclass.constructor.call(this,config);
  954. };
  955. Ext.extend(MODx.window.QuickUpdateResource,MODx.Window);
  956. Ext.reg('modx-window-quick-update-modResource',MODx.window.QuickUpdateResource);
  957. MODx.getQRContentField = function(id,cls) {
  958. id = id || 'qur';
  959. cls = cls || 'modDocument';
  960. var dm = Ext.getBody().getViewSize();
  961. var o = {};
  962. switch (cls) {
  963. case 'modSymLink':
  964. o = {
  965. xtype: 'textfield'
  966. ,fieldLabel: _('symlink')
  967. ,name: 'content'
  968. ,id: 'modx-'+id+'-content'
  969. ,anchor: '100%'
  970. ,maxLength: 255
  971. ,allowBlank: false
  972. };
  973. break;
  974. case 'modWebLink':
  975. o = {
  976. xtype: 'textfield'
  977. ,fieldLabel: _('weblink')
  978. ,name: 'content'
  979. ,id: 'modx-'+id+'-content'
  980. ,anchor: '100%'
  981. ,maxLength: 255
  982. ,value: 'http://'
  983. ,allowBlank: false
  984. };
  985. break;
  986. case 'modStaticResource':
  987. o = {
  988. xtype: 'modx-combo-browser'
  989. ,browserEl: 'modx-browser'
  990. ,prependPath: false
  991. ,prependUrl: false
  992. ,hideFiles: true
  993. ,fieldLabel: _('static_resource')
  994. ,name: 'content'
  995. ,id: 'modx-'+id+'-content'
  996. ,anchor: '100%'
  997. ,maxLength: 255
  998. ,value: ''
  999. ,listeners: {
  1000. 'select':{fn:function(data) {
  1001. if (data.url.substring(0,1) == '/') {
  1002. Ext.getCmp('modx-'+id+'-content').setValue(data.url.substring(1));
  1003. }
  1004. },scope:this}
  1005. }
  1006. };
  1007. break;
  1008. case 'modResource':
  1009. case 'modDocument':
  1010. default:
  1011. o = {
  1012. xtype: 'textarea'
  1013. ,name: 'content'
  1014. ,id: 'modx-'+id+'-content'
  1015. ,hideLabel: true
  1016. ,labelSeparator: ''
  1017. ,anchor: '100% -274'
  1018. };
  1019. break;
  1020. }
  1021. return o;
  1022. };
  1023. MODx.getQRSettings = function(id,va) {
  1024. id = id || 'qur';
  1025. return [{
  1026. layout: 'column'
  1027. ,border: false
  1028. ,anchor: '100%'
  1029. ,defaults: {
  1030. labelSeparator: ''
  1031. ,labelAlign: 'top'
  1032. ,border: false
  1033. ,layout: 'form'
  1034. }
  1035. ,items: [{
  1036. columnWidth: .5
  1037. ,items: [{
  1038. xtype: 'hidden'
  1039. ,name: 'parent'
  1040. ,id: 'modx-'+id+'-parent'
  1041. ,value: va['parent']
  1042. },{
  1043. xtype: 'hidden'
  1044. ,name: 'context_key'
  1045. ,id: 'modx-'+id+'-context_key'
  1046. ,value: va['context_key']
  1047. },{
  1048. xtype: 'hidden'
  1049. ,name: 'class_key'
  1050. ,id: 'modx-'+id+'-class_key'
  1051. ,value: va['class_key']
  1052. },{
  1053. xtype: 'hidden'
  1054. ,name: 'publishedon'
  1055. ,id: 'modx-'+id+'-publishedon'
  1056. ,value: va['publishedon']
  1057. },{
  1058. xtype: 'modx-combo-content-type'
  1059. ,fieldLabel: _('resource_content_type')
  1060. ,name: 'content_type'
  1061. ,hiddenName: 'content_type'
  1062. ,id: 'modx-'+id+'-type'
  1063. ,anchor: '100%'
  1064. ,value: va['content_type'] != undefined ? va['content_type'] : (MODx.config.default_content_type || 1)
  1065. },{
  1066. xtype: 'modx-combo-content-disposition'
  1067. ,fieldLabel: _('resource_contentdispo')
  1068. ,name: 'content_dispo'
  1069. ,hiddenName: 'content_dispo'
  1070. ,id: 'modx-'+id+'-dispo'
  1071. ,anchor: '100%'
  1072. ,value: va['content_dispo'] != undefined ? va['content_dispo'] : 0
  1073. },{
  1074. xtype: 'modx-combo-class-derivatives'
  1075. ,fieldLabel: _('class_key')
  1076. ,description: '<b>[[*class_key]]</b><br />'
  1077. ,name: 'class_key'
  1078. ,hiddenName: 'class_key'
  1079. ,id: 'modx-'+id+'-class-key'
  1080. ,anchor: '100%'
  1081. ,value: va['class_key'] != undefined ? va['class_key'] : 'modDocument'
  1082. }]
  1083. },{
  1084. columnWidth: .5
  1085. ,items: [{
  1086. xtype: 'xcheckbox'
  1087. ,boxLabel: _('resource_folder')
  1088. ,description: _('resource_folder_help')
  1089. ,name: 'isfolder'
  1090. ,id: 'modx-'+id+'-isfolder'
  1091. ,inputValue: 1
  1092. ,checked: va['isfolder'] != undefined ? va['isfolder'] : false
  1093. },{
  1094. xtype: 'xcheckbox'
  1095. ,boxLabel: _('resource_richtext')
  1096. ,description: _('resource_richtext_help')
  1097. ,name: 'richtext'
  1098. ,id: 'modx-'+id+'-richtext'
  1099. ,inputValue: 1
  1100. ,checked: va['richtext'] !== undefined ? (va['richtext'] ? 1 : 0) : (MODx.config.richtext_default == '1' ? 1 : 0)
  1101. },{
  1102. xtype: 'xcheckbox'
  1103. ,boxLabel: _('resource_searchable')
  1104. ,description: _('resource_searchable_help')
  1105. ,name: 'searchable'
  1106. ,id: 'modx-'+id+'-searchable'
  1107. ,inputValue: 1
  1108. ,checked: va['searchable'] != undefined ? va['searchable'] : (MODx.config.search_default == '1' ? 1 : 0)
  1109. ,listeners: {'check': {fn:MODx.handleQUCB}}
  1110. },{
  1111. xtype: 'xcheckbox'
  1112. ,boxLabel: _('resource_cacheable')
  1113. ,description: _('resource_cacheable_help')
  1114. ,name: 'cacheable'
  1115. ,id: 'modx-'+id+'-cacheable'
  1116. ,inputValue: 1
  1117. ,checked: va['cacheable'] != undefined ? va['cacheable'] : (MODx.config.cache_default == '1' ? 1 : 0)
  1118. },{
  1119. xtype: 'xcheckbox'
  1120. ,name: 'clearCache'
  1121. ,id: 'modx-'+id+'-clearcache'
  1122. ,boxLabel: _('clear_cache_on_save')
  1123. ,description: _('clear_cache_on_save_msg')
  1124. ,inputValue: 1
  1125. ,checked: true
  1126. }]
  1127. }]
  1128. }];
  1129. };
  1130. MODx.handleQUCB = function(cb) {
  1131. var h = Ext.getCmp(cb.id+'-hd');
  1132. if (cb.checked && h) {
  1133. cb.setValue(1);
  1134. h.setValue(1);
  1135. } else if (h) {
  1136. cb.setValue(0);
  1137. h.setValue(0);
  1138. }
  1139. }