root / trunk / web / dojo / dojox / grid / _EditManager.js @ 10
History | View | Annotate | Download (3.48 KB)
| 1 | 9 | andrej.cim | /*
|
|---|---|---|---|
| 2 | Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
|
||
| 3 | Available via Academic Free License >= 2.1 OR the modified BSD license.
|
||
| 4 | see: http://dojotoolkit.org/license for details
|
||
| 5 | */
|
||
| 6 | |||
| 7 | |||
| 8 | if(!dojo._hasResource["dojox.grid._EditManager"]){ |
||
| 9 | dojo._hasResource["dojox.grid._EditManager"]=true; |
||
| 10 | dojo.provide("dojox.grid._EditManager");
|
||
| 11 | dojo.require("dojox.grid.util");
|
||
| 12 | dojo.declare("dojox.grid._EditManager",null,{constructor:function(_1){ |
||
| 13 | this.grid=_1;
|
||
| 14 | this.connections=[];
|
||
| 15 | if(dojo.isIE){
|
||
| 16 | this.connections.push(dojo.connect(document.body,"onfocus",dojo.hitch(this,"_boomerangFocus"))); |
||
| 17 | } |
||
| 18 | },info:{},destroy:function(){ |
||
| 19 | dojo.forEach(this.connections,dojo.disconnect);
|
||
| 20 | },cellFocus:function(_2,_3){ |
||
| 21 | if(this.grid.singleClickEdit||this.isEditRow(_3)){ |
||
| 22 | this.setEditCell(_2,_3);
|
||
| 23 | }else{
|
||
| 24 | this.apply();
|
||
| 25 | } |
||
| 26 | if(this.isEditing()||(_2&&_2.editable&&_2.alwaysEditing)){ |
||
| 27 | this._focusEditor(_2,_3);
|
||
| 28 | } |
||
| 29 | },rowClick:function(e){ |
||
| 30 | if(this.isEditing()&&!this.isEditRow(e.rowIndex)){ |
||
| 31 | this.apply();
|
||
| 32 | } |
||
| 33 | },styleRow:function(_4){ |
||
| 34 | if(_4.index==this.info.rowIndex){ |
||
| 35 | _4.customClasses+=" dojoxGridRowEditing";
|
||
| 36 | } |
||
| 37 | },dispatchEvent:function(e){ |
||
| 38 | var c=e.cell,ed=(c&&c["editable"])?c:0; |
||
| 39 | return ed&&ed.dispatchEvent(e.dispatch,e);
|
||
| 40 | },isEditing:function(){ |
||
| 41 | return this.info.rowIndex!==undefined; |
||
| 42 | },isEditCell:function(_5,_6){ |
||
| 43 | return (this.info.rowIndex===_5)&&(this.info.cell.index==_6); |
||
| 44 | },isEditRow:function(_7){ |
||
| 45 | return this.info.rowIndex===_7; |
||
| 46 | },setEditCell:function(_8,_9){ |
||
| 47 | if(!this.isEditCell(_9,_8.index)&&this.grid.canEdit&&this.grid.canEdit(_8,_9)){ |
||
| 48 | this.start(_8,_9,this.isEditRow(_9)||_8.editable); |
||
| 49 | } |
||
| 50 | },_focusEditor:function(_a,_b){ |
||
| 51 | dojox.grid.util.fire(_a,"focus",[_b]);
|
||
| 52 | },focusEditor:function(){ |
||
| 53 | if(this.isEditing()){ |
||
| 54 | this._focusEditor(this.info.cell,this.info.rowIndex); |
||
| 55 | } |
||
| 56 | },_boomerangWindow:500,_shouldCatchBoomerang:function(){ |
||
| 57 | return this._catchBoomerang>new Date().getTime(); |
||
| 58 | },_boomerangFocus:function(){ |
||
| 59 | if(this._shouldCatchBoomerang()){ |
||
| 60 | this.grid.focus.focusGrid();
|
||
| 61 | this.focusEditor();
|
||
| 62 | this._catchBoomerang=0; |
||
| 63 | } |
||
| 64 | },_doCatchBoomerang:function(){ |
||
| 65 | if(dojo.isIE){
|
||
| 66 | this._catchBoomerang=new Date().getTime()+this._boomerangWindow; |
||
| 67 | } |
||
| 68 | },start:function(_c,_d,_e){ |
||
| 69 | this.grid.beginUpdate();
|
||
| 70 | this.editorApply();
|
||
| 71 | if(this.isEditing()&&!this.isEditRow(_d)){ |
||
| 72 | this.applyRowEdit();
|
||
| 73 | this.grid.updateRow(_d);
|
||
| 74 | } |
||
| 75 | if(_e){
|
||
| 76 | this.info={cell:_c,rowIndex:_d}; |
||
| 77 | this.grid.doStartEdit(_c,_d);
|
||
| 78 | this.grid.updateRow(_d);
|
||
| 79 | }else{
|
||
| 80 | this.info={};
|
||
| 81 | } |
||
| 82 | this.grid.endUpdate();
|
||
| 83 | this.grid.focus.focusGrid();
|
||
| 84 | this._focusEditor(_c,_d);
|
||
| 85 | this._doCatchBoomerang();
|
||
| 86 | },_editorDo:function(_f){ |
||
| 87 | var c=this.info.cell; |
||
| 88 | if(c&&c.editable){
|
||
| 89 | c[_f](this.info.rowIndex);
|
||
| 90 | } |
||
| 91 | },editorApply:function(){ |
||
| 92 | this._editorDo("apply"); |
||
| 93 | },editorCancel:function(){ |
||
| 94 | this._editorDo("cancel"); |
||
| 95 | },applyCellEdit:function(_10,_11,_12){ |
||
| 96 | if(this.grid.canEdit(_11,_12)){ |
||
| 97 | this.grid.doApplyCellEdit(_10,_12,_11.field);
|
||
| 98 | } |
||
| 99 | },applyRowEdit:function(){ |
||
| 100 | this.grid.doApplyEdit(this.info.rowIndex,this.info.cell.field); |
||
| 101 | },apply:function(){ |
||
| 102 | if(this.isEditing()){ |
||
| 103 | this.grid.beginUpdate();
|
||
| 104 | this.editorApply();
|
||
| 105 | this.applyRowEdit();
|
||
| 106 | this.info={};
|
||
| 107 | this.grid.endUpdate();
|
||
| 108 | this.grid.focus.focusGrid();
|
||
| 109 | this._doCatchBoomerang();
|
||
| 110 | } |
||
| 111 | },cancel:function(){ |
||
| 112 | if(this.isEditing()){ |
||
| 113 | this.grid.beginUpdate();
|
||
| 114 | this.editorCancel();
|
||
| 115 | this.info={};
|
||
| 116 | this.grid.endUpdate();
|
||
| 117 | this.grid.focus.focusGrid();
|
||
| 118 | this._doCatchBoomerang();
|
||
| 119 | } |
||
| 120 | },save:function(_13,_14){ |
||
| 121 | var c=this.info.cell; |
||
| 122 | if(this.isEditRow(_13)&&(!_14||c.view==_14)&&c.editable){ |
||
| 123 | c.save(c,this.info.rowIndex);
|
||
| 124 | } |
||
| 125 | },restore:function(_15,_16){ |
||
| 126 | var c=this.info.cell; |
||
| 127 | if(this.isEditRow(_16)&&c.view==_15&&c.editable){ |
||
| 128 | c.restore(c,this.info.rowIndex);
|
||
| 129 | } |
||
| 130 | }}); |
||
| 131 | } |