|
12
|
1 |
/* TODO: Separate Project-specific data from Source */ |
|
|
2 |
|
|
|
3 |
/* model.js is where data is stored in a standard form, whatever the serializer */ |
|
23
|
4 |
IriSP.Model = (function (ns) { |
|
12
|
5 |
|
|
|
6 |
var Model = { |
|
|
7 |
_SOURCE_STATUS_EMPTY : 0, |
|
|
8 |
_SOURCE_STATUS_WAITING : 1, |
|
|
9 |
_SOURCE_STATUS_READY : 2, |
|
|
10 |
_ID_AUTO_INCREMENT : 0, |
|
|
11 |
_ID_BASE : (function(_d) { |
|
|
12 |
function pad(n){return n<10 ? '0'+n : n} |
|
|
13 |
function fillrand(n) { |
|
|
14 |
var _res = '' |
|
|
15 |
for (var i=0; i<n; i++) { |
|
|
16 |
_res += Math.floor(16*Math.random()).toString(16); |
|
|
17 |
} |
|
|
18 |
return _res; |
|
|
19 |
} |
|
|
20 |
return _d.getUTCFullYear() + '-' |
|
|
21 |
+ pad(_d.getUTCMonth()+1) + '-' |
|
|
22 |
+ pad(_d.getUTCDate()) + '-' |
|
|
23 |
+ fillrand(16); |
|
|
24 |
})(new Date()), |
|
|
25 |
getUID : function() { |
|
|
26 |
var _n = (++this._ID_AUTO_INCREMENT).toString(); |
|
|
27 |
while (_n.length < 4) { |
|
|
28 |
_n = '0' + _n |
|
|
29 |
} |
|
|
30 |
return "autoid-" + this._ID_BASE + '-' + _n; |
|
|
31 |
}, |
|
23
|
32 |
regexpFromTextOrArray : function(_textOrArray, _testOnly, _iexact) { |
|
|
33 |
var _testOnly = _testOnly || false, |
|
|
34 |
_iexact = _iexact || false; |
|
12
|
35 |
function escapeText(_text) { |
|
|
36 |
return _text.replace(/([\\\*\+\?\|\{\[\}\]\(\)\^\$\.\#\/])/gm, '\\$1'); |
|
|
37 |
} |
|
|
38 |
var _source = |
|
|
39 |
typeof _textOrArray === "string" |
|
|
40 |
? escapeText(_textOrArray) |
|
23
|
41 |
: ns._(_textOrArray).map(escapeText).join("|"), |
|
|
42 |
_flags = 'im'; |
|
|
43 |
if (!_testOnly) { |
|
|
44 |
_source = '(' + _source + ')'; |
|
|
45 |
_flags += 'g'; |
|
12
|
46 |
} |
|
23
|
47 |
if (_iexact) { |
|
|
48 |
_source = '^' + _source + '$'; |
|
|
49 |
} |
|
|
50 |
return new RegExp( _source, _flags); |
|
12
|
51 |
}, |
|
|
52 |
isoToDate : function(_str) { |
|
|
53 |
// http://delete.me.uk/2005/03/iso8601.html |
|
|
54 |
var regexp = "([0-9]{4})(-([0-9]{2})(-([0-9]{2})(T([0-9]{2}):([0-9]{2})(:([0-9]{2})(\.([0-9]+))?)?(Z|(([-+])([0-9]{2}):([0-9]{2})))?)?)?)?"; |
|
|
55 |
var d = _str.match(new RegExp(regexp)); |
|
|
56 |
|
|
|
57 |
var offset = 0; |
|
|
58 |
var date = new Date(d[1], 0, 1); |
|
|
59 |
|
|
|
60 |
if (d[3]) { date.setMonth(d[3] - 1); } |
|
|
61 |
if (d[5]) { date.setDate(d[5]); } |
|
|
62 |
if (d[7]) { date.setHours(d[7]); } |
|
|
63 |
if (d[8]) { date.setMinutes(d[8]); } |
|
|
64 |
if (d[10]) { date.setSeconds(d[10]); } |
|
|
65 |
if (d[12]) { date.setMilliseconds(Number("0." + d[12]) * 1000); } |
|
|
66 |
if (d[14]) { |
|
|
67 |
offset = (Number(d[16]) * 60) + Number(d[17]); |
|
|
68 |
offset *= ((d[15] == '-') ? 1 : -1); |
|
|
69 |
} |
|
|
70 |
|
|
|
71 |
offset -= date.getTimezoneOffset(); |
|
|
72 |
time = (Number(date) + (offset * 60 * 1000)); |
|
|
73 |
var _res = new Date(); |
|
|
74 |
_res.setTime(Number(time)); |
|
|
75 |
return _res; |
|
|
76 |
}, |
|
|
77 |
dateToIso : function(d) { |
|
|
78 |
function pad(n){return n<10 ? '0'+n : n} |
|
|
79 |
return d.getUTCFullYear()+'-' |
|
|
80 |
+ pad(d.getUTCMonth()+1)+'-' |
|
|
81 |
+ pad(d.getUTCDate())+'T' |
|
|
82 |
+ pad(d.getUTCHours())+':' |
|
|
83 |
+ pad(d.getUTCMinutes())+':' |
|
|
84 |
+ pad(d.getUTCSeconds())+'Z' |
|
|
85 |
} |
|
|
86 |
} |
|
|
87 |
|
|
|
88 |
/* |
|
|
89 |
* Model.List is a class for a list of elements (e.g. annotations, medias, etc. that each have a distinct ID) |
|
|
90 |
*/ |
|
|
91 |
Model.List = function(_directory) { |
|
|
92 |
Array.call(this); |
|
|
93 |
this.directory = _directory; |
|
|
94 |
this.idIndex = []; |
|
|
95 |
this.__events = {}; |
|
|
96 |
if (typeof _directory == "undefined") { |
|
|
97 |
console.trace(); |
|
|
98 |
throw "Error : new Model.List(directory): directory is undefined"; |
|
|
99 |
} |
|
|
100 |
} |
|
|
101 |
|
|
|
102 |
Model.List.prototype = new Array(); |
|
|
103 |
|
|
|
104 |
Model.List.prototype.hasId = function(_id) { |
|
|
105 |
return ns._(this.idIndex).include(_id); |
|
|
106 |
} |
|
|
107 |
|
|
|
108 |
/* On recent browsers, forEach and map are defined and do what we want. |
|
|
109 |
* Otherwise, we'll use the Underscore.js functions |
|
|
110 |
*/ |
|
|
111 |
if (typeof Array.prototype.forEach === "undefined") { |
|
|
112 |
Model.List.prototype.forEach = function(_callback) { |
|
|
113 |
var _this = this; |
|
|
114 |
ns._(this).forEach(function(_value, _key) { |
|
|
115 |
_callback(_value, _key, _this); |
|
|
116 |
}); |
|
|
117 |
} |
|
|
118 |
} |
|
|
119 |
|
|
|
120 |
if (typeof Array.prototype.map === "undefined") { |
|
|
121 |
Model.List.prototype.map = function(_callback) { |
|
|
122 |
var _this = this; |
|
|
123 |
return ns._(this).map(function(_value, _key) { |
|
|
124 |
return _callback(_value, _key, _this); |
|
|
125 |
}); |
|
|
126 |
} |
|
|
127 |
} |
|
|
128 |
|
|
|
129 |
Model.List.prototype.pluck = function(_key) { |
|
|
130 |
return this.map(function(_value) { |
|
|
131 |
return _value[_key]; |
|
|
132 |
}); |
|
|
133 |
} |
|
|
134 |
|
|
|
135 |
/* We override Array's filter function because it doesn't return an Model.List |
|
|
136 |
*/ |
|
|
137 |
Model.List.prototype.filter = function(_callback) { |
|
|
138 |
var _this = this, |
|
|
139 |
_res = new Model.List(this.directory); |
|
|
140 |
_res.addElements(ns._(this).filter(function(_value, _key) { |
|
|
141 |
return _callback(_value, _key, _this); |
|
|
142 |
})); |
|
|
143 |
return _res; |
|
|
144 |
} |
|
|
145 |
|
|
|
146 |
Model.List.prototype.slice = function(_start, _end) { |
|
|
147 |
var _res = new Model.List(this.directory); |
|
|
148 |
_res.addElements(Array.prototype.slice.call(this, _start, _end)); |
|
|
149 |
return _res; |
|
|
150 |
} |
|
|
151 |
|
|
|
152 |
Model.List.prototype.splice = function(_start, _end) { |
|
|
153 |
var _res = new Model.List(this.directory); |
|
|
154 |
_res.addElements(Array.prototype.splice.call(this, _start, _end)); |
|
|
155 |
this.idIndex.splice(_start, _end); |
|
|
156 |
return _res; |
|
|
157 |
} |
|
|
158 |
|
|
|
159 |
/* Array has a sort function, but it's not as interesting as Underscore.js's sortBy |
|
|
160 |
* and won't return a new Model.List |
|
|
161 |
*/ |
|
|
162 |
Model.List.prototype.sortBy = function(_callback) { |
|
|
163 |
var _this = this, |
|
|
164 |
_res = new Model.List(this.directory); |
|
|
165 |
_res.addElements(ns._(this).sortBy(function(_value, _key) { |
|
|
166 |
return _callback(_value, _key, _this); |
|
|
167 |
})); |
|
|
168 |
return _res; |
|
|
169 |
} |
|
|
170 |
|
|
|
171 |
/* Title and Description are basic information for (almost) all element types, |
|
|
172 |
* here we can search by these criteria |
|
|
173 |
*/ |
|
23
|
174 |
Model.List.prototype.searchByTitle = function(_text, _iexact) { |
|
|
175 |
var _iexact = _iexact || false, |
|
|
176 |
_rgxp = Model.regexpFromTextOrArray(_text, true); |
|
12
|
177 |
return this.filter(function(_element) { |
|
|
178 |
return _rgxp.test(_element.title); |
|
|
179 |
}); |
|
|
180 |
} |
|
|
181 |
|
|
23
|
182 |
Model.List.prototype.searchByDescription = function(_text, _iexact) { |
|
|
183 |
var _iexact = _iexact || false, |
|
|
184 |
_rgxp = Model.regexpFromTextOrArray(_text, true); |
|
12
|
185 |
return this.filter(function(_element) { |
|
|
186 |
return _rgxp.test(_element.description); |
|
|
187 |
}); |
|
|
188 |
} |
|
|
189 |
|
|
23
|
190 |
Model.List.prototype.searchByTextFields = function(_text, _iexact) { |
|
|
191 |
var _iexact = _iexact || false, |
|
|
192 |
_rgxp = Model.regexpFromTextOrArray(_text, true); |
|
12
|
193 |
return this.filter(function(_element) { |
|
|
194 |
return _rgxp.test(_element.description) || _rgxp.test(_element.title); |
|
|
195 |
}); |
|
|
196 |
} |
|
|
197 |
|
|
|
198 |
Model.List.prototype.getTitles = function() { |
|
|
199 |
return this.map(function(_el) { |
|
|
200 |
return _el.title; |
|
|
201 |
}); |
|
|
202 |
} |
|
|
203 |
|
|
|
204 |
Model.List.prototype.addId = function(_id) { |
|
|
205 |
var _el = this.directory.getElement(_id) |
|
|
206 |
if (!this.hasId(_id) && typeof _el !== "undefined") { |
|
|
207 |
this.idIndex.push(_id); |
|
|
208 |
Array.prototype.push.call(this, _el); |
|
|
209 |
} |
|
|
210 |
} |
|
|
211 |
|
|
|
212 |
Model.List.prototype.push = function(_el) { |
|
|
213 |
if (typeof _el === "undefined") { |
|
|
214 |
return; |
|
|
215 |
} |
|
|
216 |
var _index = (ns._(this.idIndex).indexOf(_el.id)); |
|
|
217 |
if (_index === -1) { |
|
|
218 |
this.idIndex.push(_el.id); |
|
|
219 |
Array.prototype.push.call(this, _el); |
|
|
220 |
} else { |
|
|
221 |
this[_index] = _el; |
|
|
222 |
} |
|
|
223 |
} |
|
|
224 |
|
|
|
225 |
Model.List.prototype.addIds = function(_array) { |
|
|
226 |
var _l = _array.length, |
|
|
227 |
_this = this; |
|
|
228 |
ns._(_array).forEach(function(_id) { |
|
|
229 |
_this.addId(_id); |
|
|
230 |
}); |
|
|
231 |
} |
|
|
232 |
|
|
|
233 |
Model.List.prototype.addElements = function(_array) { |
|
|
234 |
var _this = this; |
|
|
235 |
ns._(_array).forEach(function(_el) { |
|
|
236 |
_this.push(_el); |
|
|
237 |
}); |
|
|
238 |
} |
|
|
239 |
|
|
|
240 |
Model.List.prototype.removeId = function(_id, _deleteFromDirectory) { |
|
|
241 |
var _deleteFromDirectory = _deleteFromDirectory || false, |
|
|
242 |
_index = (ns._(this.idIndex).indexOf(_id)); |
|
|
243 |
if (_index !== -1) { |
|
|
244 |
this.splice(_index,1); |
|
|
245 |
} |
|
|
246 |
if (_deleteFromDirectory) { |
|
|
247 |
delete this.directory.elements[_id]; |
|
|
248 |
} |
|
|
249 |
} |
|
|
250 |
|
|
|
251 |
Model.List.prototype.removeElement = function(_el, _deleteFromDirectory) { |
|
|
252 |
var _deleteFromDirectory = _deleteFromDirectory || false; |
|
|
253 |
this.removeId(_el.id); |
|
|
254 |
} |
|
|
255 |
|
|
|
256 |
Model.List.prototype.removeIds = function(_list, _deleteFromDirectory) { |
|
|
257 |
var _deleteFromDirectory = _deleteFromDirectory || false, |
|
|
258 |
_this = this; |
|
|
259 |
ns._(_list).forEach(function(_id) { |
|
|
260 |
_this.removeId(_id); |
|
|
261 |
}); |
|
|
262 |
} |
|
|
263 |
|
|
|
264 |
Model.List.prototype.removeElements = function(_list, _deleteFromDirectory) { |
|
|
265 |
var _deleteFromDirectory = _deleteFromDirectory || false, |
|
|
266 |
_this = this; |
|
|
267 |
ns._(_list).forEach(function(_el) { |
|
|
268 |
_this.removeElement(_el); |
|
|
269 |
}); |
|
|
270 |
} |
|
|
271 |
|
|
|
272 |
Model.List.prototype.on = function(_event, _callback) { |
|
|
273 |
if (typeof this.__events[_event] === "undefined") { |
|
|
274 |
this.__events[_event] = []; |
|
|
275 |
} |
|
|
276 |
this.__events[_event].push(_callback); |
|
|
277 |
} |
|
|
278 |
|
|
|
279 |
Model.List.prototype.off = function(_event, _callback) { |
|
|
280 |
if (typeof this.__events[_event] !== "undefined") { |
|
|
281 |
this.__events[_event] = ns._(this.__events[_event]).reject(function(_fn) { |
|
|
282 |
return _fn === _callback; |
|
|
283 |
}); |
|
|
284 |
} |
|
|
285 |
} |
|
|
286 |
|
|
|
287 |
Model.List.prototype.trigger = function(_event, _data) { |
|
|
288 |
var _list = this; |
|
|
289 |
ns._(this.__events[_event]).each(function(_callback) { |
|
|
290 |
_callback.call(_list, _data); |
|
|
291 |
}); |
|
|
292 |
} |
|
|
293 |
|
|
|
294 |
/* A simple time management object, that helps converting millisecs to seconds and strings, |
|
|
295 |
* without the clumsiness of the original Date object. |
|
|
296 |
*/ |
|
|
297 |
|
|
|
298 |
Model.Time = function(_milliseconds) { |
|
|
299 |
this.milliseconds = 0; |
|
|
300 |
this.setMilliseconds(_milliseconds); |
|
|
301 |
} |
|
|
302 |
|
|
|
303 |
Model.Time.prototype.setMilliseconds = function(_milliseconds) { |
|
|
304 |
var _ante = _milliseconds; |
|
|
305 |
switch(typeof _milliseconds) { |
|
|
306 |
case "string": |
|
|
307 |
this.milliseconds = parseFloat(_milliseconds); |
|
|
308 |
break; |
|
|
309 |
case "number": |
|
|
310 |
this.milliseconds = _milliseconds; |
|
|
311 |
break; |
|
|
312 |
case "object": |
|
|
313 |
this.milliseconds = parseFloat(_milliseconds.valueOf()); |
|
|
314 |
break; |
|
|
315 |
default: |
|
|
316 |
this.milliseconds = 0; |
|
|
317 |
} |
|
|
318 |
if (this.milliseconds === NaN) { |
|
|
319 |
this.milliseconds = _ante; |
|
|
320 |
} |
|
|
321 |
} |
|
|
322 |
|
|
|
323 |
Model.Time.prototype.setSeconds = function(_seconds) { |
|
|
324 |
this.milliseconds = 1000 * _seconds; |
|
|
325 |
} |
|
|
326 |
|
|
|
327 |
Model.Time.prototype.getSeconds = function() { |
|
|
328 |
return this.milliseconds / 1000; |
|
|
329 |
} |
|
|
330 |
|
|
|
331 |
Model.Time.prototype.getHMS = function() { |
|
|
332 |
var _totalSeconds = Math.abs(Math.floor(this.getSeconds())); |
|
|
333 |
return { |
|
|
334 |
hours : Math.floor(_totalSeconds / 3600), |
|
|
335 |
minutes : (Math.floor(_totalSeconds / 60) % 60), |
|
|
336 |
seconds : _totalSeconds % 60 |
|
|
337 |
} |
|
|
338 |
} |
|
|
339 |
|
|
|
340 |
Model.Time.prototype.add = function(_milliseconds) { |
|
|
341 |
this.milliseconds += new Model.Time(_milliseconds).milliseconds; |
|
|
342 |
} |
|
|
343 |
|
|
|
344 |
Model.Time.prototype.valueOf = function() { |
|
|
345 |
return this.milliseconds; |
|
|
346 |
} |
|
|
347 |
|
|
|
348 |
Model.Time.prototype.toString = function() { |
|
|
349 |
function pad(_n) { |
|
|
350 |
var _res = _n.toString(); |
|
|
351 |
while (_res.length < 2) { |
|
|
352 |
_res = '0' + _res; |
|
|
353 |
} |
|
|
354 |
return _res; |
|
|
355 |
} |
|
|
356 |
var _hms = this.getHMS(), |
|
|
357 |
_res = ''; |
|
|
358 |
if (_hms.hours) { |
|
25
|
359 |
_res += _hms.hours + ':' |
|
12
|
360 |
} |
|
|
361 |
_res += pad(_hms.minutes) + ':' + pad(_hms.seconds); |
|
|
362 |
return _res; |
|
|
363 |
} |
|
|
364 |
|
|
|
365 |
/* Model.Reference handles references between elements |
|
|
366 |
*/ |
|
|
367 |
|
|
|
368 |
Model.Reference = function(_source, _idRef) { |
|
|
369 |
this.source = _source; |
|
|
370 |
this.id = _idRef; |
|
|
371 |
if (typeof _idRef === "object") { |
|
|
372 |
this.isList = true; |
|
|
373 |
} else { |
|
|
374 |
this.isList = false; |
|
|
375 |
} |
|
|
376 |
this.refresh(); |
|
|
377 |
} |
|
|
378 |
|
|
|
379 |
Model.Reference.prototype.refresh = function() { |
|
|
380 |
if (this.isList) { |
|
|
381 |
this.contents = new Model.List(this.source.directory); |
|
|
382 |
this.contents.addIds(this.id); |
|
|
383 |
} else { |
|
|
384 |
this.contents = this.source.getElement(this.id); |
|
|
385 |
} |
|
|
386 |
|
|
|
387 |
} |
|
|
388 |
|
|
|
389 |
Model.Reference.prototype.getContents = function() { |
|
|
390 |
if (typeof this.contents === "undefined" || (this.isList && this.contents.length != this.id.length)) { |
|
|
391 |
this.refresh(); |
|
|
392 |
} |
|
|
393 |
return this.contents; |
|
|
394 |
} |
|
|
395 |
|
|
|
396 |
Model.Reference.prototype.isOrHasId = function(_idRef) { |
|
|
397 |
if (this.isList) { |
|
|
398 |
return (ns._(this.id).indexOf(_idRef) !== -1) |
|
|
399 |
} else { |
|
|
400 |
return (this.id == _idRef); |
|
|
401 |
} |
|
|
402 |
} |
|
|
403 |
|
|
|
404 |
/* */ |
|
|
405 |
|
|
|
406 |
Model.Element = function(_id, _source) { |
|
|
407 |
this.elementType = 'element'; |
|
|
408 |
if (typeof _source === "undefined") { |
|
|
409 |
return; |
|
|
410 |
} |
|
|
411 |
if (typeof _id === "undefined" || !_id) { |
|
|
412 |
_id = Model.getUID(); |
|
|
413 |
} |
|
|
414 |
this.source = _source; |
|
|
415 |
this.id = _id; |
|
|
416 |
this.title = ""; |
|
|
417 |
this.description = ""; |
|
|
418 |
this.__events = {} |
|
|
419 |
this.source.directory.addElement(this); |
|
|
420 |
} |
|
|
421 |
|
|
|
422 |
Model.Element.prototype.toString = function() { |
|
|
423 |
return this.elementType + (this.elementType !== 'element' ? ', id=' + this.id + ', title="' + this.title + '"' : ''); |
|
|
424 |
} |
|
|
425 |
|
|
|
426 |
Model.Element.prototype.setReference = function(_elementType, _idRef) { |
|
|
427 |
this[_elementType] = new Model.Reference(this.source, _idRef); |
|
|
428 |
} |
|
|
429 |
|
|
|
430 |
Model.Element.prototype.getReference = function(_elementType) { |
|
|
431 |
if (typeof this[_elementType] !== "undefined") { |
|
|
432 |
return this[_elementType].getContents(); |
|
|
433 |
} |
|
|
434 |
} |
|
|
435 |
|
|
|
436 |
Model.Element.prototype.getRelated = function(_elementType, _global) { |
|
|
437 |
_global = (typeof _global !== "undefined" && _global); |
|
|
438 |
var _this = this; |
|
|
439 |
return this.source.getList(_elementType, _global).filter(function(_el) { |
|
|
440 |
var _ref = _el[_this.elementType]; |
|
|
441 |
return _ref && _ref.isOrHasId(_this.id); |
|
|
442 |
}); |
|
|
443 |
} |
|
|
444 |
|
|
|
445 |
Model.Element.prototype.on = function(_event, _callback) { |
|
|
446 |
if (typeof this.__events[_event] === "undefined") { |
|
|
447 |
this.__events[_event] = []; |
|
|
448 |
} |
|
|
449 |
this.__events[_event].push(_callback); |
|
|
450 |
} |
|
|
451 |
|
|
|
452 |
Model.Element.prototype.off = function(_event, _callback) { |
|
|
453 |
if (typeof this.__events[_event] !== "undefined") { |
|
|
454 |
this.__events[_event] = ns._(this.__events[_event]).reject(function(_fn) { |
|
|
455 |
return _fn === _callback; |
|
|
456 |
}); |
|
|
457 |
} |
|
|
458 |
} |
|
|
459 |
|
|
|
460 |
Model.Element.prototype.trigger = function(_event, _data) { |
|
|
461 |
var _element = this; |
|
|
462 |
ns._(this.__events[_event]).each(function(_callback) { |
|
|
463 |
_callback.call(_element, _data); |
|
|
464 |
}); |
|
|
465 |
} |
|
|
466 |
|
|
|
467 |
/* */ |
|
|
468 |
|
|
|
469 |
Model.Playable = function(_id, _source) { |
|
|
470 |
Model.Element.call(this, _id, _source); |
|
|
471 |
if (typeof _source === "undefined") { |
|
|
472 |
return; |
|
|
473 |
} |
|
|
474 |
this.elementType = 'playable'; |
|
|
475 |
this.currentTime = new Model.Time(); |
|
|
476 |
this.volume = .5; |
|
|
477 |
this.paused = true; |
|
|
478 |
this.muted = false; |
|
|
479 |
var _this = this; |
|
|
480 |
this.on("play", function() { |
|
|
481 |
_this.paused = false; |
|
|
482 |
}); |
|
|
483 |
this.on("pause", function() { |
|
|
484 |
_this.paused = true; |
|
|
485 |
}); |
|
|
486 |
this.on("timeupdate", function(_time) { |
|
|
487 |
_this.currentTime = _time; |
|
|
488 |
}); |
|
|
489 |
} |
|
|
490 |
|
|
|
491 |
Model.Playable.prototype = new Model.Element(); |
|
|
492 |
|
|
|
493 |
Model.Playable.prototype.getCurrentTime = function() { |
|
|
494 |
return this.currentTime; |
|
|
495 |
} |
|
|
496 |
|
|
|
497 |
Model.Playable.prototype.getVolume = function() { |
|
|
498 |
return this.volume; |
|
|
499 |
} |
|
|
500 |
|
|
|
501 |
Model.Playable.prototype.getPaused = function() { |
|
|
502 |
return this.paused; |
|
|
503 |
} |
|
|
504 |
|
|
|
505 |
Model.Playable.prototype.getMuted = function() { |
|
|
506 |
return this.muted; |
|
|
507 |
} |
|
|
508 |
|
|
|
509 |
Model.Playable.prototype.setCurrentTime = function(_time) { |
|
|
510 |
this.trigger("setcurrenttime",_time); |
|
|
511 |
} |
|
|
512 |
|
|
|
513 |
Model.Playable.prototype.setVolume = function(_vol) { |
|
|
514 |
this.trigger("setvolume",_vol); |
|
|
515 |
} |
|
|
516 |
|
|
|
517 |
Model.Playable.prototype.setMuted = function(_muted) { |
|
|
518 |
this.trigger("setmuted",_muted); |
|
|
519 |
} |
|
|
520 |
|
|
|
521 |
Model.Playable.prototype.play = function() { |
|
|
522 |
this.trigger("setplay"); |
|
|
523 |
} |
|
|
524 |
|
|
|
525 |
Model.Playable.prototype.pause = function() { |
|
|
526 |
this.trigger("setpause"); |
|
|
527 |
} |
|
|
528 |
|
|
|
529 |
|
|
|
530 |
/* */ |
|
|
531 |
|
|
|
532 |
Model.Media = function(_id, _source) { |
|
|
533 |
Model.Playable.call(this, _id, _source); |
|
|
534 |
this.elementType = 'media'; |
|
|
535 |
this.duration = new Model.Time(); |
|
|
536 |
this.video = ''; |
|
|
537 |
|
|
|
538 |
var _this = this; |
|
|
539 |
this.on("timeupdate", function(_time) { |
|
|
540 |
_this.getAnnotations().filter(function(_a) { |
|
|
541 |
return (_a.end <= _time || _a.begin > _time) && _a.playing |
|
|
542 |
}).forEach(function(_a) { |
|
|
543 |
_a.playing = false; |
|
|
544 |
_a.trigger("leave"); |
|
|
545 |
}); |
|
|
546 |
_this.getAnnotations().filter(function(_a) { |
|
|
547 |
return _a.begin <= _time && _a.end > _time && !_a.playing |
|
|
548 |
}).forEach(function(_a) { |
|
|
549 |
_a.playing = true; |
|
|
550 |
_a.trigger("enter"); |
|
|
551 |
}); |
|
|
552 |
}); |
|
|
553 |
} |
|
|
554 |
|
|
|
555 |
Model.Media.prototype = new Model.Playable(); |
|
|
556 |
|
|
|
557 |
/* Default functions to be overriden by players */ |
|
|
558 |
|
|
|
559 |
Model.Media.prototype.setDuration = function(_durationMs) { |
|
|
560 |
this.duration.setMilliseconds(_durationMs); |
|
|
561 |
} |
|
|
562 |
|
|
|
563 |
Model.Media.prototype.getAnnotations = function() { |
|
|
564 |
return this.getRelated("annotation"); |
|
|
565 |
} |
|
|
566 |
|
|
|
567 |
Model.Media.prototype.getAnnotationsByTypeTitle = function(_title) { |
|
|
568 |
var _annTypes = this.source.getAnnotationTypes().searchByTitle(_title).pluck("id"); |
|
|
569 |
if (_annTypes.length) { |
|
|
570 |
return this.getAnnotations().filter(function(_annotation) { |
|
|
571 |
return ns._(_annTypes).indexOf(_annotation.getAnnotationType().id) !== -1; |
|
|
572 |
}); |
|
|
573 |
} else { |
|
|
574 |
return new Model.List(this.source.directory) |
|
|
575 |
} |
|
|
576 |
} |
|
|
577 |
|
|
|
578 |
/* */ |
|
|
579 |
|
|
|
580 |
Model.Tag = function(_id, _source) { |
|
|
581 |
Model.Element.call(this, _id, _source); |
|
|
582 |
this.elementType = 'tag'; |
|
|
583 |
} |
|
|
584 |
|
|
|
585 |
Model.Tag.prototype = new Model.Element(); |
|
|
586 |
|
|
|
587 |
Model.Tag.prototype.getAnnotations = function() { |
|
|
588 |
return this.getRelated("annotation"); |
|
|
589 |
} |
|
|
590 |
|
|
|
591 |
/* */ |
|
|
592 |
Model.AnnotationType = function(_id, _source) { |
|
|
593 |
Model.Element.call(this, _id, _source); |
|
|
594 |
this.elementType = 'annotationType'; |
|
|
595 |
} |
|
|
596 |
|
|
|
597 |
Model.AnnotationType.prototype = new Model.Element(); |
|
|
598 |
|
|
|
599 |
Model.AnnotationType.prototype.getAnnotations = function() { |
|
|
600 |
return this.getRelated("annotation"); |
|
|
601 |
} |
|
|
602 |
|
|
|
603 |
/* Annotation |
|
|
604 |
* */ |
|
|
605 |
|
|
|
606 |
Model.Annotation = function(_id, _source) { |
|
|
607 |
Model.Element.call(this, _id, _source); |
|
|
608 |
this.elementType = 'annotation'; |
|
|
609 |
this.begin = new Model.Time(); |
|
|
610 |
this.end = new Model.Time(); |
|
|
611 |
this.tag = new Model.Reference(_source, []); |
|
|
612 |
this.playing = false; |
|
|
613 |
var _this = this; |
|
|
614 |
this.on("click", function() { |
|
|
615 |
_this.getMedia().setCurrentTime(_this.begin); |
|
|
616 |
}); |
|
|
617 |
} |
|
|
618 |
|
|
|
619 |
Model.Annotation.prototype = new Model.Element(); |
|
|
620 |
|
|
|
621 |
Model.Annotation.prototype.setBegin = function(_beginMs) { |
|
25
|
622 |
this.begin.setMilliseconds(Math.max(0,_beginMs)); |
|
|
623 |
this.trigger("change-begin"); |
|
|
624 |
if (this.end < this.begin) { |
|
|
625 |
this.setEnd(this.begin); |
|
|
626 |
} |
|
12
|
627 |
} |
|
|
628 |
|
|
25
|
629 |
Model.Annotation.prototype.setEnd = function(_endMs) { |
|
|
630 |
this.end.setMilliseconds(Math.min(_endMs, this.getMedia().duration.milliseconds)); |
|
|
631 |
this.trigger("change-end"); |
|
|
632 |
if (this.end < this.begin) { |
|
|
633 |
this.setBegin(this.end); |
|
|
634 |
} |
|
|
635 |
} |
|
|
636 |
|
|
|
637 |
Model.Annotation.prototype.setDuration = function(_durMs) { |
|
|
638 |
this.setEnd(_durMs + this.begin.milliseconds); |
|
12
|
639 |
} |
|
|
640 |
|
|
|
641 |
Model.Annotation.prototype.setMedia = function(_idRef) { |
|
|
642 |
this.setReference("media", _idRef); |
|
|
643 |
} |
|
|
644 |
|
|
|
645 |
Model.Annotation.prototype.getMedia = function() { |
|
|
646 |
return this.getReference("media"); |
|
|
647 |
} |
|
|
648 |
|
|
|
649 |
Model.Annotation.prototype.setAnnotationType = function(_idRef) { |
|
|
650 |
this.setReference("annotationType", _idRef); |
|
|
651 |
} |
|
|
652 |
|
|
|
653 |
Model.Annotation.prototype.getAnnotationType = function() { |
|
|
654 |
return this.getReference("annotationType"); |
|
|
655 |
} |
|
|
656 |
|
|
|
657 |
Model.Annotation.prototype.setTags = function(_idRefs) { |
|
|
658 |
this.setReference("tag", _idRefs); |
|
|
659 |
} |
|
|
660 |
|
|
|
661 |
Model.Annotation.prototype.getTags = function() { |
|
|
662 |
return this.getReference("tag"); |
|
|
663 |
} |
|
|
664 |
|
|
|
665 |
Model.Annotation.prototype.getTagTexts = function() { |
|
|
666 |
return this.getTags().getTitles(); |
|
|
667 |
} |
|
|
668 |
|
|
|
669 |
Model.Annotation.prototype.getDuration = function() { |
|
|
670 |
return new Model.Time(this.end.milliseconds - this.begin.milliseconds) |
|
|
671 |
} |
|
|
672 |
|
|
|
673 |
/* */ |
|
|
674 |
|
|
|
675 |
Model.MashedAnnotation = function(_mashup, _annotation) { |
|
|
676 |
Model.Element.call(this, _mashup.id + "_" + _annotation.id, _annotation.source); |
|
|
677 |
this.elementType = 'mashedAnnotation'; |
|
|
678 |
this.annotation = _annotation; |
|
25
|
679 |
this.begin = new Model.Time(); |
|
|
680 |
this.end = new Model.Time(); |
|
|
681 |
this.duration = new Model.Time(); |
|
12
|
682 |
this.title = this.annotation.title; |
|
25
|
683 |
this.media_title = this.getMedia().title; |
|
12
|
684 |
this.description = this.annotation.description; |
|
|
685 |
this.color = this.annotation.color; |
|
|
686 |
var _this = this; |
|
|
687 |
this.on("click", function() { |
|
|
688 |
_mashup.setCurrentTime(_this.begin); |
|
|
689 |
}); |
|
|
690 |
} |
|
|
691 |
|
|
|
692 |
Model.MashedAnnotation.prototype = new Model.Element(null); |
|
|
693 |
|
|
|
694 |
Model.MashedAnnotation.prototype.getMedia = function() { |
|
|
695 |
return this.annotation.getReference("media"); |
|
|
696 |
} |
|
|
697 |
|
|
|
698 |
Model.MashedAnnotation.prototype.getAnnotationType = function() { |
|
|
699 |
return this.annotation.getReference("annotationType"); |
|
|
700 |
} |
|
|
701 |
|
|
|
702 |
Model.MashedAnnotation.prototype.getTags = function() { |
|
|
703 |
return this.annotation.getReference("tag"); |
|
|
704 |
} |
|
|
705 |
|
|
|
706 |
Model.MashedAnnotation.prototype.getTagTexts = function() { |
|
|
707 |
return this.annotation.getTags().getTitles(); |
|
|
708 |
} |
|
|
709 |
|
|
|
710 |
Model.MashedAnnotation.prototype.getDuration = function() { |
|
|
711 |
return this.annotation.getDuration(); |
|
|
712 |
} |
|
|
713 |
|
|
25
|
714 |
Model.MashedAnnotation.prototype.setBegin = function(_begin) { |
|
|
715 |
this.begin.setMilliseconds(_begin); |
|
|
716 |
this.duration.setMilliseconds(this.annotation.getDuration()); |
|
|
717 |
this.end.setMilliseconds(_begin + this.duration); |
|
|
718 |
} |
|
|
719 |
|
|
12
|
720 |
/* */ |
|
|
721 |
|
|
|
722 |
Model.Mashup = function(_id, _source) { |
|
|
723 |
Model.Playable.call(this, _id, _source); |
|
|
724 |
this.elementType = 'mashup'; |
|
|
725 |
this.duration = new Model.Time(); |
|
|
726 |
this.segments = new Model.List(_source.directory); |
|
|
727 |
var _currentMedia = null; |
|
|
728 |
var _this = this; |
|
|
729 |
this.on("timeupdate", function(_time) { |
|
|
730 |
_this.getAnnotations().filter(function(_a) { |
|
|
731 |
return (_a.end <= _time || _a.begin > _time) && _a.playing |
|
|
732 |
}).forEach(function(_a) { |
|
|
733 |
_a.playing = false; |
|
|
734 |
_a.trigger("leave"); |
|
|
735 |
}); |
|
|
736 |
_this.getAnnotations().filter(function(_a) { |
|
|
737 |
return _a.begin <= _time && _a.end > _time && !_a.playing |
|
|
738 |
}).forEach(function(_a) { |
|
|
739 |
_a.playing = true; |
|
|
740 |
_a.trigger("enter"); |
|
|
741 |
var _m = _a.getMedia(); |
|
|
742 |
if (_m !== _currentMedia) { |
|
|
743 |
if (_currentMedia) { |
|
|
744 |
_currentMedia.trigger("leave"); |
|
|
745 |
} |
|
|
746 |
_m.trigger("enter"); |
|
|
747 |
_currentMedia = _m; |
|
|
748 |
} |
|
|
749 |
}); |
|
|
750 |
}); |
|
25
|
751 |
this._updateTimes = function() { |
|
|
752 |
_this.updateTimes(); |
|
|
753 |
} |
|
|
754 |
this.on("add-segments", this._updateTimes); |
|
|
755 |
this.on("remove-segments", this._updateTimes); |
|
12
|
756 |
} |
|
|
757 |
|
|
|
758 |
Model.Mashup.prototype = new Model.Playable(); |
|
|
759 |
|
|
25
|
760 |
Model.Mashup.prototype.updateTimes = function() { |
|
|
761 |
var _time = 0; |
|
|
762 |
this.segments.forEach(function(_segment) { |
|
|
763 |
_segment.setBegin(_time); |
|
|
764 |
_time = _segment.end; |
|
|
765 |
}); |
|
|
766 |
this.duration.setMilliseconds(_time); |
|
|
767 |
} |
|
|
768 |
|
|
|
769 |
Model.Mashup.prototype.addSegment = function(_annotation, _defer) { |
|
|
770 |
var _mashedAnnotation = new Model.MashedAnnotation(this, _annotation), |
|
|
771 |
_defer = _defer || false; |
|
12
|
772 |
this.segments.push(_mashedAnnotation); |
|
25
|
773 |
_annotation.on("change-begin", this._updateTimes); |
|
|
774 |
_annotation.on("change-end", this._updateTimes); |
|
|
775 |
if (!_defer) { |
|
|
776 |
this.trigger("add-segments"); |
|
|
777 |
} |
|
|
778 |
} |
|
|
779 |
|
|
|
780 |
Model.Mashup.prototype.addSegmentById = function(_elId, _defer) { |
|
|
781 |
var _annotation = this.source.getElement(_elId), |
|
|
782 |
_defer = _defer || false; |
|
|
783 |
if (typeof _annotation !== "undefined") { |
|
|
784 |
this.addSegment(_annotation, _defer); |
|
|
785 |
} |
|
12
|
786 |
} |
|
|
787 |
|
|
25
|
788 |
Model.Mashup.prototype.addSegments = function(_segments) { |
|
|
789 |
var _this = this; |
|
|
790 |
ns._(_segments).forEach(function(_segment) { |
|
|
791 |
_this.addSegment(_segment, true); |
|
|
792 |
}); |
|
|
793 |
this.trigger("add-segments"); |
|
|
794 |
} |
|
|
795 |
|
|
|
796 |
Model.Mashup.prototype.addSegmentsById = function(_segments) { |
|
|
797 |
var _this = this; |
|
|
798 |
ns._(_segments).forEach(function(_segment) { |
|
|
799 |
_this.addSegmentById(_segment, true); |
|
|
800 |
}); |
|
|
801 |
this.trigger("add-segments"); |
|
|
802 |
} |
|
|
803 |
|
|
|
804 |
Model.Mashup.prototype.removeSegment = function(_annotation, _defer) { |
|
|
805 |
var _defer = _defer || false; |
|
|
806 |
_annotation.off("change-begin", this._updateTimes); |
|
|
807 |
_annotation.off("change-end", this._updateTimes); |
|
|
808 |
this.segments.removeElement(_annotation); |
|
|
809 |
if (!_defer) { |
|
|
810 |
this.trigger("remove-segments"); |
|
|
811 |
} |
|
|
812 |
} |
|
|
813 |
|
|
|
814 |
Model.Mashup.prototype.removeSegmentById = function(_annId, _defer) { |
|
|
815 |
var _defer = _defer || false; |
|
|
816 |
var _annotation = this.source.getElementById(_annId); |
|
|
817 |
if (_annotation) { |
|
|
818 |
this.removeSegment(_annotation, _defer); |
|
|
819 |
} |
|
|
820 |
this.segments.removeElement(_annotation); |
|
|
821 |
if (!_defer) { |
|
|
822 |
this.trigger("remove-segments"); |
|
12
|
823 |
} |
|
|
824 |
} |
|
|
825 |
|
|
|
826 |
Model.Mashup.prototype.getAnnotations = function() { |
|
|
827 |
return this.segments; |
|
|
828 |
} |
|
|
829 |
|
|
|
830 |
Model.Mashup.prototype.getMedias = function() { |
|
25
|
831 |
var medias = new Model.List(_source.directory); |
|
|
832 |
this.segments.each(function(_annotation) { |
|
|
833 |
medias.push(_annotation.getMedia()) |
|
|
834 |
}) |
|
|
835 |
return medias; |
|
12
|
836 |
} |
|
|
837 |
|
|
|
838 |
Model.Mashup.prototype.getAnnotationsByTypeTitle = function(_title) { |
|
|
839 |
var _annTypes = this.source.getAnnotationTypes().searchByTitle(_title).pluck("id"); |
|
|
840 |
if (_annTypes.length) { |
|
|
841 |
return this.getAnnotations().filter(function(_annotation) { |
|
|
842 |
return ns._(_annTypes).indexOf(_annotation.getAnnotationType().id) !== -1; |
|
|
843 |
}); |
|
|
844 |
} else { |
|
|
845 |
return new Model.List(this.source.directory) |
|
|
846 |
} |
|
|
847 |
} |
|
|
848 |
|
|
|
849 |
Model.Mashup.prototype.getAnnotationAtTime = function(_time) { |
|
|
850 |
var _list = this.segments.filter(function(_annotation) { |
|
|
851 |
return _annotation.begin <= _time && _annotation.end > _time; |
|
|
852 |
}); |
|
|
853 |
if (_list.length) { |
|
|
854 |
return _list[0]; |
|
|
855 |
} else { |
|
|
856 |
return undefined; |
|
|
857 |
} |
|
|
858 |
} |
|
|
859 |
|
|
|
860 |
Model.Mashup.prototype.getMediaAtTime = function(_time) { |
|
|
861 |
var _annotation = this.getAnnotationAtTime(_time); |
|
|
862 |
if (typeof _annotation !== "undefined") { |
|
|
863 |
return _annotation.getMedia(); |
|
|
864 |
} else { |
|
|
865 |
return undefined; |
|
|
866 |
} |
|
|
867 |
} |
|
|
868 |
|
|
|
869 |
/* */ |
|
|
870 |
|
|
|
871 |
Model.Source = function(_config) { |
|
|
872 |
this.status = Model._SOURCE_STATUS_EMPTY; |
|
|
873 |
this.elementType = "source"; |
|
|
874 |
if (typeof _config !== "undefined") { |
|
|
875 |
var _this = this; |
|
|
876 |
ns._(_config).forEach(function(_v, _k) { |
|
|
877 |
_this[_k] = _v; |
|
|
878 |
}) |
|
|
879 |
this.callbackQueue = []; |
|
|
880 |
this.contents = {}; |
|
|
881 |
this.get(); |
|
|
882 |
} |
|
|
883 |
} |
|
|
884 |
|
|
|
885 |
Model.Source.prototype = new Model.Element(); |
|
|
886 |
|
|
|
887 |
Model.Source.prototype.addList = function(_listId, _contents) { |
|
|
888 |
if (typeof this.contents[_listId] === "undefined") { |
|
|
889 |
this.contents[_listId] = new Model.List(this.directory); |
|
|
890 |
} |
|
|
891 |
this.contents[_listId].addElements(_contents); |
|
|
892 |
} |
|
|
893 |
|
|
|
894 |
Model.Source.prototype.getList = function(_listId, _global) { |
|
|
895 |
_global = (typeof _global !== "undefined" && _global); |
|
|
896 |
if (_global || typeof this.contents[_listId] === "undefined") { |
|
|
897 |
return this.directory.getGlobalList().filter(function(_e) { |
|
|
898 |
return (_e.elementType === _listId); |
|
|
899 |
}); |
|
|
900 |
} else { |
|
|
901 |
return this.contents[_listId]; |
|
|
902 |
} |
|
|
903 |
} |
|
|
904 |
|
|
|
905 |
Model.Source.prototype.forEach = function(_callback) { |
|
|
906 |
var _this = this; |
|
|
907 |
ns._(this.contents).forEach(function(_value, _key) { |
|
|
908 |
_callback.call(_this, _value, _key); |
|
|
909 |
}) |
|
|
910 |
} |
|
|
911 |
|
|
|
912 |
Model.Source.prototype.getElement = function(_elId) { |
|
|
913 |
return this.directory.getElement(_elId); |
|
|
914 |
} |
|
|
915 |
|
|
|
916 |
Model.Source.prototype.get = function() { |
|
|
917 |
this.status = Model._SOURCE_STATUS_WAITING; |
|
|
918 |
this.handleCallbacks(); |
|
|
919 |
} |
|
|
920 |
|
|
|
921 |
/* We defer the callbacks calls so they execute after the queue is cleared */ |
|
|
922 |
Model.Source.prototype.deferCallback = function(_callback) { |
|
|
923 |
var _this = this; |
|
|
924 |
ns._.defer(function() { |
|
|
925 |
_callback.call(_this); |
|
|
926 |
}); |
|
|
927 |
} |
|
|
928 |
|
|
|
929 |
Model.Source.prototype.handleCallbacks = function() { |
|
|
930 |
this.status = Model._SOURCE_STATUS_READY; |
|
|
931 |
while (this.callbackQueue.length) { |
|
|
932 |
this.deferCallback(this.callbackQueue.splice(0,1)[0]); |
|
|
933 |
} |
|
|
934 |
} |
|
|
935 |
Model.Source.prototype.onLoad = function(_callback) { |
|
|
936 |
if (this.status === Model._SOURCE_STATUS_READY) { |
|
|
937 |
this.deferCallback(_callback); |
|
|
938 |
} else { |
|
|
939 |
this.callbackQueue.push(_callback); |
|
|
940 |
} |
|
|
941 |
} |
|
|
942 |
|
|
|
943 |
Model.Source.prototype.serialize = function() { |
|
|
944 |
return this.serializer.serialize(this); |
|
|
945 |
} |
|
|
946 |
|
|
|
947 |
Model.Source.prototype.deSerialize = function(_data) { |
|
|
948 |
this.serializer.deSerialize(_data, this); |
|
|
949 |
} |
|
|
950 |
|
|
|
951 |
Model.Source.prototype.getAnnotations = function(_global) { |
|
|
952 |
_global = (typeof _global !== "undefined" && _global); |
|
|
953 |
return this.getList("annotation", _global); |
|
|
954 |
} |
|
|
955 |
|
|
|
956 |
Model.Source.prototype.getMedias = function(_global) { |
|
|
957 |
_global = (typeof _global !== "undefined" && _global); |
|
|
958 |
return this.getList("media", _global); |
|
|
959 |
} |
|
|
960 |
|
|
|
961 |
Model.Source.prototype.getTags = function(_global) { |
|
|
962 |
_global = (typeof _global !== "undefined" && _global); |
|
|
963 |
return this.getList("tag", _global); |
|
|
964 |
} |
|
|
965 |
|
|
|
966 |
Model.Source.prototype.getMashups = function(_global) { |
|
|
967 |
_global = (typeof _global !== "undefined" && _global); |
|
|
968 |
return this.getList("mashup", _global); |
|
|
969 |
} |
|
|
970 |
|
|
|
971 |
Model.Source.prototype.getAnnotationTypes = function(_global) { |
|
|
972 |
_global = (typeof _global !== "undefined" && _global); |
|
|
973 |
return this.getList("annotationType", _global); |
|
|
974 |
} |
|
|
975 |
|
|
|
976 |
Model.Source.prototype.getAnnotationsByTypeTitle = function(_title, _global) { |
|
|
977 |
_global = (typeof _global !== "undefined" && _global); |
|
|
978 |
var _res = new Model.List(this.directory), |
|
|
979 |
_annTypes = this.getAnnotationTypes(_global).searchByTitle(_title); |
|
|
980 |
_annTypes.forEach(function(_annType) { |
|
|
981 |
_res.addElements(_annType.getAnnotations(_global)); |
|
|
982 |
}) |
|
|
983 |
return _res; |
|
|
984 |
} |
|
|
985 |
|
|
|
986 |
Model.Source.prototype.getDuration = function() { |
|
|
987 |
var _m = this.currentMedia; |
|
|
988 |
if (typeof _m !== "undefined") { |
|
|
989 |
return this.currentMedia.duration; |
|
|
990 |
} |
|
|
991 |
} |
|
|
992 |
|
|
|
993 |
Model.Source.prototype.getCurrentMedia = function(_opts) { |
|
|
994 |
if (typeof this.currentMedia === "undefined") { |
|
|
995 |
if (_opts.is_mashup) { |
|
|
996 |
var _mashups = this.getMashups(); |
|
|
997 |
if (_mashups.length) { |
|
|
998 |
this.currentMedia = _mashups[0]; |
|
|
999 |
} |
|
|
1000 |
} else { |
|
|
1001 |
var _medias = this.getMedias(); |
|
|
1002 |
if (_medias.length) { |
|
|
1003 |
this.currentMedia = _medias[0]; |
|
|
1004 |
} |
|
|
1005 |
} |
|
|
1006 |
} |
|
|
1007 |
return this.currentMedia; |
|
|
1008 |
} |
|
|
1009 |
|
|
|
1010 |
Model.Source.prototype.merge = function(_source) { |
|
|
1011 |
var _this = this; |
|
|
1012 |
_source.forEach(function(_value, _key) { |
|
|
1013 |
_this.getList(_key).addElements(_value); |
|
|
1014 |
}); |
|
|
1015 |
} |
|
|
1016 |
|
|
|
1017 |
/* */ |
|
|
1018 |
|
|
|
1019 |
Model.RemoteSource = function(_config) { |
|
|
1020 |
Model.Source.call(this, _config); |
|
|
1021 |
} |
|
|
1022 |
|
|
|
1023 |
Model.RemoteSource.prototype = new Model.Source(); |
|
|
1024 |
|
|
|
1025 |
Model.RemoteSource.prototype.get = function() { |
|
|
1026 |
this.status = Model._SOURCE_STATUS_WAITING; |
|
|
1027 |
var _this = this; |
|
|
1028 |
this.serializer.loadData(this.url, function(_result) { |
|
|
1029 |
_this.deSerialize(_result); |
|
|
1030 |
_this.handleCallbacks(); |
|
|
1031 |
}); |
|
|
1032 |
} |
|
|
1033 |
|
|
|
1034 |
/* */ |
|
|
1035 |
|
|
|
1036 |
Model.Directory = function() { |
|
|
1037 |
this.remoteSources = {}; |
|
|
1038 |
this.elements = {}; |
|
|
1039 |
} |
|
|
1040 |
|
|
|
1041 |
Model.Directory.prototype.remoteSource = function(_properties) { |
|
|
1042 |
if (typeof _properties !== "object" || typeof _properties.url === "undefined") { |
|
|
1043 |
throw "Error : Model.Directory.remoteSource(configuration): configuration.url is undefined"; |
|
|
1044 |
} |
|
|
1045 |
var _config = ns._({ directory: this }).extend(_properties); |
|
|
1046 |
if (typeof this.remoteSources[_properties.url] === "undefined") { |
|
|
1047 |
this.remoteSources[_properties.url] = new Model.RemoteSource(_config); |
|
|
1048 |
} |
|
|
1049 |
return this.remoteSources[_properties.url]; |
|
|
1050 |
} |
|
|
1051 |
|
|
|
1052 |
Model.Directory.prototype.newLocalSource = function(_properties) { |
|
|
1053 |
var _config = ns._({ directory: this }).extend(_properties), |
|
|
1054 |
_res = new Model.Source(_config); |
|
|
1055 |
return _res; |
|
|
1056 |
} |
|
|
1057 |
|
|
|
1058 |
Model.Directory.prototype.getElement = function(_id) { |
|
|
1059 |
return this.elements[_id]; |
|
|
1060 |
} |
|
|
1061 |
|
|
|
1062 |
Model.Directory.prototype.addElement = function(_element) { |
|
|
1063 |
this.elements[_element.id] = _element; |
|
|
1064 |
} |
|
|
1065 |
|
|
|
1066 |
Model.Directory.prototype.getGlobalList = function() { |
|
|
1067 |
var _res = new Model.List(this); |
|
|
1068 |
_res.addIds(ns._(this.elements).keys()); |
|
|
1069 |
return _res; |
|
|
1070 |
} |
|
|
1071 |
|
|
23
|
1072 |
return Model; |
|
12
|
1073 |
|
|
|
1074 |
})(IriSP); |