| author | ymh <ymh.work@gmail.com> |
| Mon, 14 Jan 2013 16:00:07 +0100 | |
| changeset 51 | 3247fccfbd3f |
| parent 48 | 01fb9167ad75 |
| child 54 | 43c35d6ca3f0 |
| permissions | -rw-r--r-- |
| 51 | 1 |
//TODO add underscore as requirement |
| 45 | 2 |
define([ |
3 |
"dojo", |
|
| 51 | 4 |
"dojo/cookie", |
5 |
"coweb/main", |
|
6 |
"rcolor", |
|
7 |
"underscore" |
|
8 |
], function(dojo, cookie, coweb, RColor, underscore) { |
|
|
47
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
9 |
|
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
10 |
var CoRenkan = function() { |
| 45 | 11 |
}; |
12 |
||
|
47
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
13 |
var proto = CoRenkan.prototype; |
| 51 | 14 |
|
15 |
var _ = underscore; |
|
16 |
|
|
| 45 | 17 |
proto.init = function() { |
18 |
console.log("ready callback"); |
|
19 |
|
|
20 |
//this.initCollab(); |
|
| 51 | 21 |
var that = this; |
22 |
|
|
| 45 | 23 |
var sess = coweb.initSession(); |
| 51 | 24 |
|
| 45 | 25 |
sess.onStatusChange = function(status) { |
26 |
console.log(status); |
|
|
47
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
27 |
if(typeof that.onStatusChange === "function") { |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
28 |
that.onStatusChange(status); |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
29 |
} |
| 45 | 30 |
}; |
| 51 | 31 |
|
32 |
sess.prepare().then(function(data) { |
|
33 |
console.log("Prepare ok : ", data); |
|
34 |
}); |
|
| 45 | 35 |
this.project = null; |
36 |
|
|
37 |
}; |
|
38 |
|
|
39 |
proto.initCollab = function(id) { |
|
40 |
this.collab = coweb.initCollab({id : id}); |
|
|
48
01fb9167ad75
Correct bug on insert, delete move objects
ymh <ymh.work@gmail.com>
parents:
47
diff
changeset
|
41 |
this.collab.subscribeSync("project", this, "onRemoteProjectChange"); |
|
01fb9167ad75
Correct bug on insert, delete move objects
ymh <ymh.work@gmail.com>
parents:
47
diff
changeset
|
42 |
this.collab.subscribeSync("user", this, "onRemoteUserChange"); |
|
01fb9167ad75
Correct bug on insert, delete move objects
ymh <ymh.work@gmail.com>
parents:
47
diff
changeset
|
43 |
this.collab.subscribeSync("node", this, "onRemoteNodeChange"); |
|
01fb9167ad75
Correct bug on insert, delete move objects
ymh <ymh.work@gmail.com>
parents:
47
diff
changeset
|
44 |
this.collab.subscribeSync("edge", this, "onRemoteEdgeChange"); |
| 51 | 45 |
this.collab.subscribeSync("_roster", this, "onRemoteRosterChange"); |
46 |
|
|
47 |
this.collab.subscribeReady(this, 'onLocalJoin'); |
|
48 |
this.collab.subscribeSiteJoin(this, 'onRemoteJoin'); |
|
49 |
this.collab.subscribeSiteLeave(this, 'onRemoteLeave'); |
|
50 |
}; |
|
51 |
|
|
52 |
proto.onLocalJoin = function(params) { |
|
53 |
console.log("Local join", params); |
|
54 |
}; |
|
55 |
|
|
56 |
|
|
57 |
proto.onRemoteJoin = function(params) { |
|
58 |
console.log("Remote join", params); |
|
59 |
// do nothing |
|
60 |
}; |
|
61 |
|
|
62 |
proto.onRemoteLeave = function(params) { |
|
63 |
console.log("Remote leave", params); |
|
64 |
|
|
65 |
// remove remote site from current_user_list |
|
66 |
if(typeof this.renkan === "undefined" || this.renkan == null || typeof this.renkan.current_user_list === "undefined" || this.renkan.current_user_list == null) { |
|
67 |
return; |
|
68 |
} |
|
69 |
|
|
| 45 | 70 |
}; |
71 |
|
|
72 |
function prepareValues(obj,c) { |
|
73 |
values = {}; |
|
74 |
for(var fieldname in c.changes) { |
|
75 |
if(c.changes[fieldname]) { |
|
76 |
values[fieldname] = obj.get(fieldname); |
|
77 |
} |
|
78 |
} |
|
79 |
return values; |
|
80 |
} |
|
81 |
|
|
|
47
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
82 |
proto.addObjectBind = function(type, obj, c, options) { |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
83 |
console.log("add " + type,obj, c, options, this.project.toJSON()); |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
84 |
var values = obj.toJSON(); |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
85 |
var new_values = { |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
86 |
id: obj.id, |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
87 |
_type: type, |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
88 |
_index: options.index, |
| 51 | 89 |
_project_id : obj.get("project").get("_id"), |
90 |
_user_id : (this.project.current_user!=null)?this.project.current_user.id:null |
|
|
47
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
91 |
}; |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
92 |
for(var k in new_values) { |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
93 |
values[k] = new_values[k]; |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
94 |
} |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
95 |
console.log("add values : ", values); |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
96 |
this.collab.sendSync(type, values, "insert", options.index); |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
97 |
}; |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
98 |
|
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
99 |
proto.removeObjectBind = function(type, obj, c, options) { |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
100 |
console.log("delete " + type,obj, c, options); |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
101 |
var values = { |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
102 |
id: obj.id, |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
103 |
_type: type, |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
104 |
_index: options.index, |
| 51 | 105 |
_project_id : obj.get("project").id, |
106 |
_user_id : (this.project.current_user!=null)?this.project.current_user.id:null |
|
|
47
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
107 |
}; |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
108 |
this.collab.sendSync(type, values, "delete", options.index); |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
109 |
}; |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
110 |
|
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
111 |
proto.updateObjectBind = function(type, obj, options) { |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
112 |
console.log("change " + type,obj, options); |
|
48
01fb9167ad75
Correct bug on insert, delete move objects
ymh <ymh.work@gmail.com>
parents:
47
diff
changeset
|
113 |
if(typeof obj != "undefined" && obj.hasChanged()) { |
|
47
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
114 |
var values = { |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
115 |
id: obj.id, |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
116 |
_type: type, |
| 51 | 117 |
_project_id : obj.get("project").id, |
118 |
_user_id : (this.project.current_user!=null)?this.project.current_user.id:null |
|
|
47
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
119 |
}; |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
120 |
_.extend(values,obj.changed); |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
121 |
this.collab.sendSync(type, values); |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
122 |
} |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
123 |
}; |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
124 |
|
| 51 | 125 |
/** |
126 |
* Called when an abject is changed |
|
127 |
* |
|
128 |
*/ |
|
129 |
proto.objectChange = function(event, model, collection, options) { |
|
130 |
|
|
131 |
console.log("project change all ", event, model, collection, options); |
|
132 |
// check that current user is in user list of the project |
|
133 |
|
|
134 |
if(this.project == null || this.project.current_user == null) { |
|
135 |
return; |
|
136 |
} |
|
137 |
var current_user = this.project.current_user; |
|
138 |
|
|
139 |
if(this.project.get("users").get(current_user.id) == null) { |
|
140 |
var props = current_user.toJSON(); |
|
141 |
this.project.addUser(props); |
|
142 |
} |
|
143 |
|
|
144 |
}; |
|
145 |
||
146 |
|
|
147 |
proto.setObjects = function(renkan) { |
|
148 |
|
|
149 |
console.log(cookie("BAYEUX_BROWSER")); |
|
150 |
var project = renkan.project; |
|
151 |
this.setProject(project); |
|
152 |
this.setRenkan(renkan); |
|
153 |
|
|
154 |
this.initCollab("renkan_" + project.id); |
|
155 |
|
|
156 |
this.setUser(renkan); |
|
157 |
||
158 |
}; |
|
159 |
|
|
160 |
proto.setRenkan = function(renkan) { |
|
161 |
|
|
162 |
console.log("Set Renkan"); |
|
163 |
|
|
164 |
var that = this; |
|
165 |
|
|
166 |
renkan.current_user_list.bind("add", function(obj, c, options) { |
|
167 |
that.addObjectBind("_roster", obj, c, options); |
|
168 |
}); |
|
169 |
renkan.current_user_list.bind("remove", function(obj, c, options) { |
|
170 |
that.removeObjectBind("_roster", obj, c, options); |
|
171 |
}); |
|
172 |
renkan.current_user_list.bind("change", function(obj, options) { |
|
173 |
that.updateObjectBind("_roster", obj, options); |
|
174 |
}); |
|
175 |
|
|
176 |
renkan.current_user_list.bind("change", function(obj, options) { |
|
177 |
console.log("update roster",obj, options); |
|
178 |
// get user in project |
|
179 |
project = obj.get("project"); |
|
180 |
if(project == null) { |
|
181 |
console.log("null project return"); |
|
182 |
return; |
|
183 |
} |
|
184 |
user = project.get("users").get(obj.id); |
|
185 |
if(user == null) { |
|
186 |
console.log("user " + obj.id + " not in project. return"); |
|
187 |
return; |
|
188 |
} |
|
189 |
for(att in obj.changed) { |
|
190 |
new_val = obj.changed[att]; |
|
191 |
if(user.get("att") != new_val) { |
|
192 |
user.set(att, new_val); |
|
193 |
} |
|
194 |
} |
|
195 |
}); |
|
196 |
|
|
197 |
this.renkan = renkan; |
|
198 |
|
|
199 |
}; |
|
200 |
|
|
201 |
proto.setUser = function(renkan) { |
|
202 |
console.log("set user : " + cookie("BAYEUX_BROWSER")); |
|
203 |
|
|
204 |
if(typeof renkan === "undefined" || typeof renkan.project === "undefined" || renkan.project == null) { |
|
205 |
return; |
|
206 |
} |
|
207 |
|
|
208 |
var user_id = cookie("BAYEUX_BROWSER"); |
|
209 |
var project = renkan.project; |
|
210 |
|
|
211 |
var puser = project.get("users").get(user_id); |
|
212 |
var puser_def = null; |
|
213 |
if(puser == null) { |
|
214 |
color = new RColor(); |
|
215 |
puser_def = { |
|
216 |
id: user_id, |
|
217 |
title: "anonymous", |
|
218 |
project: project, |
|
219 |
color: color.get(true, 0.3, 0.99) |
|
220 |
}; |
|
221 |
} |
|
222 |
else { |
|
223 |
puser_def = puser.toJSON(); |
|
224 |
puser_def.project = project; |
|
225 |
} |
|
226 |
puser = renkan.current_user_list.push(puser_def); |
|
227 |
|
|
228 |
project.current_user = puser; |
|
229 |
renkan.current_user = puser.id; |
|
230 |
|
|
231 |
var that = this; |
|
232 |
|
|
233 |
project.once("all", function(event, model, collection, options){ |
|
234 |
that.objectChange(event, model, collection, options); |
|
235 |
}); |
|
236 |
project.get("nodes").once("all", function(event, model, collection, options){ |
|
237 |
that.objectChange(event, model, collection, options); |
|
238 |
}); |
|
239 |
project.get("edges").once("all", function(event, model, collection, options){ |
|
240 |
that.objectChange(event, model, collection, options); |
|
241 |
}); |
|
242 |
||
243 |
|
|
244 |
}; |
|
245 |
|
|
| 45 | 246 |
proto.setProject = function(project) { |
247 |
|
|
|
47
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
248 |
console.log("project", project); |
| 51 | 249 |
|
250 |
var projectFields = ["title", "description", "uri"]; |
|
| 45 | 251 |
var that = this; |
| 51 | 252 |
|
| 45 | 253 |
for(var fieldIndex in projectFields) { |
254 |
(function(fi){ |
|
255 |
var field = projectFields[fi]; |
|
256 |
project.bind("change:"+field, function(obj, c) { |
|
257 |
console.log(c); |
|
258 |
values = { |
|
259 |
id: obj.id, |
|
|
46
7e132e2a48ca
add most of the model and repositories
ymh <ymh.work@gmail.com>
parents:
45
diff
changeset
|
260 |
type: "project", |
|
7e132e2a48ca
add most of the model and repositories
ymh <ymh.work@gmail.com>
parents:
45
diff
changeset
|
261 |
project_id: obj.id |
| 45 | 262 |
}; |
263 |
values[field] = c; |
|
264 |
that.collab.sendSync("project", values); |
|
265 |
}); |
|
266 |
})(fieldIndex); |
|
267 |
} |
|
|
47
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
268 |
|
| 51 | 269 |
|
|
47
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
270 |
project.get("nodes").bind("add", function(obj, c, options) { |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
271 |
that.addObjectBind("node", obj, c, options); |
|
46
7e132e2a48ca
add most of the model and repositories
ymh <ymh.work@gmail.com>
parents:
45
diff
changeset
|
272 |
}); |
|
47
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
273 |
|
|
46
7e132e2a48ca
add most of the model and repositories
ymh <ymh.work@gmail.com>
parents:
45
diff
changeset
|
274 |
project.get("nodes").bind("remove", function(obj, c, options) { |
|
47
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
275 |
that.removeObjectBind("node", obj, c, options); |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
276 |
}); |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
277 |
|
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
278 |
project.get("nodes").bind("change", function(obj, options) { |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
279 |
that.updateObjectBind("node", obj, options); |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
280 |
}); |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
281 |
|
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
282 |
project.get("users").bind("add", function(obj, c, options) { |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
283 |
that.addObjectBind("user", obj, c, options); |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
284 |
}); |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
285 |
|
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
286 |
project.get("users").bind("remove", function(obj, c, options) { |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
287 |
that.removeObjectBind("user", obj, c, options); |
|
46
7e132e2a48ca
add most of the model and repositories
ymh <ymh.work@gmail.com>
parents:
45
diff
changeset
|
288 |
}); |
|
47
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
289 |
|
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
290 |
project.get("users").bind("change", function(obj, options) { |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
291 |
that.updateObjectBind("user", obj, options); |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
292 |
}); |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
293 |
|
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
294 |
project.get("edges").bind("add", function(obj, c, options) { |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
295 |
that.addObjectBind("edge", obj, c, options); |
|
46
7e132e2a48ca
add most of the model and repositories
ymh <ymh.work@gmail.com>
parents:
45
diff
changeset
|
296 |
}); |
|
47
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
297 |
|
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
298 |
project.get("edges").bind("remove", function(obj, c, options) { |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
299 |
that.removeObjectBind("edge", obj, c, options); |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
300 |
}); |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
301 |
|
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
302 |
project.get("edges").bind("change", function(obj, options) { |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
303 |
that.updateObjectBind("edge", obj, options); |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
304 |
}); |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
305 |
|
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
306 |
|
| 45 | 307 |
this.project = project; |
308 |
}; |
|
309 |
|
|
310 |
|
|
311 |
/** |
|
|
46
7e132e2a48ca
add most of the model and repositories
ymh <ymh.work@gmail.com>
parents:
45
diff
changeset
|
312 |
* Called when a remote data store for project changes in some manner. Dispatches to |
| 45 | 313 |
* local methods for insert, update, delete handling. |
314 |
* TODO: manage project list change on server |
|
315 |
* @param args Cooperative web event |
|
316 |
*/ |
|
317 |
proto.onRemoteProjectChange = function(args) { |
|
|
47
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
318 |
console.log("Remote project change", args); |
| 45 | 319 |
if (args.type === "update") { |
320 |
this.onRemoteProjectUpdate(args.value, args.position); |
|
321 |
} |
|
322 |
}; |
|
323 |
|
|
|
46
7e132e2a48ca
add most of the model and repositories
ymh <ymh.work@gmail.com>
parents:
45
diff
changeset
|
324 |
|
|
7e132e2a48ca
add most of the model and repositories
ymh <ymh.work@gmail.com>
parents:
45
diff
changeset
|
325 |
/** |
|
7e132e2a48ca
add most of the model and repositories
ymh <ymh.work@gmail.com>
parents:
45
diff
changeset
|
326 |
* Called when a remote data store for nodes changes in some manner. Dispatches to |
|
7e132e2a48ca
add most of the model and repositories
ymh <ymh.work@gmail.com>
parents:
45
diff
changeset
|
327 |
* local methods for insert, update, delete handling. |
|
7e132e2a48ca
add most of the model and repositories
ymh <ymh.work@gmail.com>
parents:
45
diff
changeset
|
328 |
* @param args Cooperative web event |
|
7e132e2a48ca
add most of the model and repositories
ymh <ymh.work@gmail.com>
parents:
45
diff
changeset
|
329 |
*/ |
|
47
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
330 |
proto.onRemoteObjectChange = function(field, args) { |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
331 |
console.log("Remote "+ field +" change",args); |
|
46
7e132e2a48ca
add most of the model and repositories
ymh <ymh.work@gmail.com>
parents:
45
diff
changeset
|
332 |
if (args.type === "insert") { |
|
47
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
333 |
this.onRemoteObjectInsert(field, args.value, args.position); |
|
46
7e132e2a48ca
add most of the model and repositories
ymh <ymh.work@gmail.com>
parents:
45
diff
changeset
|
334 |
} else if (args.type === "update") { |
|
48
01fb9167ad75
Correct bug on insert, delete move objects
ymh <ymh.work@gmail.com>
parents:
47
diff
changeset
|
335 |
this.onRemoteObjectUpdate(field, args.value, args.position); |
|
46
7e132e2a48ca
add most of the model and repositories
ymh <ymh.work@gmail.com>
parents:
45
diff
changeset
|
336 |
} else if (args.type === "delete") { |
|
48
01fb9167ad75
Correct bug on insert, delete move objects
ymh <ymh.work@gmail.com>
parents:
47
diff
changeset
|
337 |
this.onRemoteObjectDelete(field, args.position); |
|
46
7e132e2a48ca
add most of the model and repositories
ymh <ymh.work@gmail.com>
parents:
45
diff
changeset
|
338 |
} |
|
7e132e2a48ca
add most of the model and repositories
ymh <ymh.work@gmail.com>
parents:
45
diff
changeset
|
339 |
}; |
|
7e132e2a48ca
add most of the model and repositories
ymh <ymh.work@gmail.com>
parents:
45
diff
changeset
|
340 |
|
|
7e132e2a48ca
add most of the model and repositories
ymh <ymh.work@gmail.com>
parents:
45
diff
changeset
|
341 |
|
|
47
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
342 |
/** |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
343 |
* Called when a remote data store for nodes changes in some manner. Dispatches to |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
344 |
* local methods for insert, update, delete handling. |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
345 |
* @param args Cooperative web event |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
346 |
*/ |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
347 |
proto.onRemoteNodeChange = function(args) { |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
348 |
this.onRemoteObjectChange("nodes", args); |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
349 |
}; |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
350 |
|
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
351 |
|
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
352 |
/** |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
353 |
* Called when a remote data store for nodes changes in some manner. Dispatches to |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
354 |
* local methods for insert, update, delete handling. |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
355 |
* @param args Cooperative web event |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
356 |
*/ |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
357 |
proto.onRemoteUserChange = function(args) { |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
358 |
this.onRemoteObjectChange("users", args); |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
359 |
}; |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
360 |
|
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
361 |
/** |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
362 |
* Called when a remote data store for nodes changes in some manner. Dispatches to |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
363 |
* local methods for insert, update, delete handling. |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
364 |
* @param args Cooperative web event |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
365 |
*/ |
|
48
01fb9167ad75
Correct bug on insert, delete move objects
ymh <ymh.work@gmail.com>
parents:
47
diff
changeset
|
366 |
proto.onRemoteEdgeChange = function(args) { |
|
47
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
367 |
this.onRemoteObjectChange("edges", args); |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
368 |
}; |
| 51 | 369 |
|
370 |
/** |
|
371 |
* Called when a remote data store for nodes changes in some manner. Dispatches to |
|
372 |
* local methods for insert, update, delete handling. |
|
373 |
* @param args Cooperative web event |
|
374 |
*/ |
|
375 |
proto.onRemoteRosterChange = function(args) { |
|
376 |
this.onRemoteObjectChange(this.renkan.current_user_list, args); |
|
377 |
}; |
|
378 |
|
|
| 45 | 379 |
/** |
380 |
* Called when a project attribute changes value in a remote data store. |
|
381 |
* Updates the attribute value of the item with the same id in the local |
|
382 |
* data store. |
|
383 |
* |
|
384 |
* @param value Item data sent by remote data store |
|
385 |
* @param position Which item to update. |
|
386 |
*/ |
|
387 |
proto.onRemoteProjectUpdate = function(values, position) { |
|
388 |
var project_id = values['id']; |
|
389 |
if(typeof(project_id) === "undefined") { |
|
390 |
return; |
|
391 |
} |
|
392 |
|
|
393 |
if(this.project != null && project_id == this.project.id) { |
|
394 |
for(var fieldname in values) { |
|
395 |
if(fieldname != "id" && fieldname != "type") { |
|
396 |
this.project.set(fieldname, values[fieldname]); |
|
397 |
} |
|
398 |
} |
|
399 |
} |
|
400 |
|
|
|
47
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
401 |
}; |
|
46
7e132e2a48ca
add most of the model and repositories
ymh <ymh.work@gmail.com>
parents:
45
diff
changeset
|
402 |
|
|
7e132e2a48ca
add most of the model and repositories
ymh <ymh.work@gmail.com>
parents:
45
diff
changeset
|
403 |
/** |
|
47
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
404 |
* Called when an object is inserted in a remote data store. |
|
46
7e132e2a48ca
add most of the model and repositories
ymh <ymh.work@gmail.com>
parents:
45
diff
changeset
|
405 |
* |
| 51 | 406 |
* @param field_coll A collection or a string for one of the project collection |
|
46
7e132e2a48ca
add most of the model and repositories
ymh <ymh.work@gmail.com>
parents:
45
diff
changeset
|
407 |
* @param value Item data sent by remote data store |
|
7e132e2a48ca
add most of the model and repositories
ymh <ymh.work@gmail.com>
parents:
45
diff
changeset
|
408 |
* @param position Which item to update. |
|
7e132e2a48ca
add most of the model and repositories
ymh <ymh.work@gmail.com>
parents:
45
diff
changeset
|
409 |
*/ |
| 51 | 410 |
proto.onRemoteObjectInsert = function(field_coll, values, position) { |
411 |
|
|
412 |
console.log("Remote ", field_coll ," insert values ", values, "position", position); |
|
|
47
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
413 |
|
| 51 | 414 |
var coll = null; |
415 |
if(typeof field_coll === "string") { |
|
416 |
coll = this.project.get(field_coll); |
|
417 |
} |
|
418 |
else { |
|
419 |
coll = field_coll; |
|
420 |
} |
|
421 |
||
|
47
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
422 |
var object_id = values['id']; |
|
46
7e132e2a48ca
add most of the model and repositories
ymh <ymh.work@gmail.com>
parents:
45
diff
changeset
|
423 |
|
|
47
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
424 |
var obj = coll.get(object_id); |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
425 |
|
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
426 |
if(obj != null) { |
| 51 | 427 |
this.onRemoteObjectUpdate(field_coll, values, coll.indexOf(obj)); |
|
47
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
428 |
} |
|
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
429 |
else { |
|
48
01fb9167ad75
Correct bug on insert, delete move objects
ymh <ymh.work@gmail.com>
parents:
47
diff
changeset
|
430 |
var add_values = {}; |
|
01fb9167ad75
Correct bug on insert, delete move objects
ymh <ymh.work@gmail.com>
parents:
47
diff
changeset
|
431 |
for(var fieldname in values) { |
|
01fb9167ad75
Correct bug on insert, delete move objects
ymh <ymh.work@gmail.com>
parents:
47
diff
changeset
|
432 |
if(fieldname == "_id" || fieldname[0] !== '_' ) { |
|
01fb9167ad75
Correct bug on insert, delete move objects
ymh <ymh.work@gmail.com>
parents:
47
diff
changeset
|
433 |
add_values[fieldname] = values[fieldname]; |
|
01fb9167ad75
Correct bug on insert, delete move objects
ymh <ymh.work@gmail.com>
parents:
47
diff
changeset
|
434 |
} |
|
01fb9167ad75
Correct bug on insert, delete move objects
ymh <ymh.work@gmail.com>
parents:
47
diff
changeset
|
435 |
} |
| 51 | 436 |
switch(field_coll) { |
|
48
01fb9167ad75
Correct bug on insert, delete move objects
ymh <ymh.work@gmail.com>
parents:
47
diff
changeset
|
437 |
case "nodes": |
|
01fb9167ad75
Correct bug on insert, delete move objects
ymh <ymh.work@gmail.com>
parents:
47
diff
changeset
|
438 |
this.project.addNode(add_values, {at:position}); |
|
01fb9167ad75
Correct bug on insert, delete move objects
ymh <ymh.work@gmail.com>
parents:
47
diff
changeset
|
439 |
break; |
|
01fb9167ad75
Correct bug on insert, delete move objects
ymh <ymh.work@gmail.com>
parents:
47
diff
changeset
|
440 |
case "edges": |
|
01fb9167ad75
Correct bug on insert, delete move objects
ymh <ymh.work@gmail.com>
parents:
47
diff
changeset
|
441 |
this.project.addEdge(add_values, {at:position}); |
|
01fb9167ad75
Correct bug on insert, delete move objects
ymh <ymh.work@gmail.com>
parents:
47
diff
changeset
|
442 |
break; |
|
01fb9167ad75
Correct bug on insert, delete move objects
ymh <ymh.work@gmail.com>
parents:
47
diff
changeset
|
443 |
case "users": |
|
01fb9167ad75
Correct bug on insert, delete move objects
ymh <ymh.work@gmail.com>
parents:
47
diff
changeset
|
444 |
this.project.addUser(add_values, {at:position}); |
|
01fb9167ad75
Correct bug on insert, delete move objects
ymh <ymh.work@gmail.com>
parents:
47
diff
changeset
|
445 |
break; |
| 51 | 446 |
default: |
447 |
add_values.project = this.project; |
|
448 |
coll.push(add_values, {at:position}); |
|
449 |
break; |
|
|
48
01fb9167ad75
Correct bug on insert, delete move objects
ymh <ymh.work@gmail.com>
parents:
47
diff
changeset
|
450 |
} |
| 51 | 451 |
|
|
46
7e132e2a48ca
add most of the model and repositories
ymh <ymh.work@gmail.com>
parents:
45
diff
changeset
|
452 |
} |
|
7e132e2a48ca
add most of the model and repositories
ymh <ymh.work@gmail.com>
parents:
45
diff
changeset
|
453 |
|
|
7e132e2a48ca
add most of the model and repositories
ymh <ymh.work@gmail.com>
parents:
45
diff
changeset
|
454 |
}; |
|
7e132e2a48ca
add most of the model and repositories
ymh <ymh.work@gmail.com>
parents:
45
diff
changeset
|
455 |
|
|
7e132e2a48ca
add most of the model and repositories
ymh <ymh.work@gmail.com>
parents:
45
diff
changeset
|
456 |
/** |
|
47
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
457 |
* Called when a object attribute changes value in a remote data store. |
|
46
7e132e2a48ca
add most of the model and repositories
ymh <ymh.work@gmail.com>
parents:
45
diff
changeset
|
458 |
* Updates the attribute value of the item with the same id in the local |
|
7e132e2a48ca
add most of the model and repositories
ymh <ymh.work@gmail.com>
parents:
45
diff
changeset
|
459 |
* data store. |
|
7e132e2a48ca
add most of the model and repositories
ymh <ymh.work@gmail.com>
parents:
45
diff
changeset
|
460 |
* |
| 51 | 461 |
* @param field_coll A collection or a string for one of the project collection |
|
46
7e132e2a48ca
add most of the model and repositories
ymh <ymh.work@gmail.com>
parents:
45
diff
changeset
|
462 |
* @param value Item data sent by remote data store |
|
7e132e2a48ca
add most of the model and repositories
ymh <ymh.work@gmail.com>
parents:
45
diff
changeset
|
463 |
* @param position Which item to update. |
|
7e132e2a48ca
add most of the model and repositories
ymh <ymh.work@gmail.com>
parents:
45
diff
changeset
|
464 |
*/ |
| 51 | 465 |
proto.onRemoteObjectUpdate = function(field_coll, values, position) { |
466 |
||
467 |
console.log("Remote ", field_coll ," update values ", values, "position", position); |
|
|
47
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
468 |
|
| 51 | 469 |
var coll = null; |
470 |
if(typeof field_coll === "string") { |
|
471 |
coll = this.project.get(field_coll); |
|
472 |
} |
|
473 |
else { |
|
474 |
coll = field_coll; |
|
475 |
} |
|
|
48
01fb9167ad75
Correct bug on insert, delete move objects
ymh <ymh.work@gmail.com>
parents:
47
diff
changeset
|
476 |
|
|
47
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
477 |
var object_id = values['id']; |
|
46
7e132e2a48ca
add most of the model and repositories
ymh <ymh.work@gmail.com>
parents:
45
diff
changeset
|
478 |
|
|
47
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
479 |
if(this.project != null) { |
| 51 | 480 |
var obj = coll.get(object_id); |
|
48
01fb9167ad75
Correct bug on insert, delete move objects
ymh <ymh.work@gmail.com>
parents:
47
diff
changeset
|
481 |
if(obj != null) { |
|
01fb9167ad75
Correct bug on insert, delete move objects
ymh <ymh.work@gmail.com>
parents:
47
diff
changeset
|
482 |
var changed_val = {}; |
|
01fb9167ad75
Correct bug on insert, delete move objects
ymh <ymh.work@gmail.com>
parents:
47
diff
changeset
|
483 |
for(var fieldname in values) { |
|
01fb9167ad75
Correct bug on insert, delete move objects
ymh <ymh.work@gmail.com>
parents:
47
diff
changeset
|
484 |
if(fieldname != "id" && fieldname != "type") { |
|
01fb9167ad75
Correct bug on insert, delete move objects
ymh <ymh.work@gmail.com>
parents:
47
diff
changeset
|
485 |
changed_val[fieldname] = values[fieldname]; |
|
01fb9167ad75
Correct bug on insert, delete move objects
ymh <ymh.work@gmail.com>
parents:
47
diff
changeset
|
486 |
} |
|
01fb9167ad75
Correct bug on insert, delete move objects
ymh <ymh.work@gmail.com>
parents:
47
diff
changeset
|
487 |
} |
|
01fb9167ad75
Correct bug on insert, delete move objects
ymh <ymh.work@gmail.com>
parents:
47
diff
changeset
|
488 |
obj.set(changed_val); |
|
46
7e132e2a48ca
add most of the model and repositories
ymh <ymh.work@gmail.com>
parents:
45
diff
changeset
|
489 |
} |
|
7e132e2a48ca
add most of the model and repositories
ymh <ymh.work@gmail.com>
parents:
45
diff
changeset
|
490 |
} |
|
7e132e2a48ca
add most of the model and repositories
ymh <ymh.work@gmail.com>
parents:
45
diff
changeset
|
491 |
}; |
|
7e132e2a48ca
add most of the model and repositories
ymh <ymh.work@gmail.com>
parents:
45
diff
changeset
|
492 |
|
|
7e132e2a48ca
add most of the model and repositories
ymh <ymh.work@gmail.com>
parents:
45
diff
changeset
|
493 |
/** |
|
47
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
494 |
* Called when a object is deleted in a remote data store. |
|
46
7e132e2a48ca
add most of the model and repositories
ymh <ymh.work@gmail.com>
parents:
45
diff
changeset
|
495 |
* |
| 51 | 496 |
* @param field_coll A collection or a string for one of the project collection |
|
46
7e132e2a48ca
add most of the model and repositories
ymh <ymh.work@gmail.com>
parents:
45
diff
changeset
|
497 |
* @param position Which item to update. |
|
7e132e2a48ca
add most of the model and repositories
ymh <ymh.work@gmail.com>
parents:
45
diff
changeset
|
498 |
*/ |
| 51 | 499 |
proto.onRemoteObjectDelete = function(field_coll, position) { |
500 |
console.log("Remote ", field_coll," delete position", position); |
|
501 |
var coll = null; |
|
502 |
if(typeof field_coll === "string") { |
|
503 |
coll = this.project.get(field); |
|
504 |
} |
|
505 |
else { |
|
506 |
coll = field_coll; |
|
507 |
} |
|
508 |
||
509 |
coll.remove(coll.at(position)); |
|
|
46
7e132e2a48ca
add most of the model and repositories
ymh <ymh.work@gmail.com>
parents:
45
diff
changeset
|
510 |
}; |
|
47
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
511 |
|
| 45 | 512 |
|
|
47
267d67791e05
first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
46
diff
changeset
|
513 |
var app = new CoRenkan(); |
| 45 | 514 |
dojo.ready(function() { |
515 |
app.init(); |
|
516 |
}); |
|
517 |
|
|
518 |
|
|
519 |
return { |
|
520 |
app: app |
|
521 |
}; |
|
522 |
}); |