Subversion Repositories Applications.papyrus

Rev

Rev 1318 | Details | Compare with Previous | Last modification | View Log | RSS feed

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