70 if (_pos >= 0 && _pos < this.length()) { |
70 if (_pos >= 0 && _pos < this.length()) { |
71 return this.getElement(this.contents[_pos]); |
71 return this.getElement(this.contents[_pos]); |
72 } |
72 } |
73 } |
73 } |
74 |
74 |
|
75 IriSP.Model.List.prototype.hasId = function(_id) { |
|
76 return (IriSP._(this.contents).indexOf(_id) !== -1); |
|
77 } |
|
78 |
75 IriSP.Model.List.prototype.each = function(_callback) { |
79 IriSP.Model.List.prototype.each = function(_callback) { |
76 var _this = this; |
80 var _this = this; |
77 IriSP._(this.contents).each(function(_id) { |
81 IriSP._(this.contents).each(function(_id) { |
78 _callback.call(_this, _this.getElement(_id), _id); |
82 _callback.call(_this, _this.getElement(_id), _id); |
79 }); |
83 }); |
93 return _callback.call(_this, _this.getElement(_id), _id); |
97 return _callback.call(_this, _this.getElement(_id), _id); |
94 }); |
98 }); |
95 return _res; |
99 return _res; |
96 } |
100 } |
97 |
101 |
|
102 IriSP.Model.List.prototype.sortBy = function(_callback) { |
|
103 var _this = this, |
|
104 _res = new IriSP.Model.List(this.directory); |
|
105 _res.contents = IriSP._(this.contents).sortBy(function(_id) { |
|
106 return _callback.call(_this, _this.getElement(_id), _id); |
|
107 }); |
|
108 return _res; |
|
109 } |
|
110 |
98 IriSP.Model.List.prototype.searchByTitle = function(_text) { |
111 IriSP.Model.List.prototype.searchByTitle = function(_text) { |
99 var _rgxp = new RegExp('(' + _text.replace(/(\W)/gm,'\\$1') + ')','gim'); |
112 var _rgxp = new RegExp('(' + _text.replace(/(\W)/gm,'\\$1') + ')','gim'); |
100 return this.filter(function(_element) { |
113 return this.filter(function(_element) { |
101 return _rgxp.test(_element.text); |
114 return _rgxp.test(_element.title); |
102 }); |
115 }); |
103 } |
116 } |
104 |
117 |
105 IriSP.Model.List.prototype.searchByDescription = function(_text) { |
118 IriSP.Model.List.prototype.searchByDescription = function(_text) { |
106 var _rgxp = new RegExp('(' + _text.replace(/(\W)/gm,'\\$1') + ')','gim'); |
119 var _rgxp = new RegExp('(' + _text.replace(/(\W)/gm,'\\$1') + ')','gim'); |
110 } |
123 } |
111 |
124 |
112 IriSP.Model.List.prototype.searchByTextFields = function(_text) { |
125 IriSP.Model.List.prototype.searchByTextFields = function(_text) { |
113 var _rgxp = new RegExp('(' + _text.replace(/(\W)/gm,'\\$1') + ')','gim'); |
126 var _rgxp = new RegExp('(' + _text.replace(/(\W)/gm,'\\$1') + ')','gim'); |
114 return this.filter(function(_element) { |
127 return this.filter(function(_element) { |
115 return _rgxp.test(_element.description); |
128 return _rgxp.test(_element.description) || _rgxp.test(_element.title); |
116 }); |
129 }); |
117 } |
130 } |
118 |
131 |
119 IriSP.Model.List.prototype.addId = function(_id) { |
132 IriSP.Model.List.prototype.addId = function(_id) { |
120 if (this.contents.indexOf(_id) === -1) { |
133 if (!this.hasId(_id)) { |
121 this.contents.push(_id); |
134 this.contents.push(_id); |
122 } |
135 } |
123 } |
136 } |
124 |
137 |
125 IriSP.Model.List.prototype.addElement = function(_el) { |
138 IriSP.Model.List.prototype.addElement = function(_el) { |
225 if (typeof this[_elementType] !== "undefined") { |
238 if (typeof this[_elementType] !== "undefined") { |
226 return this[_elementType].getContents(); |
239 return this[_elementType].getContents(); |
227 } |
240 } |
228 } |
241 } |
229 |
242 |
230 /* */ |
243 IriSP.Model.Element.prototype.getRelated = function(_elementType) { |
231 |
244 var _this = this; |
232 IriSP.Model.Media = function(_id, _directory) { |
245 return this.source.getList(_elementType).filter(function(_el) { |
233 IriSP.Model.Element.call(this, _id, _directory); |
246 var _ref = _el[_this.elementType]; |
|
247 if (_ref.isList) { |
|
248 return _ref.contents.hasId(_this.id); |
|
249 } |
|
250 else { |
|
251 return _ref.contents === _this.id; |
|
252 } |
|
253 }); |
|
254 } |
|
255 |
|
256 /* */ |
|
257 |
|
258 IriSP.Model.Media = function(_id, _source) { |
|
259 IriSP.Model.Element.call(this, _id, _source); |
234 this.elementType = 'media'; |
260 this.elementType = 'media'; |
235 this.duration = new IriSP.Model.Time(); |
261 this.duration = new IriSP.Model.Time(); |
236 this.url = ''; |
262 this.url = ''; |
237 } |
263 } |
238 |
264 |
240 |
266 |
241 IriSP.Model.Media.prototype.setDuration = function(_durationMs) { |
267 IriSP.Model.Media.prototype.setDuration = function(_durationMs) { |
242 this.duration.milliseconds = _durationMs; |
268 this.duration.milliseconds = _durationMs; |
243 } |
269 } |
244 |
270 |
245 /* */ |
271 IriSP.Model.Media.prototype.getAnnotations = function() { |
246 |
272 return this.getRelated("annotation"); |
247 IriSP.Model.Tag = function(_id, _directory) { |
273 } |
248 IriSP.Model.Element.call(this, _id, _directory); |
274 |
|
275 /* */ |
|
276 |
|
277 IriSP.Model.Tag = function(_id, _source) { |
|
278 IriSP.Model.Element.call(this, _id, _source); |
249 this.elementType = 'tag'; |
279 this.elementType = 'tag'; |
250 } |
280 } |
251 |
281 |
252 IriSP.Model.Tag.prototype = new IriSP.Model.Element(); |
282 IriSP.Model.Tag.prototype = new IriSP.Model.Element(); |
253 |
283 |
254 /* */ |
284 IriSP.Model.Tag.prototype.getAnnotations = function() { |
255 |
285 return this.getRelated("annotation"); |
256 IriSP.Model.AnnotationType = function(_id, _directory) { |
286 } |
257 IriSP.Model.Element.call(this, _id, _directory); |
287 |
|
288 /* */ |
|
289 |
|
290 IriSP.Model.AnnotationType = function(_id, _source) { |
|
291 IriSP.Model.Element.call(this, _id, _source); |
258 this.elementType = 'annotationType'; |
292 this.elementType = 'annotationType'; |
259 } |
293 } |
260 |
294 |
261 IriSP.Model.AnnotationType.prototype = new IriSP.Model.Element(); |
295 IriSP.Model.AnnotationType.prototype = new IriSP.Model.Element(); |
|
296 |
|
297 IriSP.Model.AnnotationType.prototype.getAnnotations = function() { |
|
298 return this.getRelated("annotation"); |
|
299 } |
262 |
300 |
263 /* Annotation |
301 /* Annotation |
264 * */ |
302 * */ |
265 |
303 |
266 IriSP.Model.Annotation = function(_id, _directory) { |
304 IriSP.Model.Annotation = function(_id, _source) { |
267 IriSP.Model.Element.call(this, _id, _directory); |
305 IriSP.Model.Element.call(this, _id, _source); |
268 this.elementType = 'annotation'; |
306 this.elementType = 'annotation'; |
269 this.begin = new IriSP.Model.Time(); |
307 this.begin = new IriSP.Model.Time(); |
270 this.end = new IriSP.Model.Time(); |
308 this.end = new IriSP.Model.Time(); |
271 } |
309 } |
272 |
310 |
382 } |
420 } |
383 } |
421 } |
384 |
422 |
385 IriSP.Model.Source.prototype.setDefaultCurrentMedia = function() { |
423 IriSP.Model.Source.prototype.setDefaultCurrentMedia = function() { |
386 if (typeof this.currentMedia === "undefined") { |
424 if (typeof this.currentMedia === "undefined") { |
387 this.currentMedia = this.getList("media")[0]; |
425 this.currentMedia = this.getList("media").getElementAt(0); |
388 } |
426 } |
389 } |
427 } |
390 |
428 |
391 IriSP.Model.Source.prototype.listNamespaces = function() { |
429 IriSP.Model.Source.prototype.listNamespaces = function(_excludeSelf) { |
392 var _this = this, |
430 var _this = this, |
393 _nsls = []; |
431 _nsls = [], |
|
432 _excludeSelf = (typeof _excludeSelf !== "undefined" && _excludeSelf); |
394 this.each(function(_list) { |
433 this.each(function(_list) { |
395 IriSP._(_list.contents).each(function(_id) { |
434 IriSP._(_list.contents).each(function(_id) { |
396 var _ns = _id.replace(/:.*$/,''); |
435 var _ns = _id.replace(/:.*$/,''); |
397 if (_nsls.indexOf(_ns) === -1) { |
436 if (IriSP._(_nsls).indexOf(_ns) === -1 && (!_excludeSelf || _ns !== _this.namespace)) { |
398 _nsls.push(_ns); |
437 _nsls.push(_ns); |
399 } |
438 } |
400 }) |
439 }) |
401 }); |
440 }); |
402 return _nsls; |
441 return _nsls; |
429 return this.getList("annotation"); |
468 return this.getList("annotation"); |
430 } |
469 } |
431 |
470 |
432 IriSP.Model.Source.prototype.getMedias = function() { |
471 IriSP.Model.Source.prototype.getMedias = function() { |
433 return this.getList("media"); |
472 return this.getList("media"); |
|
473 } |
|
474 |
|
475 IriSP.Model.Source.prototype.getAnnotationTypes = function() { |
|
476 return this.getList("annotationType"); |
|
477 } |
|
478 |
|
479 IriSP.Model.Source.prototype.getAnnotationTypeByTitle = function(_title) { |
|
480 var _res = this.getAnnotationTypes().searchByTitle(_title); |
|
481 if (_res.length() > 0) { |
|
482 return _res.getElementAt(0); |
|
483 } |
434 } |
484 } |
435 |
485 |
436 IriSP.Model.Source.prototype.getDuration = function() { |
486 IriSP.Model.Source.prototype.getDuration = function() { |
437 return this.currentMedia.duration; |
487 return this.currentMedia.duration; |
438 } |
488 } |