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