modx.panel.resource.js 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992
  1. MODx.panel.Resource = function(config) {
  2. config = config || {record:{}};
  3. config.record = config.record || {};
  4. Ext.applyIf(config,{
  5. url: MODx.config.connector_url
  6. ,baseParams: {}
  7. ,id: 'modx-panel-resource'
  8. ,class_key: 'modDocument'
  9. ,resource: ''
  10. ,bodyStyle: ''
  11. ,cls: 'container form-with-labels'
  12. ,defaults: { collapsible: false ,autoHeight: true }
  13. ,forceLayout: true
  14. ,items: this.getFields(config)
  15. ,fileUpload: true
  16. ,useLoadingMask: true
  17. ,listeners: {
  18. 'setup': {fn:this.setup,scope:this}
  19. ,'success': {fn:this.success,scope:this}
  20. ,'failure': {fn:this.failure,scope:this}
  21. ,'beforeSubmit': {fn:this.beforeSubmit,scope:this}
  22. ,'fieldChange': {fn:this.onFieldChange,scope:this}
  23. ,'failureSubmit': {fn:this.failureSubmit,scope:this}
  24. }
  25. });
  26. MODx.panel.Resource.superclass.constructor.call(this,config);
  27. var ta = Ext.get('ta');
  28. if (ta) { ta.on('keydown',this.fieldChangeEvent,this); }
  29. this.on('ready',this.onReady,this);
  30. var urio = Ext.getCmp('modx-resource-uri-override');
  31. if (urio) { urio.on('check',this.freezeUri); }
  32. this.addEvents('tv-reset');
  33. };
  34. Ext.extend(MODx.panel.Resource,MODx.FormPanel,{
  35. initialized: false
  36. ,defaultClassKey: 'modDocument'
  37. ,classLexiconKey: 'document'
  38. ,rteElements: 'ta'
  39. ,rteLoaded: false
  40. ,warnUnsavedChanges: false
  41. ,setup: function() {
  42. if (!this.initialized) {
  43. this.getForm().setValues(this.config.record);
  44. var tpl = this.getForm().findField('modx-resource-template');
  45. if (tpl) {
  46. tpl.originalValue = this.config.record.template;
  47. }
  48. var pcmb = this.getForm().findField('parent-cmb');
  49. if (pcmb && Ext.isEmpty(this.config.record.parent_pagetitle)) {
  50. pcmb.setValue('');
  51. } else if (pcmb) {
  52. pcmb.setValue(this.config.record.parent_pagetitle+' ('+this.config.record.parent+')');
  53. }
  54. if (!Ext.isEmpty(this.config.record.pagetitle)) {
  55. var title = Ext.util.Format.stripTags(this.config.record.pagetitle);
  56. title = Ext.util.Format.htmlEncode(title);
  57. if (MODx.perm.tree_show_resource_ids === 1) {
  58. title = title+ ' <small>('+this.config.record.id+')</small>';
  59. }
  60. Ext.getCmp('modx-resource-header').getEl().update(title);
  61. }
  62. // initial check to enable realtime alias
  63. if (Ext.isEmpty(this.config.record.alias)) {
  64. this.config.aliaswasempty = true;
  65. } else {
  66. this.config.aliaswasempty = false;
  67. }
  68. this.config.translitloading = false; // the initial value for the realtime-alias throttling
  69. if (!Ext.isEmpty(this.config.record.resourceGroups)) {
  70. var g = Ext.getCmp('modx-grid-resource-security');
  71. if (g && Ext.isEmpty(g.config.url)) {
  72. var s = g.getStore();
  73. if (s) { s.loadData(this.config.record.resourceGroups); }
  74. }
  75. }
  76. this.defaultClassKey = this.config.record.class_key || this.defaultClassKey;
  77. this.defaultValues = this.config.record || {};
  78. if ((this.config.record && this.config.record.richtext) || MODx.request.reload || MODx.request.activeSave == 1) {
  79. this.markDirty();
  80. }
  81. // Prevent accidental navigation when stuff has not been saved
  82. if (MODx.config.confirm_navigation == 1) {
  83. var panel = this;
  84. window.onbeforeunload = function() {
  85. if (panel.warnUnsavedChanges) return _('unsaved_changes');
  86. };
  87. }
  88. if (this.config.record.deleted) {
  89. this.handlePreview('hide');
  90. }
  91. }
  92. if (MODx.config.use_editor && MODx.loadRTE) {
  93. var f = this.getForm().findField('richtext');
  94. if (f && f.getValue() == 1 && !this.rteLoaded) {
  95. MODx.loadRTE(this.rteElements);
  96. this.rteLoaded = true;
  97. } else if (f && f.getValue() == 0 && this.rteLoaded) {
  98. if (MODx.unloadRTE) {
  99. MODx.unloadRTE(this.rteElements);
  100. }
  101. this.rteLoaded = false;
  102. }
  103. }
  104. this.fireEvent('ready');
  105. this.initialized = true;
  106. MODx.fireEvent('ready');
  107. MODx.sleep(4); /* delay load event to allow FC rules to move before loading RTE */
  108. if (MODx.afterTVLoad) { MODx.afterTVLoad(); }
  109. this.fireEvent('load');
  110. }
  111. /**
  112. * Handle the preview button visibility according to the resource "deleted" status
  113. *
  114. * @param {string} action The action to perform on the preview button (hide/show)
  115. */
  116. ,handlePreview: function(action) {
  117. var previewBtn = Ext.getCmp('modx-abtn-preview');
  118. if (previewBtn == undefined) {
  119. // Button not found, let's try again in a few ms
  120. Ext.defer(function() {
  121. this.handlePreview(action);
  122. }, 200, this);
  123. } else {
  124. var toolBar = Ext.getCmp('modx-page-update-resource').ab
  125. ,btnIndex = toolBar.items.indexOf(previewBtn);
  126. // Do the desired action on the button and its sibling (a spacer)
  127. previewBtn[action]();
  128. toolBar.items.get(btnIndex + 1)[action]();
  129. }
  130. }
  131. ,beforeDestroy: function(){
  132. if (this.rteLoaded && MODx.unloadRTE){
  133. MODx.unloadRTE(this.rteElements);
  134. this.rteLoaded = false;
  135. }
  136. MODx.panel.Resource.superclass.beforeDestroy.call(this);
  137. }
  138. ,beforeSubmit: function(o) {
  139. var ta = Ext.get('ta');
  140. if (ta) {
  141. var v = ta.dom.value;
  142. var hc = Ext.getCmp('hiddenContent');
  143. if (hc) { hc.setValue(v); }
  144. }
  145. var g = Ext.getCmp('modx-grid-resource-security');
  146. if (g) {
  147. Ext.apply(o.form.baseParams,{
  148. resource_groups: g.encode()
  149. });
  150. }
  151. if (ta) {
  152. this.cleanupEditor();
  153. }
  154. if(this.getForm().baseParams.action == 'resource/create') {
  155. var btn = Ext.getCmp('modx-abtn-save');
  156. if (btn) { btn.disable(); }
  157. }
  158. return this.fireEvent('save',{
  159. values: this.getForm().getValues()
  160. ,stay: Ext.state.Manager.get('modx.stay.'+MODx.request.a,'stay')
  161. });
  162. }
  163. ,success: function(o) {
  164. this.warnUnsavedChanges = false;
  165. var g = Ext.getCmp('modx-grid-resource-security');
  166. if (g) { g.getStore().commitChanges(); }
  167. var t = Ext.getCmp('modx-resource-tree');
  168. if (t) {
  169. var ctx = Ext.getCmp('modx-resource-context-key').getValue();
  170. var pa = Ext.getCmp('modx-resource-parent-hidden').getValue();
  171. var pao = Ext.getCmp('modx-resource-parent-old-hidden').getValue();
  172. var v = ctx+'_'+pa;
  173. var n = t.getNodeById(v);
  174. if(pa !== pao) {
  175. t.refresh();
  176. Ext.getCmp('modx-resource-parent-old-hidden').setValue(pa);
  177. } else {
  178. if(typeof n!=="undefined"){
  179. n.leaf = false;
  180. }
  181. t.refreshNode(v,true);
  182. }
  183. }
  184. var object = o.result.object;
  185. // object.parent is undefined on template changing.
  186. if (this.config.resource && object.parent !== undefined && (object.class_key != this.defaultClassKey || object.parent != this.defaultValues.parent)) {
  187. location.href = location.href;
  188. } else {
  189. if (object.deleted !== this.record.deleted) {
  190. if (object.deleted) {
  191. var action = 'hide';
  192. } else {
  193. action = 'show';
  194. }
  195. this.handlePreview(action);
  196. }
  197. this.record = object;
  198. this.getForm().setValues(object);
  199. Ext.getCmp('modx-page-update-resource').config.preview_url = object.preview_url;
  200. }
  201. }
  202. ,failureSubmit: function() {
  203. // This array contains the components we want to traverse in the order we prioritize them
  204. var forms = [
  205. 'modx-resource-settings', // Document
  206. 'modx-page-settings', // Settings
  207. 'modx-panel-resource-tv' // Template Variables
  208. ];
  209. var tab_name = null;
  210. // Loop each component and traverse the children recursively
  211. for (var i = 0; i < forms.length; i++) {
  212. var component = Ext.getCmp(forms[i]);
  213. if (component && component.el && component.el.dom) {
  214. if (this.traverseNode(component.el.dom)) {
  215. tab_name = forms[i];
  216. // We want to switch to the first tab that has an invalid state, no matter if the current
  217. // or any later tabs also have such states. We can therefore quit early here.
  218. break;
  219. }
  220. }
  221. }
  222. // If no invalid states were found, this check makes sure we don't switch tabs for no reason
  223. if (tab_name === null) {
  224. return;
  225. }
  226. var tabs = Ext.getCmp('modx-resource-tabs');
  227. var tabs_index = null;
  228. // The next check needs the tabs index value to check if it is hidden or not
  229. if (tabs && tabs.items && tabs.items.keys) {
  230. tabs_index = tabs.items.keys.indexOf(tab_name);
  231. }
  232. // We are already on a tab that has an invalid state. No need to switch
  233. if (!tabs.items.items[tabs_index].hidden) {
  234. return;
  235. }
  236. // Activate the tab (this is done by passing the name of the tab)
  237. tabs.activate(tab_name);
  238. }
  239. ,traverseNode: function(node) {
  240. if (typeof node.classList !== 'undefined' && node.classList.contains('x-form-invalid')) {
  241. return true;
  242. }
  243. if (typeof node.children == 'undefined') {
  244. return false;
  245. }
  246. for (var i = 0; i < node.children.length; i++) {
  247. if (this.traverseNode(node.children[i])) {
  248. return true;
  249. }
  250. }
  251. return false;
  252. }
  253. ,failure: function(o) {
  254. this.warnUnsavedChanges = true;
  255. if(this.getForm().baseParams.action == 'resource/create') {
  256. var btn = Ext.getCmp('modx-abtn-save');
  257. if (btn) { btn.enable(); }
  258. }
  259. this.fireEvent('failureSubmit');
  260. }
  261. ,freezeUri: function(cb) {
  262. var uri = Ext.getCmp('modx-resource-uri');
  263. if (!uri) { return false; }
  264. if (cb.checked) {
  265. uri.show();
  266. } else {
  267. uri.hide();
  268. }
  269. }
  270. // used for realtime-alias transliteration
  271. ,translitAlias: function(string) {
  272. if (!this.config.translitloading) {
  273. this.config.translitloading = true;
  274. MODx.Ajax.request({
  275. url: MODx.config.connector_url
  276. ,params: {
  277. action: 'resource/translit'
  278. ,string: string
  279. }
  280. ,listeners: {
  281. 'success': {fn:function(r) {
  282. var alias = Ext.getCmp('modx-resource-alias');
  283. if (!Ext.isEmpty(r.object.transliteration)) {
  284. alias.setValue(r.object.transliteration);
  285. this.config.translitloading = false;
  286. }
  287. },scope:this}
  288. }
  289. });
  290. }
  291. }
  292. ,generateAliasRealTime: function(title) {
  293. // check some system settings before doing real time alias transliteration
  294. if (parseInt(MODx.config.friendly_alias_realtime) && parseInt(MODx.config.automatic_alias)) {
  295. // handles the realtime-alias transliteration
  296. if (this.config.aliaswasempty && title !== '') {
  297. this.translitAlias(title);
  298. }
  299. }
  300. }
  301. ,templateWarning: function() {
  302. var t = Ext.getCmp('modx-resource-template');
  303. if (!t) { return false; }
  304. if(t.getValue() !== t.originalValue) {
  305. Ext.Msg.confirm(_('warning'), _('resource_change_template_confirm'), function(e) {
  306. if (e == 'yes') {
  307. var nt = t.getValue();
  308. var f = Ext.getCmp('modx-page-update-resource');
  309. f.config.action = 'resource/reload';
  310. this.warnUnsavedChanges = false;
  311. MODx.activePage.submitForm({
  312. success: {fn:function(r) {
  313. MODx.loadPage(r.result.object.action, 'id='+r.result.object.id+'&reload='+r.result.object.reload + '&class_key='+ r.result.object.class_key);
  314. },scope:this}
  315. },{
  316. bypassValidCheck: true
  317. },{
  318. reloadOnly: true
  319. });
  320. } else {
  321. t.setValue(this.config.record.template);
  322. }
  323. },this);
  324. }
  325. }
  326. ,onFieldChange: function(o) {
  327. //a11y - Set Active Input
  328. if (o && o.field) {
  329. Ext.state.Manager.set('curFocus', o.field.id);
  330. if (o.field.name === 'syncsite') {
  331. return;
  332. }
  333. }
  334. if (this.isReady || MODx.request.reload) {
  335. this.warnUnsavedChanges = true;
  336. }
  337. }
  338. ,cleanupEditor: function() {
  339. if (MODx.onSaveEditor) {
  340. var fld = Ext.getCmp('ta');
  341. if (fld) { MODx.onSaveEditor(fld); }
  342. }
  343. }
  344. ,getFields: function(config) {
  345. var it = [];
  346. it.push({
  347. title: _(this.classLexiconKey)
  348. ,id: 'modx-resource-settings'
  349. ,cls: 'modx-resource-tab'
  350. ,layout: 'form'
  351. ,labelAlign: 'top'
  352. ,labelSeparator: ''
  353. ,bodyCssClass: 'tab-panel-wrapper main-wrapper'
  354. ,autoHeight: true
  355. ,defaults: {
  356. border: false
  357. ,msgTarget: 'under'
  358. ,width: 400
  359. }
  360. ,items: this.getMainFields(config)
  361. });
  362. it.push({
  363. id: 'modx-page-settings'
  364. ,title: _('settings')
  365. ,cls: 'modx-resource-tab'
  366. ,layout: 'form'
  367. ,forceLayout: true
  368. ,deferredRender: false
  369. ,labelWidth: 200
  370. ,bodyCssClass: 'main-wrapper'
  371. ,autoHeight: true
  372. ,defaults: {
  373. border: false
  374. ,msgTarget: 'under'
  375. }
  376. ,items: this.getSettingFields(config)
  377. });
  378. if (config.show_tvs && MODx.config.tvs_below_content != 1) {
  379. it.push(this.getTemplateVariablesPanel(config));
  380. }
  381. if (MODx.perm.resourcegroup_resource_list == 1) {
  382. it.push(this.getAccessPermissionsTab(config));
  383. }
  384. var its = [];
  385. its.push(this.getPageHeader(config),{
  386. id:'modx-resource-tabs'
  387. ,xtype: 'modx-tabs'
  388. ,forceLayout: true
  389. ,deferredRender: false
  390. ,collapsible: true
  391. ,animCollapse: false
  392. ,itemId: 'tabs'
  393. ,items: it
  394. });
  395. var ct = this.getContentField(config);
  396. if (ct) {
  397. its.push({
  398. title: _('resource_content')
  399. ,id: 'modx-resource-content'
  400. ,layout: 'form'
  401. ,bodyCssClass: 'main-wrapper'
  402. ,autoHeight: true
  403. ,collapsible: true
  404. ,animCollapse: false
  405. ,hideMode: 'offsets'
  406. ,items: ct
  407. });
  408. }
  409. if (MODx.config.tvs_below_content == 1) {
  410. var tvs = this.getTemplateVariablesPanel(config);
  411. its.push(tvs);
  412. }
  413. return its;
  414. }
  415. ,getPageHeader: function(config) {
  416. config = config || {record:{}};
  417. return {
  418. html: _('document_new')
  419. ,id: 'modx-resource-header'
  420. ,xtype: 'modx-header'
  421. };
  422. }
  423. ,getTemplateVariablesPanel: function(config) {
  424. return {
  425. xtype: 'modx-panel-resource-tv'
  426. ,collapsed: false
  427. ,resource: config.resource
  428. ,class_key: config.record.class_key || 'modDocument'
  429. ,template: config.record.template
  430. ,anchor: '100%'
  431. ,border: true
  432. ,style: 'visibility: visible'
  433. };
  434. }
  435. ,getMainFields: function(config) {
  436. config = config || {record:{}};
  437. return [{
  438. layout:'column'
  439. ,border: false
  440. ,anchor: '100%'
  441. ,id: 'modx-resource-main-columns'
  442. ,defaults: {
  443. labelSeparator: ''
  444. ,labelAlign: 'top'
  445. ,border: false
  446. ,msgTarget: 'under'
  447. }
  448. ,items:[{
  449. columnWidth: .67
  450. ,layout: 'form'
  451. ,id: 'modx-resource-main-left'
  452. ,defaults: { msgTarget: 'under' }
  453. ,items: this.getMainLeftFields(config)
  454. },{
  455. columnWidth: .33
  456. ,layout: 'form'
  457. ,labelWidth: 0
  458. ,border: false
  459. ,id: 'modx-resource-main-right'
  460. ,style: 'margin-right: 0'
  461. ,defaults: { msgTarget: 'under' }
  462. ,items: this.getMainRightFields(config)
  463. }]
  464. },{
  465. html: MODx.onDocFormRender, border: false
  466. },{
  467. xtype: 'hidden'
  468. ,fieldLabel: _('id')
  469. ,hideLabel: true
  470. ,description: '<b>[[*id]]</b><br />'
  471. ,name: 'id'
  472. ,id: 'modx-resource-id'
  473. ,anchor: '100%'
  474. ,value: config.resource || config.record.id
  475. ,submitValue: true
  476. },{
  477. xtype: 'hidden'
  478. ,name: 'type'
  479. ,value: 'document'
  480. },{
  481. xtype: 'hidden'
  482. ,name: 'context_key'
  483. ,id: 'modx-resource-context-key'
  484. ,value: config.record.context_key || 'web'
  485. },{
  486. xtype: 'hidden'
  487. ,name: 'content'
  488. ,id: 'hiddenContent'
  489. ,value: (config.record.content || config.record.ta) || ''
  490. },{
  491. xtype: 'hidden'
  492. ,name: 'create-resource-token'
  493. ,id: 'modx-create-resource-token'
  494. ,value: config.record.create_resource_token || ''
  495. },{
  496. xtype: 'hidden'
  497. ,name: 'reloaded'
  498. ,value: !Ext.isEmpty(MODx.request.reload) ? 1 : 0
  499. },{
  500. xtype: 'hidden'
  501. ,name: 'parent'
  502. ,value: config.record.parent || 0
  503. ,id: 'modx-resource-parent-hidden'
  504. },{
  505. xtype: 'hidden'
  506. ,name: 'parent-original'
  507. ,value: config.record.parent || 0
  508. ,id: 'modx-resource-parent-old-hidden'
  509. }];
  510. }
  511. ,getMainLeftFields: function(config) {
  512. config = config || {record:{}};
  513. return [{
  514. xtype: 'textfield'
  515. ,fieldLabel: _('resource_pagetitle')+'<span class="required">*</span>'
  516. ,description: '<b>[[*pagetitle]]</b><br />'+_('resource_pagetitle_help')
  517. ,name: 'pagetitle'
  518. ,id: 'modx-resource-pagetitle'
  519. ,maxLength: 255
  520. ,anchor: '100%'
  521. ,allowBlank: false
  522. ,enableKeyEvents: true
  523. ,listeners: {
  524. 'keyup': {fn: function(f) {
  525. var title = Ext.util.Format.stripTags(f.getValue());
  526. this.generateAliasRealTime(title);
  527. title = Ext.util.Format.htmlEncode(title);
  528. if (MODx.request.a !== 'resource/create' && MODx.perm.tree_show_resource_ids === 1) {
  529. title = title+ ' <small>('+this.config.record.id+')</small>';
  530. }
  531. Ext.getCmp('modx-resource-header').getEl().update(title);
  532. }, scope: this}
  533. // also do realtime transliteration of alias on blur of pagetitle field
  534. // as sometimes (when typing very fast) the last letter(s) are not catched
  535. ,'blur': {fn: function(f,e) {
  536. var title = Ext.util.Format.stripTags(f.getValue());
  537. this.generateAliasRealTime(title);
  538. }, scope: this}
  539. }
  540. },{
  541. xtype: 'textfield'
  542. ,fieldLabel: _('resource_longtitle')
  543. ,description: '<b>[[*longtitle]]</b><br />'+_('resource_longtitle_help')
  544. ,name: 'longtitle'
  545. ,id: 'modx-resource-longtitle'
  546. ,maxLength: 255
  547. ,anchor: '100%'
  548. ,value: config.record.longtitle || ''
  549. },{
  550. xtype: 'textarea'
  551. ,fieldLabel: _('resource_description')
  552. ,description: '<b>[[*description]]</b><br />'+_('resource_description_help')
  553. ,name: 'description'
  554. ,id: 'modx-resource-description'
  555. ,grow: true
  556. ,anchor: '100%'
  557. ,value: config.record.description || ''
  558. },{
  559. xtype: 'textarea'
  560. ,fieldLabel: _('resource_summary')
  561. ,description: '<b>[[*introtext]]</b><br />'+_('resource_summary_help')
  562. ,name: 'introtext'
  563. ,id: 'modx-resource-introtext'
  564. ,grow: true
  565. ,anchor: '100%'
  566. ,value: config.record.introtext || ''
  567. }];
  568. }
  569. ,getMainRightFields: function(config) {
  570. config = config || {};
  571. var aliasLength = ~~MODx.config['friendly_alias_max_length'] || 0;
  572. return [{
  573. xtype: 'modx-combo-template'
  574. ,fieldLabel: _('resource_template')
  575. ,description: '<b>[[*template]]</b><br />'+_('resource_template_help')
  576. ,name: 'template'
  577. ,id: 'modx-resource-template'
  578. ,anchor: '100%'
  579. ,editable: true
  580. ,typeAhead: true
  581. ,typeAheadDelay: 300
  582. ,forceSelection: true
  583. ,baseParams: {
  584. action: 'element/template/getList'
  585. ,combo: '1'
  586. ,limit: 0
  587. }
  588. ,listeners: {
  589. 'select': {fn: this.templateWarning,scope: this}
  590. }
  591. },{
  592. xtype: 'textfield'
  593. ,fieldLabel: _('resource_alias')
  594. ,description: '<b>[[*alias]]</b><br />'+_('resource_alias_help')
  595. ,name: 'alias'
  596. ,id: 'modx-resource-alias'
  597. ,maxLength: (aliasLength > 255 || aliasLength === 0) ? 255 : aliasLength
  598. ,anchor: '100%'
  599. ,value: config.record.alias || ''
  600. ,listeners: {
  601. 'change': {fn: function(f,e) {
  602. // when the alias is manually cleared, enable real time alias
  603. if (Ext.isEmpty(f.getValue())) {
  604. this.config.aliaswasempty = true;
  605. }
  606. }, scope: this}
  607. }
  608. },{
  609. xtype: 'textfield'
  610. ,fieldLabel: _('resource_menutitle')
  611. ,description: '<b>[[*menutitle]]</b><br />'+_('resource_menutitle_help')
  612. ,name: 'menutitle'
  613. ,id: 'modx-resource-menutitle'
  614. ,maxLength: 255
  615. ,anchor: '100%'
  616. ,value: config.record.menutitle || ''
  617. },{
  618. xtype: 'textfield'
  619. ,fieldLabel: _('resource_link_attributes')
  620. ,description: '<b>[[*link_attributes]]</b><br />'+_('resource_link_attributes_help')
  621. ,name: 'link_attributes'
  622. ,id: 'modx-resource-link-attributes'
  623. ,maxLength: 255
  624. ,anchor: '100%'
  625. ,value: config.record.link_attributes || ''
  626. },{
  627. xtype: 'xcheckbox'
  628. ,boxLabel: _('resource_hide_from_menus')
  629. ,hideLabel: true
  630. ,description: '<b>[[*hidemenu]]</b><br />'+_('resource_hide_from_menus_help')
  631. ,name: 'hidemenu'
  632. ,id: 'modx-resource-hidemenu'
  633. ,inputValue: 1
  634. ,checked: parseInt(config.record.hidemenu) || false
  635. },{
  636. xtype: 'xcheckbox'
  637. ,boxLabel: _('resource_published')
  638. ,hideLabel: true
  639. ,description: '<b>[[*published]]</b><br />'+_('resource_published_help')
  640. ,name: 'published'
  641. ,id: 'modx-resource-published'
  642. ,inputValue: 1
  643. ,checked: parseInt(config.record.published)
  644. }]
  645. }
  646. ,getSettingFields: function(config) {
  647. config = config || {record:{}};
  648. var s = [{
  649. layout:'column'
  650. ,border: false
  651. ,anchor: '100%'
  652. ,defaults: {
  653. labelSeparator: ''
  654. ,labelAlign: 'top'
  655. ,border: false
  656. ,layout: 'form'
  657. ,msgTarget: 'under'
  658. }
  659. ,items:[{
  660. columnWidth: .5
  661. ,id: 'modx-page-settings-left'
  662. ,defaults: { msgTarget: 'under' }
  663. ,items: this.getSettingLeftFields(config)
  664. },{
  665. columnWidth: .5
  666. ,id: 'modx-page-settings-right'
  667. ,defaults: { msgTarget: 'under' }
  668. ,items: this.getSettingRightFields(config)
  669. }]
  670. }];
  671. return s;
  672. }
  673. ,getSettingLeftFields: function(config) {
  674. return [{
  675. xtype: 'modx-field-parent-change'
  676. ,fieldLabel: _('resource_parent')
  677. ,description: '<b>[[*parent]]</b><br />'+_('resource_parent_help')
  678. ,name: 'parent-cmb'
  679. ,id: 'modx-resource-parent'
  680. ,value: config.record.parent || 0
  681. ,anchor: '100%'
  682. },{
  683. xtype: 'modx-combo-class-derivatives'
  684. ,fieldLabel: _('resource_type')
  685. ,description: '<b>[[*class_key]]</b><br />'
  686. ,name: 'class_key'
  687. ,hiddenName: 'class_key'
  688. ,id: 'modx-resource-class-key'
  689. ,allowBlank: false
  690. ,value: config.record.class_key || 'modDocument'
  691. ,anchor: '100%'
  692. },{
  693. xtype: 'modx-combo-content-type'
  694. ,fieldLabel: _('resource_content_type')
  695. ,description: '<b>[[*content_type]]</b><br />'+_('resource_content_type_help')
  696. ,name: 'content_type'
  697. ,hiddenName: 'content_type'
  698. ,id: 'modx-resource-content-type'
  699. ,anchor: '100%'
  700. ,value: config.record.content_type || (MODx.config.default_content_type || 1)
  701. },{
  702. xtype: 'modx-combo-content-disposition'
  703. ,fieldLabel: _('resource_contentdispo')
  704. ,description: '<b>[[*content_dispo]]</b><br />'+_('resource_contentdispo_help')
  705. ,name: 'content_dispo'
  706. ,hiddenName: 'content_dispo'
  707. ,id: 'modx-resource-content-dispo'
  708. ,anchor: '100%'
  709. ,value: config.record.content_dispo || 0
  710. },{
  711. xtype: 'numberfield'
  712. ,fieldLabel: _('resource_menuindex')
  713. ,description: '<b>[[*menuindex]]</b><br />'+_('resource_menuindex_help')
  714. ,name: 'menuindex'
  715. ,id: 'modx-resource-menuindex'
  716. ,width: 75
  717. ,value: parseInt(config.record.menuindex) || 0
  718. }];
  719. }
  720. ,getSettingRightFields: function(config) {
  721. return [{
  722. xtype: 'xdatetime'
  723. ,fieldLabel: _('resource_publishedon')
  724. ,description: '<b>[[*publishedon]]</b><br />'+_('resource_publishedon_help')
  725. ,name: 'publishedon'
  726. ,id: 'modx-resource-publishedon'
  727. ,allowBlank: true
  728. ,dateFormat: MODx.config.manager_date_format
  729. ,timeFormat: MODx.config.manager_time_format
  730. ,startDay: parseInt(MODx.config.manager_week_start)
  731. ,dateWidth: 120
  732. ,timeWidth: 120
  733. ,offset_time: MODx.config.server_offset_time
  734. ,value: config.record.publishedon
  735. },{
  736. xtype: MODx.config.publish_document ? 'xdatetime' : 'hidden'
  737. ,fieldLabel: _('resource_publishdate')
  738. ,description: '<b>[[*pub_date]]</b><br />'+_('resource_publishdate_help')
  739. ,name: 'pub_date'
  740. ,id: 'modx-resource-pub-date'
  741. ,allowBlank: true
  742. ,dateFormat: MODx.config.manager_date_format
  743. ,timeFormat: MODx.config.manager_time_format
  744. ,startDay: parseInt(MODx.config.manager_week_start)
  745. ,dateWidth: 120
  746. ,timeWidth: 120
  747. ,offset_time: MODx.config.server_offset_time
  748. ,value: config.record.pub_date
  749. },{
  750. xtype: MODx.config.publish_document ? 'xdatetime' : 'hidden'
  751. ,fieldLabel: _('resource_unpublishdate')
  752. ,description: '<b>[[*unpub_date]]</b><br />'+_('resource_unpublishdate_help')
  753. ,name: 'unpub_date'
  754. ,id: 'modx-resource-unpub-date'
  755. ,allowBlank: true
  756. ,dateFormat: MODx.config.manager_date_format
  757. ,timeFormat: MODx.config.manager_time_format
  758. ,startDay: parseInt(MODx.config.manager_week_start)
  759. ,dateWidth: 120
  760. ,timeWidth: 120
  761. ,offset_time: MODx.config.server_offset_time
  762. ,value: config.record.unpub_date
  763. },{
  764. xtype: 'fieldset'
  765. ,items: this.getSettingRightFieldset(config)
  766. }];
  767. }
  768. ,getSettingRightFieldset: function(config) {
  769. return [{
  770. layout: 'column'
  771. ,id: 'modx-page-settings-box-columns'
  772. ,border: false
  773. ,anchor: '100%'
  774. ,defaults: {
  775. labelSeparator: ''
  776. ,labelAlign: 'top'
  777. ,border: false
  778. ,layout: 'form'
  779. ,msgTarget: 'under'
  780. }
  781. ,items: [{
  782. columnWidth: .5
  783. ,id: 'modx-page-settings-right-box-left'
  784. ,defaults: { msgTarget: 'under' }
  785. ,items: this.getSettingRightFieldsetLeft(config)
  786. },{
  787. columnWidth: .5
  788. ,id: 'modx-page-settings-right-box-right'
  789. ,defaults: { msgTarget: 'under' }
  790. ,items: this.getSettingRightFieldsetRight(config)
  791. }]
  792. }];
  793. }
  794. ,getSettingRightFieldsetLeft: function(config) {
  795. return [{
  796. xtype: 'xcheckbox'
  797. ,boxLabel: _('resource_folder')
  798. ,description: '<b>[[*isfolder]]</b><br />'+_('resource_folder_help')
  799. ,hideLabel: true
  800. ,name: 'isfolder'
  801. ,id: 'modx-resource-isfolder'
  802. ,inputValue: 1
  803. ,checked: parseInt(config.record.isfolder) || 0
  804. },{
  805. xtype: 'xcheckbox'
  806. ,boxLabel: _('resource_searchable')
  807. ,description: '<b>[[*searchable]]</b><br />'+_('resource_searchable_help')
  808. ,hideLabel: true
  809. ,name: 'searchable'
  810. ,id: 'modx-resource-searchable'
  811. ,inputValue: 1
  812. ,checked: parseInt(config.record.searchable)
  813. },{
  814. xtype: 'xcheckbox'
  815. ,boxLabel: _('resource_alias_visible')
  816. ,description: '<b>[[*alias_visible]]</b><br />'+_('resource_alias_visible_help')
  817. ,hideLabel: true
  818. ,name: 'alias_visible'
  819. ,id: 'modx-resource-alias-visible'
  820. ,inputValue: 1
  821. ,checked: parseInt(config.record.alias_visible) || 1
  822. },{
  823. xtype: 'xcheckbox'
  824. ,boxLabel: _('resource_richtext')
  825. ,description: '<b>[[*richtext]]</b><br />'+_('resource_richtext_help')
  826. ,hideLabel: true
  827. ,name: 'richtext'
  828. ,id: 'modx-resource-richtext'
  829. ,inputValue: 1
  830. ,checked: parseInt(config.record.richtext)
  831. },{
  832. xtype: 'xcheckbox'
  833. ,boxLabel: _('resource_uri_override')
  834. ,description: _('resource_uri_override_help')
  835. ,hideLabel: true
  836. ,name: 'uri_override'
  837. ,value: 1
  838. ,checked: parseInt(config.record.uri_override) ? true : false
  839. ,id: 'modx-resource-uri-override'
  840. },{
  841. xtype: 'textfield'
  842. ,fieldLabel: _('resource_uri')
  843. ,description: '<b>[[*uri]]</b><br />'+_('resource_uri_help')
  844. ,name: 'uri'
  845. ,id: 'modx-resource-uri'
  846. ,maxLength: 255
  847. ,anchor: '160%'
  848. ,value: config.record.uri || ''
  849. ,hidden: !config.record.uri_override
  850. }];
  851. }
  852. ,getSettingRightFieldsetRight: function(config) {
  853. return [{
  854. xtype: 'xcheckbox'
  855. ,boxLabel: _('resource_cacheable')
  856. ,description: '<b>[[*cacheable]]</b><br />'+_('resource_cacheable_help')
  857. ,hideLabel: true
  858. ,name: 'cacheable'
  859. ,id: 'modx-resource-cacheable'
  860. ,inputValue: 1
  861. ,checked: parseInt(config.record.cacheable)
  862. },{
  863. xtype: 'xcheckbox'
  864. ,boxLabel: _('resource_syncsite')
  865. ,description: _('resource_syncsite_help')
  866. ,hideLabel: true
  867. ,name: 'syncsite'
  868. ,id: 'modx-resource-syncsite'
  869. ,inputValue: 1
  870. ,checked: config.record.syncsite !== undefined && config.record.syncsite !== null ? parseInt(config.record.syncsite) : true
  871. },{
  872. xtype: 'xcheckbox'
  873. ,boxLabel: _('deleted')
  874. ,description: '<b>[[*deleted]]</b>'
  875. ,hideLabel: true
  876. ,name: 'deleted'
  877. ,id: 'modx-resource-deleted'
  878. ,inputValue: 1
  879. ,checked: parseInt(config.record.deleted) || false
  880. }];
  881. }
  882. ,getContentField: function(config) {
  883. return [{
  884. id: 'modx-content-above'
  885. ,border: false
  886. },{
  887. xtype: 'textarea'
  888. ,name: 'ta'
  889. ,id: 'ta'
  890. ,hideLabel: true
  891. ,anchor: '100%'
  892. ,height: 400
  893. ,grow: false
  894. ,value: (config.record.content || config.record.ta) || ''
  895. },{
  896. id: 'modx-content-below'
  897. ,border: false
  898. }];
  899. }
  900. ,getAccessPermissionsTab: function(config) {
  901. return {
  902. id: 'modx-resource-access-permissions'
  903. ,autoHeight: true
  904. ,title: _('resource_groups')
  905. ,layout: 'form'
  906. ,anchor: '100%'
  907. ,items: [{
  908. html: '<p>'+_('resource_access_message')+'</p>'
  909. ,xtype: 'modx-description'
  910. },{
  911. xtype: 'modx-grid-resource-security'
  912. ,cls: 'main-wrapper'
  913. ,preventRender: true
  914. ,resource: config.resource
  915. ,mode: config.mode || 'update'
  916. ,"parent": config.record["parent"] || 0
  917. ,"token": config.record.create_resource_token
  918. ,reloaded: !Ext.isEmpty(MODx.request.reload)
  919. ,listeners: {
  920. 'afteredit': {fn:this.fieldChangeEvent,scope:this}
  921. }
  922. }]
  923. };
  924. }
  925. });
  926. Ext.reg('modx-panel-resource',MODx.panel.Resource);
  927. var triggerDirtyField = function(fld) {
  928. Ext.getCmp('modx-panel-resource').fieldChangeEvent(fld);
  929. };
  930. MODx.triggerRTEOnChange = function() {
  931. triggerDirtyField(Ext.getCmp('ta'));
  932. };
  933. MODx.fireResourceFormChange = function(f,nv,ov) {
  934. Ext.getCmp('modx-panel-resource').fireEvent('fieldChange');
  935. };