update.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /**
  2. * Loads the resource update page
  3. *
  4. * @class MODx.page.UpdateResource
  5. * @extends MODx.Component
  6. * @param {Object} config An object of config properties
  7. * @xtype modx-page-resource-update
  8. */
  9. MODx.page.UpdateResource = function(config) {
  10. config = config || {record:{}};
  11. config.record = config.record || {};
  12. Ext.apply(config.record,{
  13. 'parent-cmb': config.record['parent']
  14. });
  15. Ext.applyIf(config,{
  16. url: MODx.config.connector_url
  17. ,which_editor: 'none'
  18. ,formpanel: 'modx-panel-resource'
  19. ,id: 'modx-page-update-resource'
  20. ,action: 'resource/update'
  21. ,components: [{
  22. xtype: config.panelXType || 'modx-panel-resource'
  23. ,renderTo: config.panelRenderTo || 'modx-panel-resource-div'
  24. ,resource: config.resource
  25. ,record: config.record || {}
  26. ,publish_document: config.publish_document
  27. ,show_tvs: config.show_tvs
  28. ,mode: config.mode
  29. ,url: config.url
  30. }]
  31. ,buttons: this.getButtons(config)
  32. });
  33. MODx.page.UpdateResource.superclass.constructor.call(this,config);
  34. if (!Ext.isIE) {
  35. Ext.EventManager.on(window, 'beforeunload',function(e) {
  36. MODx.releaseLock(this.config.resource);
  37. MODx.sleep(400);
  38. return false;
  39. }, this);
  40. }
  41. new Ext.KeyMap(Ext.getBody(), {
  42. key: 'p'
  43. ,alt: true
  44. ,ctrl: true
  45. ,fn: this.preview
  46. ,scope: this
  47. });
  48. };
  49. Ext.extend(MODx.page.UpdateResource,MODx.Component,{
  50. preview: function() {
  51. window.open(this.config.preview_url);
  52. return false;
  53. }
  54. ,duplicateResource: function(btn,e) {
  55. MODx.msg.confirm({
  56. text: _('resource_duplicate_confirm')
  57. ,url: MODx.config.connector_url
  58. ,params: {
  59. action: 'resource/duplicate'
  60. ,id: this.config.resource
  61. }
  62. ,listeners: {
  63. success: {fn:function(r) {
  64. MODx.loadPage('resource/update', 'id='+r.object.id);
  65. },scope:this}
  66. }
  67. });
  68. }
  69. ,deleteResource: function(btn,e) {
  70. MODx.msg.confirm({
  71. title: this.config.record.pagetitle ? _('resource_delete') + ' ' + this.config.record.pagetitle + ' (' + this.config.resource + ')' : _('resource_delete')
  72. ,text: _('resource_delete_confirm')
  73. ,url: MODx.config.connector_url
  74. ,params: {
  75. action: 'resource/delete'
  76. ,id: this.config.resource
  77. }
  78. ,listeners: {
  79. success: {fn:function(r) {
  80. MODx.loadPage('resource/update', 'id='+r.object.id);
  81. },scope:this}
  82. }
  83. });
  84. }
  85. ,cancel: function(btn,e) {
  86. var fp = Ext.getCmp(this.config.formpanel);
  87. if (fp && fp.isDirty()) {
  88. Ext.Msg.confirm(_('warning'),_('resource_cancel_dirty_confirm'),function(e) {
  89. if (e == 'yes') {
  90. fp.warnUnsavedChanges = false;
  91. MODx.releaseLock(MODx.request.id);
  92. MODx.sleep(400);
  93. MODx.loadPage('?');
  94. }
  95. },this);
  96. } else {
  97. MODx.releaseLock(MODx.request.id);
  98. MODx.loadPage('?');
  99. }
  100. }
  101. ,getButtons: function(cfg) {
  102. var btns = [];
  103. btns.push({
  104. text: cfg.lockedText || _('locked')
  105. ,id: 'modx-abtn-locked'
  106. ,handler: Ext.emptyFn
  107. ,hidden: (cfg.canSave == 1)
  108. ,disabled: true
  109. });
  110. btns.push({
  111. process: 'resource/update'
  112. ,text: _('save')
  113. ,id: 'modx-abtn-save'
  114. ,cls: 'primary-button'
  115. ,method: 'remote'
  116. ,hidden: !(cfg.canSave == 1)
  117. //,checkDirty: MODx.request.reload ? false : true
  118. ,keys: [{
  119. key: MODx.config.keymap_save || 's'
  120. ,ctrl: true
  121. }]
  122. });
  123. if (cfg.canDuplicate == 1 && (cfg.record.parent !== parseInt(MODx.config.tree_root_id) || cfg.canCreateRoot == 1)) {
  124. btns.push({
  125. text: _('duplicate')
  126. ,id: 'modx-abtn-duplicate'
  127. ,handler: this.duplicateResource
  128. ,scope:this
  129. });
  130. }
  131. if (cfg.canDelete == 1 && !cfg.locked) {
  132. btns.push({
  133. text: _('delete')
  134. ,id: 'modx-abtn-delete'
  135. ,handler: this.deleteResource
  136. ,scope:this
  137. });
  138. }
  139. btns.push({
  140. text: _('view')
  141. ,id: 'modx-abtn-preview'
  142. ,handler: this.preview
  143. ,scope: this
  144. });
  145. btns.push({
  146. text: _('cancel')
  147. ,id: 'modx-abtn-cancel'
  148. ,handler: this.cancel
  149. ,scope: this
  150. });
  151. btns.push({
  152. text: _('help_ex')
  153. ,id: 'modx-abtn-help'
  154. ,handler: MODx.loadHelpPane
  155. });
  156. return btns;
  157. }
  158. });
  159. Ext.reg('modx-page-resource-update',MODx.page.UpdateResource);