| author | ymh <ymh.work@gmail.com> |
| Mon, 27 Apr 2015 17:22:46 +0200 | |
| changeset 435 | e529b633c339 |
| parent 433 | e457ec945e50 |
| child 443 | 4c7ab16e5845 |
| child 449 | aae670254c49 |
| permissions | -rw-r--r-- |
| 23 | 1 |
(function() { |
| 195 | 2 |
"use strict"; |
| 23 | 3 |
var root = this; |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
282
diff
changeset
|
4 |
|
| 23 | 5 |
var Backbone = root.Backbone; |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
282
diff
changeset
|
6 |
|
| 23 | 7 |
var Models = root.Rkns.Models = {}; |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
282
diff
changeset
|
8 |
|
| 23 | 9 |
Models.getUID = function(obj) { |
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
10 |
var guid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
11 |
function(c) { |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
12 |
var r = Math.random() * 16 | 0, v = c === 'x' ? r |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
13 |
: (r & 0x3 | 0x8); |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
14 |
return v.toString(16); |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
15 |
}); |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
16 |
if (typeof obj !== 'undefined') { |
| 298 | 17 |
return obj.type + "-" + guid; |
18 |
} |
|
19 |
else { |
|
20 |
return guid; |
|
21 |
} |
|
| 23 | 22 |
}; |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
282
diff
changeset
|
23 |
|
| 23 | 24 |
var RenkanModel = Backbone.RelationalModel.extend({ |
25 |
idAttribute : "_id", |
|
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
26 |
constructor : function(options) { |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
282
diff
changeset
|
27 |
|
| 23 | 28 |
if (typeof options !== "undefined") { |
| 27 | 29 |
options._id = options._id || options.id || Models.getUID(this); |
| 68 | 30 |
options.title = options.title || ""; |
| 23 | 31 |
options.description = options.description || ""; |
32 |
options.uri = options.uri || ""; |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
282
diff
changeset
|
33 |
|
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
34 |
if (typeof this.prepare === "function") { |
| 23 | 35 |
options = this.prepare(options); |
36 |
} |
|
37 |
} |
|
38 |
Backbone.RelationalModel.prototype.constructor.call(this, options); |
|
39 |
}, |
|
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
40 |
validate : function() { |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
41 |
if (!this.type) { |
| 23 | 42 |
return "object has no type"; |
43 |
} |
|
44 |
}, |
|
45 |
addReference : function(_options, _propName, _list, _id, _default) { |
|
46 |
var _element = _list.get(_id); |
|
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
47 |
if (typeof _element === "undefined" && |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
48 |
typeof _default !== "undefined") { |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
49 |
_options[_propName] = _default; |
| 23 | 50 |
} |
51 |
else { |
|
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
52 |
_options[_propName] = _element; |
| 23 | 53 |
} |
54 |
} |
|
55 |
}); |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
282
diff
changeset
|
56 |
|
| 23 | 57 |
// USER |
58 |
var User = Models.User = RenkanModel.extend({ |
|
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
59 |
type : "user", |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
60 |
prepare : function(options) { |
| 23 | 61 |
options.color = options.color || "#666666"; |
62 |
return options; |
|
| 24 | 63 |
}, |
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
64 |
toJSON : function() { |
| 24 | 65 |
return { |
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
66 |
_id : this.get("_id"), |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
67 |
title : this.get("title"), |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
68 |
uri : this.get("uri"), |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
69 |
description : this.get("description"), |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
70 |
color : this.get("color") |
| 27 | 71 |
}; |
|
211
d87f6bdee43d
upgrade libs + add no minified versions of libs + improve build + allow disabling zoom on scroll
ymh <ymh.work@gmail.com>
parents:
195
diff
changeset
|
72 |
} |
| 23 | 73 |
}); |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
282
diff
changeset
|
74 |
|
| 23 | 75 |
// NODE |
76 |
var Node = Models.Node = RenkanModel.extend({ |
|
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
77 |
type : "node", |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
78 |
relations : [ { |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
79 |
type : Backbone.HasOne, |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
80 |
key : "created_by", |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
81 |
relatedModel : User |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
82 |
} ], |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
83 |
prepare : function(options) { |
| 195 | 84 |
var project = options.project; |
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
85 |
this.addReference(options, "created_by", project.get("users"), |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
86 |
options.created_by, project.current_user); |
| 23 | 87 |
options.description = options.description || ""; |
88 |
return options; |
|
| 24 | 89 |
}, |
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
90 |
toJSON : function() { |
| 24 | 91 |
return { |
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
92 |
_id : this.get("_id"), |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
93 |
title : this.get("title"), |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
94 |
uri : this.get("uri"), |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
95 |
description : this.get("description"), |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
96 |
position : this.get("position"), |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
97 |
image : this.get("image"), |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
98 |
color : this.get("color"), |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
99 |
created_by : this.get("created_by") ? this.get("created_by") |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
100 |
.get("_id") : null, |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
101 |
size : this.get("size"), |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
102 |
clip_path : this.get("clip_path"), |
|
435
e529b633c339
Add shape management, correction on shape manip[ulation on the client, correct 404 error on space creation, increment version
ymh <ymh.work@gmail.com>
parents:
433
diff
changeset
|
103 |
shape : this.get("shape"), |
|
e529b633c339
Add shape management, correction on shape manip[ulation on the client, correct 404 error on space creation, increment version
ymh <ymh.work@gmail.com>
parents:
433
diff
changeset
|
104 |
type : this.get("type"), |
|
e529b633c339
Add shape management, correction on shape manip[ulation on the client, correct 404 error on space creation, increment version
ymh <ymh.work@gmail.com>
parents:
433
diff
changeset
|
105 |
hidden : this.get("hidden") |
| 27 | 106 |
}; |
|
211
d87f6bdee43d
upgrade libs + add no minified versions of libs + improve build + allow disabling zoom on scroll
ymh <ymh.work@gmail.com>
parents:
195
diff
changeset
|
107 |
} |
| 23 | 108 |
}); |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
282
diff
changeset
|
109 |
|
| 23 | 110 |
// EDGE |
111 |
var Edge = Models.Edge = RenkanModel.extend({ |
|
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
112 |
type : "edge", |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
113 |
relations : [ { |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
114 |
type : Backbone.HasOne, |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
115 |
key : "created_by", |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
116 |
relatedModel : User |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
117 |
}, { |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
118 |
type : Backbone.HasOne, |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
119 |
key : "from", |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
120 |
relatedModel : Node |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
121 |
}, { |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
122 |
type : Backbone.HasOne, |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
123 |
key : "to", |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
124 |
relatedModel : Node |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
125 |
} ], |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
126 |
prepare : function(options) { |
| 195 | 127 |
var project = options.project; |
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
128 |
this.addReference(options, "created_by", project.get("users"), |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
129 |
options.created_by, project.current_user); |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
130 |
this.addReference(options, "from", project.get("nodes"), |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
131 |
options.from); |
| 23 | 132 |
this.addReference(options, "to", project.get("nodes"), options.to); |
133 |
return options; |
|
| 24 | 134 |
}, |
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
135 |
toJSON : function() { |
| 24 | 136 |
return { |
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
137 |
_id : this.get("_id"), |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
138 |
title : this.get("title"), |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
139 |
uri : this.get("uri"), |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
140 |
description : this.get("description"), |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
141 |
from : this.get("from") ? this.get("from").get("_id") : null, |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
142 |
to : this.get("to") ? this.get("to").get("_id") : null, |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
143 |
color : this.get("color"), |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
144 |
created_by : this.get("created_by") ? this.get("created_by") |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
145 |
.get("_id") : null |
| 27 | 146 |
}; |
|
211
d87f6bdee43d
upgrade libs + add no minified versions of libs + improve build + allow disabling zoom on scroll
ymh <ymh.work@gmail.com>
parents:
195
diff
changeset
|
147 |
} |
| 23 | 148 |
}); |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
282
diff
changeset
|
149 |
|
| 281 | 150 |
// View |
151 |
var View = Models.View = RenkanModel.extend({ |
|
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
152 |
type : "view", |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
153 |
relations : [ { |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
154 |
type : Backbone.HasOne, |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
155 |
key : "created_by", |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
156 |
relatedModel : User |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
157 |
} ], |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
158 |
prepare : function(options) { |
| 299 | 159 |
var project = options.project; |
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
160 |
this.addReference(options, "created_by", project.get("users"), |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
161 |
options.created_by, project.current_user); |
| 299 | 162 |
options.description = options.description || ""; |
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
163 |
if (typeof options.offset !== "undefined") { |
| 299 | 164 |
var offset = {}; |
165 |
if (Array.isArray(options.offset)) { |
|
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
166 |
offset.x = options.offset[0]; |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
167 |
offset.y = options.offset.length > 1 ? options.offset[1] |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
168 |
: options.offset[0]; |
| 299 | 169 |
} |
170 |
else if (options.offset.x != null) { |
|
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
171 |
offset.x = options.offset.x; |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
172 |
offset.y = options.offset.y; |
| 299 | 173 |
} |
174 |
options.offset = offset; |
|
175 |
} |
|
176 |
return options; |
|
177 |
}, |
|
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
178 |
toJSON : function() { |
| 282 | 179 |
return { |
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
180 |
_id : this.get("_id"), |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
181 |
zoom_level : this.get("zoom_level"), |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
182 |
offset : this.get("offset"), |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
183 |
title : this.get("title"), |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
184 |
description : this.get("description"), |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
185 |
created_by : this.get("created_by") ? this.get("created_by") |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
186 |
.get("_id") : null |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
187 |
// Don't need project id |
| 282 | 188 |
}; |
189 |
} |
|
| 281 | 190 |
}); |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
282
diff
changeset
|
191 |
|
| 23 | 192 |
// PROJECT |
193 |
var Project = Models.Project = RenkanModel.extend({ |
|
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
194 |
type : "project", |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
195 |
blacklist : [ 'save_status', ], |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
196 |
relations : [ { |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
197 |
type : Backbone.HasMany, |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
198 |
key : "users", |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
199 |
relatedModel : User, |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
200 |
reverseRelation : { |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
201 |
key : 'project', |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
202 |
includeInJSON : '_id' |
|
211
d87f6bdee43d
upgrade libs + add no minified versions of libs + improve build + allow disabling zoom on scroll
ymh <ymh.work@gmail.com>
parents:
195
diff
changeset
|
203 |
} |
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
204 |
}, { |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
205 |
type : Backbone.HasMany, |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
206 |
key : "nodes", |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
207 |
relatedModel : Node, |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
208 |
reverseRelation : { |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
209 |
key : 'project', |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
210 |
includeInJSON : '_id' |
|
211
d87f6bdee43d
upgrade libs + add no minified versions of libs + improve build + allow disabling zoom on scroll
ymh <ymh.work@gmail.com>
parents:
195
diff
changeset
|
211 |
} |
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
212 |
}, { |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
213 |
type : Backbone.HasMany, |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
214 |
key : "edges", |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
215 |
relatedModel : Edge, |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
216 |
reverseRelation : { |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
217 |
key : 'project', |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
218 |
includeInJSON : '_id' |
|
211
d87f6bdee43d
upgrade libs + add no minified versions of libs + improve build + allow disabling zoom on scroll
ymh <ymh.work@gmail.com>
parents:
195
diff
changeset
|
219 |
} |
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
220 |
}, { |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
221 |
type : Backbone.HasMany, |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
222 |
key : "views", |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
223 |
relatedModel : View, |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
224 |
reverseRelation : { |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
225 |
key : 'project', |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
226 |
includeInJSON : '_id' |
| 281 | 227 |
} |
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
228 |
} ], |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
229 |
addUser : function(_props, _options) { |
| 23 | 230 |
_props.project = this; |
| 56 | 231 |
var _user = User.findOrCreate(_props); |
232 |
this.get("users").push(_user, _options); |
|
| 23 | 233 |
return _user; |
234 |
}, |
|
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
235 |
addNode : function(_props, _options) { |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
282
diff
changeset
|
236 |
_props.project = this; |
| 56 | 237 |
var _node = Node.findOrCreate(_props); |
238 |
this.get("nodes").push(_node, _options); |
|
| 23 | 239 |
return _node; |
240 |
}, |
|
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
241 |
addEdge : function(_props, _options) { |
| 23 | 242 |
_props.project = this; |
| 56 | 243 |
var _edge = Edge.findOrCreate(_props); |
244 |
this.get("edges").push(_edge, _options); |
|
| 23 | 245 |
return _edge; |
246 |
}, |
|
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
247 |
addView : function(_props, _options) { |
| 281 | 248 |
_props.project = this; |
249 |
// TODO: check if need to replace with create only |
|
250 |
var _view = View.findOrCreate(_props); |
|
251 |
// TODO: Should we remember only one view? |
|
252 |
this.get("views").push(_view, _options); |
|
253 |
return _view; |
|
254 |
}, |
|
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
255 |
removeNode : function(_model) { |
| 23 | 256 |
this.get("nodes").remove(_model); |
257 |
}, |
|
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
258 |
removeEdge : function(_model) { |
| 23 | 259 |
this.get("edges").remove(_model); |
260 |
}, |
|
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
261 |
validate : function(options) { |
| 24 | 262 |
var _project = this; |
| 433 | 263 |
_.each( |
264 |
[].concat(options.users, options.nodes, options.edges,options.views), |
|
265 |
function(_item) { |
|
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
266 |
if (_item) { |
|
212
ee7b5831d382
correct model to accept null objects ?
ymh <ymh.work@gmail.com>
parents:
211
diff
changeset
|
267 |
_item.project = _project; |
|
ee7b5831d382
correct model to accept null objects ?
ymh <ymh.work@gmail.com>
parents:
211
diff
changeset
|
268 |
} |
| 433 | 269 |
} |
270 |
); |
|
| 24 | 271 |
}, |
| 23 | 272 |
// Add event handler to remove edges when a node is removed |
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
273 |
initialize : function() { |
| 23 | 274 |
var _this = this; |
275 |
this.on("remove:nodes", function(_node) { |
|
276 |
_this.get("edges").remove( |
|
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
277 |
_this.get("edges").filter( |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
278 |
function(_edge) { |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
279 |
return _edge.get("from") === _node || |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
280 |
_edge.get("to") === _node; |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
281 |
})); |
| 23 | 282 |
}); |
|
362
8f33cbeb4f32
Add blacklist and override project.toJSON to exclude attributes in blackList
rougeronj
parents:
332
diff
changeset
|
283 |
}, |
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
284 |
toJSON : function() { |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
285 |
var json = _.clone(this.attributes); |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
286 |
for ( var attr in json) { |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
287 |
if ((json[attr] instanceof Backbone.Model) || |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
288 |
(json[attr] instanceof Backbone.Collection) || |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
289 |
(json[attr] instanceof RenkanModel)) { |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
290 |
json[attr] = json[attr].toJSON(); |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
291 |
} |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
292 |
} |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
293 |
return _.omit(json, this.blacklist); |
| 23 | 294 |
} |
295 |
}); |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
282
diff
changeset
|
296 |
|
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
297 |
var RosterUser = Models.RosterUser = Backbone.Model |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
298 |
.extend({ |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
299 |
type : "roster_user", |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
300 |
idAttribute : "_id", |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
282
diff
changeset
|
301 |
|
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
302 |
constructor : function(options) { |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
282
diff
changeset
|
303 |
|
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
304 |
if (typeof options !== "undefined") { |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
305 |
options._id = options._id || |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
306 |
options.id || |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
307 |
Models.getUID(this); |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
308 |
options.title = options.title || "(untitled " + this.type + ")"; |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
309 |
options.description = options.description || ""; |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
310 |
options.uri = options.uri || ""; |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
311 |
options.project = options.project || null; |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
312 |
options.site_id = options.site_id || 0; |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
282
diff
changeset
|
313 |
|
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
314 |
if (typeof this.prepare === "function") { |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
315 |
options = this.prepare(options); |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
316 |
} |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
317 |
} |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
318 |
Backbone.Model.prototype.constructor.call(this, options); |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
319 |
}, |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
282
diff
changeset
|
320 |
|
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
321 |
validate : function() { |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
322 |
if (!this.type) { |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
323 |
return "object has no type"; |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
324 |
} |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
325 |
}, |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
282
diff
changeset
|
326 |
|
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
327 |
prepare : function(options) { |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
328 |
options.color = options.color || "#666666"; |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
329 |
return options; |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
330 |
}, |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
282
diff
changeset
|
331 |
|
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
332 |
toJSON : function() { |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
333 |
return { |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
334 |
_id : this.get("_id"), |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
335 |
title : this.get("title"), |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
336 |
uri : this.get("uri"), |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
337 |
description : this.get("description"), |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
338 |
color : this.get("color"), |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
339 |
project : (this.get("project") != null) ? this.get( |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
340 |
"project").get("id") : null, |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
341 |
site_id : this.get("site_id") |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
342 |
}; |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
343 |
} |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
344 |
}); |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
345 |
|
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
346 |
var UsersList = Models.UsersList = Backbone.Collection.extend({ |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
347 |
model : RosterUser |
| 56 | 348 |
}); |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
282
diff
changeset
|
349 |
|
| 23 | 350 |
}).call(window); |