modx.tree.resource.js 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354
  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.connector_url
  13. ,action: 'resource/getNodes'
  14. ,title: ''
  15. ,rootVisible: false
  16. ,expandFirst: true
  17. ,enableDD: (MODx.config.enable_dragdrop != '0') ? true : false
  18. ,ddGroup: 'modx-treedrop-dd'
  19. ,remoteToolbar: true
  20. ,remoteToolbarAction: 'resource/gettoolbar'
  21. ,sortAction: 'resource/sort'
  22. ,sortBy: this.getDefaultSortBy(config)
  23. ,tbarCfg: {
  24. // hidden: true
  25. id: config.id ? config.id+'-tbar' : 'modx-tree-resource-tbar'
  26. }
  27. ,baseParams: {
  28. sortBy: this.getDefaultSortBy(config)
  29. ,currentResource: MODx.request.id || 0
  30. ,currentAction: MODx.request.a || 0
  31. }
  32. });
  33. MODx.tree.Resource.superclass.constructor.call(this,config);
  34. this.addEvents('loadCreateMenus', 'emptyTrash');
  35. this.on('afterSort',this._handleAfterDrop,this);
  36. };
  37. Ext.extend(MODx.tree.Resource,MODx.tree.Tree,{
  38. forms: {}
  39. ,windows: {}
  40. ,stores: {}
  41. ,_initExpand: function() {
  42. var treeState = Ext.state.Manager.get(this.treestate_id);
  43. if ((Ext.isString(treeState) || Ext.isEmpty(treeState)) && this.root) {
  44. if (this.root) {this.root.expand();}
  45. var wn = this.getNodeById('web_0');
  46. if (wn && this.config.expandFirst) {
  47. wn.select();
  48. wn.expand();
  49. }
  50. } else {
  51. // If we have disabled context sort, make sure dragging and dropping is disabled on the root elements
  52. // in the tree. This corresponds to the context nodes.
  53. if (MODx.config.context_tree_sort !== '1') {
  54. if (typeof(this.root) !== 'undefined' && typeof(this.root.childNodes) !== 'undefined') {
  55. for (var i = 0; i < this.root.childNodes.length; i++) {
  56. this.root.childNodes[i].draggable = false;
  57. }
  58. }
  59. }
  60. for (var i=0;i<treeState.length;i++) {
  61. this.expandPath(treeState[i]);
  62. }
  63. }
  64. }
  65. /*,addSearchToolbar: function() {
  66. this.searchField = new Ext.form.TextField({
  67. emptyText: _('search_ellipsis')
  68. ,listeners: {
  69. 'change': {fn: this.search,scope:this}
  70. ,'render': {fn: function(cmp) {
  71. new Ext.KeyMap(cmp.getEl(), {
  72. key: Ext.EventObject.ENTER
  73. ,fn: function() {
  74. this.fireEvent('change',this.getValue());
  75. this.blur();
  76. return true;}
  77. ,scope: cmp
  78. });
  79. },scope:this}
  80. }
  81. });
  82. this.searchBar = new Ext.Toolbar({
  83. renderTo: this.tbar
  84. ,id: 'modx-resource-searchbar'
  85. ,items: [this.searchField]
  86. });
  87. this.on('resize', function(){
  88. this.searchField.setWidth(this.getWidth() - 12);
  89. }, this);
  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. this.cm.activeNode = n;
  107. this.cm.removeAll();
  108. if (n.attributes.menu && n.attributes.menu.items) {
  109. this.addContextMenuItem(n.attributes.menu.items);
  110. } else {
  111. var m = [];
  112. switch (n.attributes.type) {
  113. case 'modResource':
  114. case 'modDocument':
  115. m = this._getModResourceMenu(n);
  116. break;
  117. case 'modContext':
  118. m = this._getModContextMenu(n);
  119. break;
  120. }
  121. this.addContextMenuItem(m);
  122. }
  123. this.cm.showAt(e.xy);
  124. e.stopEvent();
  125. }
  126. ,duplicateResource: function(item,e) {
  127. var node = this.cm.activeNode;
  128. var id = node.id.split('_');id = id[1];
  129. var name = node.ui.textNode.innerText;
  130. var r = {
  131. resource: id
  132. ,is_folder: node.getUI().hasClass('folder')
  133. };
  134. var w = MODx.load({
  135. xtype: 'modx-window-resource-duplicate'
  136. ,resource: id
  137. ,pagetitle: name
  138. ,hasChildren: node.attributes.hasChildren
  139. ,childCount: node.attributes.childCount
  140. ,listeners: {
  141. 'success': {fn:function() {
  142. node.parentNode.attributes.childCount = parseInt(node.parentNode.attributes.childCount) + 1;
  143. this.refreshNode(node.id);
  144. },scope:this
  145. }
  146. }
  147. });
  148. w.config.hasChildren = node.attributes.hasChildren;
  149. w.setValues(r);
  150. w.show(e.target);
  151. }
  152. ,duplicateContext: function(itm,e) {
  153. var node = this.cm.activeNode;
  154. var key = node.attributes.pk;
  155. var r = {
  156. key: key
  157. ,newkey: ''
  158. };
  159. var w = MODx.load({
  160. xtype: 'modx-window-context-duplicate'
  161. ,record: r
  162. ,listeners: {
  163. 'success': {fn:function() {this.refresh();},scope:this}
  164. }
  165. });
  166. w.show(e.target);
  167. }
  168. ,removeContext: function(itm,e) {
  169. var node = this.cm.activeNode;
  170. var key = node.attributes.pk;
  171. MODx.msg.confirm({
  172. title: _('context_remove')
  173. ,text: _('context_remove_confirm')
  174. ,url: MODx.config.connector_url
  175. ,params: {
  176. action: 'context/remove'
  177. ,key: key
  178. }
  179. ,listeners: {
  180. 'success': {fn:function() {
  181. var cmp = Ext.getCmp('modx-grid-context');
  182. if (cmp) {
  183. cmp.refresh();
  184. }
  185. this.refresh();
  186. },scope:this}
  187. }
  188. });
  189. }
  190. ,preview: function() {
  191. window.open(this.cm.activeNode.attributes.preview_url);
  192. }
  193. ,deleteDocument: function(itm,e) {
  194. var node = this.cm.activeNode;
  195. var id = node.id.split('_');id = id[1];
  196. var pagetitle = node.ui.textNode.innerText;
  197. MODx.msg.confirm({
  198. title: pagetitle ? _('resource_delete') + ' ' + pagetitle : _('resource_delete')
  199. ,text: _('resource_delete_confirm')
  200. ,url: MODx.config.connector_url
  201. ,params: {
  202. action: 'resource/delete'
  203. ,id: id
  204. }
  205. ,listeners: {
  206. 'success': {fn:function(data) {
  207. var trashButton = this.getTopToolbar().findById('emptifier');
  208. if (trashButton) {
  209. if (data.object.deletedCount == 0) {
  210. trashButton.disable();
  211. } else {
  212. trashButton.enable();
  213. }
  214. trashButton.setTooltip(_('trash.manage_recycle_bin_tooltip', {count: data.object.deletedCount}));
  215. }
  216. var n = this.cm.activeNode;
  217. var ui = n.getUI();
  218. ui.addClass('deleted');
  219. n.cascade(function(nd) {
  220. nd.getUI().addClass('deleted');
  221. },this);
  222. // refresh the trash manager if possible
  223. var trashlist = Ext.getCmp('modx-trash-resources');
  224. if (trashlist) {
  225. trashlist.refresh();
  226. }
  227. Ext.get(ui.getEl()).frame();
  228. },scope:this}
  229. }
  230. });
  231. }
  232. ,undeleteDocument: function(itm,e) {
  233. var node = this.cm.activeNode;
  234. var id = node.id.split('_');id = id[1];
  235. MODx.Ajax.request({
  236. url: MODx.config.connector_url
  237. ,params: {
  238. action: 'resource/undelete'
  239. ,id: id
  240. }
  241. ,listeners: {
  242. 'success': {fn:function(data) {
  243. var trashButton = this.getTopToolbar().findById('emptifier');
  244. if (trashButton) {
  245. if (data.object.deletedCount == 0) {
  246. trashButton.disable();
  247. } else {
  248. trashButton.enable();
  249. }
  250. trashButton.setTooltip(_('trash.manage_recycle_bin_tooltip', {count: data.object.deletedCount}));
  251. }
  252. var n = this.cm.activeNode;
  253. var ui = n.getUI();
  254. ui.removeClass('deleted');
  255. n.cascade(function(nd) {
  256. nd.getUI().removeClass('deleted');
  257. },this);
  258. // refresh the trash manager if possible
  259. var trashlist = Ext.getCmp('modx-trash-resources');
  260. if (trashlist) {
  261. trashlist.refresh();
  262. }
  263. Ext.get(ui.getEl()).frame();
  264. },scope:this}
  265. }
  266. });
  267. }
  268. ,publishDocument: function(itm,e) {
  269. var node = this.cm.activeNode;
  270. var id = node.id.split('_');id = id[1];
  271. MODx.msg.confirm({
  272. title: _('resource_publish')
  273. ,text: _('resource_publish_confirm')
  274. ,url: MODx.config.connector_url
  275. ,params: {
  276. action: 'resource/publish'
  277. ,id: id
  278. }
  279. ,listeners: {
  280. 'success': {fn:function() {
  281. var ui = this.cm.activeNode.getUI();
  282. ui.removeClass('unpublished');
  283. Ext.get(ui.getEl()).frame();
  284. },scope:this}
  285. }
  286. });
  287. }
  288. ,unpublishDocument: function(itm,e) {
  289. var node = this.cm.activeNode;
  290. var id = node.id.split('_');id = id[1];
  291. MODx.msg.confirm({
  292. title: _('resource_unpublish')
  293. ,text: _('resource_unpublish_confirm')
  294. ,url: MODx.config.connector_url
  295. ,params: {
  296. action: 'resource/unpublish'
  297. ,id: id
  298. }
  299. ,listeners: {
  300. 'success': {fn:function() {
  301. var ui = this.cm.activeNode.getUI();
  302. ui.addClass('unpublished');
  303. Ext.get(ui.getEl()).frame();
  304. },scope:this}
  305. }
  306. });
  307. }
  308. ,getDefaultSortBy: function(config) {
  309. var v = 'menuindex';
  310. if (!Ext.isEmpty(config) && !Ext.isEmpty(config.sortBy)) {
  311. v = config.sortBy;
  312. } else {
  313. var d = Ext.state.Manager.get(this.treestate_id+'-sort-default');
  314. if (d != MODx.config.tree_default_sort) {
  315. v = MODx.config.tree_default_sort;
  316. Ext.state.Manager.set(this.treestate_id+'-sort-default',v);
  317. Ext.state.Manager.set(this.treestate_id+'-sort',v);
  318. } else {
  319. v = Ext.state.Manager.get(this.treestate_id+'-sort') || MODx.config.tree_default_sort;
  320. }
  321. }
  322. return v;
  323. }
  324. ,filterSort: function(itm, e) {
  325. this.getLoader().baseParams = {
  326. action: this.config.action
  327. ,sortBy: itm.sortBy
  328. ,sortDir: itm.sortDir
  329. ,node: this.cm.activeNode.ide
  330. };
  331. this.refreshActiveNode()
  332. }
  333. ,hideFilter: function(itm,e) {
  334. this.filterBar.destroy();
  335. this._filterVisible = false;
  336. }
  337. ,_handleAfterDrop: function(o,r) {
  338. var targetNode = o.event.target;
  339. var dropNode = o.event.dropNode;
  340. if (o.event.point == 'append' && targetNode) {
  341. var ui = targetNode.getUI();
  342. ui.addClass('haschildren');
  343. ui.removeClass('icon-resource');
  344. }
  345. if((MODx.request.a == MODx.action['resource/update']) && dropNode.attributes.pk == MODx.request.id){
  346. var parentFieldCmb = Ext.getCmp('modx-resource-parent');
  347. var parentFieldHidden = Ext.getCmp('modx-resource-parent-hidden');
  348. if(parentFieldCmb && parentFieldHidden){
  349. parentFieldHidden.setValue(dropNode.parentNode.attributes.pk);
  350. parentFieldCmb.setValue(dropNode.parentNode.attributes.text.replace(/(<([^>]+)>)/ig,""));
  351. }
  352. }
  353. }
  354. ,_handleDrop: function(e){
  355. var dropNode = e.dropNode;
  356. var targetParent = e.target;
  357. if (targetParent.findChild('id',dropNode.attributes.id) !== null) {return false;}
  358. if (dropNode.attributes.type == 'modContext' && (targetParent.getDepth() > 1 || (targetParent.attributes.id == targetParent.attributes.pk + '_0' && e.point == 'append'))) {
  359. return false;
  360. }
  361. if (dropNode.attributes.type !== 'modContext' && targetParent.getDepth() <= 1 && e.point !== 'append') {
  362. return false;
  363. }
  364. if (MODx.config.resource_classes_drop[targetParent.attributes.classKey] == undefined) {
  365. if (targetParent.attributes.hide_children_in_tree) { return false; }
  366. } else if (MODx.config.resource_classes_drop[targetParent.attributes.classKey] == 0) {
  367. return false;
  368. }
  369. return dropNode.attributes.text != 'root' && dropNode.attributes.text !== ''
  370. && targetParent.attributes.text != 'root' && targetParent.attributes.text !== '';
  371. }
  372. ,getContextSettingForNode: function(node,ctx,setting,dv) {
  373. var val = dv || null;
  374. if (node.attributes.type != 'modContext') {
  375. var t = node.getOwnerTree();
  376. var rn = t.getRootNode();
  377. var cn = rn.findChild('ctx',ctx,false);
  378. if (cn) {
  379. val = cn.attributes.settings[setting];
  380. }
  381. } else {
  382. val = node.attributes.settings[setting];
  383. }
  384. return val;
  385. }
  386. ,quickCreate: function(itm,e,cls,ctx,p) {
  387. cls = cls || 'modDocument';
  388. var r = {
  389. class_key: cls
  390. ,context_key: ctx || 'web'
  391. ,'parent': p || 0
  392. ,'template': parseInt(this.getContextSettingForNode(this.cm.activeNode,ctx,'default_template',MODx.config.default_template))
  393. ,'richtext': parseInt(this.getContextSettingForNode(this.cm.activeNode,ctx,'richtext_default',MODx.config.richtext_default))
  394. ,'hidemenu': parseInt(this.getContextSettingForNode(this.cm.activeNode,ctx,'hidemenu_default',MODx.config.hidemenu_default))
  395. ,'searchable': parseInt(this.getContextSettingForNode(this.cm.activeNode,ctx,'search_default',MODx.config.search_default))
  396. ,'cacheable': parseInt(this.getContextSettingForNode(this.cm.activeNode,ctx,'cache_default',MODx.config.cache_default))
  397. ,'published': parseInt(this.getContextSettingForNode(this.cm.activeNode,ctx,'publish_default',MODx.config.publish_default))
  398. ,'content_type': parseInt(this.getContextSettingForNode(this.cm.activeNode,ctx,'default_content_type',MODx.config.default_content_type))
  399. };
  400. if (this.cm.activeNode.attributes.type != 'modContext') {
  401. var t = this.cm.activeNode.getOwnerTree();
  402. var rn = t.getRootNode();
  403. var cn = rn.findChild('ctx',ctx,false);
  404. if (cn) {
  405. r['template'] = cn.attributes.settings.default_template;
  406. }
  407. } else {
  408. r['template'] = this.cm.activeNode.attributes.settings.default_template;
  409. }
  410. var w = MODx.load({
  411. xtype: 'modx-window-quick-create-modResource'
  412. ,record: r
  413. ,listeners: {
  414. 'success':{
  415. fn: function() {
  416. this.refreshNode(this.cm.activeNode.id, this.cm.activeNode.childNodes.length > 0);
  417. }
  418. ,scope: this}
  419. ,'hide':{fn:function() {this.destroy();}}
  420. ,'show':{fn:function() {this.center();}}
  421. }
  422. });
  423. w.setValues(r);
  424. w.show(e.target,function() {
  425. Ext.isSafari ? w.setPosition(null,30) : w.center();
  426. },this);
  427. }
  428. ,quickUpdate: function(itm,e,cls) {
  429. MODx.Ajax.request({
  430. url: MODx.config.connector_url
  431. ,params: {
  432. action: 'resource/get'
  433. ,id: this.cm.activeNode.attributes.pk
  434. ,skipFormatDates: true
  435. }
  436. ,listeners: {
  437. 'success': {fn:function(r) {
  438. var pr = r.object;
  439. pr.class_key = cls;
  440. var w = MODx.load({
  441. xtype: 'modx-window-quick-update-modResource'
  442. ,record: pr
  443. ,listeners: {
  444. 'success':{fn:function(r) {
  445. this.refreshNode(this.cm.activeNode.id);
  446. var newTitle = '<span dir="ltr">' + r.f.findField('pagetitle').getValue() + ' (' + w.record.id + ')</span>';
  447. w.setTitle(w.title.replace(/<span.*\/span>/, newTitle));
  448. },scope:this}
  449. ,'hide':{fn:function() {this.destroy();}}
  450. }
  451. });
  452. w.title += ': <span dir="ltr">' + Ext.util.Format.htmlEncode(w.record.pagetitle) + ' ('+ w.record.id + ')</span>';
  453. w.setValues(r.object);
  454. w.show(e.target,function() {
  455. Ext.isSafari ? w.setPosition(null,30) : w.center();
  456. },this);
  457. },scope:this}
  458. }
  459. });
  460. }
  461. ,_getModContextMenu: function(n) {
  462. var a = n.attributes;
  463. var ui = n.getUI();
  464. var m = [];
  465. m.push({
  466. text: '<b>'+a.text+'</b>'
  467. ,handler: function() {return false;}
  468. ,header: true
  469. });
  470. m.push('-');
  471. if (ui.hasClass('pedit')) {
  472. m.push({
  473. text: _('edit_context')
  474. ,handler: function() {
  475. var at = this.cm.activeNode.attributes;
  476. this.loadAction('a=context/update&key='+at.pk);
  477. }
  478. });
  479. }
  480. m.push({
  481. text: _('context_refresh')
  482. ,handler: function() {
  483. this.refreshNode(this.cm.activeNode.id,true);
  484. }
  485. });
  486. if (ui.hasClass('pnewdoc')) {
  487. m.push('-');
  488. this._getCreateMenus(m,'0',ui);
  489. }
  490. if (ui.hasClass('pnew')) {
  491. m.push({
  492. text: _('context_duplicate')
  493. ,handler: this.duplicateContext
  494. });
  495. }
  496. if (ui.hasClass('pdelete')) {
  497. m.push('-');
  498. m.push({
  499. text: _('context_remove')
  500. ,handler: this.removeContext
  501. });
  502. }
  503. if(!ui.hasClass('x-tree-node-leaf')) {
  504. m.push('-');
  505. m.push(this._getSortMenu());
  506. }
  507. return m;
  508. }
  509. ,overviewResource: function() {this.loadAction('a=resource/data')}
  510. ,quickUpdateResource: function(itm,e) {
  511. this.quickUpdate(itm,e,itm.classKey);
  512. }
  513. ,editResource: function() {this.loadAction('a=resource/update');}
  514. ,_getModResourceMenu: function(n) {
  515. var a = n.attributes;
  516. var ui = n.getUI();
  517. var m = [];
  518. m.push({
  519. text: '<b>'+a.text+'</b>'
  520. ,handler: function() {return false;}
  521. ,header: true
  522. });
  523. m.push('-');
  524. if (ui.hasClass('pview')) {
  525. m.push({
  526. text: _('resource_overview')
  527. ,handler: this.overviewResource
  528. });
  529. }
  530. if (ui.hasClass('pedit')) {
  531. m.push({
  532. text: _('resource_edit')
  533. ,handler: this.editResource
  534. });
  535. }
  536. if (ui.hasClass('pqupdate')) {
  537. m.push({
  538. text: _('quick_update_resource')
  539. ,classKey: a.classKey
  540. ,handler: this.quickUpdateResource
  541. });
  542. }
  543. if (ui.hasClass('pduplicate')) {
  544. m.push({
  545. text: _('resource_duplicate')
  546. ,handler: this.duplicateResource
  547. });
  548. }
  549. m.push({
  550. text: _('resource_refresh')
  551. ,handler: this.refreshResource
  552. ,scope: this
  553. });
  554. if (ui.hasClass('pnew')) {
  555. m.push('-');
  556. this._getCreateMenus(m,null,ui);
  557. }
  558. if (ui.hasClass('psave')) {
  559. m.push('-');
  560. if (ui.hasClass('ppublish') && ui.hasClass('unpublished')) {
  561. m.push({
  562. text: _('resource_publish')
  563. ,handler: this.publishDocument
  564. });
  565. } else if (ui.hasClass('punpublish')) {
  566. m.push({
  567. text: _('resource_unpublish')
  568. ,handler: this.unpublishDocument
  569. });
  570. }
  571. if (ui.hasClass('pundelete') && ui.hasClass('deleted')) {
  572. m.push({
  573. text: _('resource_undelete')
  574. ,handler: this.undeleteDocument
  575. });
  576. } else if (ui.hasClass('pdelete') && !ui.hasClass('deleted')) {
  577. m.push({
  578. text: _('resource_delete')
  579. ,handler: this.deleteDocument
  580. });
  581. }
  582. }
  583. if(!ui.hasClass('x-tree-node-leaf')) {
  584. m.push('-');
  585. m.push(this._getSortMenu());
  586. }
  587. if (ui.hasClass('pview') && a.preview_url != '') {
  588. m.push('-');
  589. m.push({
  590. text: _('resource_view')
  591. ,handler: this.preview
  592. });
  593. }
  594. return m;
  595. }
  596. ,refreshResource: function() {
  597. this.refreshNode(this.cm.activeNode.id);
  598. }
  599. ,createResourceHere: function(itm) {
  600. var at = this.cm.activeNode.attributes;
  601. var p = itm.usePk ? itm.usePk : at.pk;
  602. this.loadAction(
  603. 'a=resource/create&class_key=' + itm.classKey + '&parent=' + p + (at.ctx ? '&context_key='+at.ctx : '')
  604. );
  605. }
  606. ,createResource: function(itm,e) {
  607. var at = this.cm.activeNode.attributes;
  608. var p = itm.usePk ? itm.usePk : at.pk;
  609. this.quickCreate(itm,e,itm.classKey,at.ctx,p);
  610. }
  611. ,_getCreateMenus: function(m,pk,ui) {
  612. var types = MODx.config.resource_classes;
  613. var o = this.fireEvent('loadCreateMenus',types);
  614. if (Ext.isObject(o)) {
  615. Ext.apply(types,o);
  616. }
  617. var coreTypes = ['modDocument','modWebLink','modSymLink','modStaticResource'];
  618. var ct = [];
  619. var qct = [];
  620. for (var k in types) {
  621. if (coreTypes.indexOf(k) != -1) {
  622. if (!ui.hasClass('pnew_'+k)) {
  623. continue;
  624. }
  625. }
  626. ct.push({
  627. text: types[k]['text_create_here']
  628. ,classKey: k
  629. ,usePk: pk ? pk : false
  630. ,handler: this.createResourceHere
  631. ,scope: this
  632. });
  633. if (ui && ui.hasClass('pqcreate')) {
  634. qct.push({
  635. text: types[k]['text_create']
  636. ,classKey: k
  637. ,handler: this.createResource
  638. ,scope: this
  639. });
  640. }
  641. }
  642. m.push({
  643. text: _('create')
  644. ,handler: function() {return false;}
  645. ,menu: {items: ct}
  646. });
  647. if (ui && ui.hasClass('pqcreate')) {
  648. m.push({
  649. text: _('quick_create')
  650. ,handler: function() {return false;}
  651. ,menu: {items: qct}
  652. });
  653. }
  654. return m;
  655. }
  656. /**
  657. * Handles all drag events into the tree.
  658. * @param {Object} dropEvent The node dropped on the parent node.
  659. */
  660. ,_handleDrag: function(dropEvent) {
  661. function simplifyNodes(node) {
  662. var resultNode = {};
  663. var kids = node.childNodes;
  664. var len = kids.length;
  665. for (var i = 0; i < len; i++) {
  666. resultNode[kids[i].id] = simplifyNodes(kids[i]);
  667. }
  668. return resultNode;
  669. }
  670. var encNodes = Ext.encode(simplifyNodes(dropEvent.tree.root));
  671. this.fireEvent('beforeSort',encNodes);
  672. MODx.Ajax.request({
  673. url: this.config.url
  674. ,params: {
  675. target: dropEvent.target.attributes.id
  676. ,source: dropEvent.source.dragData.node.attributes.id
  677. ,point: dropEvent.point
  678. ,data: encodeURIComponent(encNodes)
  679. ,action: this.config.sortAction || 'sort'
  680. }
  681. ,listeners: {
  682. 'success': {fn:function(r) {
  683. var el = dropEvent.dropNode.getUI().getTextEl();
  684. if (el) {Ext.get(el).frame();}
  685. this.fireEvent('afterSort',{event:dropEvent,result:r});
  686. },scope:this}
  687. ,'failure': {fn:function(r) {
  688. MODx.form.Handler.errorJSON(r);
  689. this.refresh();
  690. return false;
  691. },scope:this}
  692. }
  693. });
  694. }
  695. ,_getSortMenu: function(){
  696. return [{
  697. text: _('sort_by')
  698. ,handler: function() {return false;}
  699. ,menu: {
  700. items:[{
  701. text: _('tree_order')
  702. ,sortBy: 'menuindex'
  703. ,sortDir: 'ASC'
  704. ,handler: this.filterSort
  705. ,scope: this
  706. },{
  707. text: _('recently_updated')
  708. ,sortBy: 'editedon'
  709. ,sortDir: 'ASC'
  710. ,handler: this.filterSort
  711. ,scope: this
  712. },{
  713. text: _('newest')
  714. ,sortBy: 'createdon'
  715. ,sortDir: 'DESC'
  716. ,handler: this.filterSort
  717. ,scope: this
  718. },{
  719. text: _('oldest')
  720. ,sortBy: 'createdon'
  721. ,sortDir: 'ASC'
  722. ,handler: this.filterSort
  723. ,scope: this
  724. },{
  725. text: _('publish_date')
  726. ,sortBy: 'pub_date'
  727. ,sortDir: 'ASC'
  728. ,handler: this.filterSort
  729. ,scope: this
  730. },{
  731. text: _('unpublish_date')
  732. ,sortBy: 'unpub_date'
  733. ,sortDir: 'ASC'
  734. ,handler: this.filterSort
  735. ,scope: this
  736. },{
  737. text: _('publishedon')
  738. ,sortBy: 'publishedon'
  739. ,sortDir: 'ASC'
  740. ,handler: this.filterSort
  741. ,scope: this
  742. },{
  743. text: _('title')
  744. ,sortBy: 'pagetitle'
  745. ,sortDir: 'ASC'
  746. ,handler: this.filterSort
  747. ,scope: this
  748. },{
  749. text: _('alias')
  750. ,sortBy: 'alias'
  751. ,sortDir: 'ASC'
  752. ,handler: this.filterSort
  753. ,scope: this
  754. }]
  755. }
  756. }];
  757. }
  758. ,handleCreateClick: function(node){
  759. this.cm.activeNode = node;
  760. var itm = {
  761. usePk: '0'
  762. ,classKey: 'modDocument'
  763. };
  764. this.createResourceHere(itm);
  765. }
  766. ,handleDirectCreateClick: function(node){
  767. this.cm.activeNode = node;
  768. this.createResourceHere({
  769. classKey: 'modDocument'
  770. });
  771. }
  772. /**
  773. * Renders the item text without any special formatting. The resource/getnodes processor already protects against XSS.
  774. */
  775. ,renderItemText: function(item) {
  776. return item.text;
  777. }
  778. });
  779. Ext.reg('modx-tree-resource',MODx.tree.Resource);
  780. MODx.window.QuickCreateResource = function(config) {
  781. config = config || {};
  782. this.ident = config.ident || 'qcr'+Ext.id();
  783. Ext.applyIf(config,{
  784. title: _('quick_create_resource')
  785. ,id: this.ident
  786. ,bwrapCssClass: 'x-window-with-tabs'
  787. ,width: 700
  788. //,height: ['modSymLink', 'modWebLink', 'modStaticResource'].indexOf(config.record.class_key) == -1 ? 640 : 498
  789. // ,autoHeight: false
  790. ,layout: 'anchor'
  791. ,url: MODx.config.connector_url
  792. ,action: 'resource/create'
  793. // ,shadow: false
  794. ,fields: [{
  795. xtype: 'modx-tabs'
  796. ,bodyStyle: { background: 'transparent' }
  797. ,border: true
  798. ,deferredRender: false
  799. ,autoHeight: false
  800. ,autoScroll: false
  801. ,anchor: '100% 100%'
  802. ,items: [{
  803. title: _('resource')
  804. ,layout: 'form'
  805. ,cls: 'modx-panel'
  806. // ,bodyStyle: { background: 'transparent', padding: '10px' } // we handle this in CSS
  807. ,autoHeight: false
  808. ,anchor: '100% 100%'
  809. ,labelWidth: 100
  810. ,items: [{
  811. xtype: 'hidden'
  812. ,name: 'id'
  813. },{
  814. layout: 'column'
  815. ,border: false
  816. ,items: [{
  817. columnWidth: .6
  818. ,border: false
  819. ,layout: 'form'
  820. ,items: [{
  821. xtype: 'textfield'
  822. ,name: 'pagetitle'
  823. ,id: 'modx-'+this.ident+'-pagetitle'
  824. ,fieldLabel: _('resource_pagetitle')+'<span class="required">*</span>'
  825. ,description: '<b>[[*pagetitle]]</b><br />'+_('resource_pagetitle_help')
  826. ,anchor: '100%'
  827. ,allowBlank: false
  828. },{
  829. xtype: 'textfield'
  830. ,name: 'longtitle'
  831. ,id: 'modx-'+this.ident+'-longtitle'
  832. ,fieldLabel: _('resource_longtitle')
  833. ,description: '<b>[[*longtitle]]</b><br />'+_('resource_longtitle_help')
  834. ,anchor: '100%'
  835. },{
  836. xtype: 'textarea'
  837. ,name: 'description'
  838. ,id: 'modx-'+this.ident+'-description'
  839. ,fieldLabel: _('resource_description')
  840. ,description: '<b>[[*description]]</b><br />'+_('resource_description_help')
  841. ,anchor: '100%'
  842. ,grow: false
  843. ,height: 50
  844. },{
  845. xtype: 'textarea'
  846. ,name: 'introtext'
  847. ,id: 'modx-'+this.ident+'-introtext'
  848. ,fieldLabel: _('resource_summary')
  849. ,description: '<b>[[*introtext]]</b><br />'+_('resource_summary_help')
  850. ,anchor: '100%'
  851. ,height: 50
  852. }]
  853. },{
  854. columnWidth: .4
  855. ,border: false
  856. ,layout: 'form'
  857. ,items: [{
  858. xtype: 'modx-combo-template'
  859. ,name: 'template'
  860. ,id: 'modx-'+this.ident+'-template'
  861. ,fieldLabel: _('resource_template')
  862. ,description: '<b>[[*template]]</b><br />'+_('resource_template_help')
  863. ,editable: false
  864. ,anchor: '100%'
  865. ,baseParams: {
  866. action: 'element/template/getList'
  867. ,combo: '1'
  868. ,limit: 0
  869. }
  870. ,value: MODx.config.default_template
  871. },{
  872. xtype: 'textfield'
  873. ,name: 'alias'
  874. ,id: 'modx-'+this.ident+'-alias'
  875. ,fieldLabel: _('resource_alias')
  876. ,description: '<b>[[*alias]]</b><br />'+_('resource_alias_help')
  877. ,anchor: '100%'
  878. },{
  879. xtype: 'textfield'
  880. ,name: 'menutitle'
  881. ,id: 'modx-'+this.ident+'-menutitle'
  882. ,fieldLabel: _('resource_menutitle')
  883. ,description: '<b>[[*menutitle]]</b><br />'+_('resource_menutitle_help')
  884. ,anchor: '100%'
  885. },{
  886. xtype: 'textfield'
  887. ,fieldLabel: _('resource_link_attributes')
  888. ,description: '<b>[[*link_attributes]]</b><br />'+_('resource_link_attributes_help')
  889. ,name: 'link_attributes'
  890. ,id: 'modx-'+this.ident+'-attributes'
  891. ,maxLength: 255
  892. ,anchor: '100%'
  893. },{
  894. xtype: 'xcheckbox'
  895. ,boxLabel: _('resource_hide_from_menus')
  896. ,description: '<b>[[*hidemenu]]</b><br />'+_('resource_hide_from_menus_help')
  897. ,hideLabel: true
  898. ,name: 'hidemenu'
  899. ,id: 'modx-'+this.ident+'-hidemenu'
  900. ,inputValue: 1
  901. ,checked: MODx.config.hidemenu_default == '1' ? 1 : 0
  902. },{
  903. xtype: 'xcheckbox'
  904. ,name: 'published'
  905. ,id: 'modx-'+this.ident+'-published'
  906. ,boxLabel: _('resource_published')
  907. ,description: '<b>[[*published]]</b><br />'+_('resource_published_help')
  908. ,hideLabel: true
  909. ,inputValue: 1
  910. ,checked: MODx.config.publish_default == '1' ? 1 : 0
  911. }]
  912. }]
  913. },MODx.getQRContentField(this.ident,config.record.class_key)]
  914. },{
  915. id: 'modx-'+this.ident+'-settings'
  916. ,title: _('settings')
  917. ,layout: 'form'
  918. ,cls: 'modx-panel'
  919. ,autoHeight: true
  920. ,forceLayout: true
  921. ,labelWidth: 100
  922. ,defaults: {
  923. autoHeight: true
  924. ,border: false
  925. }
  926. // ,bodyStyle: { padding: '10px' } // we handle this in CSS
  927. ,items: MODx.getQRSettings(this.ident,config.record)
  928. }]
  929. }]
  930. ,keys: [{
  931. key: Ext.EventObject.ENTER
  932. ,shift: true
  933. ,fn: this.submit
  934. ,scope: this
  935. }]
  936. });
  937. MODx.window.QuickCreateResource.superclass.constructor.call(this,config);
  938. };
  939. Ext.extend(MODx.window.QuickCreateResource,MODx.Window);
  940. Ext.reg('modx-window-quick-create-modResource',MODx.window.QuickCreateResource);
  941. MODx.window.QuickUpdateResource = function(config) {
  942. config = config || {};
  943. this.ident = config.ident || 'qur'+Ext.id();
  944. Ext.applyIf(config,{
  945. title: _('quick_update_resource')
  946. ,id: this.ident
  947. ,action: 'resource/update'
  948. ,buttons: [{
  949. text: config.cancelBtnText || _('cancel')
  950. ,scope: this
  951. ,handler: function() { this.hide(); }
  952. },{
  953. text: config.saveBtnText || _('save')
  954. ,scope: this
  955. ,handler: function() { this.submit(false); }
  956. },{
  957. text: config.saveBtnText || _('save_and_close')
  958. ,cls: 'primary-button'
  959. ,scope: this
  960. ,handler: this.submit
  961. }]
  962. });
  963. MODx.window.QuickUpdateResource.superclass.constructor.call(this,config);
  964. };
  965. Ext.extend(MODx.window.QuickUpdateResource,MODx.window.QuickCreateResource);
  966. Ext.reg('modx-window-quick-update-modResource',MODx.window.QuickUpdateResource);
  967. MODx.getQRContentField = function(id,cls) {
  968. id = id || 'qur';
  969. cls = cls || 'modDocument';
  970. var dm = Ext.getBody().getViewSize();
  971. var o = {};
  972. switch (cls) {
  973. case 'modSymLink':
  974. o = {
  975. xtype: 'textfield'
  976. ,fieldLabel: _('symlink')
  977. ,name: 'content'
  978. ,id: 'modx-'+id+'-content'
  979. ,anchor: '100%'
  980. ,maxLength: 255
  981. ,allowBlank: false
  982. };
  983. break;
  984. case 'modWebLink':
  985. o = {
  986. xtype: 'textfield'
  987. ,fieldLabel: _('weblink')
  988. ,name: 'content'
  989. ,id: 'modx-'+id+'-content'
  990. ,anchor: '100%'
  991. ,maxLength: 255
  992. ,value: 'http://'
  993. ,allowBlank: false
  994. };
  995. break;
  996. case 'modStaticResource':
  997. o = {
  998. xtype: 'modx-combo-browser'
  999. ,browserEl: 'modx-browser'
  1000. ,prependPath: false
  1001. ,prependUrl: false
  1002. // ,hideFiles: true
  1003. ,fieldLabel: _('static_resource')
  1004. ,name: 'content'
  1005. ,id: 'modx-'+id+'-content'
  1006. ,anchor: '100%'
  1007. ,maxLength: 255
  1008. ,value: ''
  1009. ,listeners: {
  1010. 'select':{fn:function(data) {
  1011. if (data.url.substring(0,1) == '/') {
  1012. Ext.getCmp('modx-'+id+'-content').setValue(data.url.substring(1));
  1013. }
  1014. },scope:this}
  1015. }
  1016. };
  1017. break;
  1018. case 'modResource':
  1019. case 'modDocument':
  1020. default:
  1021. o = {
  1022. xtype: 'textarea'
  1023. ,name: 'content'
  1024. ,id: 'modx-'+id+'-content'
  1025. // ,hideLabel: true
  1026. ,fieldLabel: _('content')
  1027. ,labelSeparator: ''
  1028. ,anchor: '100%'
  1029. ,style: 'min-height: 200px'
  1030. ,grow: true
  1031. };
  1032. break;
  1033. }
  1034. return o;
  1035. };
  1036. MODx.getQRSettings = function(id,va) {
  1037. id = id || 'qur';
  1038. return [{
  1039. layout: 'column'
  1040. ,border: false
  1041. ,anchor: '100%'
  1042. ,defaults: {
  1043. labelSeparator: ''
  1044. ,labelAlign: 'top'
  1045. ,border: false
  1046. ,layout: 'form'
  1047. }
  1048. ,items: [{
  1049. columnWidth: .5
  1050. ,items: [{
  1051. xtype: 'hidden'
  1052. ,name: 'parent'
  1053. ,id: 'modx-'+id+'-parent'
  1054. ,value: va['parent']
  1055. },{
  1056. xtype: 'hidden'
  1057. ,name: 'context_key'
  1058. ,id: 'modx-'+id+'-context_key'
  1059. ,value: va['context_key']
  1060. },{
  1061. xtype: 'hidden'
  1062. ,name: 'class_key'
  1063. ,id: 'modx-'+id+'-class_key'
  1064. ,value: va['class_key']
  1065. },{
  1066. xtype: 'hidden'
  1067. ,name: 'publishedon'
  1068. ,id: 'modx-'+id+'-publishedon'
  1069. ,value: va['publishedon']
  1070. },{
  1071. xtype: 'modx-field-parent-change'
  1072. ,fieldLabel: _('resource_parent')
  1073. ,description: '<b>[[*parent]]</b><br />'+_('resource_parent_help')
  1074. ,name: 'parent-cmb'
  1075. ,id: 'modx-'+id+'-parent-change'
  1076. ,value: va['parent'] || 0
  1077. ,anchor: '100%'
  1078. ,parentcmp: 'modx-'+id+'-parent'
  1079. ,contextcmp: 'modx-'+id+'-context_key'
  1080. ,currentid: va['id']
  1081. },{
  1082. xtype: 'modx-combo-class-derivatives'
  1083. ,fieldLabel: _('resource_type')
  1084. ,description: '<b>[[*class_key]]</b><br />'
  1085. ,name: 'class_key'
  1086. ,hiddenName: 'class_key'
  1087. ,id: 'modx-'+id+'-class-key'
  1088. ,anchor: '100%'
  1089. ,value: va['class_key'] != undefined ? va['class_key'] : 'modDocument'
  1090. },{
  1091. xtype: 'modx-combo-content-type'
  1092. ,fieldLabel: _('resource_content_type')
  1093. ,description: '<b>[[*content_type]]</b><br />'+_('resource_content_type_help')
  1094. ,name: 'content_type'
  1095. ,hiddenName: 'content_type'
  1096. ,id: 'modx-'+id+'-type'
  1097. ,anchor: '100%'
  1098. ,value: va['content_type'] != undefined ? va['content_type'] : (MODx.config.default_content_type || 1)
  1099. },{
  1100. xtype: 'modx-combo-content-disposition'
  1101. ,fieldLabel: _('resource_contentdispo')
  1102. ,description: '<b>[[*content_dispo]]</b><br />'+_('resource_contentdispo_help')
  1103. ,name: 'content_dispo'
  1104. ,hiddenName: 'content_dispo'
  1105. ,id: 'modx-'+id+'-dispo'
  1106. ,anchor: '100%'
  1107. ,value: va['content_dispo'] != undefined ? va['content_dispo'] : 0
  1108. },{
  1109. xtype: 'numberfield'
  1110. ,fieldLabel: _('resource_menuindex')
  1111. ,description: '<b>[[*menuindex]]</b><br />'+_('resource_menuindex_help')
  1112. ,name: 'menuindex'
  1113. ,id: 'modx-'+id+'-menuindex'
  1114. ,width: 75
  1115. ,value: va['menuindex'] || 0
  1116. }]
  1117. },{
  1118. columnWidth: .5
  1119. ,items: [{
  1120. xtype: 'xdatetime'
  1121. ,fieldLabel: _('resource_publishedon')
  1122. ,description: '<b>[[*publishedon]]</b><br />'+_('resource_publishedon_help')
  1123. ,name: 'publishedon'
  1124. ,id: 'modx-'+id+'-publishedon'
  1125. ,allowBlank: true
  1126. ,dateFormat: MODx.config.manager_date_format
  1127. ,timeFormat: MODx.config.manager_time_format
  1128. ,startDay: parseInt(MODx.config.manager_week_start)
  1129. ,dateWidth: 153
  1130. ,timeWidth: 153
  1131. ,offset_time: MODx.config.server_offset_time
  1132. ,value: va['publishedon']
  1133. },{
  1134. xtype: va['canpublish'] ? 'xdatetime' : 'hidden'
  1135. ,fieldLabel: _('resource_publishdate')
  1136. ,description: '<b>[[*pub_date]]</b><br />'+_('resource_publishdate_help')
  1137. ,name: 'pub_date'
  1138. ,id: 'modx-'+id+'-pub-date'
  1139. ,allowBlank: true
  1140. ,dateFormat: MODx.config.manager_date_format
  1141. ,timeFormat: MODx.config.manager_time_format
  1142. ,startDay: parseInt(MODx.config.manager_week_start)
  1143. ,dateWidth: 153
  1144. ,timeWidth: 153
  1145. ,offset_time: MODx.config.server_offset_time
  1146. ,value: va['pub_date']
  1147. },{
  1148. xtype: va['canpublish'] ? 'xdatetime' : 'hidden'
  1149. ,fieldLabel: _('resource_unpublishdate')
  1150. ,description: '<b>[[*unpub_date]]</b><br />'+_('resource_unpublishdate_help')
  1151. ,name: 'unpub_date'
  1152. ,id: 'modx-'+id+'-unpub-date'
  1153. ,allowBlank: true
  1154. ,dateFormat: MODx.config.manager_date_format
  1155. ,timeFormat: MODx.config.manager_time_format
  1156. ,startDay: parseInt(MODx.config.manager_week_start)
  1157. ,dateWidth: 153
  1158. ,timeWidth: 153
  1159. ,offset_time: MODx.config.server_offset_time
  1160. ,value: va['unpub_date']
  1161. },{
  1162. xtype: 'xcheckbox'
  1163. ,boxLabel: _('resource_folder')
  1164. ,description: _('resource_folder_help')
  1165. ,hideLabel: true
  1166. ,name: 'isfolder'
  1167. ,id: 'modx-'+id+'-isfolder'
  1168. ,inputValue: 1
  1169. ,checked: va['isfolder'] != undefined ? va['isfolder'] : false
  1170. },{
  1171. xtype: 'xcheckbox'
  1172. ,boxLabel: _('resource_richtext')
  1173. ,description: _('resource_richtext_help')
  1174. ,hideLabel: true
  1175. ,name: 'richtext'
  1176. ,id: 'modx-'+id+'-richtext'
  1177. ,inputValue: 1
  1178. ,checked: va['richtext'] !== undefined ? (va['richtext'] ? 1 : 0) : (MODx.config.richtext_default == '1' ? 1 : 0)
  1179. },{
  1180. xtype: 'xcheckbox'
  1181. ,boxLabel: _('resource_searchable')
  1182. ,description: _('resource_searchable_help')
  1183. ,hideLabel: true
  1184. ,name: 'searchable'
  1185. ,id: 'modx-'+id+'-searchable'
  1186. ,inputValue: 1
  1187. ,checked: va['searchable'] != undefined ? va['searchable'] : (MODx.config.search_default == '1' ? 1 : 0)
  1188. ,listeners: {'check': {fn:MODx.handleQUCB}}
  1189. },{
  1190. xtype: 'xcheckbox'
  1191. ,boxLabel: _('resource_cacheable')
  1192. ,description: _('resource_cacheable_help')
  1193. ,hideLabel: true
  1194. ,name: 'cacheable'
  1195. ,id: 'modx-'+id+'-cacheable'
  1196. ,inputValue: 1
  1197. ,checked: va['cacheable'] != undefined ? va['cacheable'] : (MODx.config.cache_default == '1' ? 1 : 0)
  1198. },{
  1199. xtype: 'xcheckbox'
  1200. ,name: 'clearCache'
  1201. ,id: 'modx-'+id+'-clearcache'
  1202. ,boxLabel: _('clear_cache_on_save')
  1203. ,description: _('clear_cache_on_save_msg')
  1204. ,hideLabel: true
  1205. ,inputValue: 1
  1206. ,checked: true
  1207. },{
  1208. xtype: 'xcheckbox'
  1209. ,boxLabel: _('deleted')
  1210. ,description: _('resource_delete')
  1211. ,hideLabel: true
  1212. ,name: 'deleted'
  1213. ,id: 'modx-'+id+'-deleted'
  1214. ,inputValue: 1
  1215. ,checked: va['deleted'] != undefined ? va['deleted'] : 0
  1216. },{
  1217. xtype: 'xcheckbox'
  1218. ,boxLabel: _('resource_alias_visible')
  1219. ,description: _('resource_alias_visible_help')
  1220. ,hideLabel: true
  1221. ,name: 'alias_visible'
  1222. ,id: 'modx-'+id+'-alias-visible'
  1223. ,inputValue: 1
  1224. ,checked: va['alias_visible'] != undefined ? va['alias_visible'] : 1
  1225. },{
  1226. xtype: 'xcheckbox'
  1227. ,boxLabel: _('resource_uri_override')
  1228. ,description: _('resource_uri_override_help')
  1229. ,hideLabel: true
  1230. ,name: 'uri_override'
  1231. ,id: 'modx-'+id+'-uri-override'
  1232. ,value: 1
  1233. ,checked: parseInt(va['uri_override']) ? true : false
  1234. ,listeners: {'check': {fn:MODx.handleFreezeUri}}
  1235. },{
  1236. xtype: 'textfield'
  1237. ,fieldLabel: _('resource_uri')
  1238. ,description: '<b>[[*uri]]</b><br />'+_('resource_uri_help')
  1239. ,name: 'uri'
  1240. ,id: 'modx-'+id+'-uri'
  1241. ,maxLength: 255
  1242. ,anchor: '100%'
  1243. ,value: va['uri'] || ''
  1244. ,hidden: !va['uri_override']
  1245. }]
  1246. }]
  1247. }];
  1248. };
  1249. MODx.handleQUCB = function(cb) {
  1250. var h = Ext.getCmp(cb.id+'-hd');
  1251. if (cb.checked && h) {
  1252. cb.setValue(1);
  1253. h.setValue(1);
  1254. } else if (h) {
  1255. cb.setValue(0);
  1256. h.setValue(0);
  1257. }
  1258. };
  1259. MODx.handleFreezeUri = function(cb) {
  1260. var uri = Ext.getCmp(cb.id.replace('-override', ''));
  1261. if (!uri) { return false; }
  1262. if (cb.checked) {
  1263. uri.show();
  1264. } else {
  1265. uri.hide();
  1266. }
  1267. };
  1268. Ext.override(Ext.tree.AsyncTreeNode,{
  1269. listeners: {
  1270. click: {fn: function(){
  1271. console.log('Clicked me!',arguments);
  1272. return false;
  1273. },scope: this}
  1274. }
  1275. });