LabelEditor.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. This file is part of Ext JS 4
  3. Copyright (c) 2011 Sencha Inc
  4. Contact: http://www.sencha.com/contact
  5. GNU General Public License Usage
  6. 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.
  7. If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
  8. */
  9. /**
  10. * @class Ext.ux.DataView.LabelEditor
  11. * @extends Ext.Editor
  12. */
  13. Ext.define('Ext.ux.DataView.LabelEditor', {
  14. extend: 'Ext.Editor',
  15. alignment: 'tl-tl',
  16. completeOnEnter: true,
  17. cancelOnEsc: true,
  18. shim: false,
  19. autoSize: {
  20. width: 'boundEl',
  21. height: 'field'
  22. },
  23. labelSelector: 'x-editable',
  24. requires: [
  25. 'Ext.form.field.Text'
  26. ],
  27. constructor: function(config) {
  28. config.field = config.field || Ext.create('Ext.form.field.Text', {
  29. allowBlank: false,
  30. selectOnFocus:true
  31. });
  32. this.callParent([config]);
  33. },
  34. init: function(view) {
  35. this.view = view;
  36. this.mon(view, 'render', this.bindEvents, this);
  37. this.on('complete', this.onSave, this);
  38. },
  39. // initialize events
  40. bindEvents: function() {
  41. this.mon(this.view.getEl(), {
  42. click: {
  43. fn: this.onClick,
  44. scope: this
  45. }
  46. });
  47. },
  48. // on mousedown show editor
  49. onClick: function(e, target) {
  50. var me = this,
  51. item, record;
  52. if (Ext.fly(target).hasCls(me.labelSelector) && !me.editing && !e.ctrlKey && !e.shiftKey) {
  53. e.stopEvent();
  54. item = me.view.findItemByChild(target);
  55. record = me.view.store.getAt(me.view.indexOf(item));
  56. me.startEdit(target, record.data[me.dataIndex]);
  57. me.activeRecord = record;
  58. } else if (me.editing) {
  59. me.field.blur();
  60. e.preventDefault();
  61. }
  62. },
  63. // update record
  64. onSave: function(ed, value) {
  65. this.activeRecord.set(this.dataIndex, value);
  66. }
  67. });