/adei/ui

To get this branch, use:
bzr branch http://darksoft.org/webbzr/adei/ui

« back to all changes in this revision

Viewing changes to includes/dhtmlx.orig/ext/dhtmlxtree_ed.js

  • Committer: Suren A. Chilingaryan
  • Date: 2008-10-30 01:27:40 UTC
  • mto: This revision was merged to the branch mainline in revision 116.
  • Revision ID: csa@dside.dyndns.org-20081030012740-svt0yigxj5uzwxyj
Few steps on source tree integration in javascript frontend

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//v.2.0 build 81009
 
2
 
 
3
/*
 
4
Copyright DHTMLX LTD. http://www.dhtmlx.com
 
5
You allowed to use this component or parts of it under GPL terms
 
6
To use it on other terms or get Professional edition of the component please contact us at sales@dhtmlx.com
 
7
*/
 
8
/*
 
9
Purpose: item edit extension
 
10
*/
 
11
 
 
12
 
 
13
/**
 
14
*     @desc: enable editing of item text
 
15
*     @param:  mode - true/false
 
16
*     @type: public
 
17
*     @topic: 0
 
18
*/
 
19
dhtmlXTreeObject.prototype.enableItemEditor=function(mode){
 
20
        this._eItEd=convertStringToBoolean(mode);
 
21
        if (!this._eItEdFlag){
 
22
 
 
23
            this._edn_click_IE=true;
 
24
            this._edn_dblclick=true;
 
25
            this._ie_aFunc=this.aFunc;
 
26
            this._ie_dblclickFuncHandler=this.dblclickFuncHandler;
 
27
 
 
28
            this.setOnDblClickHandler(function (a,b) {
 
29
                if (this._edn_dblclick) this._editItem(a,b);
 
30
                return true;
 
31
                                });
 
32
 
 
33
            this.setOnClickHandler(function (a,b) {
 
34
                this._stopEditItem(a,b);
 
35
                    if ((this.ed_hist_clcik==a)&&(this._edn_click_IE))
 
36
                        this._editItem(a,b);
 
37
                this.ed_hist_clcik=a;
 
38
                return true;
 
39
                });
 
40
 
 
41
            this._eItEdFlag=true;
 
42
 
 
43
            }
 
44
        };
 
45
 
 
46
/**
 
47
*     @desc: set onEdit handler ( multi handler event)
 
48
*     @param:  func - function which will be called on edit related events
 
49
*     @type: depricated
 
50
*     @event:  onEdit
 
51
*     @depricated: use grid.attachEvent("onEdit",func); instead
 
52
*     @eventdesc: Event occurs on 4 different stages of edit process: before editing started (cancelable), after editing started, before closing (cancelable), after closed
 
53
*     @eventparam: state - 0 before editing started , 1 after editing started, 2 before closing, 3 after closed
 
54
*     @eventparam: id - id of edited items
 
55
*     @eventparam: tree - tree object
 
56
*     @eventparam: value - for stage 0 and 2, value of editor
 
57
*     @eventreturn: for stages 0 and 2; true - confirm opening/closing, false - deny opening/closing;  text - edit value
 
58
*     @topic: 0
 
59
*/
 
60
dhtmlXTreeObject.prototype.setOnEditHandler=function(func){
 
61
                this.attachEvent("onEdit",func);
 
62
        };
 
63
 
 
64
 
 
65
 
 
66
/**
 
67
*     @desc: define which events must start editing
 
68
*     @param:  click_IE - click on already selected item - true/false [true by default]
 
69
*     @param:  dblclick - on double click
 
70
*     @type: public
 
71
*     @topic: 0
 
72
*/
 
73
dhtmlXTreeObject.prototype.setEditStartAction=function(click_IE, dblclick){
 
74
        this._edn_click_IE=convertStringToBoolean(click_IE);
 
75
        this._edn_dblclick=convertStringToBoolean(dblclick);
 
76
        };
 
