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 |
|
|
|
11 |
dojo.provide("dojo.widget.TreeRpcControllerV3");
|
|
|
12 |
dojo.require("dojo.event.*");
|
|
|
13 |
dojo.require("dojo.json");
|
|
|
14 |
dojo.require("dojo.io.*");
|
|
|
15 |
dojo.require("dojo.widget.TreeLoadingControllerV3");
|
|
|
16 |
dojo.widget.defineWidget("dojo.widget.TreeRpcControllerV3", dojo.widget.TreeLoadingControllerV3, {extraRpcOnEdit:false, doMove:function (child, newParent, index, sync) {
|
|
|
17 |
var params = {child:this.getInfo(child), childTree:this.getInfo(child.tree), oldParent:this.getInfo(child.parent), oldParentTree:this.getInfo(child.parent.tree), newParent:this.getInfo(newParent), newParentTree:this.getInfo(newParent.tree), newIndex:index};
|
|
|
18 |
var deferred = this.runRpc({url:this.getRpcUrl("move"), sync:sync, params:params});
|
|
|
19 |
var _this = this;
|
|
|
20 |
var args = arguments;
|
|
|
21 |
deferred.addCallback(function () {
|
|
|
22 |
dojo.widget.TreeBasicControllerV3.prototype.doMove.apply(_this, args);
|
|
|
23 |
});
|
|
|
24 |
return deferred;
|
|
|
25 |
}, prepareDetach:function (node, sync) {
|
|
|
26 |
var deferred = this.startProcessing(node);
|
|
|
27 |
return deferred;
|
|
|
28 |
}, finalizeDetach:function (node) {
|
|
|
29 |
this.finishProcessing(node);
|
|
|
30 |
}, doDetach:function (node, sync) {
|
|
|
31 |
var params = {node:this.getInfo(node), tree:this.getInfo(node.tree)};
|
|
|
32 |
var deferred = this.runRpc({url:this.getRpcUrl("detach"), sync:sync, params:params});
|
|
|
33 |
var _this = this;
|
|
|
34 |
var args = arguments;
|
|
|
35 |
deferred.addCallback(function () {
|
|
|
36 |
dojo.widget.TreeBasicControllerV3.prototype.doDetach.apply(_this, args);
|
|
|
37 |
});
|
|
|
38 |
return deferred;
|
|
|
39 |
}, requestEditConfirmation:function (node, action, sync) {
|
|
|
40 |
if (!this.extraRpcOnEdit) {
|
|
|
41 |
return dojo.Deferred.prototype.makeCalled();
|
|
|
42 |
}
|
|
|
43 |
var _this = this;
|
|
|
44 |
var deferred = this.startProcessing(node);
|
|
|
45 |
var params = {node:this.getInfo(node), tree:this.getInfo(node.tree)};
|
|
|
46 |
deferred.addCallback(function () {
|
|
|
47 |
return _this.runRpc({url:_this.getRpcUrl(action), sync:sync, params:params});
|
|
|
48 |
});
|
|
|
49 |
deferred.addBoth(function (r) {
|
|
|
50 |
_this.finishProcessing(node);
|
|
|
51 |
return r;
|
|
|
52 |
});
|
|
|
53 |
return deferred;
|
|
|
54 |
}, editLabelSave:function (node, newContent, sync) {
|
|
|
55 |
var deferred = this.startProcessing(node);
|
|
|
56 |
var _this = this;
|
|
|
57 |
var params = {node:this.getInfo(node), tree:this.getInfo(node.tree), newContent:newContent};
|
|
|
58 |
deferred.addCallback(function () {
|
|
|
59 |
return _this.runRpc({url:_this.getRpcUrl("editLabelSave"), sync:sync, params:params});
|
|
|
60 |
});
|
|
|
61 |
deferred.addBoth(function (r) {
|
|
|
62 |
_this.finishProcessing(node);
|
|
|
63 |
return r;
|
|
|
64 |
});
|
|
|
65 |
return deferred;
|
|
|
66 |
}, editLabelStart:function (node, sync) {
|
|
|
67 |
if (!this.canEditLabel(node)) {
|
|
|
68 |
return false;
|
|
|
69 |
}
|
|
|
70 |
var _this = this;
|
|
|
71 |
if (!this.editor.isClosed()) {
|
|
|
72 |
var deferred = this.editLabelFinish(this.editor.saveOnBlur, sync);
|
|
|
73 |
deferred.addCallback(function () {
|
|
|
74 |
return _this.editLabelStart(node, sync);
|
|
|
75 |
});
|
|
|
76 |
return deferred;
|
|
|
77 |
}
|
|
|
78 |
var deferred = this.requestEditConfirmation(node, "editLabelStart", sync);
|
|
|
79 |
deferred.addCallback(function () {
|
|
|
80 |
_this.doEditLabelStart(node);
|
|
|
81 |
});
|
|
|
82 |
return deferred;
|
|
|
83 |
}, editLabelFinish:function (save, sync) {
|
|
|
84 |
var _this = this;
|
|
|
85 |
var node = this.editor.node;
|
|
|
86 |
var deferred = dojo.Deferred.prototype.makeCalled();
|
|
|
87 |
if (!save && !node.isPhantom) {
|
|
|
88 |
deferred = this.requestEditConfirmation(this.editor.node, "editLabelFinishCancel", sync);
|
|
|
89 |
}
|
|
|
90 |
if (save) {
|
|
|
91 |
if (node.isPhantom) {
|
|
|
92 |
deferred = this.sendCreateChildRequest(node.parent, node.getParentIndex(), {title:this.editor.getContents()}, sync);
|
|
|
93 |
} else {
|
|
|
94 |
deferred = this.editLabelSave(node, this.editor.getContents(), sync);
|
|
|
95 |
}
|
|
|
96 |
}
|
|
|
97 |
deferred.addCallback(function (server_data) {
|
|
|
98 |
_this.doEditLabelFinish(save, server_data);
|
|
|
99 |
});
|
|
|
100 |
deferred.addErrback(function (r) {
|
|
|
101 |
_this.doEditLabelFinish(false);
|
|
|
102 |
return false;
|
|
|
103 |
});
|
|
|
104 |
return deferred;
|
|
|
105 |
}, createAndEdit:function (parent, index, sync) {
|
|
|
106 |
var data = {title:parent.tree.defaultChildTitle};
|
|
|
107 |
if (!this.canCreateChild(parent, index, data)) {
|
|
|
108 |
return false;
|
|
|
109 |
}
|
|
|
110 |
if (!this.editor.isClosed()) {
|
|
|
111 |
var deferred = this.editLabelFinish(this.editor.saveOnBlur, sync);
|
|
|
112 |
deferred.addCallback(function () {
|
|
|
113 |
return _this.createAndEdit(parent, index, sync);
|
|
|
114 |
});
|
|
|
115 |
return deferred;
|
|
|
116 |
}
|
|
|
117 |
var _this = this;
|
|
|
118 |
var deferred = this.prepareCreateChild(parent, index, data, sync);
|
|
|
119 |
deferred.addCallback(function () {
|
|
|
120 |
var child = _this.makeDefaultNode(parent, index);
|
|
|
121 |
child.isPhantom = true;
|
|
|
122 |
return child;
|
|
|
123 |
});
|
|
|
124 |
deferred.addBoth(function (r) {
|
|
|
125 |
_this.finalizeCreateChild(parent, index, data, sync);
|
|
|
126 |
return r;
|
|
|
127 |
});
|
|
|
128 |
deferred.addCallback(function (child) {
|
|
|
129 |
var d = _this.exposeCreateChild(parent, index, data, sync);
|
|
|
130 |
d.addCallback(function () {
|
|
|
131 |
return child;
|
|
|
132 |
});
|
|
|
133 |
return d;
|
|
|
134 |
});
|
|
|
135 |
deferred.addCallback(function (child) {
|
|
|
136 |
_this.doEditLabelStart(child);
|
|
|
137 |
return child;
|
|
|
138 |
});
|
|
|
139 |
return deferred;
|
|
|
140 |
}, prepareDestroyChild:function (node, sync) {
|
|
|
141 |
var deferred = this.startProcessing(node);
|
|
|
142 |
return deferred;
|
|
|
143 |
}, finalizeDestroyChild:function (node) {
|
|
|
144 |
this.finishProcessing(node);
|
|
|
145 |
}, doDestroyChild:function (node, sync) {
|
|
|
146 |
var params = {node:this.getInfo(node), tree:this.getInfo(node.tree)};
|
|
|
147 |
var deferred = this.runRpc({url:this.getRpcUrl("destroyChild"), sync:sync, params:params});
|
|
|
148 |
var _this = this;
|
|
|
149 |
var args = arguments;
|
|
|
150 |
deferred.addCallback(function () {
|
|
|
151 |
dojo.widget.TreeBasicControllerV3.prototype.doDestroyChild.apply(_this, args);
|
|
|
152 |
});
|
|
|
153 |
return deferred;
|
|
|
154 |
}, sendCreateChildRequest:function (parent, index, data, sync) {
|
|
|
155 |
var params = {tree:this.getInfo(parent.tree), parent:this.getInfo(parent), index:index, data:data};
|
|
|
156 |
var deferred = this.runRpc({url:this.getRpcUrl("createChild"), sync:sync, params:params});
|
|
|
157 |
return deferred;
|
|
|
158 |
}, doCreateChild:function (parent, index, data, sync) {
|
|
|
159 |
if (dojo.lang.isUndefined(data.title)) {
|
|
|
160 |
data.title = parent.tree.defaultChildTitle;
|
|
|
161 |
}
|
|
|
162 |
var deferred = this.sendCreateChildRequest(parent, index, data, sync);
|
|
|
163 |
var _this = this;
|
|
|
164 |
var args = arguments;
|
|
|
165 |
deferred.addCallback(function (server_data) {
|
|
|
166 |
dojo.lang.mixin(data, server_data);
|
|
|
167 |
return dojo.widget.TreeBasicControllerV3.prototype.doCreateChild.call(_this, parent, index, data);
|
|
|
168 |
});
|
|
|
169 |
return deferred;
|
|
|
170 |
}, doClone:function (child, newParent, index, deep, sync) {
|
|
|
171 |
var params = {child:this.getInfo(child), oldParent:this.getInfo(child.parent), oldParentTree:this.getInfo(child.parent.tree), newParent:this.getInfo(newParent), newParentTree:this.getInfo(newParent.tree), index:index, deep:deep ? true : false, tree:this.getInfo(child.tree)};
|
|
|
172 |
var deferred = this.runRpc({url:this.getRpcUrl("clone"), sync:sync, params:params});
|
|
|
173 |
var _this = this;
|
|
|
174 |
var args = arguments;
|
|
|
175 |
deferred.addCallback(function () {
|
|
|
176 |
dojo.widget.TreeBasicControllerV3.prototype.doClone.apply(_this, args);
|
|
|
177 |
});
|
|
|
178 |
return deferred;
|
|
|
179 |
}});
|
|
|
180 |
|