create.js 4.5 KB

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