modx.tree.directory.js 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063
  1. /**
  2. * Generates the Directory Tree
  3. *
  4. * @class MODx.tree.Directory
  5. * @extends MODx.tree.Tree
  6. * @param {Object} config An object of options.
  7. * @xtype modx-tree-directory
  8. */
  9. MODx.tree.Directory = function(config) {
  10. config = config || {};
  11. config.id = config.id || Ext.id();
  12. Ext.applyIf(config,{
  13. rootVisible: true
  14. ,rootName: 'Filesystem'
  15. ,rootId: '/'
  16. ,title: _('files')
  17. ,ddAppendOnly: true
  18. ,ddGroup: 'modx-treedrop-sources-dd'
  19. ,url: MODx.config.connector_url
  20. ,hideSourceCombo: false
  21. ,baseParams: {
  22. hideFiles: config.hideFiles || false
  23. ,hideTooltips: config.hideTooltips || false
  24. ,wctx: MODx.ctx || 'web'
  25. ,currentAction: MODx.request.a || 0
  26. ,currentFile: MODx.request.file || ''
  27. ,source: config.source || 0
  28. }
  29. ,action: 'browser/directory/getList'
  30. ,primaryKey: 'dir'
  31. ,useDefaultToolbar: true
  32. ,autoExpandRoot: false
  33. ,tbar: [{
  34. cls: 'x-btn-icon icon-folder'
  35. ,tooltip: {text: _('file_folder_create')}
  36. ,handler: this.createDirectory
  37. ,scope: this
  38. ,hidden: MODx.perm.directory_create ? false : true
  39. },{
  40. cls: 'x-btn-icon icon-page_white'
  41. ,tooltip: {text: _('file_create')}
  42. ,handler: this.createFile
  43. ,scope: this
  44. ,hidden: MODx.perm.file_create ? false : true
  45. },{
  46. cls: 'x-btn-icon icon-file_upload'
  47. ,tooltip: {text: _('upload_files')}
  48. ,handler: this.uploadFiles
  49. ,scope: this
  50. ,hidden: MODx.perm.file_upload ? false : true
  51. },'->',{
  52. cls: 'x-btn-icon icon-file_manager'
  53. ,tooltip: {text: _('modx_browser')}
  54. ,handler: this.loadFileManager
  55. ,scope: this
  56. ,hidden: MODx.perm.file_manager && !MODx.browserOpen ? false : true
  57. }]
  58. ,tbarCfg: {
  59. id: config.id+'-tbar'
  60. }
  61. });
  62. MODx.tree.Directory.superclass.constructor.call(this,config);
  63. this.addEvents({
  64. 'beforeUpload': true
  65. ,'afterUpload': true
  66. ,'afterQuickCreate': true
  67. ,'afterRename': true
  68. ,'afterRemove': true
  69. ,'fileBrowserSelect': true
  70. ,'changeSource': true
  71. ,'afterSort': true
  72. });
  73. this.on('click',function(n,e) {
  74. n.select();
  75. this.cm.activeNode = n;
  76. },this);
  77. this.on('render',function() {
  78. var el = Ext.get(this.config.id);
  79. el.createChild({tag: 'div', id: this.config.id+'_tb'});
  80. el.createChild({tag: 'div', id: this.config.id+'_filter'});
  81. this.addSourceToolbar();
  82. // this.getRootNode().pseudoroot = true
  83. // console.log(this.getRootNode())
  84. },this);
  85. //this.addSourceToolbar();
  86. this.on('show',function() {
  87. if (!this.config.hideSourceCombo) {
  88. try { this.sourceCombo.show(); } catch (e) {}
  89. }
  90. },this);
  91. this._init();
  92. this.on('afterrender', this.showRefresh, this);
  93. this.on('afterSort',this._handleAfterDrop,this);
  94. };
  95. Ext.extend(MODx.tree.Directory,MODx.tree.Tree,{
  96. windows: {}
  97. /**
  98. * Build the contextual menu for the root node
  99. *
  100. * @param {Ext.data.Node} node
  101. *
  102. * @returns {Array}
  103. */
  104. ,getRootMenu: function(node) {
  105. var menu = [];
  106. if (MODx.perm.directory_create) {
  107. menu.push({
  108. text: _('file_folder_create')
  109. ,handler: this.createDirectory
  110. ,scope: this
  111. });
  112. }
  113. if (MODx.perm.file_create) {
  114. menu.push({
  115. text: _('file_create')
  116. ,handler: this.createFile
  117. ,scope: this
  118. });
  119. }
  120. if (MODx.perm.file_upload) {
  121. menu.push({
  122. text: _('upload_files')
  123. ,handler: this.uploadFiles
  124. ,scope: this
  125. });
  126. }
  127. if (node.ownerTree.el.hasClass('pupdate')) {
  128. // User is allowed to edit media sources
  129. menu.push([
  130. '-'
  131. ,{
  132. text: _('update')
  133. ,handler: function() {
  134. MODx.loadPage('source/update', 'id=' + node.ownerTree.source);
  135. }
  136. }
  137. ])
  138. }
  139. // if (MODx.perm.file_manager) {
  140. // menu.push({
  141. // text: _('modx_browser')
  142. // ,handler: this.loadFileManager
  143. // ,scope: this
  144. // });
  145. // }
  146. return menu;
  147. }
  148. /**
  149. * Override to handle root nodes contextual menus
  150. *
  151. * @param node
  152. * @param e
  153. */
  154. ,_showContextMenu: function(node,e) {
  155. this.cm.activeNode = node;
  156. this.cm.removeAll();
  157. var m;
  158. if (node.isRoot) {
  159. m = this.getRootMenu(node);
  160. } else if (node.attributes.menu && node.attributes.menu.items) {
  161. m = node.attributes.menu.items;
  162. }
  163. if (m && m.length > 0) {
  164. this.addContextMenuItem(m);
  165. this.cm.showAt(e.xy);
  166. }
  167. e.preventDefault();
  168. e.stopEvent();
  169. }
  170. /**
  171. * Create a refresh button on the root node
  172. *
  173. * @see MODx.Tree.Tree#_onAppend
  174. */
  175. ,showRefresh: function() {
  176. var node = this.getRootNode()
  177. ,inlineButtonsLang = this.getInlineButtonsLang(node)
  178. ,elId = node.ui.elNode.id+ '_tools'
  179. ,el = document.createElement('div');
  180. el.id = elId;
  181. el.className = 'modx-tree-node-tool-ct';
  182. node.ui.elNode.appendChild(el);
  183. MODx.load({
  184. xtype: 'modx-button'
  185. ,text: ''
  186. ,scope: this
  187. ,tooltip: new Ext.ToolTip({
  188. title: inlineButtonsLang.refresh
  189. ,target: this
  190. })
  191. ,node: node
  192. ,handler: function(btn,evt){
  193. evt.stopPropagation(evt);
  194. node.reload();
  195. }
  196. ,iconCls: 'icon-refresh'
  197. ,renderTo: elId
  198. ,listeners: {
  199. mouseover: function(button, e){
  200. button.tooltip.onTargetOver(e);
  201. }
  202. ,mouseout: function(button, e){
  203. button.tooltip.onTargetOut(e);
  204. }
  205. }
  206. });
  207. }
  208. ,addSourceToolbar: function() {
  209. this.sourceCombo = new MODx.combo.MediaSource({
  210. value: this.config.source || MODx.config.default_media_source
  211. ,listWidth: 236
  212. ,listeners: {
  213. select:{
  214. fn: this.changeSource
  215. ,scope: this
  216. }
  217. ,loaded: {
  218. fn: function(combo) {
  219. var rec = combo.store.getById(this.config.source);
  220. var rn = this.getRootNode();
  221. if (rn && rec) { rn.setText(rec.data.name); }
  222. }
  223. ,scope: this
  224. }
  225. }
  226. });
  227. this.searchBar = new Ext.Toolbar({
  228. renderTo: this.tbar
  229. ,id: this.config.id+'-sourcebar'
  230. ,items: [this.sourceCombo]
  231. });
  232. this.on('resize', function(){
  233. this.sourceCombo.setWidth(this.getWidth() - 12);
  234. }, this);
  235. if (this.config.hideSourceCombo) {
  236. try { this.sourceCombo.hide(); } catch (e) {}
  237. }
  238. }
  239. ,changeSource: function(sel) {
  240. var s = sel.getValue();
  241. var rn = this.getRootNode();
  242. if (rn) { rn.setText(sel.getRawValue()); }
  243. this.config.baseParams.source = s;
  244. this.fireEvent('changeSource',s);
  245. this.refresh();
  246. }
  247. /**
  248. * Expand the root node if appropriate
  249. */
  250. ,_init: function() {
  251. var treeState = Ext.state.Manager.get(this.treestate_id)
  252. ,rootPath = this.root.getPath('text');
  253. if (rootPath === treeState) {
  254. // Nothing to do
  255. return;
  256. }
  257. this.root.expand();
  258. }
  259. ,_initExpand: function() {
  260. var treeState = Ext.state.Manager.get(this.treestate_id);
  261. if (!Ext.isEmpty(this.config.openTo)) {
  262. this.selectPath('/'+_('files')+'/'+this.config.openTo,'text');
  263. } else {
  264. this.expandPath(treeState, 'text');
  265. }
  266. }
  267. ,_saveState: function(n) {
  268. if (!n.expanded && !n.isRoot) {
  269. // Node has been collapsed, grab its parent
  270. n = n.parentNode;
  271. }
  272. var p = n.getPath('text');
  273. Ext.state.Manager.set(this.treestate_id, p);
  274. }
  275. ,_handleAfterDrop: function(o,r) {
  276. var targetNode = o.event.target;
  277. var dropNode = o.event.dropNode;
  278. if (o.event.point == 'append' && targetNode) {
  279. var ui = targetNode.getUI();
  280. ui.addClass('haschildren');
  281. ui.removeClass('icon-resource');
  282. }
  283. if((MODx.request.a == MODx.action['resource/update']) && dropNode.attributes.pk == MODx.request.id){
  284. var parentFieldCmb = Ext.getCmp('modx-resource-parent');
  285. var parentFieldHidden = Ext.getCmp('modx-resource-parent-hidden');
  286. if(parentFieldCmb && parentFieldHidden){
  287. parentFieldHidden.setValue(dropNode.parentNode.attributes.pk);
  288. parentFieldCmb.setValue(dropNode.parentNode.attributes.text.replace(/(<([^>]+)>)/ig,""));
  289. }
  290. }
  291. targetNode.reload(true);
  292. }
  293. ,_handleDrag: function(dropEvent) {
  294. var from = dropEvent.dropNode.attributes.id;
  295. var to = dropEvent.target.attributes.id;
  296. MODx.Ajax.request({
  297. url: this.config.url
  298. ,params: {
  299. source: this.config.baseParams.source
  300. ,from: from
  301. ,to: to
  302. ,action: this.config.sortAction || 'browser/directory/sort'
  303. ,point: dropEvent.point
  304. }
  305. ,listeners: {
  306. 'success': {fn:function(r) {
  307. var el = dropEvent.dropNode.getUI().getTextEl();
  308. if (el) {Ext.get(el).frame();}
  309. this.fireEvent('afterSort',{event:dropEvent,result:r});
  310. },scope:this}
  311. ,'failure': {fn:function(r) {
  312. MODx.form.Handler.errorJSON(r);
  313. this.refresh();
  314. return false;
  315. },scope:this}
  316. }
  317. });
  318. }
  319. ,getPath:function(node) {
  320. var path, p, a;
  321. // get path for non-root node
  322. if(node !== this.root) {
  323. p = node.parentNode;
  324. a = [node.text];
  325. while(p && p !== this.root) {
  326. a.unshift(p.text);
  327. p = p.parentNode;
  328. }
  329. a.unshift(this.root.attributes.path || '');
  330. path = a.join(this.pathSeparator);
  331. }
  332. // path for root node is it's path attribute
  333. else {
  334. path = node.attributes.path || '';
  335. }
  336. // a little bit of security: strip leading / or .
  337. // full path security checking has to be implemented on server
  338. path = path.replace(/^[\/\.]*/, '');
  339. return path+'/';
  340. }
  341. ,editFile: function(itm,e) {
  342. MODx.loadPage('system/file/edit', 'file='+this.cm.activeNode.attributes.id+'&source='+this.config.source);
  343. }
  344. ,quickUpdateFile: function(itm,e) {
  345. var node = this.cm.activeNode;
  346. MODx.Ajax.request({
  347. url: MODx.config.connector_url
  348. ,params: {
  349. action: 'browser/file/get'
  350. ,file: node.attributes.id
  351. ,wctx: MODx.ctx || ''
  352. ,source: this.getSource()
  353. }
  354. ,listeners: {
  355. 'success': {fn:function(response) {
  356. var r = {
  357. file: node.attributes.id
  358. ,name: node.text
  359. ,path: node.attributes.pathRelative
  360. ,source: this.getSource()
  361. ,content: response.object.content
  362. };
  363. var w = MODx.load({
  364. xtype: 'modx-window-file-quick-update'
  365. ,record: r
  366. ,listeners: {
  367. 'hide':{fn:function() {this.destroy();}}
  368. }
  369. });
  370. w.show(e.target);
  371. },scope:this}
  372. }
  373. });
  374. }
  375. ,createFile: function(itm,e) {
  376. var active = this.cm.activeNode
  377. ,dir = active && active.attributes && (active.isRoot || active.attributes.type == 'dir')
  378. ? active.attributes.id
  379. : '';
  380. MODx.loadPage('system/file/create', 'directory='+dir+'&source='+this.getSource());
  381. }
  382. ,quickCreateFile: function(itm,e) {
  383. var node = this.cm.activeNode;
  384. var r = {
  385. directory: node.attributes.id
  386. ,source: this.getSource()
  387. };
  388. var w = MODx.load({
  389. xtype: 'modx-window-file-quick-create'
  390. ,record: r
  391. ,listeners: {
  392. 'success':{fn:function(r) {
  393. this.fireEvent('afterQuickCreate');
  394. this.refreshActiveNode();
  395. }, scope: this}
  396. ,'hide':{fn:function() {this.destroy();}}
  397. }
  398. });
  399. w.show(e.target);
  400. }
  401. ,browser: null
  402. ,loadFileManager: function(btn,e) {
  403. var refresh = false;
  404. if (this.browser === null) {
  405. this.browser = MODx.load({
  406. xtype: 'modx-browser'
  407. ,hideFiles: MODx.config.modx_browser_tree_hide_files
  408. ,rootId: '/' // prevent JS error because ui.node.elNode is undefined when this is
  409. // ,rootVisible: false
  410. ,wctx: MODx.ctx
  411. ,source: this.config.baseParams.source
  412. ,listeners: {
  413. 'select': {fn: function(data) {
  414. this.fireEvent('fileBrowserSelect',data);
  415. },scope:this}
  416. }
  417. });
  418. } else {
  419. refresh = true;
  420. }
  421. if (this.browser) {
  422. this.browser.setSource(this.config.baseParams.source);
  423. if (refresh) {
  424. this.browser.win.tree.refresh();
  425. }
  426. this.browser.show();
  427. }
  428. }
  429. /* exside: what is this? cannot find it used anywhere and basically does what renameFile() does, no? */
  430. /* candidate for removal or depreciation */
  431. ,renameNode: function(field,nv,ov) {
  432. MODx.Ajax.request({
  433. url: MODx.config.connector_url
  434. ,params: {
  435. action: 'browser/file/rename'
  436. ,new_name: nv
  437. ,old_name: ov
  438. ,file: this.treeEditor.editNode.id
  439. ,wctx: MODx.ctx || ''
  440. ,source: this.getSource()
  441. }
  442. ,listeners: {
  443. 'success': {fn:function(r) {
  444. this.fireEvent('afterRename');
  445. this.refreshActiveNode();
  446. }, scope: this}
  447. }
  448. });
  449. }
  450. ,renameDirectory: function(item,e) {
  451. var node = this.cm.activeNode;
  452. var r = {
  453. old_name: node.text
  454. ,name: node.text
  455. ,path: node.attributes.pathRelative
  456. ,source: this.getSource()
  457. };
  458. var w = MODx.load({
  459. xtype: 'modx-window-directory-rename'
  460. ,record: r
  461. ,listeners: {
  462. 'success':{fn:this.refreshParentNode,scope:this}
  463. ,'hide':{fn:function() {this.destroy();}}
  464. }
  465. });
  466. w.show(e.target);
  467. }
  468. ,renameFile: function(item,e) {
  469. var node = this.cm.activeNode;
  470. var r = {
  471. old_name: node.text
  472. ,name: node.text
  473. ,path: node.attributes.pathRelative
  474. ,source: this.getSource()
  475. };
  476. var w = MODx.load({
  477. xtype: 'modx-window-file-rename'
  478. ,record: r
  479. ,listeners: {
  480. // 'success':{fn:this.refreshParentNode,scope:this}
  481. 'success': {fn:function(r) {
  482. this.fireEvent('afterRename');
  483. this.refreshParentNode();
  484. }, scope: this}
  485. ,'hide':{fn:function() {this.destroy();}}
  486. }
  487. });
  488. w.show(e.target);
  489. }
  490. ,createDirectory: function(item,e) {
  491. var node = this.cm && this.cm.activeNode ? this.cm.activeNode : false;
  492. var r = {
  493. parent: node && node.attributes.type == 'dir' ? node.attributes.pathRelative : '/'
  494. ,source: this.getSource()
  495. };
  496. var w = MODx.load({
  497. xtype: 'modx-window-directory-create'
  498. ,record: r
  499. ,listeners: {
  500. 'success': {
  501. fn:function() {
  502. var parent = Ext.getCmp('folder-parent').getValue();
  503. if (this.cm.activeNode.constructor.name === 'constructor' || parent === '' || parent === '/') {
  504. this.refresh();
  505. } else {
  506. this.refreshActiveNode();
  507. }
  508. },scope:this
  509. }
  510. ,'hide':{fn:function() {this.destroy();}}
  511. }
  512. });
  513. w.show(e ? e.target : Ext.getBody());
  514. }
  515. ,chmodDirectory: function(item,e) {
  516. var node = this.cm.activeNode;
  517. var r = {
  518. dir: node.attributes.path
  519. ,mode: node.attributes.perms
  520. ,source: this.getSource()
  521. };
  522. var w = MODx.load({
  523. xtype: 'modx-window-directory-chmod'
  524. ,record: r
  525. ,listeners: {
  526. 'success':{fn:this.refreshActiveNode,scope:this}
  527. ,'hide':{fn:function() {this.destroy();}}
  528. }
  529. });
  530. w.show(e.target);
  531. }
  532. ,removeDirectory: function(item,e) {
  533. var node = this.cm.activeNode;
  534. MODx.msg.confirm({
  535. text: _('file_folder_remove_confirm')
  536. ,url: MODx.config.connector_url
  537. ,params: {
  538. action: 'browser/directory/remove'
  539. ,dir: node.attributes.path
  540. ,wctx: MODx.ctx || ''
  541. ,source: this.getSource()
  542. }
  543. ,listeners: {
  544. success: {
  545. fn: this._afterRemove
  546. ,scope: this
  547. }
  548. }
  549. });
  550. }
  551. ,removeFile: function(item,e) {
  552. var node = this.cm.activeNode;
  553. MODx.msg.confirm({
  554. text: _('file_confirm_remove')
  555. ,url: MODx.config.connector_url
  556. ,params: {
  557. action: 'browser/file/remove'
  558. ,file: node.attributes.pathRelative
  559. ,wctx: MODx.ctx || ''
  560. ,source: this.getSource()
  561. }
  562. ,listeners: {
  563. success: {
  564. fn: this._afterRemove
  565. ,scope: this
  566. }
  567. }
  568. });
  569. }
  570. /**
  571. * Operation executed after a node has been removed
  572. */
  573. ,_afterRemove: function() {
  574. this.fireEvent('afterRemove');
  575. this.refreshParentNode();
  576. this.cm.activeNode = null;
  577. }
  578. ,unpackFile: function(item,e) {
  579. var node = this.cm.activeNode;
  580. MODx.msg.confirm({
  581. text: _('file_download_unzip') + ' ' + node.attributes.id
  582. ,url: MODx.config.connectors_url
  583. ,params: {
  584. action: 'browser/file/unpack'
  585. ,file: node.attributes.id
  586. ,wctx: MODx.ctx || ''
  587. ,source: this.getSource()
  588. ,path: node.attributes.directory
  589. }
  590. ,listeners: {
  591. 'success':{fn:this.refreshParentNode,scope:this}
  592. }
  593. });
  594. }
  595. ,downloadFile: function(item,e) {
  596. var node = this.cm.activeNode;
  597. MODx.Ajax.request({
  598. url: MODx.config.connector_url
  599. ,params: {
  600. action: 'browser/file/download'
  601. ,file: node.attributes.pathRelative
  602. ,wctx: MODx.ctx || ''
  603. ,source: this.getSource()
  604. }
  605. ,listeners: {
  606. 'success':{fn:function(r) {
  607. if (!Ext.isEmpty(r.object.url)) {
  608. location.href = MODx.config.connector_url+'?action=browser/file/download&download=1&file='+node.attributes.id+'&HTTP_MODAUTH='+MODx.siteId+'&source='+this.getSource()+'&wctx='+MODx.ctx;
  609. }
  610. },scope:this}
  611. }
  612. });
  613. }
  614. ,copyRelativePath: function(item,e) {
  615. var node = this.cm.activeNode;
  616. var dummyRelativePathInput = document.createElement("input");
  617. document.body.appendChild(dummyRelativePathInput);
  618. dummyRelativePathInput.setAttribute('value', node.attributes.pathRelative);
  619. dummyRelativePathInput.select();
  620. document.execCommand("copy");
  621. document.body.removeChild(dummyRelativePathInput);
  622. }
  623. ,getSource: function() {
  624. return this.config.baseParams.source;
  625. }
  626. ,uploadFiles: function(btn,e) {
  627. if (!this.uploader) {
  628. this.uploader = new MODx.util.MultiUploadDialog.Dialog({
  629. url: MODx.config.connector_url
  630. ,base_params: {
  631. action: 'browser/file/upload'
  632. ,wctx: MODx.ctx || ''
  633. ,source: this.getSource()
  634. }
  635. ,cls: 'ext-ux-uploaddialog-dialog modx-upload-window'
  636. });
  637. this.uploader.on('show',this.beforeUpload,this);
  638. this.uploader.on('uploadsuccess',this.uploadSuccess,this);
  639. this.uploader.on('uploaderror',this.uploadError,this);
  640. this.uploader.on('uploadfailed',this.uploadFailed,this);
  641. }
  642. this.uploader.base_params.source = this.getSource();
  643. this.uploader.show(btn);
  644. }
  645. ,uploadError: function(dlg,file,data,rec) {}
  646. ,uploadFailed: function(dlg,file,rec) {}
  647. ,uploadSuccess:function() {
  648. if (this.cm.activeNode) {
  649. var node = this.cm.activeNode;
  650. if (node.isLeaf) {
  651. var pn = (node.isLeaf() ? node.parentNode : node);
  652. if (pn) {
  653. pn.reload();
  654. } else {
  655. this.refreshActiveNode();
  656. }
  657. this.fireEvent('afterUpload',node);
  658. } else {
  659. this.refreshActiveNode();
  660. }
  661. } else {
  662. this.refresh();
  663. this.fireEvent('afterUpload');
  664. }
  665. }
  666. ,beforeUpload: function() {
  667. var path = this.config.rootId || '/';
  668. if (this.cm.activeNode) {
  669. path = this.getPath(this.cm.activeNode);
  670. if(this.cm.activeNode.isLeaf()) {
  671. path = this.getPath(this.cm.activeNode.parentNode);
  672. }
  673. }
  674. this.uploader.setBaseParams({
  675. action: 'browser/file/upload'
  676. ,path: path
  677. ,wctx: MODx.ctx || ''
  678. ,source: this.getSource()
  679. });
  680. this.fireEvent('beforeUpload',this.cm.activeNode);
  681. }
  682. });
  683. Ext.reg('modx-tree-directory',MODx.tree.Directory);
  684. /**
  685. * Generates the Create Directory window
  686. *
  687. * @class MODx.window.CreateDirectory
  688. * @extends MODx.Window
  689. * @param {Object} config An object of configuration options.
  690. * @xtype modx-window-directory-create
  691. */
  692. MODx.window.CreateDirectory = function(config) {
  693. config = config || {};
  694. Ext.applyIf(config,{
  695. title: _('file_folder_create')
  696. // width: 430
  697. // ,height: 200
  698. ,url: MODx.config.connector_url
  699. ,action: 'browser/directory/create'
  700. ,fields: [{
  701. xtype: 'hidden'
  702. ,name: 'wctx'
  703. ,value: MODx.ctx || ''
  704. },{
  705. xtype: 'hidden'
  706. ,name: 'source'
  707. },{
  708. fieldLabel: _('name')
  709. ,name: 'name'
  710. ,xtype: 'textfield'
  711. ,anchor: '100%'
  712. ,allowBlank: false
  713. },{
  714. fieldLabel: _('file_folder_parent')
  715. ,id: 'folder-parent'
  716. ,name: 'parent'
  717. ,xtype: 'textfield'
  718. ,anchor: '100%'
  719. }]
  720. });
  721. MODx.window.CreateDirectory.superclass.constructor.call(this,config);
  722. };
  723. Ext.extend(MODx.window.CreateDirectory,MODx.Window);
  724. Ext.reg('modx-window-directory-create',MODx.window.CreateDirectory);
  725. /**
  726. * Generates the Chmod Directory window
  727. *
  728. * @class MODx.window.ChmodDirectory
  729. * @extends MODx.Window
  730. * @param {Object} config An object of configuration options.
  731. * @xtype modx-window-directory-chmod
  732. */
  733. MODx.window.ChmodDirectory = function(config) {
  734. config = config || {};
  735. Ext.applyIf(config,{
  736. title: _('file_folder_chmod')
  737. // ,width: 430
  738. // ,height: 200
  739. ,url: MODx.config.connector_url
  740. ,action: 'browser/directory/chmod'
  741. ,fields: [{
  742. xtype: 'hidden'
  743. ,name: 'wctx'
  744. ,value: MODx.ctx || ''
  745. },{
  746. xtype: 'hidden'
  747. ,name: 'source'
  748. },{
  749. name: 'dir'
  750. ,fieldLabel: _('name')
  751. ,xtype: 'statictextfield'
  752. ,anchor: '100%'
  753. ,submitValue: true
  754. },{
  755. fieldLabel: _('mode')
  756. ,name: 'mode'
  757. ,xtype: 'textfield'
  758. ,anchor: '100%'
  759. ,allowBlank: false
  760. }]
  761. });
  762. MODx.window.ChmodDirectory.superclass.constructor.call(this,config);
  763. };
  764. Ext.extend(MODx.window.ChmodDirectory,MODx.Window);
  765. Ext.reg('modx-window-directory-chmod',MODx.window.ChmodDirectory);
  766. /**
  767. * Generates the Rename Directory window
  768. *
  769. * @class MODx.window.RenameDirectory
  770. * @extends MODx.Window
  771. * @param {Object} config An object of configuration options.
  772. * @xtype modx-window-directory-rename
  773. */
  774. MODx.window.RenameDirectory = function(config) {
  775. config = config || {};
  776. Ext.applyIf(config,{
  777. title: _('rename')
  778. // ,width: 430
  779. // ,height: 200
  780. ,url: MODx.config.connector_url
  781. ,action: 'browser/directory/rename'
  782. ,fields: [{
  783. xtype: 'hidden'
  784. ,name: 'wctx'
  785. ,value: MODx.ctx || ''
  786. },{
  787. xtype: 'hidden'
  788. ,name: 'source'
  789. },{
  790. fieldLabel: _('path')
  791. ,name: 'path'
  792. ,xtype: 'statictextfield'
  793. ,submitValue: true
  794. ,anchor: '100%'
  795. },{
  796. fieldLabel: _('old_name')
  797. ,name: 'old_name'
  798. ,xtype: 'statictextfield'
  799. ,anchor: '100%'
  800. },{
  801. fieldLabel: _('new_name')
  802. ,name: 'name'
  803. ,xtype: 'textfield'
  804. ,anchor: '100%'
  805. ,allowBlank: false
  806. }]
  807. });
  808. MODx.window.RenameDirectory.superclass.constructor.call(this,config);
  809. };
  810. Ext.extend(MODx.window.RenameDirectory,MODx.Window);
  811. Ext.reg('modx-window-directory-rename',MODx.window.RenameDirectory);
  812. /**
  813. * Generates the Rename File window
  814. *
  815. * @class MODx.window.RenameFile
  816. * @extends MODx.Window
  817. * @param {Object} config An object of configuration options.
  818. * @xtype modx-window-file-rename
  819. */
  820. MODx.window.RenameFile = function(config) {
  821. config = config || {};
  822. Ext.applyIf(config,{
  823. title: _('rename')
  824. // ,width: 430
  825. // ,height: 200
  826. ,url: MODx.config.connector_url
  827. ,action: 'browser/file/rename'
  828. ,fields: [{
  829. xtype: 'hidden'
  830. ,name: 'wctx'
  831. ,value: MODx.ctx || ''
  832. },{
  833. xtype: 'hidden'
  834. ,name: 'source'
  835. },{
  836. fieldLabel: _('path')
  837. ,name: 'path'
  838. ,xtype: 'statictextfield'
  839. ,submitValue: true
  840. ,anchor: '100%'
  841. },{
  842. fieldLabel: _('old_name')
  843. ,name: 'old_name'
  844. ,xtype: 'statictextfield'
  845. ,anchor: '100%'
  846. },{
  847. fieldLabel: _('new_name')
  848. ,name: 'name'
  849. ,xtype: 'textfield'
  850. ,anchor: '100%'
  851. ,allowBlank: false
  852. },{
  853. name: 'dir'
  854. ,xtype: 'hidden'
  855. }]
  856. });
  857. MODx.window.RenameFile.superclass.constructor.call(this,config);
  858. };
  859. Ext.extend(MODx.window.RenameFile,MODx.Window);
  860. Ext.reg('modx-window-file-rename',MODx.window.RenameFile);
  861. /**
  862. * Generates the Quick Update File window
  863. *
  864. * @class MODx.window.QuickUpdateFile
  865. * @extends MODx.Window
  866. * @param {Object} config An object of configuration options.
  867. * @xtype modx-window-file-quick-update
  868. */
  869. MODx.window.QuickUpdateFile = function(config) {
  870. config = config || {};
  871. Ext.applyIf(config,{
  872. title: _('file_quick_update')
  873. ,width: 600
  874. // ,height: 640
  875. // ,autoHeight: false
  876. ,layout: 'anchor'
  877. ,url: MODx.config.connector_url
  878. ,action: 'browser/file/update'
  879. ,fields: [{
  880. xtype: 'hidden'
  881. ,name: 'wctx'
  882. ,value: MODx.ctx || ''
  883. },{
  884. xtype: 'hidden'
  885. ,name: 'source'
  886. },{
  887. xtype: 'hidden'
  888. ,name: 'file'
  889. },{
  890. fieldLabel: _('name')
  891. ,name: 'name'
  892. ,xtype: 'statictextfield'
  893. ,anchor: '100%'
  894. },{
  895. fieldLabel: _('path')
  896. ,name: 'path'
  897. ,xtype: 'statictextfield'
  898. ,anchor: '100%'
  899. },{
  900. fieldLabel: _('content')
  901. ,xtype: 'textarea'
  902. ,name: 'content'
  903. ,anchor: '100%'
  904. ,height: 200
  905. }]
  906. ,keys: [{
  907. key: Ext.EventObject.ENTER
  908. ,shift: true
  909. ,fn: this.submit
  910. ,scope: this
  911. }]
  912. ,buttons: [{
  913. text: config.cancelBtnText || _('cancel')
  914. ,scope: this
  915. ,handler: function() { this.hide(); }
  916. },{
  917. text: config.saveBtnText || _('save')
  918. ,scope: this
  919. ,handler: function() { this.submit(false); }
  920. },{
  921. text: config.saveBtnText || _('save_and_close')
  922. ,cls: 'primary-button'
  923. ,scope: this
  924. ,handler: this.submit
  925. }]
  926. });
  927. MODx.window.QuickUpdateFile.superclass.constructor.call(this,config);
  928. };
  929. Ext.extend(MODx.window.QuickUpdateFile,MODx.Window);
  930. Ext.reg('modx-window-file-quick-update',MODx.window.QuickUpdateFile);
  931. /**
  932. * Generates the Quick Create File window
  933. *
  934. * @class MODx.window.QuickCreateFile
  935. * @extends MODx.Window
  936. * @param {Object} config An object of configuration options.
  937. * @xtype modx-window-file-quick-create
  938. */
  939. MODx.window.QuickCreateFile = function(config) {
  940. config = config || {};
  941. Ext.applyIf(config,{
  942. title: _('file_quick_create')
  943. ,width: 600
  944. // ,height: 640
  945. // ,autoHeight: false
  946. ,layout: 'anchor'
  947. ,url: MODx.config.connector_url
  948. ,action: 'browser/file/create'
  949. ,fields: [{
  950. xtype: 'hidden'
  951. ,name: 'wctx'
  952. ,value: MODx.ctx || ''
  953. },{
  954. xtype: 'hidden'
  955. ,name: 'source'
  956. },{
  957. fieldLabel: _('directory')
  958. ,name: 'directory'
  959. ,submitValue: true
  960. ,xtype: 'statictextfield'
  961. ,anchor: '100%'
  962. },{
  963. fieldLabel: _('name')
  964. ,name: 'name'
  965. ,xtype: 'textfield'
  966. ,anchor: '100%'
  967. ,allowBlank: false
  968. },{
  969. fieldLabel: _('content')
  970. ,xtype: 'textarea'
  971. ,name: 'content'
  972. ,anchor: '100%'
  973. ,height: 200
  974. }]
  975. ,keys: [{
  976. key: Ext.EventObject.ENTER
  977. ,shift: true
  978. ,fn: this.submit
  979. ,scope: this
  980. }]
  981. /* this is the default config found also in widgets/core/modx.window.js, no need to redeclare here */
  982. /*,buttons: [{
  983. text: config.cancelBtnText || _('cancel')
  984. ,scope: this
  985. ,handler: function() { this.hide(); }
  986. },{
  987. text: config.saveBtnText || _('save')
  988. ,scope: this
  989. ,handler: this.submit
  990. }]*/
  991. });
  992. MODx.window.QuickCreateFile.superclass.constructor.call(this,config);
  993. };
  994. Ext.extend(MODx.window.QuickCreateFile,MODx.Window);
  995. Ext.reg('modx-window-file-quick-create',MODx.window.QuickCreateFile);