X-Git-Url: http://git.roojs.org/?a=blobdiff_plain;f=docs%2Fsrc%2FRoo_tree_TreeEditor.js.html;fp=docs%2Fsrc%2FRoo_tree_TreeEditor.js.html;h=c952331003e5114e8eb39b953f4808efac73cc61;hb=9ff8ded6bbbd258ecd646184ba26020874e2c085;hp=0000000000000000000000000000000000000000;hpb=2542b67d1a0768025056f2f330bfe50b64d1ad38;p=roojs1 diff --git a/docs/src/Roo_tree_TreeEditor.js.html b/docs/src/Roo_tree_TreeEditor.js.html new file mode 100644 index 0000000000..c952331003 --- /dev/null +++ b/docs/src/Roo_tree_TreeEditor.js.html @@ -0,0 +1,163 @@ +/home/alan/gitlive/roojs1/Roo/tree/TreeEditor.js/* + * Based on: + * Ext JS Library 1.1.1 + * Copyright(c) 2006-2007, Ext JS, LLC. + * + * Originally Released Under LGPL - original licence link has changed is not relivant. + * + * Fork - LGPL + * <script type="text/javascript"> + */ +/** + * @class Roo.tree.TreeEditor + * @extends Roo.Editor + * Provides editor functionality for inline tree node editing. Any valid {@link Roo.form.Field} can be used + * as the editor field. + * @constructor + * @param {Object} config (used to be the tree panel.) + * @param {Object} oldconfig DEPRECIATED Either a prebuilt {@link Roo.form.Field} instance or a Field config object + * + * @cfg {Roo.tree.TreePanel} tree The tree to bind to. + * @cfg {Roo.form.TextField|Object} field The field configuration + * + * + */ +Roo.tree.TreeEditor = function(config, oldconfig) { // was -- (tree, config){ + var tree = config; + var field; + if (oldconfig) { // old style.. + field = oldconfig.events ? oldconfig : new Roo.form.TextField(oldconfig); + } else { + // new style.. + tree = config.tree; + config.field = config.field || {}; + config.field.xtype = 'TextField'; + field = Roo.factory(config.field, Roo.form); + } + config = config || {}; + + + this.addEvents({ + /** + * @event beforenodeedit + * Fires when editing is initiated, but before the value changes. Editing can be canceled by returning + * false from the handler of this event. + * @param {Editor} this + * @param {Roo.tree.Node} node + */ + "beforenodeedit" : true + }); + + //Roo.log(config); + Roo.tree.TreeEditor.superclass.constructor.call(this, field, config); + + this.tree = tree; + + tree.on('beforeclick', this.beforeNodeClick, this); + tree.getTreeEl().on('mousedown', this.hide, this); + this.on('complete', this.updateNode, this); + this.on('beforestartedit', this.fitToTree, this); + this.on('startedit', this.bindScroll, this, {delay:10}); + this.on('specialkey', this.onSpecialKey, this); +}; + +Roo.extend(Roo.tree.TreeEditor, Roo.Editor, { + /** + * @cfg {String} alignment + * The position to align to (see {@link Roo.Element#alignTo} for more details, defaults to "l-l"). + */ + alignment: "l-l", + // inherit + autoSize: false, + /** + * @cfg {Boolean} hideEl + * True to hide the bound element while the editor is displayed (defaults to false) + */ + hideEl : false, + /** + * @cfg {String} cls + * CSS class to apply to the editor (defaults to "x-small-editor x-tree-editor") + */ + cls: "x-small-editor x-tree-editor", + /** + * @cfg {Boolean} shim + * True to shim the editor if selects/iframes could be displayed beneath it (defaults to false) + */ + shim:false, + // inherit + shadow:"frame", + /** + * @cfg {Number} maxWidth + * The maximum width in pixels of the editor field (defaults to 250). Note that if the maxWidth would exceed + * the containing tree element's size, it will be automatically limited for you to the container width, taking + * scroll and client offsets into account prior to each edit. + */ + maxWidth: 250, + + editDelay : 350, + + // private + fitToTree : function(ed, el){ + var td = this.tree.getTreeEl().dom, nd = el.dom; + if(td.scrollLeft > nd.offsetLeft){ // ensure the node left point is visible + td.scrollLeft = nd.offsetLeft; + } + var w = Math.min( + this.maxWidth, + (td.clientWidth > 20 ? td.clientWidth : td.offsetWidth) - Math.max(0, nd.offsetLeft-td.scrollLeft) - /*cushion*/5); + this.setSize(w, ''); + + return this.fireEvent('beforenodeedit', this, this.editNode); + + }, + + // private + triggerEdit : function(node){ + this.completeEdit(); + this.editNode = node; + this.startEdit(node.ui.textNode, node.text); + }, + + // private + bindScroll : function(){ + this.tree.getTreeEl().on('scroll', this.cancelEdit, this); + }, + + // private + beforeNodeClick : function(node, e){ + var sinceLast = (this.lastClick ? this.lastClick.getElapsed() : 0); + this.lastClick = new Date(); + if(sinceLast > this.editDelay && this.tree.getSelectionModel().isSelected(node)){ + e.stopEvent(); + this.triggerEdit(node); + return false; + } + return true; + }, + + // private + updateNode : function(ed, value){ + this.tree.getTreeEl().un('scroll', this.cancelEdit, this); + this.editNode.setText(value); + }, + + // private + onHide : function(){ + Roo.tree.TreeEditor.superclass.onHide.call(this); + if(this.editNode){ + this.editNode.ui.focus(); + } + }, + + // private + onSpecialKey : function(field, e){ + var k = e.getKey(); + if(k == e.ESC){ + e.stopEvent(); + this.cancelEdit(); + }else if(k == e.ENTER && !e.hasModifier()){ + e.stopEvent(); + this.completeEdit(); + } + } +}); \ No newline at end of file