Source of js/Ext.ux.FileTreeMenu.js:
  1. // vim: ts=4:sw=4:nu:fdc=4:nospell
  2. /**
  3. * Ext.ux.FileTreeMenu
  4. *
  5. * @author Ing. Jozef Sakáloš
  6. * @version $Id: Ext.ux.FileTreeMenu.js 520 2009-01-31 02:59:29Z jozo $
  7. * @date 13. March 2008
  8. *
  9. * @license Ext.ux.FileTreeMenu is licensed under the terms of
  10. * the Open Source LGPL 3.0 license. Commercial use is permitted to the extent
  11. * that the code/component(s) do NOT become part of another Open Source or Commercially
  12. * licensed development library or toolkit without explicit permission.
  13. *
  14. * License details: http://www.gnu.org/licenses/lgpl.html
  15. */
  16.  
  17. /*global Ext */
  18.  
  19. /**
  20. * @class Ext.ux.FileTreeMenu
  21. * @extends Ext.menu.Menu
  22. * @constructor
  23. * Creates new FileTreeMenu object
  24. * @param {Object} config A configuration object
  25. */
  26. Ext.ux.FileTreeMenu = function(config) {
  27. config = config || {};
  28.  
  29. var uploadPanelConfig = {
  30. contextmenu:this
  31. ,buttonsAt:config.buttonsAt || 'tbar'
  32. ,singleUpload:config.singleUpload || false
  33. ,maxFileSize:config.maxFileSize
  34. ,enableProgress:config.enableProgress
  35. };
  36. if(config.baseParams) {
  37. config.baseParams.cmd = config.baseParams.cmd || 'upload';
  38. config.baseParams.dir = config.baseParams.dir || '.';
  39. uploadPanelConfig.baseParams = config.baseParams;
  40. }
  41.  
  42. // {{{
  43. Ext.apply(config, {
  44. items:[{
  45. text:'&#160'
  46. ,cls:'ux-ftm-nodename'
  47. ,disabledClass:''
  48. ,disabled:true
  49. ,cmd:'nodename'
  50. },{
  51. text:this.openText + ' (Enter)'
  52. ,iconCls:this.openIconCls
  53. ,cmd:'open'
  54. ,menu:{
  55. items:[{
  56. text:this.openSelfText
  57. ,iconCls:this.openSelfIconCls
  58. ,cmd:'open-self'
  59. },{
  60. text:this.openPopupText
  61. ,iconCls:this.openPopupIconCls
  62. ,cmd:'open-popup'
  63. },{
  64. text:this.openBlankText
  65. ,iconCls:this.openBlankIconCls
  66. ,cmd:'open-blank'
  67. },{
  68. text:this.openDwnldText
  69. ,iconCls:this.openDwnldIconCls
  70. ,cmd:'open-dwnld'
  71. }]
  72. }
  73. }
  74. ,new Ext.menu.Separator({cmd:'sep-open'})
  75. ,{
  76. text:this.reloadText + ' (Ctrl+E)'
  77. ,iconCls:this.reloadIconCls
  78. ,cmd:'reload'
  79. },{
  80. text:this.expandText + ' (Ctrl+ →)'
  81. ,iconCls:this.expandIconCls
  82. ,cmd:'expand'
  83. },{
  84. text:this.collapseText + ' (Ctrl+ ←)'
  85. ,iconCls:this.collapseIconCls
  86. ,cmd:'collapse'
  87. }
  88. ,new Ext.menu.Separator({cmd:'sep-collapse'})
  89. ,{
  90. text:this.renameText + ' (F2)'
  91. ,iconCls:this.renameIconCls
  92. ,cmd:'rename'
  93. },{
  94. text:this.deleteText + ' (' + this.deleteKeyName + ')'
  95. ,iconCls:this.deleteIconCls
  96. ,cmd:'delete'
  97. },{
  98. text:this.newdirText + '... (Ctrl+N)'
  99. ,iconCls:this.newdirIconCls
  100. ,cmd:'newdir'
  101. }
  102. ,new Ext.menu.Separator({cmd:'sep-upload'})
  103. ,{
  104. text:this.uploadFileText + ' (Ctrl+U)'
  105. ,iconCls:this.uploadIconCls
  106. ,hideOnClick:false
  107. ,cmd:'upload'
  108. }
  109. ,new Ext.menu.Adapter(new Ext.ux.UploadPanel(uploadPanelConfig), {
  110. hideOnClick:false
  111. ,cmd:'upload-panel'
  112. })
  113. ]
  114. }); // eo apply
  115. // }}}
  116.  
  117. // call parent
  118. Ext.ux.FileTreeMenu.superclass.constructor.call(this, config);
  119.  
  120. // relay event from submenu
  121. this.relayEvents(this.getItemByCmd('open').menu, ['click', 'itemclick']);
  122.  
  123. }; // eo constructor
  124.  
  125. Ext.extend(Ext.ux.FileTreeMenu, Ext.menu.Menu, {
  126. // configuration options overridable from outside
  127. /**
  128. * @cfg {String} collapseIconCls icon class for collapse all item
  129. */
  130. collapseIconCls:'icon-collapse-all'
  131.  
  132. /**
  133. * @cfg {String} collapseText text for collapse all item
  134. */
  135. ,collapseText: 'Collapse all'
  136.  
  137. /**
  138. * @cfg {String} deleteIconCls icon class for delete item
  139. */
  140. ,deleteIconCls:'icon-cross'
  141.  
  142. /**
  143. * @cfg {String} deleteKeyName text for delete item shortcut
  144. */
  145. ,deleteKeyName:'Delete Key'
  146.  
  147. /**
  148. * @cfg {String} deleteText text for delete item
  149. */
  150. ,deleteText:'Delete'
  151.  
  152. /**
  153. * @cfg {String} expandIconCls icon class for expand all item
  154. */
  155. ,expandIconCls:'icon-expand-all'
  156.  
  157. /**
  158. * @cfg {String} expandText text for expand all item
  159. */
  160. ,expandText: 'Expand all'
  161.  
  162. /**
  163. * @cfg {String} newdirIconCls icon class for new directory item
  164. */
  165. ,newdirIconCls:'icon-folder-add'
  166.  
  167. /**
  168. * @cfg {String} newdirText text for new directory item
  169. */
  170. ,newdirText:'New folder'
  171.  
  172. /**
  173. * @cfg {String} openBlankIconCls icon class for open in new window item
  174. */
  175. ,openBlankIconCls:'icon-open-blank'
  176.  
  177. /**
  178. * @cfg {String} openBlankText text for open in new window item
  179. */
  180. ,openBlankText:'Open in new window'
  181.  
  182. /**
  183. * @cfg {String} openDwnldIconCls icon class for download item
  184. */
  185. ,openDwnldIconCls:'icon-open-download'
  186.  
  187. /**
  188. * @cfg {String} openDwnldText text for download item
  189. */
  190. ,openDwnldText:'Download'
  191.  
  192. /**
  193. * @cfg {String} openIconCls icon class for open submenu
  194. */
  195. ,openIconCls:'icon-open'
  196.  
  197. /**
  198. * @cfg {String} openPopupIconCls icon class for open in popup item
  199. */
  200. ,openPopupIconCls:'icon-open-popup'
  201.  
  202. /**
  203. * @cfg {String} text for open in poput item
  204. */
  205. ,openPopupText:'Open in popup'
  206.  
  207. /**
  208. * @cfg {String} openSelfIconCls icon class for open in this window item
  209. */
  210. ,openSelfIconCls:'icon-open-self'
  211.  
  212. /**
  213. * @cfg {String} openSelfText text for open in this window item
  214. */
  215. ,openSelfText:'Open in this window'
  216.  
  217. /**
  218. * @cfg {String} openText text for open submenu
  219. */
  220. ,openText:'Open'
  221.  
  222. /**
  223. * @cfg {String} reloadIconCls icon class for reload item
  224. */
  225. ,reloadIconCls:'icon-refresh'
  226.  
  227. /**
  228. * @cfg {String} reloadText text for reload item
  229. */
  230. ,reloadText:'R<span style="text-decoration:underline">e</span>load'
  231.  
  232. /**
  233. * @cfg {String} icon class for rename item
  234. */
  235. ,renameIconCls:'icon-pencil'
  236.  
  237. /**
  238. * @cfg {String} renameText text for rename item
  239. */
  240. ,renameText: 'Rename'
  241.  
  242. /**
  243. * @cfg {String} uploadFileText text for upload file item
  244. */
  245. ,uploadFileText:'<span style="text-decoration:underline">U</span>pload file'
  246.  
  247. /**
  248. * @cfg {String} uploadIconCls icon class for upload file item
  249. */
  250. ,uploadIconCls:'icon-upload'
  251.  
  252. /**
  253. * @cfg {String} uploadText text for word 'Upload'
  254. */
  255. ,uploadText:'Upload'
  256.  
  257. /**
  258. * @cfg {Number} width Width of the menu.
  259. * Cannot be empty as we have upload panel inside.
  260. */
  261. ,width:190
  262.  
  263. // {{{
  264. /**
  265. * Returns menu item identified by cmd. Unique cmd is used to identify menu items.
  266. * I cannot use ids as they are applied to underlying DOM elements that would prevent
  267. * to have more than one menu on the page.
  268. * @param {String} cmd
  269. * Valid cmds are:
  270. * - nodename
  271. * - open
  272. * - open-self
  273. * - open-popup
  274. * - open-blank
  275. * - open-dwnld
  276. * - sep-open (for separator after open submenu)
  277. * - reload
  278. * - expand
  279. * - collapse
  280. * - sep-collapse (for separator after collapse item)
  281. * - rename
  282. * - delete
  283. * - newdir
  284. * - sep-upload (for separator before upload panel)
  285. * - upload (for upload file item that does nothing)
  286. * - upload-panel (for upload panel)
  287. * @return {Ext.menu.Item} menu item
  288. */
  289. ,getItemByCmd:function(cmd) {
  290. var open;
  291. var item = this.items.find(function(i) {
  292. return cmd === i.cmd;
  293. });
  294. if(!item) {
  295. open = this.items.find(function(i) {
  296. return 'open' === i.cmd;
  297. });
  298. if(!open) {
  299. return null;
  300. }
  301. item = open.menu.items.find(function(i) {
  302. return cmd === i.cmd;
  303. });
  304. }
  305. return item;
  306. } // eo function getItemByCmd
  307. // }}}
  308. // {{{
  309. /**
  310. * Sets/Unsets item identified by cmd to disabled/enabled state
  311. * @param {String} cmd Item indentifier, see getItemByCmd for explanation
  312. * @param {Boolean} disabled true to disable the item
  313. */
  314. ,setItemDisabled:function(cmd, disabled) {
  315. var item = this.getItemByCmd(cmd);
  316. if(item) {
  317. item.setDisabled(disabled);
  318. }
  319. } // eo function setItemDisabled
  320. // }}}
  321. // {{{
  322. /**
  323. * destroys uploadPanel if we have one
  324. * @private
  325. */
  326. ,beforeDestroy:function() {
  327. var uploadPanel = this.getItemByCmd('upload-panel');
  328. if(uploadPanel && uploadPanel.component) {
  329. uploadPanel.component.purgeListeners();
  330. uploadPanel.component.destroy();
  331. uploadPanel.component = null;
  332. }
  333. } // eo function beforeDestroy
  334. // }}}
  335.  
  336. }); // eo extend
  337.  
  338. // register xtype
  339. Ext.reg('filetreemenu', Ext.ux.FileTreeMenu);
  340.  
  341. // eof