77
 
 
78
dhtmlXTreeObject.prototype._stopEdit=function(a){
 
79
    if  (this._editCell){
 
80
        this.dADTempOff=this.dADTempOffEd;
 
81
        if (this._editCell.id!=a){
 
82
 
 
83
                var editText=true;
 
84
                    editText=this.callEvent("onEdit",[2,this._editCell.id,this,this._editCell.span.childNodes[0].value]);
 
85
                if (editText===true)
 
86
                    editText=this._editCell.span.childNodes[0].value;
 
87
                else if (editText===false) editText=this._editCell._oldValue;
 
88
 
 
89
                this._editCell.span.innerHTML=editText;
 
90
                this._editCell.label=this._editCell.span.innerHTML;
 
91
                        var cSS=this._editCell.i_sel?"selectedTreeRow":"standartTreeRow";
 
92
                this._editCell.span.className=cSS;
 
93
                this._editCell.span.parentNode.className="standartTreeRow";
 
94
                this._editCell.span.onclick=function(){};
 
95
                var id=this._editCell.id; this._editCell=null;
 
96
                
 
97
                if (this.childCalc)  this._fixChildCountLabel(this._editCell);
 
98
                this.callEvent("onEdit",[3,id,this]);
 
99
                
 
100
                        if (this._enblkbrd){
 
101
                                this.parentObject.lastChild.focus();
 
102
                                this.parentObject.lastChild.focus();
 
103
                        }
 
104
        }
 
105
    }
 
106
}
 
107
 
 
108
dhtmlXTreeObject.prototype._stopEditItem=function(id,tree){
 
109
    this._stopEdit(id);
 
110
};
 
111
 
 
112
/**
 
113
*     @desc:  switch currently edited item back to normal view
 
114
*     @type: public
 
115
*     @topic: 0
 
116
*/
 
117
 
 
118
dhtmlXTreeObject.prototype.stopEdit=function(){
 
119
    if (this._editCell)
 
120
        this._stopEdit(this._editCell.id+"_non");
 
121
}
 
122
 
 
123
/**
 
124
*     @desc: open editor for specified item
 
125
*     @param:  id - item ID
 
126
*     @type: public
 
127
*     @topic: 0
 
128
*/
 
129
dhtmlXTreeObject.prototype.editItem=function(id){
 
130
    this._editItem(id,this);
 
131
}
 
132
 
 
133
dhtmlXTreeObject.prototype._editItem=function(id,tree){
 
134
    if (this._eItEd){
 
135
        this._stopEdit();
 
136
        var temp=this._globalIdStorageFind(id);
 
137
                if (!temp) return;
 
138
                                
 
139
        editText=this.callEvent("onEdit",[0,id,this,temp.span.innerHTML]);
 
140
 
 
141
        if (editText===true)
 
142
            editText=temp.label;
 
143
        else if (editText===false) return;
 
144
 
 
145
        this.dADTempOffEd=this.dADTempOff;
 
146
        this.dADTempOff=false;
 
147
 
 
148
 
 
149
        this._editCell=temp;
 
150
        temp._oldValue=editText;
 
151
        temp.span.innerHTML="<input type='text' class='intreeeditRow' />";
 
152
 
 
153
        temp.span.childNodes[0].value=editText;
 
154
 
 
155
        temp.span.childNodes[0].onselectstart=function(e){
 
156
            (e||event).cancelBubble=true;
 
157
            return true;
 
158
        }
 
159
        temp.span.childNodes[0].onmousedown=function(e){
 
160
            (e||event).cancelBubble=true;
 
161
            return true;
 
162
        }
 
163
 
 
164
        temp.span.childNodes[0].focus();
 
165
        temp.span.childNodes[0].focus();
 
166
//              temp.span.childNodes[0].select();
 
167
        temp.span.onclick=function (e){ (e||event).cancelBubble=true; return false; };
 
168
        temp.span.className="";
 
169
        temp.span.parentNode.className="";
 
170
 
 
171
        var self=this;
 
172
 
 
173
        temp.span.childNodes[0].onkeydown=function(e){
 
174
                        (e||event).cancelBubble=true;
 
175
                }
 
176
        temp.span.childNodes[0].onkeypress=function(e){
 
177
            if (!e) e=window.event;
 
178
            if (e.keyCode==13){
 
179
                 self._stopEdit(-1);
 
180
                                 }
 
181
                        else if (e.keyCode==27){
 
182
                self._editCell.span.childNodes[0].value=self._editCell._oldValue;
 
183
                                self._stopEdit(-1);
 
184
                        }
 
185
        }
 
186
        this.callEvent("onEdit",[1,id,this]);
 
187
    }
 
188
};
 
189
//(c)dhtmlx ltd. www.dhtmlx.com