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