1318 |
alexandre_ |
1 |
/*
|
|
|
2 |
Copyright (c) 2004-2006, The Dojo Foundation
|
|
|
3 |
All Rights Reserved.
|
|
|
4 |
|
|
|
5 |
Licensed under the Academic Free License version 2.1 or above OR the
|
|
|
6 |
modified BSD license. For more information on Dojo licensing, see:
|
|
|
7 |
|
|
|
8 |
http://dojotoolkit.org/community/licensing.shtml
|
|
|
9 |
*/
|
|
|
10 |
|
1422 |
alexandre_ |
11 |
|
|
|
12 |
|
1318 |
alexandre_ |
13 |
dojo.provide("dojo.widget.TreeLoadingController");
|
|
|
14 |
dojo.require("dojo.widget.TreeBasicController");
|
|
|
15 |
dojo.require("dojo.event.*");
|
|
|
16 |
dojo.require("dojo.json");
|
|
|
17 |
dojo.require("dojo.io.*");
|
|
|
18 |
dojo.widget.defineWidget("dojo.widget.TreeLoadingController", dojo.widget.TreeBasicController, {RPCUrl:"", RPCActionParam:"action", RPCErrorHandler:function (type, obj, evt) {
|
|
|
19 |
alert("RPC Error: " + (obj.message || "no message"));
|
|
|
20 |
}, preventCache:true, getRPCUrl:function (action) {
|
|
|
21 |
if (this.RPCUrl == "local") {
|
|
|
22 |
var dir = document.location.href.substr(0, document.location.href.lastIndexOf("/"));
|
|
|
23 |
var localUrl = dir + "/" + action;
|
|
|
24 |
return localUrl;
|
|
|
25 |
}
|
|
|
26 |
if (!this.RPCUrl) {
|
|
|
27 |
dojo.raise("Empty RPCUrl: can't load");
|
|
|
28 |
}
|
|
|
29 |
return this.RPCUrl + (this.RPCUrl.indexOf("?") > -1 ? "&" : "?") + this.RPCActionParam + "=" + action;
|
|
|
30 |
}, loadProcessResponse:function (node, result, callObj, callFunc) {
|
|
|
31 |
if (!dojo.lang.isUndefined(result.error)) {
|
|
|
32 |
this.RPCErrorHandler("server", result.error);
|
|
|
33 |
return false;
|
|
|
34 |
}
|
|
|
35 |
var newChildren = result;
|
|
|
36 |
if (!dojo.lang.isArray(newChildren)) {
|
|
|
37 |
dojo.raise("loadProcessResponse: Not array loaded: " + newChildren);
|
|
|
38 |
}
|
|
|
39 |
for (var i = 0; i < newChildren.length; i++) {
|
|
|
40 |
newChildren[i] = dojo.widget.createWidget(node.widgetType, newChildren[i]);
|
|
|
41 |
node.addChild(newChildren[i]);
|
|
|
42 |
}
|
|
|
43 |
node.state = node.loadStates.LOADED;
|
|
|
44 |
if (dojo.lang.isFunction(callFunc)) {
|
|
|
45 |
callFunc.apply(dojo.lang.isUndefined(callObj) ? this : callObj, [node, newChildren]);
|
|
|
46 |
}
|
|
|
47 |
}, getInfo:function (obj) {
|
|
|
48 |
return obj.getInfo();
|
|
|
49 |
}, runRPC:function (kw) {
|
|
|
50 |
var _this = this;
|
|
|
51 |
var handle = function (type, data, evt) {
|
|
|
52 |
if (kw.lock) {
|
|
|
53 |
dojo.lang.forEach(kw.lock, function (t) {
|
|
|
54 |
t.unlock();
|
|
|
55 |
});
|
|
|
56 |
}
|
|
|
57 |
if (type == "load") {
|
|
|
58 |
kw.load.call(this, data);
|
|
|
59 |
} else {
|
|
|
60 |
this.RPCErrorHandler(type, data, evt);
|
|
|
61 |
}
|
|
|
62 |
};
|
|
|
63 |
if (kw.lock) {
|
|
|
64 |
dojo.lang.forEach(kw.lock, function (t) {
|
|
|
65 |
t.lock();
|
|
|
66 |
});
|
|
|
67 |
}
|
|
|
68 |
dojo.io.bind({url:kw.url, handle:dojo.lang.hitch(this, handle), mimetype:"text/json", preventCache:_this.preventCache, sync:kw.sync, content:{data:dojo.json.serialize(kw.params)}});
|
|
|
69 |
}, loadRemote:function (node, sync, callObj, callFunc) {
|
|
|
70 |
var _this = this;
|
|
|
71 |
var params = {node:this.getInfo(node), tree:this.getInfo(node.tree)};
|
|
|
72 |
this.runRPC({url:this.getRPCUrl("getChildren"), load:function (result) {
|
|
|
73 |
_this.loadProcessResponse(node, result, callObj, callFunc);
|
|
|
74 |
}, sync:sync, lock:[node], params:params});
|
|
|
75 |
}, expand:function (node, sync, callObj, callFunc) {
|
|
|
76 |
if (node.state == node.loadStates.UNCHECKED && node.isFolder) {
|
|
|
77 |
this.loadRemote(node, sync, this, function (node, newChildren) {
|
|
|
78 |
this.expand(node, sync, callObj, callFunc);
|
|
|
79 |
});
|
|
|
80 |
return;
|
|
|
81 |
}
|
|
|
82 |
dojo.widget.TreeBasicController.prototype.expand.apply(this, arguments);
|
|
|
83 |
}, doMove:function (child, newParent, index) {
|
|
|
84 |
if (newParent.isTreeNode && newParent.state == newParent.loadStates.UNCHECKED) {
|
|
|
85 |
this.loadRemote(newParent, true);
|
|
|
86 |
}
|
|
|
87 |
return dojo.widget.TreeBasicController.prototype.doMove.apply(this, arguments);
|
|
|
88 |
}, doCreateChild:function (parent, index, data, callObj, callFunc) {
|
|
|
89 |
if (parent.state == parent.loadStates.UNCHECKED) {
|
|
|
90 |
this.loadRemote(parent, true);
|
|
|
91 |
}
|
|
|
92 |
return dojo.widget.TreeBasicController.prototype.doCreateChild.apply(this, arguments);
|
|
|
93 |
}});
|
|
|
94 |
|