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