LabelEditor.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /**
  2. * @class Ext.ux.DataView.LabelEditor
  3. * @extends Ext.Editor
  4. */
  5. Ext.define('Ext.ux.DataView.LabelEditor', {
  6. extend: 'Ext.Editor',
  7. alignment: 'tl-tl',
  8. completeOnEnter: true,
  9. cancelOnEsc: true,
  10. shim: false,
  11. autoSize: {
  12. width: 'boundEl',
  13. height: 'field'
  14. },
  15. labelSelector: 'x-editable',
  16. requires: [
  17. 'Ext.form.field.Text'
  18. ],
  19. constructor: function(config) {
  20. config.field = config.field || Ext.create('Ext.form.field.Text', {
  21. allowBlank: false,
  22. selectOnFocus:true
  23. });
  24. this.callParent([config]);
  25. },
  26. init: function(view) {
  27. this.view = view;
  28. this.mon(view, 'render', this.bindEvents, this);
  29. this.on('complete', this.onSave, this);
  30. },
  31. // initialize events
  32. bindEvents: function() {
  33. this.mon(this.view.getEl(), {
  34. click: {
  35. fn: this.onClick,
  36. scope: this
  37. }
  38. });
  39. },
  40. // on mousedown show editor
  41. onClick: function(e, target) {
  42. var me = this,
  43. item, record;
  44. if (Ext.fly(target).hasCls(me.labelSelector) && !me.editing && !e.ctrlKey && !e.shiftKey) {
  45. e.stopEvent();
  46. item = me.view.findItemByChild(target);
  47. record = me.view.store.getAt(me.view.indexOf(item));
  48. me.startEdit(target, record.data[me.dataIndex]);
  49. me.activeRecord = record;
  50. } else if (me.editing) {
  51. me.field.blur();
  52. e.preventDefault();
  53. }
  54. },
  55. // update record
  56. onSave: function(ed, value) {
  57. this.activeRecord.set(this.dataIndex, value);
  58. }
  59. });