📄 ext.ux.filetreepanel.js
字号:
,newname:newName } }; Ext.Ajax.request(options); return true; } // }}} // {{{ /** * sets uploadPanel's destination path * @private */ ,onBeforeUpload:function(uploadPanel) { var menu = this.getContextMenu(); var path = this.getPath(menu.node); if(menu.node.isLeaf()) { path = path.replace(/\/[^\/]+$/, '', path); } uploadPanel.setPath(path); } // eo function onBeforeUpload // }}} // {{{ /** * reloads tree node on upload finish * @private */ ,onAllFinished:function(uploader) { var menu = this.getContextMenu(); (menu.node.isLeaf() ? menu.node.parentNode : menu.node).reload(); } // eo function onAllFinished // }}} // {{{ /** * @private * context menu click handler * @param {Ext.menu.Menu} context menu * @param {Ext.menu.Item} item clicked * @param {Ext.EventObject} raw event */ ,onContextClick:function(menu, item, e) { if(item.disabled) { return; } var node = menu.node; if(!node) { node = menu.parentMenu.node; } switch(item.cmd) { case 'reload': node.reload(); break; case 'expand': node.expand(true); break; case 'collapse': node.collapse(true); break; case 'open': this.openNode(node); break; case 'open-self': this.openNode(node, '_self'); break; case 'open-popup': this.openNode(node, 'popup'); break; case 'open-blank': this.openNode(node, '_blank'); break; case 'open-dwnld': this.openNode(node, 'download'); break; case 'rename': this.treeEditor.triggerEdit(node); break; case 'delete': this.deleteNode(node); break; case 'newdir': this.createNewDir(node); break; default: break; } } // eo function onContextClick // }}} // {{{ /** * contextmenu event handler * @private */ ,onContextMenu:function(node, e) { if(this.readOnly) { return false; } this.showContextMenu(node); return false; } // eo function onContextMenu // }}} // {{{ /** * dblclick handlers * @private */ ,onDblClick:function(node, e) { this.openNode(node); } // eo function onDblClick // }}} // {{{ /** * Destroys the FileTreePanel and sub-components * @private */ ,onDestroy:function() { // destroy contextmenu if(this.contextmenu) { this.contextmenu.purgeListeners(); this.contextmenu.destroy(); this.contextmenu = null; } // destroy treeEditor if(this.treeEditor) { this.treeEditor.purgeListeners(); this.treeEditor.destroy(); this.treeEditor = null; } // remover reference to treeSorter if(this.treeSorter) { this.treeSorter = null; } // call parent Ext.ux.FileTreePanel.superclass.onDestroy.call(this); } // eo function onDestroy // }}} // {{{ /** * runs when editing of a node (rename) is completed * @private * @param {Ext.Editor} editor * @param {String} newName * @param {String} oldName */ ,onEditComplete:function(editor, newName, oldName) { var node = editor.editNode; if(newName === oldName || editor.creatingNewDir) { editor.creatingNewDir = false; return; } var path = this.getPath(node.parentNode); var options = { url:this.renameUrl || this.url ,method:this.method ,scope:this ,callback:this.cmdCallback ,node:node ,oldName:oldName ,params:{ cmd:'rename' ,oldname:path + '/' + oldName ,newname:path + '/' + newName } }; Ext.Ajax.request(options); } // }}} // {{{ /** * create new directory handler * @private * runs after editing of new directory name is completed * @param {Ext.Editor} editor */ ,onNewDir:function(editor) { var path = this.getPath(editor.editNode); var options = { url:this.newdirUrl || this.url ,method:this.method ,scope:this ,node:editor.editNode ,callback:this.cmdCallback ,params:{ cmd:'newdir' ,dir:path } }; Ext.Ajax.request(options); } // }}} // {{{ /** * called while dragging over, decides if drop is allowed * @private * @param {Object} dd event */ ,onNodeDragOver:function(e) { e.cancel = e.target.disabled || e.dropNode.parentNode === e.target.parentNode && e.target.isLeaf(); } // eo function onNodeDragOver // }}} // {{{ /** * called when node is dropped * @private * @param {Object} dd event */ ,onNodeDrop:function(e) { // failure can be signalled by cmdCallback // put drop node to the original parent in that case if(true === e.failure) { e.oldParent.appendChild(e.dropNode); return; } // if we already have node with the same text, remove the duplicate var sameNode = e.dropNode.parentNode.findChild('text', e.dropNode.text); if(sameNode && sameNode !== e.dropNode) { sameNode.parentNode.removeChild(sameNode); } } // }}} // {{{ /** * Opens node * @param {Ext.tree.AsyncTreeNode} node * @param {String} mode Can be "_self", "_blank", or "popup". Defaults to (this.openMode) */ ,openNode:function(node, mode) { if(!this.enableOpen) { return; } mode = mode || this.openMode; var url; var path; if(node.isLeaf()) { path = this.getPath(node); url = this.hrefPrefix + path + this.hrefSuffix; // fire beforeopen event if(true !== this.eventsSuspended && false === this.fireEvent('beforeopen', this, node.text, url, mode)) { return; } switch(mode) { case 'popup': if(!this.popup || this.popup.closed) { this.popup = window.open(url, this.hrefTarget, this.popupFeatures); } this.popup.location = url; if(this.focusPopup) { this.popup.focus(); } break; case '_self': window.location = url; break; case '_blank': window.open(url); break; case 'download': this.downloadFile(path); break; } // fire open event if(true !== this.eventsSuspended) { this.fireEvent('open', this, node.text, url, mode); } } } // }}} // {{{ /** * Sets/Unsets delete of files/directories disabled/enabled * @param {Boolean} disabled * @return {Ext.ux.FileTreePanel} this */ ,setDeleteDisabled:function(disabled) { disabled = !(!disabled); if(!this.enableDelete === disabled) { return this; } this.hideContextMenu(); this.enableDelete = !disabled; } // eo function setDeleteDisabled // }}} // {{{ /** * Sets/Unsets creation of new directory disabled/enabled * @param {Boolean} disabled * @return {Ext.ux.FileTreePanel} this */ ,setNewdirDisabled:function(disabled) { disabled = !(!disabled); if(!this.enableNewDir === disabled) { return this; } this.hideContextMenu(); this.enableNewDir = !disabled; } // eo function setNewdirDisabled // }}} // {{{ /** * Sets/Unsets open files disabled/enabled * @param {Boolean} disabled * @return {Ext.ux.FileTreePanel} this */ ,setOpenDisabled:function(disabled) { disabled = !(!disabled); if(!this.enableOpen === disabled) { return this; } this.hideContextMenu(); this.enableOpen = !disabled; return this; } // eo function setOpenDisabled // }}} // {{{ /** * Sets/Unsets this tree to/from readOnly state * @param {Boolean} readOnly * @return {Ext.ux.FileTreePanel} this */ ,setReadOnly:function(readOnly) { readOnly = !(!readOnly); if(this.readOnly === readOnly) { return this; } this.hideContextMenu(); if(this.dragZone) { this.dragZone.locked = readOnly; } this.readOnly = readOnly; return this; } // eo function setReadOnly // }}} // {{{ /** * Sets/Unsets rename of files/directories disabled/enabled * @param {Boolean} disabled * @return {Ext.ux.FileTreePanel} this */ ,setRenameDisabled:function(disabled) { disabled = !(!disabled); if(!this.enableRename === disabled) { return this; } this.hideContextMenu(); if(this.dragZone) { this.dragZone.locked = disabled; } this.enableRename = !disabled; return this; } // eo function setRenameDisabled // }}} // {{{ /** * Sets/Unsets uploading of files disabled/enabled * @param {Boolean} disabled * @return {Ext.ux.FileTreePanel} this */ ,setUploadDisabled:function(disabled) { disabled = !(!disabled); if(!this.enableUpload === disabled) { return this; } this.hideContextMenu(); this.enableUpload = !disabled; return this; } // of function setUploadDisabled // }}} // {{{ /** * adjusts context menu depending on many things and shows it * @private * @param {Ext.tree.AsyncTreeNode} node Node on which was right-clicked */ ,showContextMenu:function(node) { // setup node alignment var topAlign = false; var alignEl = this.topMenu ? this.topMenu.getEl() : this.body; if(!node) { node = this.getSelectionModel().getSelectedNode(); topAlign = true; } else { alignEl = node.getUI().getEl(); } if(!node) { return; } var menu = this.getContextMenu(); menu.node = node; // set node name menu.getItemByCmd('nodename').setText(Ext.util.Format.ellipsis(node.text, 22)); // enable/disable items depending on node clicked menu.setItemDisabled('open', !node.isLeaf()); menu.setItemDisabled('reload', node.isLeaf()); menu.setItemDisabled('expand', node.isLeaf()); menu.setItemDisabled('collapse', node.isLeaf()); menu.setItemDisabled('delete', node === this.root || node.disabled); menu.setItemDisabled('rename', this.readOnly || node === this.root || node.disabled); menu.setItemDisabled('newdir', this.readOnly || (node.isLeaf() ? node.parentNode.disabled : node.disabled)); menu.setItemDisabled('upload', node.isLeaf() ? node.parentNode.disabled : node.disabled); menu.setItemDisabled('upload-panel', node.isLeaf() ? node.parentNode.disabled : node.disabled); // show/hide logic menu.getItemByCmd('open').setVisible(this.enableOpen); menu.getItemByCmd('delete').setVisible(this.enableDelete); menu.getItemByCmd('newdir').setVisible(this.enableNewDir); menu.getItemByCmd('rename').setVisible(this.enableRename); menu.getItemByCmd('upload').setVisible(this.enableUpload); menu.getItemByCmd('upload-panel').setVisible(this.enableUpload); menu.getItemByCmd('sep-upload').setVisible(this.enableUpload); menu.getItemByCmd('sep-collapse').setVisible(this.enableNewDir || this.enableDelete || this.enableRename); // select node node.select(); // show menu if(topAlign) { menu.showAt(menu.getEl().getAlignToXY(alignEl, 'tl-bl?')); } else { menu.showAt(menu.getEl().getAlignToXY(alignEl, 'tl-tl?', [0, 18])); } } // eo function // }}} // {{{ /** * universal show error function * @private * @param {String} msg message * @param {String} title title */ ,showError:function(msg, title) { Ext.Msg.show({ title:title || this.errorText ,msg:Ext.util.Format.ellipsis(msg, this.maxMsgLen) ,fixCursor:true ,icon:Ext.Msg.ERROR ,buttons:Ext.Msg.OK ,minWidth:1200 > String(msg).length ? 360 : 600 }); } // eo function showError // }}} // {{{ /** * updates class of leaf after rename * @private * @param {Ext.tree.AsyncTreeNode} node Node to update class of * @param {String} oldName Name the node had before */ ,updateCls:function(node, oldName) { if(node.isLeaf()) { Ext.fly(node.getUI().iconNode).removeClass(this.getFileCls(oldName)); Ext.fly(node.getUI().iconNode).addClass(this.getFileCls(node.text)); } } // }}}}); // eo extend// register xtypeExt.reg('filetreepanel', Ext.ux.FileTreePanel);// eof
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -