rztree 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +22 -0
- data/README.md +73 -0
- data/lib/rztree.rb +5 -0
- data/lib/rztree/engine.rb +14 -0
- data/lib/rztree/non_digest.rake +16 -0
- data/lib/rztree/version.rb +3 -0
- data/vendor/assets/images/line_conn.gif +0 -0
- data/vendor/assets/images/loading.gif +0 -0
- data/vendor/assets/images/zTreeStandard.gif +0 -0
- data/vendor/assets/images/zTreeStandard.png +0 -0
- data/vendor/assets/javascripts/jquery.ztree.all-3.5.js +3504 -0
- data/vendor/assets/javascripts/jquery.ztree.core-3.5.js +1684 -0
- data/vendor/assets/javascripts/jquery.ztree.excheck-3.5.js +628 -0
- data/vendor/assets/javascripts/jquery.ztree.exedit-3.5.js +1191 -0
- data/vendor/assets/javascripts/jquery.ztree.exhide-3.5.js +367 -0
- data/vendor/assets/stylesheets/zTreeStyle.css +97 -0
- metadata +88 -0
@@ -0,0 +1,628 @@
|
|
1
|
+
/*
|
2
|
+
* JQuery zTree excheck v3.5.17
|
3
|
+
* http://zTree.me/
|
4
|
+
*
|
5
|
+
* Copyright (c) 2010 Hunter.z
|
6
|
+
*
|
7
|
+
* Licensed same as jquery - MIT License
|
8
|
+
* http://www.opensource.org/licenses/mit-license.php
|
9
|
+
*
|
10
|
+
* email: hunter.z@263.net
|
11
|
+
* Date: 2014-05-08
|
12
|
+
*/
|
13
|
+
(function($){
|
14
|
+
//default consts of excheck
|
15
|
+
var _consts = {
|
16
|
+
event: {
|
17
|
+
CHECK: "ztree_check"
|
18
|
+
},
|
19
|
+
id: {
|
20
|
+
CHECK: "_check"
|
21
|
+
},
|
22
|
+
checkbox: {
|
23
|
+
STYLE: "checkbox",
|
24
|
+
DEFAULT: "chk",
|
25
|
+
DISABLED: "disable",
|
26
|
+
FALSE: "false",
|
27
|
+
TRUE: "true",
|
28
|
+
FULL: "full",
|
29
|
+
PART: "part",
|
30
|
+
FOCUS: "focus"
|
31
|
+
},
|
32
|
+
radio: {
|
33
|
+
STYLE: "radio",
|
34
|
+
TYPE_ALL: "all",
|
35
|
+
TYPE_LEVEL: "level"
|
36
|
+
}
|
37
|
+
},
|
38
|
+
//default setting of excheck
|
39
|
+
_setting = {
|
40
|
+
check: {
|
41
|
+
enable: false,
|
42
|
+
autoCheckTrigger: false,
|
43
|
+
chkStyle: _consts.checkbox.STYLE,
|
44
|
+
nocheckInherit: false,
|
45
|
+
chkDisabledInherit: false,
|
46
|
+
radioType: _consts.radio.TYPE_LEVEL,
|
47
|
+
chkboxType: {
|
48
|
+
"Y": "ps",
|
49
|
+
"N": "ps"
|
50
|
+
}
|
51
|
+
},
|
52
|
+
data: {
|
53
|
+
key: {
|
54
|
+
checked: "checked"
|
55
|
+
}
|
56
|
+
},
|
57
|
+
callback: {
|
58
|
+
beforeCheck:null,
|
59
|
+
onCheck:null
|
60
|
+
}
|
61
|
+
},
|
62
|
+
//default root of excheck
|
63
|
+
_initRoot = function (setting) {
|
64
|
+
var r = data.getRoot(setting);
|
65
|
+
r.radioCheckedList = [];
|
66
|
+
},
|
67
|
+
//default cache of excheck
|
68
|
+
_initCache = function(treeId) {},
|
69
|
+
//default bind event of excheck
|
70
|
+
_bindEvent = function(setting) {
|
71
|
+
var o = setting.treeObj,
|
72
|
+
c = consts.event;
|
73
|
+
o.bind(c.CHECK, function (event, srcEvent, treeId, node) {
|
74
|
+
event.srcEvent = srcEvent;
|
75
|
+
tools.apply(setting.callback.onCheck, [event, treeId, node]);
|
76
|
+
});
|
77
|
+
},
|
78
|
+
_unbindEvent = function(setting) {
|
79
|
+
var o = setting.treeObj,
|
80
|
+
c = consts.event;
|
81
|
+
o.unbind(c.CHECK);
|
82
|
+
},
|
83
|
+
//default event proxy of excheck
|
84
|
+
_eventProxy = function(e) {
|
85
|
+
var target = e.target,
|
86
|
+
setting = data.getSetting(e.data.treeId),
|
87
|
+
tId = "", node = null,
|
88
|
+
nodeEventType = "", treeEventType = "",
|
89
|
+
nodeEventCallback = null, treeEventCallback = null;
|
90
|
+
|
91
|
+
if (tools.eqs(e.type, "mouseover")) {
|
92
|
+
if (setting.check.enable && tools.eqs(target.tagName, "span") && target.getAttribute("treeNode"+ consts.id.CHECK) !== null) {
|
93
|
+
tId = tools.getNodeMainDom(target).id;
|
94
|
+
nodeEventType = "mouseoverCheck";
|
95
|
+
}
|
96
|
+
} else if (tools.eqs(e.type, "mouseout")) {
|
97
|
+
if (setting.check.enable && tools.eqs(target.tagName, "span") && target.getAttribute("treeNode"+ consts.id.CHECK) !== null) {
|
98
|
+
tId = tools.getNodeMainDom(target).id;
|
99
|
+
nodeEventType = "mouseoutCheck";
|
100
|
+
}
|
101
|
+
} else if (tools.eqs(e.type, "click")) {
|
102
|
+
if (setting.check.enable && tools.eqs(target.tagName, "span") && target.getAttribute("treeNode"+ consts.id.CHECK) !== null) {
|
103
|
+
tId = tools.getNodeMainDom(target).id;
|
104
|
+
nodeEventType = "checkNode";
|
105
|
+
}
|
106
|
+
}
|
107
|
+
if (tId.length>0) {
|
108
|
+
node = data.getNodeCache(setting, tId);
|
109
|
+
switch (nodeEventType) {
|
110
|
+
case "checkNode" :
|
111
|
+
nodeEventCallback = _handler.onCheckNode;
|
112
|
+
break;
|
113
|
+
case "mouseoverCheck" :
|
114
|
+
nodeEventCallback = _handler.onMouseoverCheck;
|
115
|
+
break;
|
116
|
+
case "mouseoutCheck" :
|
117
|
+
nodeEventCallback = _handler.onMouseoutCheck;
|
118
|
+
break;
|
119
|
+
}
|
120
|
+
}
|
121
|
+
var proxyResult = {
|
122
|
+
stop: nodeEventType === "checkNode",
|
123
|
+
node: node,
|
124
|
+
nodeEventType: nodeEventType,
|
125
|
+
nodeEventCallback: nodeEventCallback,
|
126
|
+
treeEventType: treeEventType,
|
127
|
+
treeEventCallback: treeEventCallback
|
128
|
+
};
|
129
|
+
return proxyResult
|
130
|
+
},
|
131
|
+
//default init node of excheck
|
132
|
+
_initNode = function(setting, level, n, parentNode, isFirstNode, isLastNode, openFlag) {
|
133
|
+
if (!n) return;
|
134
|
+
var checkedKey = setting.data.key.checked;
|
135
|
+
if (typeof n[checkedKey] == "string") n[checkedKey] = tools.eqs(n[checkedKey], "true");
|
136
|
+
n[checkedKey] = !!n[checkedKey];
|
137
|
+
n.checkedOld = n[checkedKey];
|
138
|
+
if (typeof n.nocheck == "string") n.nocheck = tools.eqs(n.nocheck, "true");
|
139
|
+
n.nocheck = !!n.nocheck || (setting.check.nocheckInherit && parentNode && !!parentNode.nocheck);
|
140
|
+
if (typeof n.chkDisabled == "string") n.chkDisabled = tools.eqs(n.chkDisabled, "true");
|
141
|
+
n.chkDisabled = !!n.chkDisabled || (setting.check.chkDisabledInherit && parentNode && !!parentNode.chkDisabled);
|
142
|
+
if (typeof n.halfCheck == "string") n.halfCheck = tools.eqs(n.halfCheck, "true");
|
143
|
+
n.halfCheck = !!n.halfCheck;
|
144
|
+
n.check_Child_State = -1;
|
145
|
+
n.check_Focus = false;
|
146
|
+
n.getCheckStatus = function() {return data.getCheckStatus(setting, n);};
|
147
|
+
|
148
|
+
if (setting.check.chkStyle == consts.radio.STYLE && setting.check.radioType == consts.radio.TYPE_ALL && n[checkedKey] ) {
|
149
|
+
var r = data.getRoot(setting);
|
150
|
+
r.radioCheckedList.push(n);
|
151
|
+
}
|
152
|
+
},
|
153
|
+
//add dom for check
|
154
|
+
_beforeA = function(setting, node, html) {
|
155
|
+
var checkedKey = setting.data.key.checked;
|
156
|
+
if (setting.check.enable) {
|
157
|
+
data.makeChkFlag(setting, node);
|
158
|
+
html.push("<span ID='", node.tId, consts.id.CHECK, "' class='", view.makeChkClass(setting, node), "' treeNode", consts.id.CHECK, (node.nocheck === true?" style='display:none;'":""),"></span>");
|
159
|
+
}
|
160
|
+
},
|
161
|
+
//update zTreeObj, add method of check
|
162
|
+
_zTreeTools = function(setting, zTreeTools) {
|
163
|
+
zTreeTools.checkNode = function(node, checked, checkTypeFlag, callbackFlag) {
|
164
|
+
var checkedKey = this.setting.data.key.checked;
|
165
|
+
if (node.chkDisabled === true) return;
|
166
|
+
if (checked !== true && checked !== false) {
|
167
|
+
checked = !node[checkedKey];
|
168
|
+
}
|
169
|
+
callbackFlag = !!callbackFlag;
|
170
|
+
|
171
|
+
if (node[checkedKey] === checked && !checkTypeFlag) {
|
172
|
+
return;
|
173
|
+
} else if (callbackFlag && tools.apply(this.setting.callback.beforeCheck, [this.setting.treeId, node], true) == false) {
|
174
|
+
return;
|
175
|
+
}
|
176
|
+
if (tools.uCanDo(this.setting) && this.setting.check.enable && node.nocheck !== true) {
|
177
|
+
node[checkedKey] = checked;
|
178
|
+
var checkObj = $$(node, consts.id.CHECK, this.setting);
|
179
|
+
if (checkTypeFlag || this.setting.check.chkStyle === consts.radio.STYLE) view.checkNodeRelation(this.setting, node);
|
180
|
+
view.setChkClass(this.setting, checkObj, node);
|
181
|
+
view.repairParentChkClassWithSelf(this.setting, node);
|
182
|
+
if (callbackFlag) {
|
183
|
+
this.setting.treeObj.trigger(consts.event.CHECK, [null, this.setting.treeId, node]);
|
184
|
+
}
|
185
|
+
}
|
186
|
+
}
|
187
|
+
|
188
|
+
zTreeTools.checkAllNodes = function(checked) {
|
189
|
+
view.repairAllChk(this.setting, !!checked);
|
190
|
+
}
|
191
|
+
|
192
|
+
zTreeTools.getCheckedNodes = function(checked) {
|
193
|
+
var childKey = this.setting.data.key.children;
|
194
|
+
checked = (checked !== false);
|
195
|
+
return data.getTreeCheckedNodes(this.setting, data.getRoot(this.setting)[childKey], checked);
|
196
|
+
}
|
197
|
+
|
198
|
+
zTreeTools.getChangeCheckedNodes = function() {
|
199
|
+
var childKey = this.setting.data.key.children;
|
200
|
+
return data.getTreeChangeCheckedNodes(this.setting, data.getRoot(this.setting)[childKey]);
|
201
|
+
}
|
202
|
+
|
203
|
+
zTreeTools.setChkDisabled = function(node, disabled, inheritParent, inheritChildren) {
|
204
|
+
disabled = !!disabled;
|
205
|
+
inheritParent = !!inheritParent;
|
206
|
+
inheritChildren = !!inheritChildren;
|
207
|
+
view.repairSonChkDisabled(this.setting, node, disabled, inheritChildren);
|
208
|
+
view.repairParentChkDisabled(this.setting, node.getParentNode(), disabled, inheritParent);
|
209
|
+
}
|
210
|
+
|
211
|
+
var _updateNode = zTreeTools.updateNode;
|
212
|
+
zTreeTools.updateNode = function(node, checkTypeFlag) {
|
213
|
+
if (_updateNode) _updateNode.apply(zTreeTools, arguments);
|
214
|
+
if (!node || !this.setting.check.enable) return;
|
215
|
+
var nObj = $$(node, this.setting);
|
216
|
+
if (nObj.get(0) && tools.uCanDo(this.setting)) {
|
217
|
+
var checkObj = $$(node, consts.id.CHECK, this.setting);
|
218
|
+
if (checkTypeFlag == true || this.setting.check.chkStyle === consts.radio.STYLE) view.checkNodeRelation(this.setting, node);
|
219
|
+
view.setChkClass(this.setting, checkObj, node);
|
220
|
+
view.repairParentChkClassWithSelf(this.setting, node);
|
221
|
+
}
|
222
|
+
}
|
223
|
+
},
|
224
|
+
//method of operate data
|
225
|
+
_data = {
|
226
|
+
getRadioCheckedList: function(setting) {
|
227
|
+
var checkedList = data.getRoot(setting).radioCheckedList;
|
228
|
+
for (var i=0, j=checkedList.length; i<j; i++) {
|
229
|
+
if(!data.getNodeCache(setting, checkedList[i].tId)) {
|
230
|
+
checkedList.splice(i, 1);
|
231
|
+
i--; j--;
|
232
|
+
}
|
233
|
+
}
|
234
|
+
return checkedList;
|
235
|
+
},
|
236
|
+
getCheckStatus: function(setting, node) {
|
237
|
+
if (!setting.check.enable || node.nocheck || node.chkDisabled) return null;
|
238
|
+
var checkedKey = setting.data.key.checked,
|
239
|
+
r = {
|
240
|
+
checked: node[checkedKey],
|
241
|
+
half: node.halfCheck ? node.halfCheck : (setting.check.chkStyle == consts.radio.STYLE ? (node.check_Child_State === 2) : (node[checkedKey] ? (node.check_Child_State > -1 && node.check_Child_State < 2) : (node.check_Child_State > 0)))
|
242
|
+
};
|
243
|
+
return r;
|
244
|
+
},
|
245
|
+
getTreeCheckedNodes: function(setting, nodes, checked, results) {
|
246
|
+
if (!nodes) return [];
|
247
|
+
var childKey = setting.data.key.children,
|
248
|
+
checkedKey = setting.data.key.checked,
|
249
|
+
onlyOne = (checked && setting.check.chkStyle == consts.radio.STYLE && setting.check.radioType == consts.radio.TYPE_ALL);
|
250
|
+
results = !results ? [] : results;
|
251
|
+
for (var i = 0, l = nodes.length; i < l; i++) {
|
252
|
+
if (nodes[i].nocheck !== true && nodes[i].chkDisabled !== true && nodes[i][checkedKey] == checked) {
|
253
|
+
results.push(nodes[i]);
|
254
|
+
if(onlyOne) {
|
255
|
+
break;
|
256
|
+
}
|
257
|
+
}
|
258
|
+
data.getTreeCheckedNodes(setting, nodes[i][childKey], checked, results);
|
259
|
+
if(onlyOne && results.length > 0) {
|
260
|
+
break;
|
261
|
+
}
|
262
|
+
}
|
263
|
+
return results;
|
264
|
+
},
|
265
|
+
getTreeChangeCheckedNodes: function(setting, nodes, results) {
|
266
|
+
if (!nodes) return [];
|
267
|
+
var childKey = setting.data.key.children,
|
268
|
+
checkedKey = setting.data.key.checked;
|
269
|
+
results = !results ? [] : results;
|
270
|
+
for (var i = 0, l = nodes.length; i < l; i++) {
|
271
|
+
if (nodes[i].nocheck !== true && nodes[i].chkDisabled !== true && nodes[i][checkedKey] != nodes[i].checkedOld) {
|
272
|
+
results.push(nodes[i]);
|
273
|
+
}
|
274
|
+
data.getTreeChangeCheckedNodes(setting, nodes[i][childKey], results);
|
275
|
+
}
|
276
|
+
return results;
|
277
|
+
},
|
278
|
+
makeChkFlag: function(setting, node) {
|
279
|
+
if (!node) return;
|
280
|
+
var childKey = setting.data.key.children,
|
281
|
+
checkedKey = setting.data.key.checked,
|
282
|
+
chkFlag = -1;
|
283
|
+
if (node[childKey]) {
|
284
|
+
for (var i = 0, l = node[childKey].length; i < l; i++) {
|
285
|
+
var cNode = node[childKey][i];
|
286
|
+
var tmp = -1;
|
287
|
+
if (setting.check.chkStyle == consts.radio.STYLE) {
|
288
|
+
if (cNode.nocheck === true || cNode.chkDisabled === true) {
|
289
|
+
tmp = cNode.check_Child_State;
|
290
|
+
} else if (cNode.halfCheck === true) {
|
291
|
+
tmp = 2;
|
292
|
+
} else if (cNode[checkedKey]) {
|
293
|
+
tmp = 2;
|
294
|
+
} else {
|
295
|
+
tmp = cNode.check_Child_State > 0 ? 2:0;
|
296
|
+
}
|
297
|
+
if (tmp == 2) {
|
298
|
+
chkFlag = 2; break;
|
299
|
+
} else if (tmp == 0){
|
300
|
+
chkFlag = 0;
|
301
|
+
}
|
302
|
+
} else if (setting.check.chkStyle == consts.checkbox.STYLE) {
|
303
|
+
if (cNode.nocheck === true || cNode.chkDisabled === true) {
|
304
|
+
tmp = cNode.check_Child_State;
|
305
|
+
} else if (cNode.halfCheck === true) {
|
306
|
+
tmp = 1;
|
307
|
+
} else if (cNode[checkedKey] ) {
|
308
|
+
tmp = (cNode.check_Child_State === -1 || cNode.check_Child_State === 2) ? 2 : 1;
|
309
|
+
} else {
|
310
|
+
tmp = (cNode.check_Child_State > 0) ? 1 : 0;
|
311
|
+
}
|
312
|
+
if (tmp === 1) {
|
313
|
+
chkFlag = 1; break;
|
314
|
+
} else if (tmp === 2 && chkFlag > -1 && i > 0 && tmp !== chkFlag) {
|
315
|
+
chkFlag = 1; break;
|
316
|
+
} else if (chkFlag === 2 && tmp > -1 && tmp < 2) {
|
317
|
+
chkFlag = 1; break;
|
318
|
+
} else if (tmp > -1) {
|
319
|
+
chkFlag = tmp;
|
320
|
+
}
|
321
|
+
}
|
322
|
+
}
|
323
|
+
}
|
324
|
+
node.check_Child_State = chkFlag;
|
325
|
+
}
|
326
|
+
},
|
327
|
+
//method of event proxy
|
328
|
+
_event = {
|
329
|
+
|
330
|
+
},
|
331
|
+
//method of event handler
|
332
|
+
_handler = {
|
333
|
+
onCheckNode: function (event, node) {
|
334
|
+
if (node.chkDisabled === true) return false;
|
335
|
+
var setting = data.getSetting(event.data.treeId),
|
336
|
+
checkedKey = setting.data.key.checked;
|
337
|
+
if (tools.apply(setting.callback.beforeCheck, [setting.treeId, node], true) == false) return true;
|
338
|
+
node[checkedKey] = !node[checkedKey];
|
339
|
+
view.checkNodeRelation(setting, node);
|
340
|
+
var checkObj = $$(node, consts.id.CHECK, setting);
|
341
|
+
view.setChkClass(setting, checkObj, node);
|
342
|
+
view.repairParentChkClassWithSelf(setting, node);
|
343
|
+
setting.treeObj.trigger(consts.event.CHECK, [event, setting.treeId, node]);
|
344
|
+
return true;
|
345
|
+
},
|
346
|
+
onMouseoverCheck: function(event, node) {
|
347
|
+
if (node.chkDisabled === true) return false;
|
348
|
+
var setting = data.getSetting(event.data.treeId),
|
349
|
+
checkObj = $$(node, consts.id.CHECK, setting);
|
350
|
+
node.check_Focus = true;
|
351
|
+
view.setChkClass(setting, checkObj, node);
|
352
|
+
return true;
|
353
|
+
},
|
354
|
+
onMouseoutCheck: function(event, node) {
|
355
|
+
if (node.chkDisabled === true) return false;
|
356
|
+
var setting = data.getSetting(event.data.treeId),
|
357
|
+
checkObj = $$(node, consts.id.CHECK, setting);
|
358
|
+
node.check_Focus = false;
|
359
|
+
view.setChkClass(setting, checkObj, node);
|
360
|
+
return true;
|
361
|
+
}
|
362
|
+
},
|
363
|
+
//method of tools for zTree
|
364
|
+
_tools = {
|
365
|
+
|
366
|
+
},
|
367
|
+
//method of operate ztree dom
|
368
|
+
_view = {
|
369
|
+
checkNodeRelation: function(setting, node) {
|
370
|
+
var pNode, i, l,
|
371
|
+
childKey = setting.data.key.children,
|
372
|
+
checkedKey = setting.data.key.checked,
|
373
|
+
r = consts.radio;
|
374
|
+
if (setting.check.chkStyle == r.STYLE) {
|
375
|
+
var checkedList = data.getRadioCheckedList(setting);
|
376
|
+
if (node[checkedKey]) {
|
377
|
+
if (setting.check.radioType == r.TYPE_ALL) {
|
378
|
+
for (i = checkedList.length-1; i >= 0; i--) {
|
379
|
+
pNode = checkedList[i];
|
380
|
+
if (pNode[checkedKey] && pNode != node) {
|
381
|
+
pNode[checkedKey] = false;
|
382
|
+
checkedList.splice(i, 1);
|
383
|
+
|
384
|
+
view.setChkClass(setting, $$(pNode, consts.id.CHECK, setting), pNode);
|
385
|
+
if (pNode.parentTId != node.parentTId) {
|
386
|
+
view.repairParentChkClassWithSelf(setting, pNode);
|
387
|
+
}
|
388
|
+
}
|
389
|
+
}
|
390
|
+
checkedList.push(node);
|
391
|
+
} else {
|
392
|
+
var parentNode = (node.parentTId) ? node.getParentNode() : data.getRoot(setting);
|
393
|
+
for (i = 0, l = parentNode[childKey].length; i < l; i++) {
|
394
|
+
pNode = parentNode[childKey][i];
|
395
|
+
if (pNode[checkedKey] && pNode != node) {
|
396
|
+
pNode[checkedKey] = false;
|
397
|
+
view.setChkClass(setting, $$(pNode, consts.id.CHECK, setting), pNode);
|
398
|
+
}
|
399
|
+
}
|
400
|
+
}
|
401
|
+
} else if (setting.check.radioType == r.TYPE_ALL) {
|
402
|
+
for (i = 0, l = checkedList.length; i < l; i++) {
|
403
|
+
if (node == checkedList[i]) {
|
404
|
+
checkedList.splice(i, 1);
|
405
|
+
break;
|
406
|
+
}
|
407
|
+
}
|
408
|
+
}
|
409
|
+
|
410
|
+
} else {
|
411
|
+
if (node[checkedKey] && (!node[childKey] || node[childKey].length==0 || setting.check.chkboxType.Y.indexOf("s") > -1)) {
|
412
|
+
view.setSonNodeCheckBox(setting, node, true);
|
413
|
+
}
|
414
|
+
if (!node[checkedKey] && (!node[childKey] || node[childKey].length==0 || setting.check.chkboxType.N.indexOf("s") > -1)) {
|
415
|
+
view.setSonNodeCheckBox(setting, node, false);
|
416
|
+
}
|
417
|
+
if (node[checkedKey] && setting.check.chkboxType.Y.indexOf("p") > -1) {
|
418
|
+
view.setParentNodeCheckBox(setting, node, true);
|
419
|
+
}
|
420
|
+
if (!node[checkedKey] && setting.check.chkboxType.N.indexOf("p") > -1) {
|
421
|
+
view.setParentNodeCheckBox(setting, node, false);
|
422
|
+
}
|
423
|
+
}
|
424
|
+
},
|
425
|
+
makeChkClass: function(setting, node) {
|
426
|
+
var checkedKey = setting.data.key.checked,
|
427
|
+
c = consts.checkbox, r = consts.radio,
|
428
|
+
fullStyle = "";
|
429
|
+
if (node.chkDisabled === true) {
|
430
|
+
fullStyle = c.DISABLED;
|
431
|
+
} else if (node.halfCheck) {
|
432
|
+
fullStyle = c.PART;
|
433
|
+
} else if (setting.check.chkStyle == r.STYLE) {
|
434
|
+
fullStyle = (node.check_Child_State < 1)? c.FULL:c.PART;
|
435
|
+
} else {
|
436
|
+
fullStyle = node[checkedKey] ? ((node.check_Child_State === 2 || node.check_Child_State === -1) ? c.FULL:c.PART) : ((node.check_Child_State < 1)? c.FULL:c.PART);
|
437
|
+
}
|
438
|
+
var chkName = setting.check.chkStyle + "_" + (node[checkedKey] ? c.TRUE : c.FALSE) + "_" + fullStyle;
|
439
|
+
chkName = (node.check_Focus && node.chkDisabled !== true) ? chkName + "_" + c.FOCUS : chkName;
|
440
|
+
return consts.className.BUTTON + " " + c.DEFAULT + " " + chkName;
|
441
|
+
},
|
442
|
+
repairAllChk: function(setting, checked) {
|
443
|
+
if (setting.check.enable && setting.check.chkStyle === consts.checkbox.STYLE) {
|
444
|
+
var checkedKey = setting.data.key.checked,
|
445
|
+
childKey = setting.data.key.children,
|
446
|
+
root = data.getRoot(setting);
|
447
|
+
for (var i = 0, l = root[childKey].length; i<l ; i++) {
|
448
|
+
var node = root[childKey][i];
|
449
|
+
if (node.nocheck !== true && node.chkDisabled !== true) {
|
450
|
+
node[checkedKey] = checked;
|
451
|
+
}
|
452
|
+
view.setSonNodeCheckBox(setting, node, checked);
|
453
|
+
}
|
454
|
+
}
|
455
|
+
},
|
456
|
+
repairChkClass: function(setting, node) {
|
457
|
+
if (!node) return;
|
458
|
+
data.makeChkFlag(setting, node);
|
459
|
+
if (node.nocheck !== true) {
|
460
|
+
var checkObj = $$(node, consts.id.CHECK, setting);
|
461
|
+
view.setChkClass(setting, checkObj, node);
|
462
|
+
}
|
463
|
+
},
|
464
|
+
repairParentChkClass: function(setting, node) {
|
465
|
+
if (!node || !node.parentTId) return;
|
466
|
+
var pNode = node.getParentNode();
|
467
|
+
view.repairChkClass(setting, pNode);
|
468
|
+
view.repairParentChkClass(setting, pNode);
|
469
|
+
},
|
470
|
+
repairParentChkClassWithSelf: function(setting, node) {
|
471
|
+
if (!node) return;
|
472
|
+
var childKey = setting.data.key.children;
|
473
|
+
if (node[childKey] && node[childKey].length > 0) {
|
474
|
+
view.repairParentChkClass(setting, node[childKey][0]);
|
475
|
+
} else {
|
476
|
+
view.repairParentChkClass(setting, node);
|
477
|
+
}
|
478
|
+
},
|
479
|
+
repairSonChkDisabled: function(setting, node, chkDisabled, inherit) {
|
480
|
+
if (!node) return;
|
481
|
+
var childKey = setting.data.key.children;
|
482
|
+
if (node.chkDisabled != chkDisabled) {
|
483
|
+
node.chkDisabled = chkDisabled;
|
484
|
+
}
|
485
|
+
view.repairChkClass(setting, node);
|
486
|
+
if (node[childKey] && inherit) {
|
487
|
+
for (var i = 0, l = node[childKey].length; i < l; i++) {
|
488
|
+
var sNode = node[childKey][i];
|
489
|
+
view.repairSonChkDisabled(setting, sNode, chkDisabled, inherit);
|
490
|
+
}
|
491
|
+
}
|
492
|
+
},
|
493
|
+
repairParentChkDisabled: function(setting, node, chkDisabled, inherit) {
|
494
|
+
if (!node) return;
|
495
|
+
if (node.chkDisabled != chkDisabled && inherit) {
|
496
|
+
node.chkDisabled = chkDisabled;
|
497
|
+
}
|
498
|
+
view.repairChkClass(setting, node);
|
499
|
+
view.repairParentChkDisabled(setting, node.getParentNode(), chkDisabled, inherit);
|
500
|
+
},
|
501
|
+
setChkClass: function(setting, obj, node) {
|
502
|
+
if (!obj) return;
|
503
|
+
if (node.nocheck === true) {
|
504
|
+
obj.hide();
|
505
|
+
} else {
|
506
|
+
obj.show();
|
507
|
+
}
|
508
|
+
obj.attr('class', view.makeChkClass(setting, node));
|
509
|
+
},
|
510
|
+
setParentNodeCheckBox: function(setting, node, value, srcNode) {
|
511
|
+
var childKey = setting.data.key.children,
|
512
|
+
checkedKey = setting.data.key.checked,
|
513
|
+
checkObj = $$(node, consts.id.CHECK, setting);
|
514
|
+
if (!srcNode) srcNode = node;
|
515
|
+
data.makeChkFlag(setting, node);
|
516
|
+
if (node.nocheck !== true && node.chkDisabled !== true) {
|
517
|
+
node[checkedKey] = value;
|
518
|
+
view.setChkClass(setting, checkObj, node);
|
519
|
+
if (setting.check.autoCheckTrigger && node != srcNode) {
|
520
|
+
setting.treeObj.trigger(consts.event.CHECK, [null, setting.treeId, node]);
|
521
|
+
}
|
522
|
+
}
|
523
|
+
if (node.parentTId) {
|
524
|
+
var pSign = true;
|
525
|
+
if (!value) {
|
526
|
+
var pNodes = node.getParentNode()[childKey];
|
527
|
+
for (var i = 0, l = pNodes.length; i < l; i++) {
|
528
|
+
if ((pNodes[i].nocheck !== true && pNodes[i].chkDisabled !== true && pNodes[i][checkedKey])
|
529
|
+
|| ((pNodes[i].nocheck === true || pNodes[i].chkDisabled === true) && pNodes[i].check_Child_State > 0)) {
|
530
|
+
pSign = false;
|
531
|
+
break;
|
532
|
+
}
|
533
|
+
}
|
534
|
+
}
|
535
|
+
if (pSign) {
|
536
|
+
view.setParentNodeCheckBox(setting, node.getParentNode(), value, srcNode);
|
537
|
+
}
|
538
|
+
}
|
539
|
+
},
|
540
|
+
setSonNodeCheckBox: function(setting, node, value, srcNode) {
|
541
|
+
if (!node) return;
|
542
|
+
var childKey = setting.data.key.children,
|
543
|
+
checkedKey = setting.data.key.checked,
|
544
|
+
checkObj = $$(node, consts.id.CHECK, setting);
|
545
|
+
if (!srcNode) srcNode = node;
|
546
|
+
|
547
|
+
var hasDisable = false;
|
548
|
+
if (node[childKey]) {
|
549
|
+
for (var i = 0, l = node[childKey].length; i < l && node.chkDisabled !== true; i++) {
|
550
|
+
var sNode = node[childKey][i];
|
551
|
+
view.setSonNodeCheckBox(setting, sNode, value, srcNode);
|
552
|
+
if (sNode.chkDisabled === true) hasDisable = true;
|
553
|
+
}
|
554
|
+
}
|
555
|
+
|
556
|
+
if (node != data.getRoot(setting) && node.chkDisabled !== true) {
|
557
|
+
if (hasDisable && node.nocheck !== true) {
|
558
|
+
data.makeChkFlag(setting, node);
|
559
|
+
}
|
560
|
+
if (node.nocheck !== true && node.chkDisabled !== true) {
|
561
|
+
node[checkedKey] = value;
|
562
|
+
if (!hasDisable) node.check_Child_State = (node[childKey] && node[childKey].length > 0) ? (value ? 2 : 0) : -1;
|
563
|
+
} else {
|
564
|
+
node.check_Child_State = -1;
|
565
|
+
}
|
566
|
+
view.setChkClass(setting, checkObj, node);
|
567
|
+
if (setting.check.autoCheckTrigger && node != srcNode && node.nocheck !== true && node.chkDisabled !== true) {
|
568
|
+
setting.treeObj.trigger(consts.event.CHECK, [null, setting.treeId, node]);
|
569
|
+
}
|
570
|
+
}
|
571
|
+
|
572
|
+
}
|
573
|
+
},
|
574
|
+
|
575
|
+
_z = {
|
576
|
+
tools: _tools,
|
577
|
+
view: _view,
|
578
|
+
event: _event,
|
579
|
+
data: _data
|
580
|
+
};
|
581
|
+
$.extend(true, $.fn.zTree.consts, _consts);
|
582
|
+
$.extend(true, $.fn.zTree._z, _z);
|
583
|
+
|
584
|
+
var zt = $.fn.zTree,
|
585
|
+
tools = zt._z.tools,
|
586
|
+
consts = zt.consts,
|
587
|
+
view = zt._z.view,
|
588
|
+
data = zt._z.data,
|
589
|
+
event = zt._z.event,
|
590
|
+
$$ = tools.$;
|
591
|
+
|
592
|
+
data.exSetting(_setting);
|
593
|
+
data.addInitBind(_bindEvent);
|
594
|
+
data.addInitUnBind(_unbindEvent);
|
595
|
+
data.addInitCache(_initCache);
|
596
|
+
data.addInitNode(_initNode);
|
597
|
+
data.addInitProxy(_eventProxy, true);
|
598
|
+
data.addInitRoot(_initRoot);
|
599
|
+
data.addBeforeA(_beforeA);
|
600
|
+
data.addZTreeTools(_zTreeTools);
|
601
|
+
|
602
|
+
var _createNodes = view.createNodes;
|
603
|
+
view.createNodes = function(setting, level, nodes, parentNode) {
|
604
|
+
if (_createNodes) _createNodes.apply(view, arguments);
|
605
|
+
if (!nodes) return;
|
606
|
+
view.repairParentChkClassWithSelf(setting, parentNode);
|
607
|
+
}
|
608
|
+
var _removeNode = view.removeNode;
|
609
|
+
view.removeNode = function(setting, node) {
|
610
|
+
var parentNode = node.getParentNode();
|
611
|
+
if (_removeNode) _removeNode.apply(view, arguments);
|
612
|
+
if (!node || !parentNode) return;
|
613
|
+
view.repairChkClass(setting, parentNode);
|
614
|
+
view.repairParentChkClass(setting, parentNode);
|
615
|
+
}
|
616
|
+
|
617
|
+
var _appendNodes = view.appendNodes;
|
618
|
+
view.appendNodes = function(setting, level, nodes, parentNode, initFlag, openFlag) {
|
619
|
+
var html = "";
|
620
|
+
if (_appendNodes) {
|
621
|
+
html = _appendNodes.apply(view, arguments);
|
622
|
+
}
|
623
|
+
if (parentNode) {
|
624
|
+
data.makeChkFlag(setting, parentNode);
|
625
|
+
}
|
626
|
+
return html;
|
627
|
+
}
|
628
|
+
})(jQuery);
|