| author | veltr |
| Thu, 10 May 2012 18:48:09 +0200 | |
| branch | new-model |
| changeset 887 | 6a04bd37da0a |
| parent 881 | f11b234497f7 |
| child 900 | 7673d645a8e0 |
| permissions | -rw-r--r-- |
| 854 | 1 |
/* model.js is where data is stored in a standard form, whatever the serializer */ |
2 |
||
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
3 |
IriSP.Model = { |
| 868 | 4 |
_SOURCE_STATUS_EMPTY : 0, |
5 |
_SOURCE_STATUS_WAITING : 1, |
|
6 |
_SOURCE_STATUS_READY : 2, |
|
7 |
_ID_AUTO_INCREMENT : 0, |
|
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
8 |
getUID : function() { |
| 868 | 9 |
return "autoid-" + (++this._ID_AUTO_INCREMENT); |
| 860 | 10 |
}, |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
11 |
regexpFromTextOrArray : function(_textOrArray) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
12 |
function escapeText(_text) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
13 |
return _text.replace(/([\\\*\+\?\|\{\[\}\]\(\)\^\$\.\#\/])/gm, '\\$1'); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
14 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
15 |
return new RegExp( '(' |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
16 |
+ ( |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
17 |
typeof _textOrArray === "string" |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
18 |
? escapeText(_textOrArray) |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
19 |
: IriSP._(_textOrArray).map(escapeText).join("|") |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
20 |
) |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
21 |
+ ')', |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
22 |
'gim' |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
23 |
); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
24 |
}, |
| 860 | 25 |
isoToDate : function(_str) { |
26 |
// http://delete.me.uk/2005/03/iso8601.html |
|
27 |
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})))?)?)?)?"; |
|
28 |
var d = _str.match(new RegExp(regexp)); |
|
29 |
|
|
30 |
var offset = 0; |
|
31 |
var date = new Date(d[1], 0, 1); |
|
32 |
|
|
33 |
if (d[3]) { date.setMonth(d[3] - 1); } |
|
34 |
if (d[5]) { date.setDate(d[5]); } |
|
35 |
if (d[7]) { date.setHours(d[7]); } |
|
36 |
if (d[8]) { date.setMinutes(d[8]); } |
|
37 |
if (d[10]) { date.setSeconds(d[10]); } |
|
38 |
if (d[12]) { date.setMilliseconds(Number("0." + d[12]) * 1000); } |
|
39 |
if (d[14]) { |
|
40 |
offset = (Number(d[16]) * 60) + Number(d[17]); |
|
41 |
offset *= ((d[15] == '-') ? 1 : -1); |
|
42 |
} |
|
43 |
|
|
44 |
offset -= date.getTimezoneOffset(); |
|
45 |
time = (Number(date) + (offset * 60 * 1000)); |
|
46 |
var _res = new Date(); |
|
47 |
_res.setTime(Number(time)); |
|
48 |
return _res; |
|
49 |
}, |
|
50 |
dateToIso : function(d) { |
|
51 |
function pad(n){return n<10 ? '0'+n : n} |
|
52 |
return d.getUTCFullYear()+'-' |
|
53 |
+ pad(d.getUTCMonth()+1)+'-' |
|
54 |
+ pad(d.getUTCDate())+'T' |
|
55 |
+ pad(d.getUTCHours())+':' |
|
56 |
+ pad(d.getUTCMinutes())+':' |
|
57 |
+ pad(d.getUTCSeconds())+'Z' |
|
58 |
} |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
59 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
60 |
|
| 868 | 61 |
/* |
62 |
* IriSP.Model.List is a class for a list of elements (e.g. annotations, medias, etc. that each have a distinct ID) |
|
63 |
*/ |
|
| 858 | 64 |
IriSP.Model.List = function(_directory) { |
| 866 | 65 |
Array.call(this); |
| 858 | 66 |
this.directory = _directory; |
| 866 | 67 |
this.idIndex = []; |
| 860 | 68 |
if (typeof _directory == "undefined") { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
69 |
throw "Error : new IriSP.Model.List(directory): directory is undefined"; |
| 860 | 70 |
} |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
71 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
72 |
|
| 866 | 73 |
IriSP.Model.List.prototype = new Array(); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
74 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
75 |
IriSP.Model.List.prototype.getElement = function(_id) { |
| 881 | 76 |
var _index = IriSP._(this.idIndex).indexOf(_id); |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
77 |
if (_index !== -1) { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
78 |
return this[_index]; |
| 881 | 79 |
} else { |
80 |
var _un = _id.replace(/.*:/); |
|
81 |
return IriSP._(this.idIndex).find(function(_i) { |
|
82 |
return _i.replace(/.*:/) === _un; |
|
83 |
}); |
|
| 858 | 84 |
} |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
85 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
86 |
|
| 864 | 87 |
IriSP.Model.List.prototype.hasId = function(_id) { |
| 866 | 88 |
return (IriSP._(this.idIndex).indexOf(_id) !== -1); |
| 864 | 89 |
} |
90 |
||
| 868 | 91 |
/* On recent browsers, forEach and map are defined and do what we want. |
92 |
* Otherwise, we'll use the Underscore.js functions |
|
93 |
*/ |
|
| 866 | 94 |
if (typeof Array.prototype.forEach === "undefined") { |
95 |
IriSP.Model.List.prototype.forEach = function(_callback) { |
|
96 |
var _this = this; |
|
97 |
IriSP._(this).forEach(function(_value, _key) { |
|
98 |
_callback(_value, _key, _this); |
|
99 |
}); |
|
100 |
} |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
101 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
102 |
|
| 866 | 103 |
if (typeof Array.prototype.map === "undefined") { |
104 |
IriSP.Model.List.prototype.map = function(_callback) { |
|
105 |
var _this = this; |
|
106 |
return IriSP._(this).map(function(_value, _key) { |
|
107 |
return _callback(_value, _key, _this); |
|
108 |
}); |
|
109 |
} |
|
| 858 | 110 |
} |
111 |
||
| 868 | 112 |
/* We override Array's filter function because it doesn't return an IriSP.Model.List |
113 |
*/ |
|
| 858 | 114 |
IriSP.Model.List.prototype.filter = function(_callback) { |
115 |
var _this = this, |
|
116 |
_res = new IriSP.Model.List(this.directory); |
|
| 866 | 117 |
_res.addElements(IriSP._(this).filter(function(_value, _key) { |
118 |
return _callback(_value, _key, _this); |
|
119 |
})); |
|
| 858 | 120 |
return _res; |
121 |
} |
|
122 |
||
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
123 |
IriSP.Model.List.prototype.slice = function(_start, _end) { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
124 |
var _res = new IriSP.Model.List(this.directory); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
125 |
_res.addElements(Array.prototype.slice.call(this, _start, _end)); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
126 |
return _res; |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
127 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
128 |
|
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
129 |
IriSP.Model.List.prototype.splice = function(_start, _end) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
130 |
var _res = new IriSP.Model.List(this.directory); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
131 |
_res.addElements(Array.prototype.splice.call(this, _start, _end)); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
132 |
this.idIndex.splice(_start, _end); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
133 |
return _res; |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
134 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
135 |
|
| 868 | 136 |
/* Array has a sort function, but it's not as interesting as Underscore.js's sortBy |
137 |
* and won't return a new IriSP.Model.List |
|
138 |
*/ |
|
| 864 | 139 |
IriSP.Model.List.prototype.sortBy = function(_callback) { |
140 |
var _this = this, |
|
141 |
_res = new IriSP.Model.List(this.directory); |
|
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
142 |
_res.addElements(IriSP._(this).sortBy(function(_value, _key) { |
| 866 | 143 |
return _callback(_value, _key, _this); |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
144 |
})); |
| 864 | 145 |
return _res; |
146 |
} |
|
147 |
||
| 868 | 148 |
/* Title and Description are basic information for (almost) all element types, |
149 |
* here we can search by these criteria |
|
150 |
*/ |
|
| 858 | 151 |
IriSP.Model.List.prototype.searchByTitle = function(_text) { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
152 |
var _rgxp = IriSP.Model.regexpFromTextOrArray(_text); |
| 858 | 153 |
return this.filter(function(_element) { |
| 864 | 154 |
return _rgxp.test(_element.title); |
| 858 | 155 |
}); |
156 |
} |
|
157 |
||
158 |
IriSP.Model.List.prototype.searchByDescription = function(_text) { |
|
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
159 |
var _rgxp = IriSP.Model.regexpFromTextOrArray(_text); |
| 858 | 160 |
return this.filter(function(_element) { |
161 |
return _rgxp.test(_element.description); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
162 |
}); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
163 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
164 |
|
| 858 | 165 |
IriSP.Model.List.prototype.searchByTextFields = function(_text) { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
166 |
var _rgxp = IriSP.Model.regexpFromTextOrArray(_text); |
| 858 | 167 |
return this.filter(function(_element) { |
| 864 | 168 |
return _rgxp.test(_element.description) || _rgxp.test(_element.title); |
| 858 | 169 |
}); |
170 |
} |
|
171 |
||
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
172 |
IriSP.Model.List.prototype.getTitles = function() { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
173 |
return this.map(function(_el) { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
174 |
return _el.title; |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
175 |
}); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
176 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
177 |
|
| 858 | 178 |
IriSP.Model.List.prototype.addId = function(_id) { |
| 866 | 179 |
var _el = this.directory.getElement(_id) |
180 |
if (!this.hasId(_id) && typeof _el !== "undefined") { |
|
181 |
this.idIndex.push(_id); |
|
182 |
Array.prototype.push.call(this, _el); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
183 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
184 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
185 |
|
| 866 | 186 |
IriSP.Model.List.prototype.push = function(_el) { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
187 |
if (typeof _el === "undefined") { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
188 |
return; |
| 866 | 189 |
} |
| 868 | 190 |
var _index = (IriSP._(this.idIndex).indexOf(_el.id)); |
191 |
if (_index === -1) { |
|
192 |
this.idIndex.push(_el.id); |
|
193 |
Array.prototype.push.call(this, _el); |
|
194 |
} else { |
|
195 |
this[_index] = _el; |
|
196 |
} |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
197 |
} |
| 858 | 198 |
|
| 866 | 199 |
IriSP.Model.List.prototype.addIds = function(_array) { |
200 |
var _l = _array.length, |
|
201 |
_this = this; |
|
202 |
IriSP._(_array).forEach(function(_id) { |
|
203 |
_this.addId(_id); |
|
204 |
}); |
|
| 858 | 205 |
} |
206 |
||
| 866 | 207 |
IriSP.Model.List.prototype.addElements = function(_array) { |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
208 |
var _this = this; |
| 866 | 209 |
IriSP._(_array).forEach(function(_el) { |
210 |
_this.push(_el); |
|
211 |
}); |
|
| 858 | 212 |
} |
213 |
||
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
214 |
IriSP.Model.List.prototype.removeId = function(_id) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
215 |
var _index = (IriSP._(this.idIndex).indexOf(_id)); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
216 |
if (_index !== -1) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
217 |
this.splice(_index,1); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
218 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
219 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
220 |
|
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
221 |
IriSP.Model.List.prototype.removeElement = function(_el) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
222 |
this.removeId(_el.id); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
223 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
224 |
|
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
225 |
IriSP.Model.List.prototype.removeIds = function(_list) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
226 |
var _this = this; |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
227 |
IriSP._(_list).forEach(function(_id) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
228 |
_this.removeId(_id); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
229 |
}); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
230 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
231 |
|
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
232 |
IriSP.Model.List.prototype.removeElements = function(_list) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
233 |
var _this = this; |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
234 |
IriSP._(_list).forEach(function(_el) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
235 |
_this.removeElement(_el); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
236 |
}); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
237 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
238 |
|
| 868 | 239 |
/* A simple time management object, that helps converting millisecs to seconds and strings, |
240 |
* without the clumsiness of the original Date object. |
|
241 |
*/ |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
242 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
243 |
IriSP.Model.Time = function(_milliseconds) { |
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
244 |
switch(typeof _milliseconds) { |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
245 |
case "string": |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
246 |
this.milliseconds = parseFloat(_milliseconds); |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
247 |
break; |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
248 |
case "number": |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
249 |
this.milliseconds = _milliseconds; |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
250 |
break; |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
251 |
case "object": |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
252 |
this.milliseconds = parseFloat(_milliseconds.valueOf()); |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
253 |
break; |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
254 |
default: |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
255 |
this.milliseconds = 0; |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
256 |
} |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
257 |
if (this.milliseconds === NaN) { |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
258 |
this.milliseconds = 0; |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
259 |
} |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
260 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
261 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
262 |
IriSP.Model.Time.prototype.setSeconds = function(_seconds) { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
263 |
this.milliseconds = 1000 * _seconds; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
264 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
265 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
266 |
IriSP.Model.Time.prototype.getSeconds = function() { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
267 |
return Math.floor(this.milliseconds / 1000); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
268 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
269 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
270 |
IriSP.Model.Time.prototype.getHMS = function() { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
271 |
var _totalSeconds = Math.abs(this.getSeconds()); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
272 |
return { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
273 |
hours : Math.floor(_totalSeconds / 3600), |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
274 |
minutes : (Math.floor(_totalSeconds / 60) % 60), |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
275 |
seconds : _totalSeconds % 60 |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
276 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
277 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
278 |
|
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
279 |
IriSP.Model.Time.prototype.add = function(_milliseconds) { |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
280 |
this.milliseconds += new IriSP.Model.Time(_milliseconds).milliseconds; |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
281 |
} |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
282 |
|
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
283 |
IriSP.Model.Time.prototype.valueOf = function() { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
284 |
return this.milliseconds; |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
285 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
286 |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
287 |
IriSP.Model.Time.prototype.toString = function() { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
288 |
function pad(_n) { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
289 |
var _res = _n.toString(); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
290 |
while (_res.length < 2) { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
291 |
_res = '0' + _res; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
292 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
293 |
return _res; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
294 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
295 |
var _hms = this.getHMS(), |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
296 |
_res = ''; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
297 |
if (_hms.hours) { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
298 |
_res += pad(_hms.hours) + ':' |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
299 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
300 |
_res += pad(_hms.minutes) + ':' + pad(_hms.seconds); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
301 |
return _res; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
302 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
303 |
|
| 868 | 304 |
/* IriSP.Model.Reference handles references between elements |
305 |
*/ |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
306 |
|
| 860 | 307 |
IriSP.Model.Reference = function(_source, _idRef) { |
308 |
this.source = _source; |
|
| 858 | 309 |
if (typeof _idRef === "object") { |
310 |
this.isList = true; |
|
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
311 |
this.id = IriSP._(_idRef).map(function(_id) { |
| 860 | 312 |
return _source.getNamespaced(_id).fullname; |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
313 |
}); |
| 858 | 314 |
} else { |
315 |
this.isList = false; |
|
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
316 |
this.id = _source.getNamespaced(_idRef).fullname; |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
317 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
318 |
this.refresh(); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
319 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
320 |
|
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
321 |
IriSP.Model.Reference.prototype.refresh = function() { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
322 |
if (this.isList) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
323 |
this.contents = new IriSP.Model.List(this.source.directory); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
324 |
this.contents.addIds(this.id); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
325 |
} else { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
326 |
this.contents = this.source.directory.getElement(this.id); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
327 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
328 |
|
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
329 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
330 |
|
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
331 |
IriSP.Model.Reference.prototype.getContents = function() { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
332 |
if (typeof this.contents === "undefined" || (this.isList && this.contents.length != this.id.length)) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
333 |
this.refresh(); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
334 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
335 |
return this.contents; |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
336 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
337 |
|
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
338 |
IriSP.Model.Reference.prototype.isOrHasId = function(_idRef) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
339 |
if (this.isList) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
340 |
return (IriSP._(this.id).indexOf(_idRef) !== -1) |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
341 |
} else { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
342 |
return (this.id == _idRef); |
| 858 | 343 |
} |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
344 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
345 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
346 |
/* */ |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
347 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
348 |
IriSP.Model.Element = function(_id, _source) { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
349 |
this.elementType = 'element'; |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
350 |
if (typeof _source === "undefined") { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
351 |
return; |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
352 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
353 |
if (typeof _id === "undefined" || !_id) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
354 |
_id = IriSP.Model.getUID(); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
355 |
} |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
356 |
this.source = _source; |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
357 |
this.namespacedId = _source.getNamespaced(_id) |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
358 |
this.id = this.namespacedId.fullname; |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
359 |
this.title = ""; |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
360 |
this.description = ""; |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
361 |
this.source.directory.addElement(this); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
362 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
363 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
364 |
IriSP.Model.Element.prototype.toString = function() { |
| 858 | 365 |
return this.elementType + (this.elementType !== 'element' ? ', id=' + this.id + ', title="' + this.title + '"' : ''); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
366 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
367 |
|
| 858 | 368 |
IriSP.Model.Element.prototype.setReference = function(_elementType, _idRef) { |
| 860 | 369 |
this[_elementType] = new IriSP.Model.Reference(this.source, _idRef); |
| 854 | 370 |
} |
371 |
||
| 858 | 372 |
IriSP.Model.Element.prototype.getReference = function(_elementType) { |
373 |
if (typeof this[_elementType] !== "undefined") { |
|
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
374 |
return this[_elementType].getContents(); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
375 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
376 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
377 |
|
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
378 |
IriSP.Model.Element.prototype.getRelated = function(_elementType, _global) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
379 |
_global = (typeof _global !== "undefined" && _global); |
| 864 | 380 |
var _this = this; |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
381 |
return this.source.getList(_elementType, _global).filter(function(_el) { |
| 864 | 382 |
var _ref = _el[_this.elementType]; |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
383 |
return _ref.isOrHasId(_this.id); |
| 864 | 384 |
}); |
385 |
} |
|
386 |
||
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
387 |
/* */ |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
388 |
|
| 864 | 389 |
IriSP.Model.Media = function(_id, _source) { |
390 |
IriSP.Model.Element.call(this, _id, _source); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
391 |
this.elementType = 'media'; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
392 |
this.duration = new IriSP.Model.Time(); |
| 866 | 393 |
this.video = ''; |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
394 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
395 |
|
| 858 | 396 |
IriSP.Model.Media.prototype = new IriSP.Model.Element(); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
397 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
398 |
IriSP.Model.Media.prototype.setDuration = function(_durationMs) { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
399 |
this.duration.milliseconds = _durationMs; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
400 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
401 |
|
| 864 | 402 |
IriSP.Model.Media.prototype.getAnnotations = function() { |
403 |
return this.getRelated("annotation"); |
|
404 |
} |
|
405 |
||
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
406 |
/* */ |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
407 |
|
| 864 | 408 |
IriSP.Model.Tag = function(_id, _source) { |
409 |
IriSP.Model.Element.call(this, _id, _source); |
|
| 858 | 410 |
this.elementType = 'tag'; |
411 |
} |
|
412 |
||
413 |
IriSP.Model.Tag.prototype = new IriSP.Model.Element(); |
|
414 |
||
| 864 | 415 |
IriSP.Model.Tag.prototype.getAnnotations = function() { |
416 |
return this.getRelated("annotation"); |
|
417 |
} |
|
418 |
||
| 858 | 419 |
/* */ |
420 |
||
| 864 | 421 |
IriSP.Model.AnnotationType = function(_id, _source) { |
422 |
IriSP.Model.Element.call(this, _id, _source); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
423 |
this.elementType = 'annotationType'; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
424 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
425 |
|
| 858 | 426 |
IriSP.Model.AnnotationType.prototype = new IriSP.Model.Element(); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
427 |
|
| 864 | 428 |
IriSP.Model.AnnotationType.prototype.getAnnotations = function() { |
429 |
return this.getRelated("annotation"); |
|
430 |
} |
|
431 |
||
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
432 |
/* Annotation |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
433 |
* */ |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
434 |
|
| 864 | 435 |
IriSP.Model.Annotation = function(_id, _source) { |
436 |
IriSP.Model.Element.call(this, _id, _source); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
437 |
this.elementType = 'annotation'; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
438 |
this.begin = new IriSP.Model.Time(); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
439 |
this.end = new IriSP.Model.Time(); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
440 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
441 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
442 |
IriSP.Model.Annotation.prototype = new IriSP.Model.Element(null); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
443 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
444 |
IriSP.Model.Annotation.prototype.setBegin = function(_beginMs) { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
445 |
this.begin.milliseconds = _beginMs; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
446 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
447 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
448 |
IriSP.Model.Annotation.prototype.setEnd = function(_beginMs) { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
449 |
this.end.milliseconds = _beginMs; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
450 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
451 |
|
| 858 | 452 |
IriSP.Model.Annotation.prototype.setMedia = function(_idRef) { |
453 |
this.setReference("media", _idRef); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
454 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
455 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
456 |
IriSP.Model.Annotation.prototype.getMedia = function() { |
| 858 | 457 |
return this.getReference("media"); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
458 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
459 |
|
| 858 | 460 |
IriSP.Model.Annotation.prototype.setAnnotationType = function(_idRef) { |
461 |
this.setReference("annotationType", _idRef); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
462 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
463 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
464 |
IriSP.Model.Annotation.prototype.getAnnotationType = function() { |
| 858 | 465 |
return this.getReference("annotationType"); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
466 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
467 |
|
| 858 | 468 |
IriSP.Model.Annotation.prototype.setTags = function(_idRefs) { |
469 |
this.setReference("tag", _idRefs); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
470 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
471 |
|
| 858 | 472 |
IriSP.Model.Annotation.prototype.getTags = function() { |
473 |
return this.getReference("tag"); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
474 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
475 |
|
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
476 |
IriSP.Model.Annotation.prototype.getTagTexts = function() { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
477 |
return this.getTags().getTitles(); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
478 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
479 |
|
| 858 | 480 |
/* */ |
481 |
||
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
482 |
IriSP.Model.MashedAnnotation = function(_annotation, _offset) { |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
483 |
IriSP.Model.Element.call(this, IriSP.Model.getUID(), _annotation.source); |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
484 |
this.elementType = 'mashedAnnotation'; |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
485 |
this.annotation = _annotation; |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
486 |
this.begin = new IriSP.Model.Time(_offset); |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
487 |
var _duration = (this.annotation.end - this.annotation.begin); |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
488 |
this.end = new IriSP.Model.Time(_offset + _duration) |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
489 |
this.title = this.annotation.title; |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
490 |
this.description = this.annotation.description; |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
491 |
} |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
492 |
|
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
493 |
IriSP.Model.MashedAnnotation.prototype = new IriSP.Model.Element(null); |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
494 |
|
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
495 |
IriSP.Model.MashedAnnotation.prototype.getMedia = function() { |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
496 |
return this.annotation.getReference("media"); |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
497 |
} |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
498 |
|
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
499 |
IriSP.Model.MashedAnnotation.prototype.getAnnotationType = function() { |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
500 |
return this.annotation.getReference("annotationType"); |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
501 |
} |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
502 |
|
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
503 |
IriSP.Model.MashedAnnotation.prototype.getTags = function() { |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
504 |
return this.annotation.getReference("tag"); |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
505 |
} |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
506 |
|
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
507 |
IriSP.Model.MashedAnnotation.prototype.getTagTexts = function() { |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
508 |
return this.annotation.getTags().getTitles(); |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
509 |
} |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
510 |
|
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
511 |
/* */ |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
512 |
|
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
513 |
IriSP.Model.Mashup = function(_id, _source) { |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
514 |
IriSP.Model.Element.call(this, _id, _source); |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
515 |
this.elementType = 'mashup'; |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
516 |
this.duration = new IriSP.Model.Time(); |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
517 |
this.segments = new IriSP.Model.List(); |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
518 |
this.medias = new IriSP.Model.List(); |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
519 |
} |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
520 |
|
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
521 |
IriSP.Model.Mashup.prototype = new IriSP.Model.Element(); |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
522 |
|
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
523 |
IriSP.Model.Mashup.prototype.addSegment = function(_annotation) { |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
524 |
this.segments.push(new IriSP.Model.MashedAnnotation(_annotation)); |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
525 |
this.medias.addElement(_annotation.getMedia()); |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
526 |
} |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
527 |
|
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
528 |
IriSP.Model.Mashup.prototype.getAnnotations = function() { |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
529 |
return this.segments; |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
530 |
} |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
531 |
|
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
532 |
IriSP.Model.Mashup.prototype.getMedias = function() { |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
533 |
return this.medias; |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
534 |
} |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
535 |
/* */ |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
536 |
|
| 860 | 537 |
IriSP.Model.Source = function(_config) { |
| 868 | 538 |
this.status = IriSP.Model._SOURCE_STATUS_EMPTY; |
| 860 | 539 |
if (typeof _config !== "undefined") { |
540 |
var _this = this; |
|
| 866 | 541 |
IriSP._(_config).forEach(function(_v, _k) { |
| 860 | 542 |
_this[_k] = _v; |
543 |
}) |
|
544 |
this.callbackQueue = []; |
|
545 |
this.contents = {}; |
|
546 |
if (typeof this.namespace === "undefined") { |
|
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
547 |
this.namespace = "metadataplayer"; |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
548 |
} else { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
549 |
if (typeof this.namespaceUrl === "undefined" && typeof this.url !== "undefined") { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
550 |
var _matches = this.url.match(/(^[^?&]+|[^?&][a-zA-Z0-9_%=?]+)/g), |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
551 |
_url = _matches[0]; |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
552 |
if (_matches.length > 1) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
553 |
_matches = IriSP._(_matches.slice(1)).reject(function(_txt) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
554 |
return /\?$/.test(_txt); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
555 |
}); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
556 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
557 |
if (_matches.length > 0) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
558 |
_url += '?' + _matches.join('&'); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
559 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
560 |
this.namespaceUrl = _url; |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
561 |
} |
| 860 | 562 |
} |
563 |
if (typeof this.namespaceUrl === "undefined") { |
|
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
564 |
this.namespaceUrl = "http://ldt.iri.centrepompidou.fr/"; |
| 860 | 565 |
} |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
566 |
this.directory.addNamespace(this.namespace, this.namespaceUrl); |
| 860 | 567 |
this.get(); |
568 |
} |
|
569 |
} |
|
570 |
||
571 |
IriSP.Model.Source.prototype.getNamespaced = function(_id) { |
|
572 |
var _tab = _id.split(':'); |
|
573 |
if (_tab.length > 1) { |
|
574 |
return { |
|
575 |
namespace : _tab[0], |
|
576 |
name : _tab[1], |
|
577 |
fullname : _id |
|
578 |
} |
|
579 |
} else { |
|
580 |
return { |
|
581 |
namespace : this.namespace, |
|
582 |
name : _id, |
|
583 |
fullname : this.namespace + ':' + _id |
|
584 |
} |
|
585 |
} |
|
586 |
} |
|
587 |
|
|
588 |
IriSP.Model.Source.prototype.unNamespace = function(_id) { |
|
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
589 |
if (typeof _id !== "undefined") { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
590 |
return _id.replace(this.namespace + ':', ''); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
591 |
} |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
592 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
593 |
|
| 858 | 594 |
IriSP.Model.Source.prototype.addList = function(_listId, _contents) { |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
595 |
if (typeof this.contents[_listId] === "undefined") { |
| 860 | 596 |
this.contents[_listId] = new IriSP.Model.List(this.directory); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
597 |
} |
| 866 | 598 |
this.contents[_listId].addElements(_contents); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
599 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
600 |
|
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
601 |
IriSP.Model.Source.prototype.getList = function(_listId, _global) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
602 |
_global = (typeof _global !== "undefined" && _global); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
603 |
if (_global || typeof this.contents[_listId] === "undefined") { |
| 860 | 604 |
return this.directory.getGlobalList().filter(function(_e) { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
605 |
return (_e.elementType === _listId); |
| 858 | 606 |
}); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
607 |
} else { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
608 |
return this.contents[_listId]; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
609 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
610 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
611 |
|
| 866 | 612 |
IriSP.Model.Source.prototype.forEach = function(_callback) { |
| 860 | 613 |
var _this = this; |
| 866 | 614 |
IriSP._(this.contents).forEach(function(_value, _key) { |
| 860 | 615 |
_callback.call(_this, _value, _key); |
616 |
}) |
|
617 |
} |
|
618 |
||
| 866 | 619 |
IriSP.Model.Source.prototype.getElement = function(_elId) { |
| 881 | 620 |
return this.directory.getElement(this.getNamespaced(_elId).fullname); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
621 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
622 |
|
| 858 | 623 |
IriSP.Model.Source.prototype.setCurrentMediaId = function(_idRef) { |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
624 |
if (typeof _idRef !== "undefined") { |
| 866 | 625 |
this.currentMedia = this.getMedias().getElement(this.getNamespaced(_idRef).fullname); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
626 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
627 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
628 |
|
| 858 | 629 |
IriSP.Model.Source.prototype.setDefaultCurrentMedia = function() { |
| 866 | 630 |
if (typeof this.currentMedia === "undefined" && this.getMedias().length) { |
631 |
this.currentMedia = this.getMedias()[0]; |
|
| 854 | 632 |
} |
633 |
} |
|
634 |
||
| 864 | 635 |
IriSP.Model.Source.prototype.listNamespaces = function(_excludeSelf) { |
| 860 | 636 |
var _this = this, |
| 864 | 637 |
_nsls = [], |
638 |
_excludeSelf = (typeof _excludeSelf !== "undefined" && _excludeSelf); |
|
| 866 | 639 |
this.forEach(function(_list) { |
640 |
IriSP._(_list).forEach(function(_el) { |
|
641 |
var _ns = _el.id.replace(/:.*$/,''); |
|
| 864 | 642 |
if (IriSP._(_nsls).indexOf(_ns) === -1 && (!_excludeSelf || _ns !== _this.namespace)) { |
| 860 | 643 |
_nsls.push(_ns); |
644 |
} |
|
645 |
}) |
|
646 |
}); |
|
647 |
return _nsls; |
|
648 |
} |
|
649 |
||
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
650 |
IriSP.Model.Source.prototype.get = function() { |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
651 |
this.status = IriSP.Model._SOURCE_STATUS_WAITING; |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
652 |
this.handleCallbacks(); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
653 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
654 |
|
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
655 |
/* We defer the callbacks calls so they execute after the queue is cleared */ |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
656 |
IriSP.Model.Source.prototype.deferCallback = function(_callback) { |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
657 |
var _this = this; |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
658 |
IriSP._.defer(function() { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
659 |
_callback.call(_this); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
660 |
}); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
661 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
662 |
|
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
663 |
IriSP.Model.Source.prototype.handleCallbacks = function() { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
664 |
this.status = IriSP.Model._SOURCE_STATUS_READY; |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
665 |
while (this.callbackQueue.length) { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
666 |
this.deferCallback(this.callbackQueue.splice(0,1)[0]); |
| 858 | 667 |
} |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
668 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
669 |
|
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
670 |
IriSP.Model.Source.prototype.onLoad = function(_callback) { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
671 |
if (this.status === IriSP.Model._SOURCE_STATUS_READY) { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
672 |
this.deferCallback(_callback); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
673 |
} else { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
674 |
this.callbackQueue.push(_callback); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
675 |
} |
| 854 | 676 |
} |
677 |
||
| 860 | 678 |
IriSP.Model.Source.prototype.serialize = function() { |
679 |
return this.serializer.serialize(this); |
|
680 |
} |
|
681 |
||
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
682 |
IriSP.Model.Source.prototype.deSerialize = function(_data) { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
683 |
this.serializer.deSerialize(_data, this); |
| 854 | 684 |
} |
685 |
||
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
686 |
IriSP.Model.Source.prototype.getAnnotations = function(_global) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
687 |
_global = (typeof _global !== "undefined" && _global); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
688 |
return this.getList("annotation", _global); |
| 854 | 689 |
} |
690 |
||
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
691 |
IriSP.Model.Source.prototype.getMedias = function(_global) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
692 |
_global = (typeof _global !== "undefined" && _global); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
693 |
return this.getList("media", _global); |
| 864 | 694 |
} |
695 |
||
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
696 |
IriSP.Model.Source.prototype.getAnnotationTypes = function(_global) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
697 |
_global = (typeof _global !== "undefined" && _global); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
698 |
return this.getList("annotationType", _global); |
| 864 | 699 |
} |
700 |
||
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
701 |
IriSP.Model.Source.prototype.getAnnotationsByTypeTitle = function(_title, _global) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
702 |
_global = (typeof _global !== "undefined" && _global); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
703 |
var _res = new IriSP.Model.List(this.directory), |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
704 |
_annTypes = this.getAnnotationTypes(_global).searchByTitle(_title); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
705 |
_annTypes.forEach(function(_annType) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
706 |
_res.addElements(_annType.getAnnotations(_global)); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
707 |
}) |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
708 |
return _res; |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
709 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
710 |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
711 |
IriSP.Model.Source.prototype.getDuration = function() { |
| 866 | 712 |
var _m = this.currentMedia; |
713 |
if (typeof _m !== "undefined") { |
|
714 |
return this.currentMedia.duration; |
|
715 |
} |
|
| 858 | 716 |
} |
717 |
||
718 |
/* */ |
|
719 |
||
| 860 | 720 |
IriSP.Model.RemoteSource = function(_config) { |
721 |
IriSP.Model.Source.call(this, _config); |
|
| 858 | 722 |
} |
723 |
||
724 |
IriSP.Model.RemoteSource.prototype = new IriSP.Model.Source(); |
|
725 |
||
726 |
IriSP.Model.RemoteSource.prototype.get = function() { |
|
| 868 | 727 |
this.status = IriSP.Model._SOURCE_STATUS_WAITING; |
| 858 | 728 |
var _this = this; |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
729 |
this.serializer.loadData(this.url, function(_result) { |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
730 |
_this.deSerialize(_result); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
731 |
_this.handleCallbacks(); |
| 858 | 732 |
}); |
| 854 | 733 |
} |
734 |
||
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
735 |
/* */ |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
736 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
737 |
IriSP.Model.Directory = function() { |
| 858 | 738 |
this.remoteSources = {}; |
739 |
this.elements = {}; |
|
| 860 | 740 |
this.namespaces = {}; |
| 858 | 741 |
} |
742 |
||
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
743 |
IriSP.Model.Directory.prototype.addNamespace = function(_namespace, _url) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
744 |
this.namespaces[_namespace] = _url; |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
745 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
746 |
|
| 858 | 747 |
IriSP.Model.Directory.prototype.remoteSource = function(_properties) { |
| 860 | 748 |
var _config = IriSP._({ directory: this }).extend(_properties); |
| 858 | 749 |
if (typeof this.remoteSources[_properties.url] === "undefined") { |
| 860 | 750 |
this.remoteSources[_properties.url] = new IriSP.Model.RemoteSource(_config); |
| 858 | 751 |
} |
752 |
return this.remoteSources[_properties.url]; |
|
| 854 | 753 |
} |
754 |
||
| 860 | 755 |
IriSP.Model.Directory.prototype.newLocalSource = function(_properties) { |
756 |
var _config = IriSP._({ directory: this }).extend(_properties), |
|
757 |
_res = new IriSP.Model.Source(_config); |
|
758 |
return _res; |
|
759 |
} |
|
760 |
||
| 858 | 761 |
IriSP.Model.Directory.prototype.getElement = function(_id) { |
| 881 | 762 |
var _res = this.elements[_id]; |
763 |
if (typeof _res === "undefined") { |
|
764 |
var _un = _id.replace(/.*:/), |
|
765 |
_keys = IriSP._(this.elements).keys(); |
|
766 |
_key = IriSP._(_keys).find(function(_i) { |
|
767 |
return _i.replace(/.*:/) === _un; |
|
768 |
}); |
|
769 |
if (typeof _key !== "undefined") { |
|
770 |
_res = this.elements[_key]; |
|
771 |
} |
|
772 |
} |
|
773 |
return _res; |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
774 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
775 |
|
| 858 | 776 |
IriSP.Model.Directory.prototype.addElement = function(_element) { |
777 |
this.elements[_element.id] = _element; |
|
778 |
} |
|
779 |
||
780 |
IriSP.Model.Directory.prototype.getGlobalList = function() { |
|
781 |
var _res = new IriSP.Model.List(this); |
|
| 866 | 782 |
_res.addIds(IriSP._(this.elements).keys()); |
| 858 | 783 |
return _res; |
| 854 | 784 |
} |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
785 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
786 |
/* */ |