| author | ymh <ymh.work@gmail.com> |
| Sat, 25 Apr 2015 04:13:53 +0200 | |
| changeset 433 | e457ec945e50 |
| parent 414 | 276042cb477c |
| child 435 | e529b633c339 |
| 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"), |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
103 |
shape : this.get("shape") |
| 27 | 104 |
}; |
|
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
|
105 |
} |
| 23 | 106 |
}); |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
282
diff
changeset
|
107 |
|
| 23 | 108 |
// EDGE |
109 |
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
|
110 |
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
|
111 |
relations : [ { |
|
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 : 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
|
113 |
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
|
114 |
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
|
115 |
}, { |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
116 |
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
|
117 |
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
|
118 |
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
|
119 |
}, { |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
120 |
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
|
121 |
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
|
122 |
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
|
123 |
} ], |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
124 |
prepare : function(options) { |
| 195 | 125 |
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
|
126 |
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
|
127 |
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
|
128 |
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
|
129 |
options.from); |
| 23 | 130 |
this.addReference(options, "to", project.get("nodes"), options.to); |
131 |
return options; |
|
| 24 | 132 |
}, |
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
133 |
toJSON : function() { |
| 24 | 134 |
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
|
135 |
_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
|
136 |
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
|
137 |
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
|
138 |
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
|
139 |
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
|
140 |
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
|
141 |
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
|
142 |
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
|
143 |
.get("_id") : null |
| 27 | 144 |
}; |
|
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
|
145 |
} |
| 23 | 146 |
}); |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
282
diff
changeset
|
147 |
|
| 281 | 148 |
// View |
149 |
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
|
150 |
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
|
151 |
relations : [ { |
|
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 : 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
|
153 |
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
|
154 |
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
|
155 |
} ], |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
156 |
prepare : function(options) { |
| 299 | 157 |
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
|
158 |
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
|
159 |
options.created_by, project.current_user); |
| 299 | 160 |
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
|
161 |
if (typeof options.offset !== "undefined") { |
| 299 | 162 |
var offset = {}; |
163 |
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
|
164 |
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
|
165 |
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
|
166 |
: options.offset[0]; |
| 299 | 167 |
} |
168 |
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
|
169 |
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
|
170 |
offset.y = options.offset.y; |
| 299 | 171 |
} |
172 |
options.offset = offset; |
|
173 |
} |
|
174 |
return options; |
|
175 |
}, |
|
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
176 |
toJSON : function() { |
| 282 | 177 |
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
|
178 |
_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
|
179 |
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
|
180 |
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
|
181 |
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
|
182 |
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
|
183 |
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
|
184 |
.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
|
185 |
// Don't need project id |
| 282 | 186 |
}; |
187 |
} |
|
| 281 | 188 |
}); |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
282
diff
changeset
|
189 |
|
| 23 | 190 |
// PROJECT |
191 |
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
|
192 |
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
|
193 |
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
|
194 |
relations : [ { |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
195 |
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
|
196 |
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
|
197 |
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
|
198 |
reverseRelation : { |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
199 |
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
|
200 |
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
|
201 |
} |
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
202 |
}, { |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
203 |
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
|
204 |
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
|
205 |
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
|
206 |
reverseRelation : { |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
207 |
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
|
208 |
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
|
209 |
} |
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
210 |
}, { |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
211 |
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
|
212 |
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
|
213 |
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
|
214 |
reverseRelation : { |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
215 |
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
|
216 |
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
|
217 |
} |
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
218 |
}, { |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
219 |
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
|
220 |
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
|
221 |
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
|
222 |
reverseRelation : { |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
223 |
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
|
224 |
includeInJSON : '_id' |
| 281 | 225 |
} |
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
226 |
} ], |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
227 |
addUser : function(_props, _options) { |
| 23 | 228 |
_props.project = this; |
| 56 | 229 |
var _user = User.findOrCreate(_props); |
230 |
this.get("users").push(_user, _options); |
|
| 23 | 231 |
return _user; |
232 |
}, |
|
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
233 |
addNode : function(_props, _options) { |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
282
diff
changeset
|
234 |
_props.project = this; |
| 56 | 235 |
var _node = Node.findOrCreate(_props); |
236 |
this.get("nodes").push(_node, _options); |
|
| 23 | 237 |
return _node; |
238 |
}, |
|
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
239 |
addEdge : function(_props, _options) { |
| 23 | 240 |
_props.project = this; |
| 56 | 241 |
var _edge = Edge.findOrCreate(_props); |
242 |
this.get("edges").push(_edge, _options); |
|
| 23 | 243 |
return _edge; |
244 |
}, |
|
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
245 |
addView : function(_props, _options) { |
| 281 | 246 |
_props.project = this; |
247 |
// TODO: check if need to replace with create only |
|
248 |
var _view = View.findOrCreate(_props); |
|
249 |
// TODO: Should we remember only one view? |
|
250 |
this.get("views").push(_view, _options); |
|
251 |
return _view; |
|
252 |
}, |
|
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
253 |
removeNode : function(_model) { |
| 23 | 254 |
this.get("nodes").remove(_model); |
255 |
}, |
|
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
256 |
removeEdge : function(_model) { |
| 23 | 257 |
this.get("edges").remove(_model); |
258 |
}, |
|
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
259 |
validate : function(options) { |
| 24 | 260 |
var _project = this; |
| 433 | 261 |
_.each( |
262 |
[].concat(options.users, options.nodes, options.edges,options.views), |
|
263 |
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
|
264 |
if (_item) { |
|
212
ee7b5831d382
correct model to accept null objects ?
ymh <ymh.work@gmail.com>
parents:
211
diff
changeset
|
265 |
_item.project = _project; |
|
ee7b5831d382
correct model to accept null objects ?
ymh <ymh.work@gmail.com>
parents:
211
diff
changeset
|
266 |
} |
| 433 | 267 |
} |
268 |
); |
|
| 24 | 269 |
}, |
| 23 | 270 |
// 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
|
271 |
initialize : function() { |
| 23 | 272 |
var _this = this; |
273 |
this.on("remove:nodes", function(_node) { |
|
274 |
_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
|
275 |
_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
|
276 |
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
|
277 |
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
|
278 |
_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
|
279 |
})); |
| 23 | 280 |
}); |
|
362
8f33cbeb4f32
Add blacklist and override project.toJSON to exclude attributes in blackList
rougeronj
parents:
332
diff
changeset
|
281 |
}, |
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
282 |
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
|
283 |
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
|
284 |
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
|
285 |
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
|
286 |
(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
|
287 |
(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
|
288 |
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
|
289 |
} |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
290 |
} |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
291 |
return _.omit(json, this.blacklist); |
| 23 | 292 |
} |
293 |
}); |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
282
diff
changeset
|
294 |
|
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
295 |
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
|
296 |
.extend({ |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
297 |
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
|
298 |
idAttribute : "_id", |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
282
diff
changeset
|
299 |
|
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
300 |
constructor : function(options) { |
|
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 |
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
|
303 |
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
|
304 |
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
|
305 |
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
|
306 |
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
|
307 |
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
|
308 |
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
|
309 |
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
|
310 |
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
|
311 |
|
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
312 |
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
|
313 |
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
|
314 |
} |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
315 |
} |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
316 |
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
|
317 |
}, |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
282
diff
changeset
|
318 |
|
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
319 |
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
|
320 |
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
|
321 |
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
|
322 |
} |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
323 |
}, |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
282
diff
changeset
|
324 |
|
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
325 |
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
|
326 |
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
|
327 |
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
|
328 |
}, |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
282
diff
changeset
|
329 |
|
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
330 |
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
|
331 |
return { |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
332 |
_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
|
333 |
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
|
334 |
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
|
335 |
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
|
336 |
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
|
337 |
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
|
338 |
"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
|
339 |
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
|
340 |
}; |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
362
diff
changeset
|
341 |
} |
|
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 |
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
|
345 |
model : RosterUser |
| 56 | 346 |
}); |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
282
diff
changeset
|
347 |
|
| 23 | 348 |
}).call(window); |