summaryrefslogtreecommitdiffstats
path: root/funcweb/funcweb/static/javascript/ext/dhtmlxtree_ed.js
blob: 402df584c4b6225ddab75a79f656db39f1aaef85 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
//v.1.6 build 80512

/*

Copyright DHTMLX LTD. http://www.dhtmlx.com

You allowed to use this component or parts of it under GPL terms

To use it on other terms or get Professional edition of the component please contact us at sales@dhtmlx.com

*/
/*

Purpose: item edit extension

*/





/**

*     @desc: enable editing of item text

*     @param:  mode - true/false

*     @type: public

*     @topic: 0

*/

dhtmlXTreeObject.prototype.enableItemEditor=function(mode){

        this._eItEd=convertStringToBoolean(mode);

        if (!this._eItEdFlag){



            this._edn_click_IE=true;

            this._edn_dblclick=true;

            this._ie_aFunc=this.aFunc;

            this._ie_dblclickFuncHandler=this.dblclickFuncHandler;



            this.setOnDblClickHandler(function (a,b) {

                if (this._edn_dblclick) this._editItem(a,b);

                return true;

				});



            this.setOnClickHandler(function (a,b) {

                this._stopEditItem(a,b);

                    if ((this.ed_hist_clcik==a)&&(this._edn_click_IE))

                        this._editItem(a,b);

                this.ed_hist_clcik=a;

                return true;

                });



            this._eItEdFlag=true;



            }

        };



/**

*     @desc: set onEdit handler ( multi handler event)

*     @param:  func - function which will be called on edit related events

*     @type: depricated

*     @event:  onEdit

*     @depricated: use grid.attachEvent("onEdit",func); instead

*     @eventdesc: Event occurs on 4 different stages of edit process: before editing started (cancelable), after editing started, before closing (cancelable), after closed

*     @eventparam: state - 0 before editing started , 1 after editing started, 2 before closing, 3 after closed

*     @eventparam: id - id of edited items

*     @eventparam: tree - tree object

*     @eventparam: value - for stage 0 and 2, value of editor

*     @eventreturn: for stages 0 and 2; true - confirm opening/closing, false - deny opening/closing;  text - edit value

*     @topic: 0

*/

dhtmlXTreeObject.prototype.setOnEditHandler=function(func){

		this.attachEvent("onEdit",func);

        };







/**

*     @desc: define which events must start editing

*     @param:  click_IE - click on already selected item - true/false [true by default]

*     @param:  dblclick - on double click

*     @type: public

*     @topic: 0

*/

dhtmlXTreeObject.prototype.setEditStartAction=function(click_IE, dblclick){

        this._edn_click_IE=convertStringToBoolean(click_IE);

        this._edn_dblclick=convertStringToBoolean(dblclick);

        };



dhtmlXTreeObject.prototype._stopEdit=function(a){

    if  (this._editCell){

        this.dADTempOff=this.dADTempOffEd;

        if (this._editCell.id!=a){



	        var editText=true;

	            editText=this.callEvent("onEdit",[2,this._editCell.id,this,this._editCell.span.childNodes[0].value]);

	        if (editText===true)

	            editText=this._editCell.span.childNodes[0].value;

	        else if (editText===false) editText=this._editCell._oldValue;



	        this._editCell.span.innerHTML=editText;

	        this._editCell.label=this._editCell.span.innerHTML;

			var cSS=this._editCell.i_sel?"selectedTreeRow":"standartTreeRow";

	        this._editCell.span.className=cSS;

	        this._editCell.span.parentNode.className="standartTreeRow";

	        this._editCell.span.onclick=function(){};

	        var id=this._editCell.id; this._editCell=null;

	        

	        if (this.childCalc)  this._fixChildCountLabel(this._editCell);

	        this.callEvent("onEdit",[3,id,this]);

	        

			if (this._enblkbrd){

				this.parentObject.lastChild.focus();

				this.parentObject.lastChild.focus();

			}

        }

    }

}



dhtmlXTreeObject.prototype._stopEditItem=function(id,tree){

    this._stopEdit(id);

};



/**

*     @desc:  switch currently edited item back to normal view

*     @type: public

*     @topic: 0

*/



dhtmlXTreeObject.prototype.stopEdit=function(){

    if (this._editCell)

        this._stopEdit(this._editCell.id+"_non");

}



/**

*     @desc: open editor for specified item

*     @param:  id - item ID

*     @type: public

*     @topic: 0

*/

dhtmlXTreeObject.prototype.editItem=function(id){

    this._editItem(id,this);

}



dhtmlXTreeObject.prototype._editItem=function(id,tree){

    if (this._eItEd){

        this._stopEdit();

        var temp=this._globalIdStorageFind(id);

		if (!temp) return;

				

        editText=this.callEvent("onEdit",[0,id,this,temp.span.innerHTML]);



        if (editText===true)

            editText=temp.label;

        else if (editText===false) return;



        this.dADTempOffEd=this.dADTempOff;

        this.dADTempOff=false;





        this._editCell=temp;

        temp._oldValue=editText;

        temp.span.innerHTML="<input type='text' class='intreeeditRow' />";



        temp.span.childNodes[0].value=editText;



        temp.span.childNodes[0].onselectstart=function(e){

            (e||event).cancelBubble=true;

            return true;

        }

        temp.span.childNodes[0].onmousedown=function(e){

            (e||event).cancelBubble=true;

            return true;

        }



        temp.span.childNodes[0].focus();

        temp.span.childNodes[0].focus();

//		temp.span.childNodes[0].select();

        temp.span.onclick=function (e){ (e||event).cancelBubble=true; return false; };

        temp.span.className="";

        temp.span.parentNode.className="";



        var self=this;



        temp.span.childNodes[0].onkeydown=function(e){

		  	(e||event).cancelBubble=true;

		}

        temp.span.childNodes[0].onkeypress=function(e){

            if (!e) e=window.event;

            if (e.keyCode==13){

                 self._stopEdit(-1);

				 }

			else if (e.keyCode==27){

            	self._editCell.span.childNodes[0].value=self._editCell._oldValue;

				self._stopEdit(-1);

			}

        }

        this.callEvent("onEdit",[1,id,this]);

    }

};

//(c)dhtmlx ltd. www.dhtmlx.com