edit.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /**
  2. * Loads the edit file page
  3. *
  4. * @class MODx.page.EditFile
  5. * @extends MODx.Component
  6. * @param {Object} config An object of config properties
  7. * @xtype modx-page-file-edit
  8. */
  9. MODx.page.EditFile = function(config) {
  10. config = config || {};
  11. var btns = [];
  12. if (config.canSave) {
  13. btns.push({
  14. process: 'browser/file/update'
  15. ,text: _('save')
  16. ,id: 'modx-abtn-save'
  17. ,cls: 'primary-button'
  18. ,method: 'remote'
  19. ,keys: [{
  20. key: MODx.config.keymap_save || 's'
  21. ,ctrl: true
  22. }]
  23. });
  24. }
  25. btns.push({
  26. text: _('cancel')
  27. ,id: 'modx-abtn-cancel'
  28. });
  29. Ext.applyIf(config,{
  30. formpanel: 'modx-panel-file-edit'
  31. ,components: [{
  32. xtype: 'modx-panel-file-edit'
  33. ,file: config.file
  34. ,record: config.record || {}
  35. }]
  36. ,buttons: btns
  37. });
  38. MODx.page.EditFile.superclass.constructor.call(this,config);
  39. };
  40. Ext.extend(MODx.page.EditFile,MODx.Component);
  41. Ext.reg('modx-page-file-edit',MODx.page.EditFile);
  42. /**
  43. * Loads the EditFile panel
  44. *
  45. * @class MODx.panel.EditFile
  46. * @extends MODx.FormPanel
  47. * @param {Object} config An object of configuration properties
  48. * @xtype modx-panel-file-edit
  49. */
  50. MODx.panel.EditFile = function(config) {
  51. config = config || {};
  52. config.record = config.record || {};
  53. Ext.applyIf(config,{
  54. id: 'modx-panel-file-edit'
  55. ,url: MODx.config.connector_url
  56. ,baseParams: {
  57. action: 'browser/file/update'
  58. ,file: config.file
  59. ,wctx: MODx.request.wctx
  60. }
  61. ,cls: 'container form-with-labels'
  62. ,class_key: 'modTemplate'
  63. ,template: ''
  64. ,bodyStyle: ''
  65. ,items: [{
  66. html: _('file_edit')+': '+config.record.basename
  67. ,id: 'modx-file-header'
  68. ,xtype: 'modx-header'
  69. },MODx.getPageStructure([{
  70. title: _('file_edit')
  71. ,id: 'modx-form-file-edit'
  72. ,defaults: { border: false ,msgTarget: 'side' }
  73. ,layout: 'form'
  74. ,labelWidth: 150
  75. ,items: [{
  76. xtype: 'panel'
  77. ,border: false
  78. ,layout: 'form'
  79. ,cls:'main-wrapper'
  80. ,items: [{
  81. xtype: 'hidden'
  82. ,name: 'source'
  83. ,value: config.record.source || 0
  84. },{
  85. xtype: 'statictextfield'
  86. ,fieldLabel: _('file_name')
  87. ,name: 'basename'
  88. ,id: 'modx-file-basename'
  89. ,anchor: '98%'
  90. ,value: config.record.basename || ''
  91. },{
  92. xtype: 'statictextfield'
  93. ,fieldLabel: _('path')
  94. ,name: 'name'
  95. ,id: 'modx-file-name'
  96. ,value: config.record.name || ''
  97. ,anchor: '98%'
  98. ,submitValue: true
  99. },{
  100. xtype: 'statictextfield'
  101. ,fieldLabel: _('file_size')
  102. ,name: 'size'
  103. ,id: 'modx-file-size'
  104. ,anchor: '98%'
  105. ,value: (config.record.size || 0) + ' B'
  106. },{
  107. xtype: 'statictextfield'
  108. ,fieldLabel: _('file_last_accessed')
  109. ,name: 'last_accessed'
  110. ,id: 'modx-file-last-accessed'
  111. ,anchor: '98%'
  112. ,value: config.record.last_accessed || ''
  113. },{
  114. xtype: 'statictextfield'
  115. ,fieldLabel: _('file_last_modified')
  116. ,name: 'last_modified'
  117. ,id: 'modx-file-last-modified'
  118. ,anchor: '98%'
  119. ,value: config.record.last_modified || ''
  120. },{
  121. xtype: 'textarea'
  122. ,hideLabel: true
  123. ,name: 'content'
  124. ,id: 'modx-file-content'
  125. ,anchor: '98%'
  126. ,grow: false
  127. ,height: 400
  128. ,value: config.record.content || ''
  129. }]
  130. }]
  131. }])]
  132. ,listeners: {
  133. 'setup': {fn:this.setup,scope:this}
  134. ,'success': {fn:this.success,scope:this}
  135. ,'beforeSubmit': {fn:this.beforeSubmit,scope:this}
  136. }
  137. });
  138. MODx.panel.EditFile.superclass.constructor.call(this,config);
  139. this.addEvents('ready');
  140. };
  141. Ext.extend(MODx.panel.EditFile,MODx.FormPanel,{
  142. initialized: false
  143. ,setup: function() {
  144. this.fireEvent('ready',this.config.record);
  145. return true;
  146. }
  147. ,success: function(r) {
  148. this.getForm().setValues(r.result.object);
  149. }
  150. ,beforeSubmit: function(o) {
  151. this.cleanupEditor();
  152. return this.fireEvent('save',{
  153. values: this.getForm().getValues()
  154. });
  155. }
  156. ,cleanupEditor: function() {
  157. if (MODx.onSaveEditor) {
  158. var fld = Ext.getCmp('modx-file-content');
  159. MODx.onSaveEditor(fld);
  160. }
  161. }
  162. });
  163. Ext.reg('modx-panel-file-edit',MODx.panel.EditFile);