165 key: 'project', |
165 key: 'project', |
166 includeInJSON: '_id' |
166 includeInJSON: '_id' |
167 }, |
167 }, |
168 } |
168 } |
169 ], |
169 ], |
170 addUser: function(_props) { |
170 addUser: function(_props, _options) { |
171 _props.project = this; |
171 _props.project = this; |
172 var _user = new User(_props); |
172 var _user = User.findOrCreate(_props); |
173 this.get("users").push(_user); |
173 this.get("users").push(_user, _options); |
174 return _user; |
174 return _user; |
175 }, |
175 }, |
176 addNode: function(_props) { |
176 addNode: function(_props, _options) { |
|
177 _props.project = this; |
|
178 var _node = Node.findOrCreate(_props); |
|
179 this.get("nodes").push(_node, _options); |
|
180 return _node; |
|
181 }, |
|
182 addEdge: function(_props, _options) { |
177 _props.project = this; |
183 _props.project = this; |
178 var _node = new Node(_props); |
184 var _edge = Edge.findOrCreate(_props); |
179 this.get("nodes").push(_node); |
185 this.get("edges").push(_edge, _options); |
180 return _node; |
|
181 }, |
|
182 addEdge: function(_props) { |
|
183 _props.project = this; |
|
184 var _edge = new Edge(_props); |
|
185 this.get("edges").push(_edge); |
|
186 return _edge; |
186 return _edge; |
187 }, |
187 }, |
188 removeNode: function(_model) { |
188 removeNode: function(_model) { |
189 this.get("nodes").remove(_model); |
189 this.get("nodes").remove(_model); |
190 }, |
190 }, |
214 ); |
214 ); |
215 }); |
215 }); |
216 } |
216 } |
217 }); |
217 }); |
218 |
218 |
|
219 var RosterUser = Models.RosterUser = Backbone.Model.extend({ |
|
220 type: "roster_user", |
|
221 idAttribute : "_id", |
|
222 |
|
223 constructor: function(options) { |
|
224 |
|
225 if (typeof options !== "undefined") { |
|
226 options._id = options._id || options.id || Models.getUID(this); |
|
227 options.title = options.title || "(untitled " + this.type + ")"; |
|
228 options.description = options.description || ""; |
|
229 options.uri = options.uri || ""; |
|
230 options.project = options.project || null; |
|
231 options.site_id = options.site_id || 0; |
|
232 |
|
233 if(typeof this.prepare === "function") { |
|
234 options = this.prepare(options); |
|
235 } |
|
236 } |
|
237 Backbone.Model.prototype.constructor.call(this, options); |
|
238 }, |
|
239 |
|
240 validate: function() { |
|
241 if(!this.type) { |
|
242 return "object has no type"; |
|
243 } |
|
244 }, |
|
245 |
|
246 prepare: function(options) { |
|
247 options.color = options.color || "#666666"; |
|
248 return options; |
|
249 }, |
|
250 |
|
251 toJSON: function() { |
|
252 return { |
|
253 _id: this.get("_id"), |
|
254 title: this.get("title"), |
|
255 uri: this.get("uri"), |
|
256 description: this.get("description"), |
|
257 color: this.get("color"), |
|
258 project: (this.get("project") != null)?this.get("project").get("id"):null, |
|
259 site_id: this.get("site_id") |
|
260 }; |
|
261 }, |
|
262 }); |
|
263 |
|
264 var UsersList = Models.UsersList = Backbone.Collection.extend({ |
|
265 model: RosterUser |
|
266 }); |
|
267 |
219 |
268 |
220 }).call(window); |
269 }).call(window); |
221 |
270 |