jquery.combotreegrid.js
6.5 KB
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
/**
* jQuery EasyUI 1.5
*
* Copyright (c) 2009-2016 www.jeasyui.com. All rights reserved.
*
* Licensed under the freeware license: http://www.jeasyui.com/license_freeware.php
* To use it on other terms please contact us: info@jeasyui.com
*
*/
(function($){
function _1(_2){
var _3=$.data(_2,"combotreegrid");
var _4=_3.options;
$(_2).addClass("combotreegrid-f").combo($.extend({},_4,{onShowPanel:function(){
var p=$(this).combotreegrid("panel");
var _5=p.outerHeight()-p.height();
var _6=p._size("minHeight");
var _7=p._size("maxHeight");
var dg=$(this).combotreegrid("grid");
dg.treegrid("resize",{width:"100%",height:(isNaN(parseInt(_4.panelHeight))?"auto":"100%"),minHeight:(_6?_6-_5:""),maxHeight:(_7?_7-_5:"")});
var _8=dg.treegrid("getSelected");
if(_8){
dg.treegrid("scrollTo",_8[_4.idField]);
}
_4.onShowPanel.call(this);
}}));
if(!_3.grid){
var _9=$(_2).combo("panel");
_3.grid=$("<table></table>").appendTo(_9);
}
_3.grid.treegrid($.extend({},_4,{border:false,checkbox:_4.multiple,onLoadSuccess:function(_a,_b){
var _c=$(_2).combotreegrid("getValues");
if(_4.multiple){
$.map($(this).treegrid("getCheckedNodes"),function(_d){
$.easyui.addArrayItem(_c,_d[_4.idField]);
});
}
_16(_2,_c);
_4.onLoadSuccess.call(this,_a,_b);
_3.remainText=false;
},onClickRow:function(_e){
if(_4.multiple){
$(this).treegrid(_e.checked?"uncheckNode":"checkNode",_e[_4.idField]);
$(this).treegrid("unselect",_e[_4.idField]);
}else{
$(_2).combo("hidePanel");
}
_11(_2);
_4.onClickRow.call(this,_e);
},onCheckNode:function(_f,_10){
_11(_2);
_4.onCheckNode.call(this,_f,_10);
}}));
};
function _11(_12){
var _13=$.data(_12,"combotreegrid");
var _14=_13.options;
var _15=_13.grid;
var vv=[];
if(_14.multiple){
vv=$.map(_15.treegrid("getCheckedNodes"),function(row){
return row[_14.idField];
});
}else{
var row=_15.treegrid("getSelected");
if(row){
vv.push(row[_14.idField]);
}
}
vv=vv.concat(_14.unselectedValues);
_16(_12,vv);
};
function _16(_17,_18){
var _19=$.data(_17,"combotreegrid");
var _1a=_19.options;
var _1b=_19.grid;
if(!$.isArray(_18)){
_18=_18.split(_1a.separator);
}
if(!_1a.multiple){
_18=_18.length?[_18[0]]:[""];
}
var vv=$.map(_18,function(_1c){
return String(_1c);
});
vv=$.grep(vv,function(v,_1d){
return _1d===$.inArray(v,vv);
});
var _1e=_1b.treegrid("getSelected");
if(_1e){
_1b.treegrid("unselect",_1e[_1a.idField]);
}
$.map(_1b.treegrid("getCheckedNodes"),function(row){
if($.inArray(String(row[_1a.idField]),vv)==-1){
_1b.treegrid("uncheckNode",row[_1a.idField]);
}
});
var ss=[];
_1a.unselectedValues=[];
$.map(vv,function(v){
var row=_1b.treegrid("find",v);
if(row){
if(_1a.multiple){
_1b.treegrid("checkNode",v);
}else{
_1b.treegrid("select",v);
}
ss.push(row[_1a.treeField]);
}else{
ss.push(_1f(v,_1a.mappingRows)||v);
_1a.unselectedValues.push(v);
}
});
if(_1a.multiple){
$.map(_1b.treegrid("getCheckedNodes"),function(row){
var id=String(row[_1a.idField]);
if($.inArray(id,vv)==-1){
vv.push(id);
ss.push(row[_1a.treeField]);
}
});
}
if(!_19.remainText){
var s=ss.join(_1a.separator);
if($(_17).combo("getText")!=s){
$(_17).combo("setText",s);
}
}
$(_17).combo("setValues",vv);
function _1f(_20,a){
var _21=$.easyui.getArrayItem(a,_1a.idField,_20);
return _21?_21[_1a.treeField]:undefined;
};
};
function _22(_23,q){
var _24=$.data(_23,"combotreegrid");
var _25=_24.options;
var _26=_24.grid;
_24.remainText=true;
_26.treegrid("clearSelections").treegrid("clearChecked").treegrid("highlightRow",-1);
if(_25.mode=="remote"){
$(_23).combotreegrid("clear");
_26.treegrid("load",$.extend({},_25.queryParams,{q:q}));
}else{
if(q){
var _27=_26.treegrid("getData");
var vv=[];
var qq=_25.multiple?q.split(_25.separator):[q];
$.map(qq,function(q){
q=$.trim(q);
if(q){
var v=undefined;
$.easyui.forEach(_27,true,function(row){
if(q.toLowerCase()==String(row[_25.treeField]).toLowerCase()){
v=row[_25.idField];
return false;
}else{
if(_25.filter.call(_23,q,row)){
_26.treegrid("expandTo",row[_25.idField]);
_26.treegrid("highlightRow",row[_25.idField]);
return false;
}
}
});
if(v==undefined){
$.easyui.forEach(_25.mappingRows,false,function(row){
if(q.toLowerCase()==String(row[_25.treeField])){
v=row[_25.idField];
return false;
}
});
}
if(v!=undefined){
vv.push(v);
}
}
});
_16(_23,vv);
_24.remainText=false;
}
}
};
function _28(_29){
_11(_29);
};
$.fn.combotreegrid=function(_2a,_2b){
if(typeof _2a=="string"){
var _2c=$.fn.combotreegrid.methods[_2a];
if(_2c){
return _2c(this,_2b);
}else{
return this.combo(_2a,_2b);
}
}
_2a=_2a||{};
return this.each(function(){
var _2d=$.data(this,"combotreegrid");
if(_2d){
$.extend(_2d.options,_2a);
}else{
_2d=$.data(this,"combotreegrid",{options:$.extend({},$.fn.combotreegrid.defaults,$.fn.combotreegrid.parseOptions(this),_2a)});
}
_1(this);
});
};
$.fn.combotreegrid.methods={options:function(jq){
var _2e=jq.combo("options");
return $.extend($.data(jq[0],"combotreegrid").options,{width:_2e.width,height:_2e.height,originalValue:_2e.originalValue,disabled:_2e.disabled,readonly:_2e.readonly});
},grid:function(jq){
return $.data(jq[0],"combotreegrid").grid;
},setValues:function(jq,_2f){
return jq.each(function(){
var _30=$(this).combotreegrid("options");
if($.isArray(_2f)){
_2f=$.map(_2f,function(_31){
if(_31&&typeof _31=="object"){
$.easyui.addArrayItem(_30.mappingRows,_30.idField,_31);
return _31[_30.idField];
}else{
return _31;
}
});
}
_16(this,_2f);
});
},setValue:function(jq,_32){
return jq.each(function(){
$(this).combotreegrid("setValues",$.isArray(_32)?_32:[_32]);
});
},clear:function(jq){
return jq.each(function(){
$(this).combotreegrid("setValues",[]);
});
},reset:function(jq){
return jq.each(function(){
var _33=$(this).combotreegrid("options");
if(_33.multiple){
$(this).combotreegrid("setValues",_33.originalValue);
}else{
$(this).combotreegrid("setValue",_33.originalValue);
}
});
}};
$.fn.combotreegrid.parseOptions=function(_34){
var t=$(_34);
return $.extend({},$.fn.combo.parseOptions(_34),$.fn.treegrid.parseOptions(_34),$.parser.parseOptions(_34,["mode",{limitToGrid:"boolean"}]));
};
$.fn.combotreegrid.defaults=$.extend({},$.fn.combo.defaults,$.fn.treegrid.defaults,{editable:false,singleSelect:true,limitToGrid:false,unselectedValues:[],mappingRows:[],mode:"local",keyHandler:{up:function(e){
},down:function(e){
},left:function(e){
},right:function(e){
},enter:function(e){
_28(this);
},query:function(q,e){
_22(this,q);
}},inputEvents:$.extend({},$.fn.combo.defaults.inputEvents,{blur:function(e){
var _35=e.data.target;
var _36=$(_35).combotreegrid("options");
if(_36.limitToGrid){
_28(_35);
}
}}),filter:function(q,row){
var _37=$(this).combotreegrid("options");
return (row[_37.treeField]||"").toLowerCase().indexOf(q.toLowerCase())>=0;
}});
})(jQuery);