2 |
2 |
3 IriSP.Model = { |
3 IriSP.Model = { |
4 SOURCE_STATUS_EMPTY : 0, |
4 SOURCE_STATUS_EMPTY : 0, |
5 SOURCE_STATUS_WAITING : 1, |
5 SOURCE_STATUS_WAITING : 1, |
6 SOURCE_STATUS_READY : 2, |
6 SOURCE_STATUS_READY : 2, |
7 IDS_AUTO_INCREMENT : 0, |
7 ID_AUTO_INCREMENT : 0 |
8 IDS_PREFIX : 'autoid-' |
8 } |
9 } |
9 |
10 |
10 /* */ |
11 /* */ |
11 |
12 |
12 IriSP.Model.List = function(_directory) { |
13 IriSP.Model.List = function() { |
13 this.contents = []; |
14 this.contents = {}; |
14 this.directory = _directory; |
15 } |
15 } |
16 |
16 |
17 IriSP.Model.List.prototype.toString = function() { |
17 IriSP.Model.List.prototype.toString = function() { |
18 return 'List of Elements, length=' + this.length(); |
18 return 'List of Elements, length=' + this.length(); |
19 } |
19 } |
20 |
20 |
21 IriSP.Model.List.prototype.keys = function() { |
|
22 return IriSP._(this.contents).keys(); |
|
23 } |
|
24 |
|
25 IriSP.Model.List.prototype.length = function() { |
21 IriSP.Model.List.prototype.length = function() { |
26 return this.keys().length; |
22 return this.contents.length; |
27 } |
23 } |
28 |
24 |
29 IriSP.Model.List.prototype.getElement = function(_id) { |
25 IriSP.Model.List.prototype.getElement = function(_id) { |
30 return this.contents[_id]; |
26 return this.directory.getElement(_id); |
31 } |
27 } |
32 |
28 |
33 IriSP.Model.List.prototype.getFirst = function() { |
29 IriSP.Model.List.prototype.getElementAt = function(_pos) { |
34 return this.contents(this.keys()[0]); |
30 if (_pos >= 0 && _pos < this.length()) { |
|
31 return this.getElement(this.contents[_pos]); |
|
32 } |
35 } |
33 } |
36 |
34 |
37 IriSP.Model.List.prototype.each = function(_callback) { |
35 IriSP.Model.List.prototype.each = function(_callback) { |
38 var _this = this; |
36 var _this = this; |
39 IriSP._(this.contents).each(function(_element, _id) { |
37 IriSP._(this.contents).each(function(_id) { |
40 _callback.call(_this, _element, _id); |
38 _callback.call(_this, _this.getElement(_id), _id); |
41 }); |
39 }); |
42 } |
40 } |
43 |
41 |
44 IriSP.Model.List.prototype.map = function(_callback) { |
42 IriSP.Model.List.prototype.map = function(_callback) { |
45 var _this = this; |
43 var _this = this; |
46 return IriSP._(this.contents).map(function(_element, _id) { |
44 return IriSP._(this.contents).map(function(_id) { |
47 return _callback.call(_this, _element, _id); |
45 return _callback.call(_this, _this.getElement(_id), _id); |
48 }); |
46 }); |
49 } |
47 } |
50 |
48 |
51 IriSP.Model.List.prototype.addElement = function(_element) { |
49 IriSP.Model.List.prototype.filter = function(_callback) { |
52 if ( typeof _element.id === "undefined" ) { |
50 var _this = this, |
53 IriSP.Model.AUTO_INCREMENT++; |
51 _res = new IriSP.Model.List(this.directory); |
54 _element.id = IriSP.Model.IDS_PREFIX + IriSP.Model.IDS_AUTO_INCREMENT; |
52 _res.contents = IriSP._(this.contents).filter(function(_id) { |
55 } |
53 return _callback.call(_this, _this.getElement(_id), _id); |
56 this.contents[_element.id] = _element; |
54 }); |
57 if ( this.hasParent ) { |
55 return _res; |
58 this.parent.addElement(_element); |
56 } |
59 } |
57 |
60 } |
58 IriSP.Model.List.prototype.searchByTitle = function(_text) { |
61 |
59 var _rgxp = new RegExp('(' + _text.replace(/(\W)/gm,'\\$1') + ')','gim'); |
62 IriSP.Model.List.prototype.addElements = function(_list) { |
60 return this.filter(function(_element) { |
63 var _this = this; |
61 return _rgxp.test(_element.text); |
64 _list.each(function(_element) { |
62 }); |
65 _this.addElement(_element); |
63 } |
66 }); |
64 |
67 } |
65 IriSP.Model.List.prototype.searchByDescription = function(_text) { |
|
66 var _rgxp = new RegExp('(' + _text.replace(/(\W)/gm,'\\$1') + ')','gim'); |
|
67 return this.filter(function(_element) { |
|
68 return _rgxp.test(_element.description); |
|
69 }); |
|
70 } |
|
71 |
|
72 IriSP.Model.List.prototype.searchByTextFields = function(_text) { |
|
73 var _rgxp = new RegExp('(' + _text.replace(/(\W)/gm,'\\$1') + ')','gim'); |
|
74 return this.filter(function(_element) { |
|
75 return _rgxp.test(_element.description); |
|
76 }); |
|
77 } |
|
78 |
|
79 IriSP.Model.List.prototype.addId = function(_id) { |
|
80 if (this.contents.indexOf(_id) === -1) { |
|
81 this.contents.push(_id); |
|
82 } |
|
83 } |
|
84 |
|
85 IriSP.Model.List.prototype.addElement = function(_el) { |
|
86 this.addId(_el.id); |
|
87 } |
|
88 |
|
89 IriSP.Model.List.prototype.addIdsFromArray = function(_array) { |
|
90 var _l = _array.length; |
|
91 for (var _i = 0; _i < _l; _i++) { |
|
92 this.addId(_array[_i]); |
|
93 } |
|
94 } |
|
95 |
|
96 IriSP.Model.List.prototype.addIdsFromList = function(_list) { |
|
97 this.addIdsFromArray(_list.contents); |
|
98 } |
|
99 |
68 /* */ |
100 /* */ |
69 |
101 |
70 IriSP.Model.Time = function(_milliseconds) { |
102 IriSP.Model.Time = function(_milliseconds) { |
71 this.milliseconds = parseInt(typeof _milliseconds !== "undefined" ? _milliseconds : 0); |
103 this.milliseconds = parseInt(typeof _milliseconds !== "undefined" ? _milliseconds : 0); |
72 } |
104 } |
103 } |
135 } |
104 _res += pad(_hms.minutes) + ':' + pad(_hms.seconds); |
136 _res += pad(_hms.minutes) + ':' + pad(_hms.seconds); |
105 return _res; |
137 return _res; |
106 } |
138 } |
107 |
139 |
108 IriSP.Model.BrokenReference = function(_elementType, _idRef) { |
140 /* */ |
109 this.id = _idRef; |
141 |
110 this.elementType = 'brokenReference'; |
142 IriSP.Model.Reference = function(_directory, _idRef) { |
111 this.originalElementType = _elementType; |
143 this.directory = _directory; |
112 this.isSolved = false; |
144 if (typeof _idRef === "object") { |
113 } |
145 this.isList = true; |
114 |
146 this.contents = new IriSP.Model.List(this.directory); |
115 IriSP.Model.BrokenReference.prototype.toString = function() { |
147 this.contents.addIdsFromArray(_idRef); |
116 return 'Broken reference to ' + IriSP.Model.ELEMENT_TYPES[_elementType].element_str + ', id=' + this.id; |
|
117 } |
|
118 |
|
119 IriSP.Model.BrokenReference.prototype.tryToSolve = function(_container) { |
|
120 if (this.isSolved) { |
|
121 return this.solution; |
|
122 } |
|
123 var _obj = _container.getElement(this.originalElementType, this.id); |
|
124 if (typeof _obj !== "undefined") { |
|
125 this.isSolved = true; |
|
126 this.solution = _obj; |
|
127 return this.solution; |
|
128 } else { |
148 } else { |
129 return undefined; |
149 this.isList = false; |
130 } |
150 this.contents = _idRef; |
|
151 } |
|
152 } |
|
153 |
|
154 IriSP.Model.Reference.prototype.getContents = function() { |
|
155 return (this.isList ? this.contents : this.directory.getElement(this.contents)); |
131 } |
156 } |
132 |
157 |
133 /* */ |
158 /* */ |
134 |
159 |
135 IriSP.Model.Element = function(_id, _source) { |
160 IriSP.Model.Element = function(_id, _source) { |
136 this.elementType = 'element'; |
161 this.elementType = 'element'; |
137 if (typeof _id === "undefined") { |
162 if (typeof _id !== "undefined" && typeof _source !== "undefined") { |
138 IriSP.Model.IDS_AUTO_INCREMENT++; |
163 this.source = _source; |
139 this.id = IriSP.Model.IDS_PREFIX + IriSP.Model.AUTO_INCREMENT; |
|
140 } else { |
|
141 this.id = _id; |
164 this.id = _id; |
142 } |
165 this.title = ""; |
143 this.source = _source; |
166 this.description = ""; |
144 this.title = ""; |
167 this.source.directory.addElement(this); |
145 this.description = ""; |
168 } |
146 } |
169 } |
147 |
170 |
148 IriSP.Model.Element.prototype.toString = function() { |
171 IriSP.Model.Element.prototype.toString = function() { |
149 return this.elementType + ', id=' + this.id + ', title="' + this.title + '"'; |
172 return this.elementType + (this.elementType !== 'element' ? ', id=' + this.id + ', title="' + this.title + '"' : ''); |
150 } |
173 } |
151 |
174 |
152 IriSP.Model.Element.prototype.getReference = function(_container, _elementType, _idRef) { |
175 IriSP.Model.Element.prototype.setReference = function(_elementType, _idRef) { |
153 var _obj = _container.getElement(_elementType, _idRef); |
176 this[_elementType] = new IriSP.Model.Reference(this.source.directory, _idRef); |
154 if (typeof _obj === "undefined") { |
177 } |
155 _obj = new IriSP.Model.BrokenReference(_elementType, _idRef); |
178 |
156 } |
179 IriSP.Model.Element.prototype.getReference = function(_elementType) { |
157 _obj.backReference(this); |
180 if (typeof this[_elementType] !== "undefined") { |
158 return _obj; |
181 return this[_elementType].getContents(); |
159 } |
182 } |
160 |
183 } |
161 IriSP.Model.Element.prototype.backReference = function(_object) { |
184 |
162 if (typeof this.referencedBy === "undefined") { |
185 /* */ |
163 this.referencedBy = {} |
186 |
164 } |
187 IriSP.Model.Media = function(_id, _directory) { |
165 if (typeof this.referencedBy[_object.elementType] === "undefined") { |
188 IriSP.Model.Element.call(this, _id, _directory); |
166 this.referencedBy[_object.elementType] = new IriSP.Model.List(); |
|
167 } |
|
168 this.referencedBy[_object.elementType].addElement(_object); |
|
169 } |
|
170 |
|
171 IriSP.Model.Element.prototype.otmCrossReference = function(_container, _elementType, _idRef) { |
|
172 if (typeof this.referencing === "undefined") { |
|
173 this.referencing = {}; |
|
174 } |
|
175 this.referencing[_elementType] = this.getReference(_container, _elementType, _idRef); |
|
176 } |
|
177 |
|
178 IriSP.Model.Element.prototype.mtmCrossReference = function(_container, _elementType, _idRefList) { |
|
179 if (typeof this.referencing === "undefined") { |
|
180 this.referencing = {}; |
|
181 } |
|
182 this.referencing[_elementType] = new IriSP.Model.List; |
|
183 for (var _i = 0; _i < _idRefList.length; _i++) { |
|
184 this.referencing[_elementType].addElement(this.getReference(_container, _elementType, _idRefList[_i])); |
|
185 } |
|
186 } |
|
187 /* */ |
|
188 |
|
189 IriSP.Model.Media = function(_id, _source) { |
|
190 IriSP.Model.Element.call(this, _id, _source); |
|
191 this.elementType = 'media'; |
189 this.elementType = 'media'; |
192 this.duration = new IriSP.Model.Time(); |
190 this.duration = new IriSP.Model.Time(); |
193 this.url = ''; |
191 this.url = ''; |
194 } |
192 } |
195 |
193 |
196 IriSP.Model.Media.prototype = new IriSP.Model.Element(null); |
194 IriSP.Model.Media.prototype = new IriSP.Model.Element(); |
197 |
195 |
198 IriSP.Model.Media.prototype.setDuration = function(_durationMs) { |
196 IriSP.Model.Media.prototype.setDuration = function(_durationMs) { |
199 this.duration.milliseconds = _durationMs; |
197 this.duration.milliseconds = _durationMs; |
200 } |
198 } |
201 |
199 |
202 /* */ |
200 /* */ |
203 |
201 |
204 IriSP.Model.AnnotationType = function(_id, _source) { |
202 IriSP.Model.Tag = function(_id, _directory) { |
205 IriSP.Model.Element.call(this, _id, _source); |
203 IriSP.Model.Element.call(this, _id, _directory); |
|
204 this.elementType = 'tag'; |
|
205 } |
|
206 |
|
207 IriSP.Model.Tag.prototype = new IriSP.Model.Element(); |
|
208 |
|
209 /* */ |
|
210 |
|
211 IriSP.Model.AnnotationType = function(_id, _directory) { |
|
212 IriSP.Model.Element.call(this, _id, _directory); |
206 this.elementType = 'annotationType'; |
213 this.elementType = 'annotationType'; |
207 } |
214 } |
208 |
215 |
209 IriSP.Model.AnnotationType.prototype = new IriSP.Model.Element(null); |
216 IriSP.Model.AnnotationType.prototype = new IriSP.Model.Element(); |
210 |
217 |
211 /* Annotation |
218 /* Annotation |
212 * */ |
219 * */ |
213 |
220 |
214 IriSP.Model.Annotation = function(_id, _source) { |
221 IriSP.Model.Annotation = function(_id, _directory) { |
215 IriSP.Model.Element.call(this, _id, _source); |
222 IriSP.Model.Element.call(this, _id, _directory); |
216 this.elementType = 'annotation'; |
223 this.elementType = 'annotation'; |
217 this.begin = new IriSP.Model.Time(); |
224 this.begin = new IriSP.Model.Time(); |
218 this.end = new IriSP.Model.Time(); |
225 this.end = new IriSP.Model.Time(); |
219 } |
226 } |
220 |
227 |
226 |
233 |
227 IriSP.Model.Annotation.prototype.setEnd = function(_beginMs) { |
234 IriSP.Model.Annotation.prototype.setEnd = function(_beginMs) { |
228 this.end.milliseconds = _beginMs; |
235 this.end.milliseconds = _beginMs; |
229 } |
236 } |
230 |
237 |
231 IriSP.Model.Annotation.prototype.setMedia = function(_idRef, _container) { |
238 IriSP.Model.Annotation.prototype.setMedia = function(_idRef) { |
232 this.otmCrossReference(_container, "media" , _idRef); |
239 this.setReference("media", _idRef); |
233 } |
240 } |
234 |
241 |
235 IriSP.Model.Annotation.prototype.getMedia = function() { |
242 IriSP.Model.Annotation.prototype.getMedia = function() { |
236 return this.referencing.media; |
243 return this.getReference("media"); |
237 } |
244 } |
238 |
245 |
239 IriSP.Model.Annotation.prototype.setAnnotationType = function(_idRef, _container) { |
246 IriSP.Model.Annotation.prototype.setAnnotationType = function(_idRef) { |
240 this.otmCrossReference(_container, "annotationType" , _idRef); |
247 this.setReference("annotationType", _idRef); |
241 } |
248 } |
242 |
249 |
243 IriSP.Model.Annotation.prototype.getAnnotationType = function() { |
250 IriSP.Model.Annotation.prototype.getAnnotationType = function() { |
244 return this.referencing.annotation_type; |
251 return this.getReference("annotationType"); |
245 } |
252 } |
246 |
253 |
247 /* A Container contains lists of elements. It corresponds to the root of Cinelab |
254 IriSP.Model.Annotation.prototype.setTags = function(_idRefs) { |
248 * */ |
255 this.setReference("tag", _idRefs); |
249 |
256 } |
250 IriSP.Model.Container = function(_parent) { |
257 |
251 this.hasParent = (typeof _parent !== "undefined"); |
258 IriSP.Model.Annotation.prototype.getTags = function() { |
252 if (this.hasParent) { |
259 return this.getReference("tag"); |
253 this.parent = _parent; |
260 } |
254 } |
261 |
255 this.contents = {} |
262 /* */ |
256 } |
263 |
257 |
264 IriSP.Model.Source = function(_properties) { |
258 IriSP.Model.Container.prototype.each = function(_callback) { |
265 this.status = IriSP.Model.SOURCE_STATUS_EMPTY; |
259 var _this = this; |
266 this.config = _properties; |
260 IriSP._(this.contents).each(function(_element, _id) { |
267 this.callbackQueue = []; |
261 _callback.call(_this, _element, _id); |
268 this.contents = {}; |
262 }); |
269 this.get(); |
263 } |
270 } |
264 |
271 |
265 IriSP.Model.Container.prototype.map = function(_callback) { |
272 IriSP.Model.Source.prototype.addList = function(_listId, _contents) { |
266 var _this = this; |
|
267 return IriSP._(this.contents).map(function(_element, _id) { |
|
268 return _callback.call(_this, _element, _id); |
|
269 }); |
|
270 } |
|
271 |
|
272 IriSP.Model.Container.prototype.addList = function(_listId, _contents) { |
|
273 if (this.hasParent) { |
|
274 this.parent.addList(_listId, _contents); |
|
275 } |
|
276 if (typeof this.contents[_listId] === "undefined") { |
273 if (typeof this.contents[_listId] === "undefined") { |
277 this.contents[_listId] = _contents; |
274 this.contents[_listId] = new IriSP.Model.List(this.config.directory); |
278 } else { |
275 } |
279 this.contents[_listId].addElements(_contents); |
276 this.contents[_listId].addIdsFromList(_contents); |
280 } |
277 } |
281 } |
278 |
282 |
279 IriSP.Model.Source.prototype.getList = function(_listId) { |
283 IriSP.Model.Container.prototype.getList = function(_listId) { |
|
284 if (typeof this.contents[_listId] === "undefined") { |
280 if (typeof this.contents[_listId] === "undefined") { |
285 if (this.hasParent) { |
281 return this.config.directory.getGlobalList.filter(function(_e) { |
286 return this.parent.getList(_listId); |
282 return (_e.elType === _listId); |
287 } else { |
283 }); |
288 return undefined; |
|
289 } |
|
290 } else { |
284 } else { |
291 return this.contents[_listId]; |
285 return this.contents[_listId]; |
292 } |
286 } |
293 } |
287 } |
294 |
288 |
295 IriSP.Model.Container.prototype.getElement = function(_listId, _elId) { |
289 IriSP.Model.Source.prototype.getElement = function(_listId, _elId) { |
296 var _list = this.getList(_listId); |
290 var _list = this.getList(_listId); |
297 return (typeof _list !== "undefined" ? _list.getElement(_elId) : undefined); |
291 return (typeof _list !== "undefined" ? _list.getElement(_elId) : undefined); |
298 } |
292 } |
299 |
293 |
300 IriSP.Model.Container.prototype.getMedias = function(_contents) { |
294 IriSP.Model.Source.prototype.setCurrentMediaId = function(_idRef) { |
|
295 if (typeof _idRef !== "undefined") { |
|
296 this.currentMedia = _idRef; |
|
297 } |
|
298 } |
|
299 |
|
300 IriSP.Model.Source.prototype.setDefaultCurrentMedia = function() { |
|
301 if (typeof this.currentMedia === "undefined") { |
|
302 this.currentMedia = this.getList("media")[0]; |
|
303 } |
|
304 } |
|
305 |
|
306 IriSP.Model.Source.prototype.get = function() { |
|
307 this.status = IriSP.Model.SOURCE_STATUS_WAITING; |
|
308 this.status = IriSP.Model.SOURCE_STATUS_READY; |
|
309 var _this = this; |
|
310 if (_this.callbackQueue.length) { |
|
311 IriSP._.each(_this.callbackQueue, function(_callback) { |
|
312 _callback.call(_this); |
|
313 }); |
|
314 } |
|
315 _this.callbackQueue = []; |
|
316 } |
|
317 |
|
318 IriSP.Model.Source.prototype.addCallback = function(_callback) { |
|
319 if (this.status === IriSP.Model.SOURCE_STATUS_READY) { |
|
320 callback.call(this); |
|
321 } else { |
|
322 this.callbackQueue.push(_callback); |
|
323 } |
|
324 } |
|
325 |
|
326 IriSP.Model.Source.prototype.getAnnotations = function() { |
|
327 return this.getList("annotation"); |
|
328 } |
|
329 |
|
330 IriSP.Model.Source.prototype.getMedias = function() { |
301 return this.getList("media"); |
331 return this.getList("media"); |
302 } |
332 } |
303 |
333 |
304 IriSP.Model.Container.prototype.getAnnotations = function(_contents) { |
334 IriSP.Model.Source.prototype.getDuration = function() { |
305 return this.getList("annotation"); |
335 return this.currentMedia.duration; |
306 } |
336 } |
307 |
337 |
308 IriSP.Model.Container.prototype.setCurrentMediaById = function(_idRef) { |
338 /* */ |
309 if (typeof _idRef !== "undefined") { |
339 |
310 this.currentMedia = this.getElement("media", _idRef); |
340 IriSP.Model.RemoteSource = function() { |
311 } |
341 IriSP.Model.Element.call(this, _id, _directory); |
312 } |
342 this.elementType = 'tag'; |
313 |
343 } |
314 IriSP.Model.Container.prototype.setDefaultCurrentMedia = function() { |
344 |
315 if (typeof this.currentMedia === "undefined") { |
345 IriSP.Model.RemoteSource.prototype = new IriSP.Model.Source(); |
316 this.currentMedia = this.getMedias().getFirst(); |
346 |
317 } |
347 IriSP.Model.RemoteSource.prototype.get = function() { |
318 } |
|
319 |
|
320 /* */ |
|
321 |
|
322 IriSP.Model.Source = function(_directory, _url, _serializer) { |
|
323 this.status = IriSP.Model.SOURCE_STATUS_EMPTY; |
|
324 if (typeof _directory === "undefined") { |
|
325 throw "Error : Model.Source called with no parent directory"; |
|
326 } |
|
327 if (typeof _url === "undefined") { |
|
328 throw "Error : Model.Source called with no URL"; |
|
329 } |
|
330 if (typeof _serializer === "undefined") { |
|
331 throw "Error : Model.Source called with no serializer"; |
|
332 } |
|
333 this.directory = _directory; |
|
334 this.serializer = _serializer; |
|
335 this.url = _url; |
|
336 this.callbackQueue = []; |
|
337 this.container = new IriSP.Model.Container(_directory.consolidated); |
|
338 this.get(); |
|
339 } |
|
340 |
|
341 IriSP.Model.Source.prototype.get = function() { |
|
342 this.status = IriSP.Model.SOURCE_STATUS_WAITING; |
348 this.status = IriSP.Model.SOURCE_STATUS_WAITING; |
343 var _this = this; |
349 var _this = this; |
344 IriSP.jQuery.getJSON(this.url, function(_result) { |
350 IriSP.jQuery.getJSON(this.url, function(_result) { |
345 _this.serializer.deSerialize(_result, _this.container); |
351 _this.serializer.deSerialize(_result, _this); |
346 if (_this.callbackQueue.length) { |
352 if (_this.callbackQueue.length) { |
347 IriSP._.each(_this.callbackQueue, function(_callback) { |
353 IriSP._.each(_this.callbackQueue, function(_callback) { |
348 _callback.call(_this); |
354 _callback.call(_this); |
349 }); |
355 }); |
350 } |
356 } |
351 _this.callbackQueue = []; |
357 _this.callbackQueue = []; |
352 _this.status = IriSP.Model.SOURCE_STATUS_READY; |
358 _this.status = IriSP.Model.SOURCE_STATUS_READY; |
353 }); |
359 }); |
354 } |
360 } |
355 |
361 |
356 IriSP.Model.Source.prototype.addCallback = function(_callback) { |
|
357 if (this.status === IriSP.Model.SOURCE_STATUS_READY) { |
|
358 callback.call(this); |
|
359 } else { |
|
360 this.callbackQueue.push(_callback); |
|
361 } |
|
362 } |
|
363 |
|
364 IriSP.Model.Source.prototype.getAnnotations = function() { |
|
365 return this.container.getAnnotations(); |
|
366 } |
|
367 |
|
368 IriSP.Model.Source.prototype.getMedias = function() { |
|
369 return this.container.getMedias(); |
|
370 } |
|
371 |
|
372 IriSP.Model.Source.prototype.getCurrentMedia = function() { |
|
373 return this.container.currentMedia; |
|
374 } |
|
375 |
|
376 IriSP.Model.Source.prototype.getDuration = function() { |
|
377 return this.getCurrentMedia().duration; |
|
378 } |
|
379 |
|
380 /* */ |
362 /* */ |
381 |
363 |
382 IriSP.Model.Directory = function() { |
364 IriSP.Model.Directory = function() { |
383 this.sources = {}; |
365 this.remoteSources = {}; |
384 this.imports = {}; |
366 this.localSource = []; |
385 this.consolidated = new IriSP.Model.Container(); |
367 this.elements = {}; |
386 } |
368 this.nameSpaces = {}; |
387 |
369 } |
388 IriSP.Model.Directory.prototype.addSource = function(_source, _serializer) { |
370 |
389 this.sources[_source] = new IriSP.Model.Source(this, _source, _serializer); |
371 IriSP.Model.Directory.prototype.remoteSource = function(_properties) { |
390 } |
372 if (typeof this.remoteSources[_properties.url] === "undefined") { |
391 |
373 this.remoteSources[_properties.url] = new IriSP.Model.RemoteSource(_properties); |
392 IriSP.Model.Directory.prototype.source = function(_source, _serializer) { |
374 } |
393 if (typeof this.sources[_source] === "undefined") { |
375 return this.remoteSources[_properties.url]; |
394 this.addSource(_source, _serializer); |
376 } |
395 } |
377 |
396 return this.sources[_source]; |
378 IriSP.Model.Directory.prototype.getElement = function(_id) { |
397 } |
379 return this.elements[_id]; |
398 |
380 } |
399 /* */ |
381 |
|
382 IriSP.Model.Directory.prototype.addElement = function(_element) { |
|
383 this.elements[_element.id] = _element; |
|
384 } |
|
385 |
|
386 IriSP.Model.Directory.prototype.getGlobalList = function() { |
|
387 var _res = new IriSP.Model.List(this); |
|
388 _res.addIdsFromArray(IriSP._(this.elements).keys()); |
|
389 return _res; |
|
390 } |
|
391 |
|
392 /* */ |