d71c0bc8971722a6cf6943bc4ddecdee71728183.svn-base 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * Ext JS Library 2.0 Copyright(c) 2006-2007, Ext JS, LLC. licensing@extjs.com
  3. *
  4. * http://extjs.com/license
  5. */
  6. Ext.grid.EditorGridPanel = Ext.extend(Ext.grid.GridPanel, {
  7. clicksToEdit : 2,
  8. isEditor : true,
  9. detectEdit : false,
  10. trackMouseOver : false,
  11. initComponent : function() {
  12. Ext.grid.EditorGridPanel.superclass.initComponent.call(this);
  13. if (!this.selModel) {
  14. this.selModel = new Ext.grid.CellSelectionModel()
  15. }
  16. this.activeEditor = null;
  17. this.addEvents("beforeedit", "afteredit", "validateedit")
  18. },
  19. initEvents : function() {
  20. Ext.grid.EditorGridPanel.superclass.initEvents.call(this);
  21. this.on("bodyscroll", this.stopEditing, this);
  22. if (this.clicksToEdit == 1) {
  23. this.on("cellclick", this.onCellDblClick, this)
  24. } else {
  25. if (this.clicksToEdit == "auto" && this.view.mainBody) {
  26. this.view.mainBody.on("mousedown",
  27. this.onAutoEditClick, this)
  28. }
  29. this.on("celldblclick", this.onCellDblClick, this)
  30. }
  31. this.getGridEl().addClass("xedit-grid")
  32. },
  33. onCellDblClick : function(B, C, A) {
  34. this.startEditing(C, A)
  35. },
  36. onAutoEditClick : function(C, B) {
  37. var E = this.view.findRowIndex(B);
  38. var A = this.view.findCellIndex(B);
  39. if (E !== false && A !== false) {
  40. if (this.selModel.getSelectedCell) {
  41. var D = this.selModel.getSelectedCell();
  42. if (D && D.cell[0] === E && D.cell[1] === A) {
  43. this.startEditing(E, A)
  44. }
  45. } else {
  46. if (this.selModel.isSelected(E)) {
  47. this.startEditing(E, A)
  48. }
  49. }
  50. }
  51. },
  52. onEditComplete : function(B, D, A) {
  53. this.editing = false;
  54. this.activeEditor = null;
  55. B.un("specialkey", this.selModel.onEditorKey, this.selModel);
  56. if (String(D) !== String(A)) {
  57. var C = B.record;
  58. var F = this.colModel.getDataIndex(B.col);
  59. var E = {
  60. grid : this,
  61. record : C,
  62. field : F,
  63. originalValue : A,
  64. value : D,
  65. row : B.row,
  66. column : B.col,
  67. cancel : false
  68. };
  69. if (this.fireEvent("validateedit", E) !== false
  70. && !E.cancel) {
  71. C.set(F, E.value);
  72. delete E.cancel;
  73. this.fireEvent("afteredit", E)
  74. }
  75. }
  76. this.view.focusCell(B.row, B.col)
  77. },
  78. startEditing : function(F, B) {
  79. this.stopEditing();
  80. if (this.colModel.isCellEditable(B, F)) {
  81. this.view.ensureVisible(F, B, true);
  82. var C = this.store.getAt(F);
  83. var E = this.colModel.getDataIndex(B);
  84. var D = {
  85. grid : this,
  86. record : C,
  87. field : E,
  88. value : C.data[E],
  89. row : F,
  90. column : B,
  91. cancel : false
  92. };
  93. if (this.fireEvent("beforeedit", D) !== false && !D.cancel) {
  94. this.editing = true;
  95. var A = this.colModel.getCellEditor(B, F);
  96. if (!A.rendered) {
  97. A.render(this.view.getEditorParent(A))
  98. }
  99. (function () {
  100. A.row = F;
  101. A.col = B;
  102. A.record = C;
  103. A.on("complete", this.onEditComplete, this, {
  104. single : true
  105. });
  106. A.on("specialkey", this.selModel.onEditorKey,
  107. this.selModel);
  108. this.activeEditor = A;
  109. var G = C.data[E];
  110. A.startEdit(this.view.getCell(F, B), G)
  111. }).defer(50, this)
  112. }
  113. }
  114. },
  115. stopEditing : function() {
  116. if (this.activeEditor) {
  117. this.activeEditor.completeEdit()
  118. }
  119. this.activeEditor = null
  120. }
  121. });
  122. Ext.reg("editorgrid", Ext.grid.EditorGridPanel);