X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/c930e9176a5a85509c5b0230e2bff5c22a591432..refs/heads/master:/examples/ux/DataView/LabelEditor.js diff --git a/examples/ux/DataView/LabelEditor.js b/examples/ux/DataView/LabelEditor.js new file mode 100644 index 00000000..25ded8d0 --- /dev/null +++ b/examples/ux/DataView/LabelEditor.js @@ -0,0 +1,89 @@ +/* + +This file is part of Ext JS 4 + +Copyright (c) 2011 Sencha Inc + +Contact: http://www.sencha.com/contact + +GNU General Public License Usage +This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html. + +If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact. + +*/ +/** + * @class Ext.ux.DataView.LabelEditor + * @extends Ext.Editor + */ +Ext.define('Ext.ux.DataView.LabelEditor', { + + extend: 'Ext.Editor', + + alignment: 'tl-tl', + + completeOnEnter: true, + + cancelOnEsc: true, + + shim: false, + + autoSize: { + width: 'boundEl', + height: 'field' + }, + + labelSelector: 'x-editable', + + requires: [ + 'Ext.form.field.Text' + ], + + constructor: function(config) { + config.field = config.field || Ext.create('Ext.form.field.Text', { + allowBlank: false, + selectOnFocus:true + }); + this.callParent([config]); + }, + + init: function(view) { + this.view = view; + this.mon(view, 'render', this.bindEvents, this); + this.on('complete', this.onSave, this); + }, + + // initialize events + bindEvents: function() { + this.mon(this.view.getEl(), { + click: { + fn: this.onClick, + scope: this + } + }); + }, + + // on mousedown show editor + onClick: function(e, target) { + var me = this, + item, record; + + if (Ext.fly(target).hasCls(me.labelSelector) && !me.editing && !e.ctrlKey && !e.shiftKey) { + e.stopEvent(); + item = me.view.findItemByChild(target); + record = me.view.store.getAt(me.view.indexOf(item)); + me.startEdit(target, record.data[me.dataIndex]); + me.activeRecord = record; + } else if (me.editing) { + me.field.blur(); + e.preventDefault(); + } + }, + + // update record + onSave: function(ed, value) { + this.activeRecord.set(this.dataIndex, value); + } +}); + +