| author | veltr |
| Mon, 05 Nov 2012 19:03:10 +0100 | |
| changeset 977 | 934a7b13a2ca |
| parent 976 | 4b9ec475026a |
| child 980 | 9ee8c00ae5b7 |
| 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 |
}, |
| 973 | 32 |
regexpFromTextOrArray : function(_textOrArray, _testOnly, _iexact) { |
33 |
var _testOnly = _testOnly || false, |
|
34 |
_iexact = _iexact || false; |
|
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
35 |
function escapeText(_text) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
36 |
return _text.replace(/([\\\*\+\?\|\{\[\}\]\(\)\^\$\.\#\/])/gm, '\\$1'); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
37 |
} |
| 925 | 38 |
var _source = |
39 |
typeof _textOrArray === "string" |
|
40 |
? escapeText(_textOrArray) |
|
| 973 | 41 |
: ns._(_textOrArray).map(escapeText).join("|"), |
42 |
_flags = 'im'; |
|
43 |
if (!_testOnly) { |
|
44 |
_source = '(' + _source + ')'; |
|
45 |
_flags += 'g'; |
|
| 925 | 46 |
} |
| 973 | 47 |
if (_iexact) { |
48 |
_source = '^' + _source + '$'; |
|
49 |
} |
|
50 |
return new RegExp( _source, _flags); |
|
|
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 |
*/ |
|
| 973 | 174 |
Model.List.prototype.searchByTitle = function(_text, _iexact) { |
175 |
var _iexact = _iexact || false, |
|
176 |
_rgxp = Model.regexpFromTextOrArray(_text, true); |
|
| 858 | 177 |
return this.filter(function(_element) { |
| 864 | 178 |
return _rgxp.test(_element.title); |
| 858 | 179 |
}); |
180 |
} |
|
181 |
||
| 973 | 182 |
Model.List.prototype.searchByDescription = function(_text, _iexact) { |
183 |
var _iexact = _iexact || false, |
|
184 |
_rgxp = Model.regexpFromTextOrArray(_text, true); |
|
| 858 | 185 |
return this.filter(function(_element) { |
186 |
return _rgxp.test(_element.description); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
187 |
}); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
188 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
189 |
|
| 973 | 190 |
Model.List.prototype.searchByTextFields = function(_text, _iexact) { |
191 |
var _iexact = _iexact || false, |
|
192 |
_rgxp = Model.regexpFromTextOrArray(_text, true); |
|
| 858 | 193 |
return this.filter(function(_element) { |
| 864 | 194 |
return _rgxp.test(_element.description) || _rgxp.test(_element.title); |
| 858 | 195 |
}); |
196 |
} |
|
197 |
||
| 970 | 198 |
Model.List.prototype.getTitles = function() { |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
199 |
return this.map(function(_el) { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
200 |
return _el.title; |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
201 |
}); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
202 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
203 |
|
| 970 | 204 |
Model.List.prototype.addId = function(_id) { |
| 866 | 205 |
var _el = this.directory.getElement(_id) |
206 |
if (!this.hasId(_id) && typeof _el !== "undefined") { |
|
207 |
this.idIndex.push(_id); |
|
208 |
Array.prototype.push.call(this, _el); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
209 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
210 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
211 |
|
| 970 | 212 |
Model.List.prototype.push = function(_el) { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
213 |
if (typeof _el === "undefined") { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
214 |
return; |
| 866 | 215 |
} |
| 970 | 216 |
var _index = (ns._(this.idIndex).indexOf(_el.id)); |
| 868 | 217 |
if (_index === -1) { |
218 |
this.idIndex.push(_el.id); |
|
219 |
Array.prototype.push.call(this, _el); |
|
220 |
} else { |
|
221 |
this[_index] = _el; |
|
222 |
} |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
223 |
} |
| 858 | 224 |
|
| 970 | 225 |
Model.List.prototype.addIds = function(_array) { |
| 866 | 226 |
var _l = _array.length, |
227 |
_this = this; |
|
| 970 | 228 |
ns._(_array).forEach(function(_id) { |
| 866 | 229 |
_this.addId(_id); |
230 |
}); |
|
| 858 | 231 |
} |
232 |
||
| 970 | 233 |
Model.List.prototype.addElements = function(_array) { |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
234 |
var _this = this; |
| 970 | 235 |
ns._(_array).forEach(function(_el) { |
| 866 | 236 |
_this.push(_el); |
237 |
}); |
|
| 858 | 238 |
} |
239 |
||
| 970 | 240 |
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
|
241 |
var _deleteFromDirectory = _deleteFromDirectory || false, |
| 970 | 242 |
_index = (ns._(this.idIndex).indexOf(_id)); |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
243 |
if (_index !== -1) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
244 |
this.splice(_index,1); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
245 |
} |
|
908
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
246 |
if (_deleteFromDirectory) { |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
247 |
delete this.directory.elements[_id]; |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
248 |
} |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
249 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
250 |
|
| 970 | 251 |
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
|
252 |
var _deleteFromDirectory = _deleteFromDirectory || false; |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
253 |
this.removeId(_el.id); |
|
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.removeIds = 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(_id) { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
260 |
_this.removeId(_id); |
|
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.removeElements = function(_list, _deleteFromDirectory) { |
|
908
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
265 |
var _deleteFromDirectory = _deleteFromDirectory || false, |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
266 |
_this = this; |
| 970 | 267 |
ns._(_list).forEach(function(_el) { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
268 |
_this.removeElement(_el); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
269 |
}); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
270 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
271 |
|
| 970 | 272 |
Model.List.prototype.on = function(_event, _callback) { |
|
937
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
273 |
if (typeof this.__events[_event] === "undefined") { |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
274 |
this.__events[_event] = []; |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
275 |
} |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
276 |
this.__events[_event].push(_callback); |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
277 |
} |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
278 |
|
| 970 | 279 |
Model.List.prototype.off = function(_event, _callback) { |
|
969
353b0881a0b9
Added On-the-fly (file-less) metadata generation test
veltr
parents:
965
diff
changeset
|
280 |
if (typeof this.__events[_event] !== "undefined") { |
| 970 | 281 |
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
|
282 |
return _fn === _callback; |
|
353b0881a0b9
Added On-the-fly (file-less) metadata generation test
veltr
parents:
965
diff
changeset
|
283 |
}); |
|
353b0881a0b9
Added On-the-fly (file-less) metadata generation test
veltr
parents:
965
diff
changeset
|
284 |
} |
|
353b0881a0b9
Added On-the-fly (file-less) metadata generation test
veltr
parents:
965
diff
changeset
|
285 |
} |
|
353b0881a0b9
Added On-the-fly (file-less) metadata generation test
veltr
parents:
965
diff
changeset
|
286 |
|
| 970 | 287 |
Model.List.prototype.trigger = function(_event, _data) { |
|
937
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
288 |
var _list = this; |
| 970 | 289 |
ns._(this.__events[_event]).each(function(_callback) { |
|
937
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
290 |
_callback.call(_list, _data); |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
291 |
}); |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
292 |
} |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
293 |
|
| 868 | 294 |
/* A simple time management object, that helps converting millisecs to seconds and strings, |
295 |
* without the clumsiness of the original Date object. |
|
296 |
*/ |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
297 |
|
| 970 | 298 |
Model.Time = function(_milliseconds) { |
| 900 | 299 |
this.milliseconds = 0; |
300 |
this.setMilliseconds(_milliseconds); |
|
301 |
} |
|
302 |
||
| 970 | 303 |
Model.Time.prototype.setMilliseconds = function(_milliseconds) { |
| 900 | 304 |
var _ante = _milliseconds; |
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
305 |
switch(typeof _milliseconds) { |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
306 |
case "string": |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
307 |
this.milliseconds = parseFloat(_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 "number": |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
310 |
this.milliseconds = _milliseconds; |
|
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 |
case "object": |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
313 |
this.milliseconds = parseFloat(_milliseconds.valueOf()); |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
314 |
break; |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
315 |
default: |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
316 |
this.milliseconds = 0; |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
317 |
} |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
318 |
if (this.milliseconds === NaN) { |
| 900 | 319 |
this.milliseconds = _ante; |
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
320 |
} |
|
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.setSeconds = function(_seconds) { |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
324 |
this.milliseconds = 1000 * _seconds; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
325 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
326 |
|
| 970 | 327 |
Model.Time.prototype.getSeconds = function() { |
| 917 | 328 |
return this.milliseconds / 1000; |
|
856
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 |
|
| 970 | 331 |
Model.Time.prototype.getHMS = function() { |
| 917 | 332 |
var _totalSeconds = Math.abs(Math.floor(this.getSeconds())); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
333 |
return { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
334 |
hours : Math.floor(_totalSeconds / 3600), |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
335 |
minutes : (Math.floor(_totalSeconds / 60) % 60), |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
336 |
seconds : _totalSeconds % 60 |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
337 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
338 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
339 |
|
| 970 | 340 |
Model.Time.prototype.add = function(_milliseconds) { |
341 |
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
|
342 |
} |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
343 |
|
| 970 | 344 |
Model.Time.prototype.valueOf = function() { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
345 |
return this.milliseconds; |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
346 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
347 |
|
| 970 | 348 |
Model.Time.prototype.toString = function() { |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
349 |
function pad(_n) { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
350 |
var _res = _n.toString(); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
351 |
while (_res.length < 2) { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
352 |
_res = '0' + _res; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
353 |
} |
|
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 |
var _hms = this.getHMS(), |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
357 |
_res = ''; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
358 |
if (_hms.hours) { |
| 976 | 359 |
_res += _hms.hours + ':' |
|
856
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 |
_res += pad(_hms.minutes) + ':' + pad(_hms.seconds); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
362 |
return _res; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
363 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
364 |
|
| 970 | 365 |
/* Model.Reference handles references between elements |
| 868 | 366 |
*/ |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
367 |
|
| 970 | 368 |
Model.Reference = function(_source, _idRef) { |
| 860 | 369 |
this.source = _source; |
| 916 | 370 |
this.id = _idRef; |
| 858 | 371 |
if (typeof _idRef === "object") { |
372 |
this.isList = true; |
|
373 |
} else { |
|
374 |
this.isList = false; |
|
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
375 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
376 |
this.refresh(); |
|
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 |
|
| 970 | 379 |
Model.Reference.prototype.refresh = function() { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
380 |
if (this.isList) { |
| 970 | 381 |
this.contents = new Model.List(this.source.directory); |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
382 |
this.contents.addIds(this.id); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
383 |
} else { |
| 957 | 384 |
this.contents = this.source.getElement(this.id); |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
385 |
} |
|
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 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
388 |
|
| 970 | 389 |
Model.Reference.prototype.getContents = function() { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
390 |
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
|
391 |
this.refresh(); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
392 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
393 |
return this.contents; |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
394 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
395 |
|
| 970 | 396 |
Model.Reference.prototype.isOrHasId = function(_idRef) { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
397 |
if (this.isList) { |
| 970 | 398 |
return (ns._(this.id).indexOf(_idRef) !== -1) |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
399 |
} else { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
400 |
return (this.id == _idRef); |
| 858 | 401 |
} |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
402 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
403 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
404 |
/* */ |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
405 |
|
| 970 | 406 |
Model.Element = function(_id, _source) { |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
407 |
this.elementType = 'element'; |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
408 |
if (typeof _source === "undefined") { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
409 |
return; |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
410 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
411 |
if (typeof _id === "undefined" || !_id) { |
| 970 | 412 |
_id = Model.getUID(); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
413 |
} |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
414 |
this.source = _source; |
| 916 | 415 |
this.id = _id; |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
416 |
this.title = ""; |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
417 |
this.description = ""; |
|
937
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
418 |
this.__events = {} |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
419 |
this.source.directory.addElement(this); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
420 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
421 |
|
| 970 | 422 |
Model.Element.prototype.toString = function() { |
| 858 | 423 |
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
|
424 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
425 |
|
| 970 | 426 |
Model.Element.prototype.setReference = function(_elementType, _idRef) { |
427 |
this[_elementType] = new Model.Reference(this.source, _idRef); |
|
| 854 | 428 |
} |
429 |
||
| 970 | 430 |
Model.Element.prototype.getReference = function(_elementType) { |
| 858 | 431 |
if (typeof this[_elementType] !== "undefined") { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
432 |
return this[_elementType].getContents(); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
433 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
434 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
435 |
|
| 970 | 436 |
Model.Element.prototype.getRelated = function(_elementType, _global) { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
437 |
_global = (typeof _global !== "undefined" && _global); |
| 864 | 438 |
var _this = this; |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
439 |
return this.source.getList(_elementType, _global).filter(function(_el) { |
| 864 | 440 |
var _ref = _el[_this.elementType]; |
|
969
353b0881a0b9
Added On-the-fly (file-less) metadata generation test
veltr
parents:
965
diff
changeset
|
441 |
return _ref && _ref.isOrHasId(_this.id); |
| 864 | 442 |
}); |
443 |
} |
|
444 |
||
| 970 | 445 |
Model.Element.prototype.on = function(_event, _callback) { |
|
937
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
446 |
if (typeof this.__events[_event] === "undefined") { |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
447 |
this.__events[_event] = []; |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
448 |
} |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
449 |
this.__events[_event].push(_callback); |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
450 |
} |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
451 |
|
| 970 | 452 |
Model.Element.prototype.off = function(_event, _callback) { |
|
969
353b0881a0b9
Added On-the-fly (file-less) metadata generation test
veltr
parents:
965
diff
changeset
|
453 |
if (typeof this.__events[_event] !== "undefined") { |
| 970 | 454 |
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
|
455 |
return _fn === _callback; |
|
353b0881a0b9
Added On-the-fly (file-less) metadata generation test
veltr
parents:
965
diff
changeset
|
456 |
}); |
|
353b0881a0b9
Added On-the-fly (file-less) metadata generation test
veltr
parents:
965
diff
changeset
|
457 |
} |
|
353b0881a0b9
Added On-the-fly (file-less) metadata generation test
veltr
parents:
965
diff
changeset
|
458 |
} |
|
353b0881a0b9
Added On-the-fly (file-less) metadata generation test
veltr
parents:
965
diff
changeset
|
459 |
|
| 970 | 460 |
Model.Element.prototype.trigger = function(_event, _data) { |
|
937
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
461 |
var _element = this; |
| 970 | 462 |
ns._(this.__events[_event]).each(function(_callback) { |
|
937
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
463 |
_callback.call(_element, _data); |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
464 |
}); |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
465 |
} |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
466 |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
467 |
/* */ |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
468 |
|
| 970 | 469 |
Model.Playable = function(_id, _source) { |
470 |
Model.Element.call(this, _id, _source); |
|
471 |
if (typeof _source === "undefined") { |
|
472 |
return; |
|
473 |
} |
|
474 |
this.elementType = 'playable'; |
|
475 |
this.currentTime = new Model.Time(); |
|
476 |
this.volume = .5; |
|
477 |
this.paused = true; |
|
478 |
this.muted = false; |
|
479 |
var _this = this; |
|
480 |
this.on("play", function() { |
|
481 |
_this.paused = false; |
|
482 |
}); |
|
483 |
this.on("pause", function() { |
|
484 |
_this.paused = true; |
|
485 |
}); |
|
486 |
this.on("timeupdate", function(_time) { |
|
487 |
_this.currentTime = _time; |
|
488 |
}); |
|
489 |
} |
|
490 |
||
491 |
Model.Playable.prototype = new Model.Element(); |
|
492 |
||
493 |
Model.Playable.prototype.getCurrentTime = function() { |
|
494 |
return this.currentTime; |
|
495 |
} |
|
496 |
||
497 |
Model.Playable.prototype.getVolume = function() { |
|
498 |
return this.volume; |
|
499 |
} |
|
500 |
||
501 |
Model.Playable.prototype.getPaused = function() { |
|
502 |
return this.paused; |
|
503 |
} |
|
504 |
||
505 |
Model.Playable.prototype.getMuted = function() { |
|
506 |
return this.muted; |
|
507 |
} |
|
508 |
||
509 |
Model.Playable.prototype.setCurrentTime = function(_time) { |
|
510 |
this.trigger("setcurrenttime",_time); |
|
511 |
} |
|
512 |
||
513 |
Model.Playable.prototype.setVolume = function(_vol) { |
|
514 |
this.trigger("setvolume",_vol); |
|
515 |
} |
|
516 |
||
517 |
Model.Playable.prototype.setMuted = function(_muted) { |
|
518 |
this.trigger("setmuted",_muted); |
|
519 |
} |
|
520 |
||
521 |
Model.Playable.prototype.play = function() { |
|
522 |
this.trigger("setplay"); |
|
523 |
} |
|
524 |
||
525 |
Model.Playable.prototype.pause = function() { |
|
526 |
this.trigger("setpause"); |
|
527 |
} |
|
528 |
||
529 |
||
530 |
/* */ |
|
531 |
||
532 |
Model.Media = function(_id, _source) { |
|
533 |
Model.Playable.call(this, _id, _source); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
534 |
this.elementType = 'media'; |
| 970 | 535 |
this.duration = new Model.Time(); |
| 866 | 536 |
this.video = ''; |
| 970 | 537 |
|
| 965 | 538 |
var _this = this; |
539 |
this.on("timeupdate", function(_time) { |
|
540 |
_this.getAnnotations().filter(function(_a) { |
|
541 |
return (_a.end <= _time || _a.begin > _time) && _a.playing |
|
542 |
}).forEach(function(_a) { |
|
543 |
_a.playing = false; |
|
544 |
_a.trigger("leave"); |
|
545 |
}); |
|
546 |
_this.getAnnotations().filter(function(_a) { |
|
547 |
return _a.begin <= _time && _a.end > _time && !_a.playing |
|
548 |
}).forEach(function(_a) { |
|
549 |
_a.playing = true; |
|
550 |
_a.trigger("enter"); |
|
551 |
}); |
|
552 |
}); |
|
|
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 = new Model.Playable(); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
556 |
|
| 957 | 557 |
/* Default functions to be overriden by players */ |
558 |
|
|
| 970 | 559 |
Model.Media.prototype.setDuration = function(_durationMs) { |
| 900 | 560 |
this.duration.setMilliseconds(_durationMs); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
561 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
562 |
|
| 970 | 563 |
Model.Media.prototype.getAnnotations = function() { |
| 864 | 564 |
return this.getRelated("annotation"); |
565 |
} |
|
566 |
||
| 970 | 567 |
Model.Media.prototype.getAnnotationsByTypeTitle = function(_title) { |
| 900 | 568 |
var _annTypes = this.source.getAnnotationTypes().searchByTitle(_title).pluck("id"); |
569 |
if (_annTypes.length) { |
|
570 |
return this.getAnnotations().filter(function(_annotation) { |
|
| 970 | 571 |
return ns._(_annTypes).indexOf(_annotation.getAnnotationType().id) !== -1; |
| 900 | 572 |
}); |
573 |
} else { |
|
| 970 | 574 |
return new Model.List(this.source.directory) |
| 900 | 575 |
} |
576 |
} |
|
577 |
||
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
578 |
/* */ |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
579 |
|
| 970 | 580 |
Model.Tag = function(_id, _source) { |
581 |
Model.Element.call(this, _id, _source); |
|
| 858 | 582 |
this.elementType = 'tag'; |
583 |
} |
|
584 |
||
| 970 | 585 |
Model.Tag.prototype = new Model.Element(); |
| 858 | 586 |
|
| 970 | 587 |
Model.Tag.prototype.getAnnotations = function() { |
| 864 | 588 |
return this.getRelated("annotation"); |
589 |
} |
|
590 |
||
| 858 | 591 |
/* */ |
| 970 | 592 |
Model.AnnotationType = function(_id, _source) { |
593 |
Model.Element.call(this, _id, _source); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
594 |
this.elementType = 'annotationType'; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
595 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
596 |
|
| 970 | 597 |
Model.AnnotationType.prototype = new Model.Element(); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
598 |
|
| 970 | 599 |
Model.AnnotationType.prototype.getAnnotations = function() { |
| 864 | 600 |
return this.getRelated("annotation"); |
601 |
} |
|
602 |
||
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
603 |
/* Annotation |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
604 |
* */ |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
605 |
|
| 970 | 606 |
Model.Annotation = function(_id, _source) { |
607 |
Model.Element.call(this, _id, _source); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
608 |
this.elementType = 'annotation'; |
| 970 | 609 |
this.begin = new Model.Time(); |
610 |
this.end = new Model.Time(); |
|
611 |
this.tag = new Model.Reference(_source, []); |
|
| 965 | 612 |
this.playing = false; |
| 964 | 613 |
var _this = this; |
614 |
this.on("click", function() { |
|
615 |
_this.getMedia().setCurrentTime(_this.begin); |
|
| 965 | 616 |
}); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
617 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
618 |
|
| 970 | 619 |
Model.Annotation.prototype = new Model.Element(); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
620 |
|
| 970 | 621 |
Model.Annotation.prototype.setBegin = function(_beginMs) { |
| 976 | 622 |
this.begin.setMilliseconds(Math.max(0,_beginMs)); |
623 |
this.trigger("change-begin"); |
|
|
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 |
|
| 976 | 626 |
Model.Annotation.prototype.setEnd = function(_endMs) { |
627 |
this.end.setMilliseconds(Math.min(_endMs)); |
|
628 |
this.trigger("change-end"); |
|
629 |
} |
|
630 |
||
631 |
Model.Annotation.prototype.setDuration = function(_durMs) { |
|
632 |
this.setEnd(_durMs + this.begin.milliseconds); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
633 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
634 |
|
| 970 | 635 |
Model.Annotation.prototype.setMedia = function(_idRef) { |
| 858 | 636 |
this.setReference("media", _idRef); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
637 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
638 |
|
| 970 | 639 |
Model.Annotation.prototype.getMedia = function() { |
| 858 | 640 |
return this.getReference("media"); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
641 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
642 |
|
| 970 | 643 |
Model.Annotation.prototype.setAnnotationType = function(_idRef) { |
| 858 | 644 |
this.setReference("annotationType", _idRef); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
645 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
646 |
|
| 970 | 647 |
Model.Annotation.prototype.getAnnotationType = function() { |
| 858 | 648 |
return this.getReference("annotationType"); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
649 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
650 |
|
| 970 | 651 |
Model.Annotation.prototype.setTags = function(_idRefs) { |
| 858 | 652 |
this.setReference("tag", _idRefs); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
653 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
654 |
|
| 970 | 655 |
Model.Annotation.prototype.getTags = function() { |
| 858 | 656 |
return this.getReference("tag"); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
657 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
658 |
|
| 970 | 659 |
Model.Annotation.prototype.getTagTexts = function() { |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
660 |
return this.getTags().getTitles(); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
661 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
662 |
|
| 970 | 663 |
Model.Annotation.prototype.getDuration = function() { |
664 |
return new Model.Time(this.end.milliseconds - this.begin.milliseconds) |
|
| 900 | 665 |
} |
666 |
||
| 858 | 667 |
/* */ |
668 |
||
| 970 | 669 |
Model.MashedAnnotation = function(_mashup, _annotation) { |
670 |
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
|
671 |
this.elementType = 'mashedAnnotation'; |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
672 |
this.annotation = _annotation; |
| 970 | 673 |
this.begin = new Model.Time(_mashup.duration); |
674 |
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
|
675 |
this.title = this.annotation.title; |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
676 |
this.description = this.annotation.description; |
| 900 | 677 |
this.color = this.annotation.color; |
| 965 | 678 |
var _this = this; |
679 |
this.on("click", function() { |
|
680 |
_mashup.setCurrentTime(_this.begin); |
|
681 |
}); |
|
|
887
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 = new Model.Element(null); |
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
685 |
|
| 970 | 686 |
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
|
687 |
return this.annotation.getReference("media"); |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
688 |
} |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
689 |
|
| 970 | 690 |
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
|
691 |
return this.annotation.getReference("annotationType"); |
|
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.MashedAnnotation.prototype.getTags = function() { |
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
695 |
return this.annotation.getReference("tag"); |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
696 |
} |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
697 |
|
| 970 | 698 |
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
|
699 |
return this.annotation.getTags().getTitles(); |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
700 |
} |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
701 |
|
| 970 | 702 |
Model.MashedAnnotation.prototype.getDuration = function() { |
| 940 | 703 |
return this.annotation.getDuration(); |
704 |
} |
|
705 |
||
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
706 |
/* */ |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
707 |
|
| 970 | 708 |
Model.Mashup = function(_id, _source) { |
709 |
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
|
710 |
this.elementType = 'mashup'; |
| 970 | 711 |
this.duration = new Model.Time(); |
712 |
this.segments = new Model.List(_source.directory); |
|
713 |
this.medias = new Model.List(_source.directory); |
|
| 965 | 714 |
var _currentMedia = null; |
715 |
var _this = this; |
|
716 |
this.on("timeupdate", function(_time) { |
|
717 |
_this.getAnnotations().filter(function(_a) { |
|
718 |
return (_a.end <= _time || _a.begin > _time) && _a.playing |
|
719 |
}).forEach(function(_a) { |
|
720 |
_a.playing = false; |
|
721 |
_a.trigger("leave"); |
|
722 |
}); |
|
723 |
_this.getAnnotations().filter(function(_a) { |
|
724 |
return _a.begin <= _time && _a.end > _time && !_a.playing |
|
725 |
}).forEach(function(_a) { |
|
726 |
_a.playing = true; |
|
727 |
_a.trigger("enter"); |
|
728 |
var _m = _a.getMedia(); |
|
729 |
if (_m !== _currentMedia) { |
|
730 |
if (_currentMedia) { |
|
731 |
_currentMedia.trigger("leave"); |
|
732 |
} |
|
733 |
_m.trigger("enter"); |
|
734 |
_currentMedia = _m; |
|
735 |
} |
|
736 |
}); |
|
737 |
}); |
|
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
738 |
} |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
739 |
|
| 970 | 740 |
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
|
741 |
|
| 970 | 742 |
Model.Mashup.prototype.addSegment = function(_annotation) { |
743 |
var _mashedAnnotation = new Model.MashedAnnotation(this, _annotation); |
|
| 900 | 744 |
this.duration.setMilliseconds(_mashedAnnotation.end); |
745 |
this.segments.push(_mashedAnnotation); |
|
746 |
this.medias.push(_annotation.getMedia()); |
|
747 |
} |
|
748 |
||
| 970 | 749 |
Model.Mashup.prototype.addSegmentById = function(_elId) { |
| 900 | 750 |
var _annotation = this.source.getElement(_elId); |
751 |
if (typeof _annotation !== "undefined") { |
|
752 |
this.addSegment(_annotation); |
|
753 |
} |
|
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
754 |
} |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
755 |
|
| 970 | 756 |
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
|
757 |
return this.segments; |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
758 |
} |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
759 |
|
| 970 | 760 |
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
|
761 |
return this.medias; |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
762 |
} |
| 900 | 763 |
|
| 970 | 764 |
Model.Mashup.prototype.getAnnotationsByTypeTitle = function(_title) { |
| 900 | 765 |
var _annTypes = this.source.getAnnotationTypes().searchByTitle(_title).pluck("id"); |
766 |
if (_annTypes.length) { |
|
767 |
return this.getAnnotations().filter(function(_annotation) { |
|
| 970 | 768 |
return ns._(_annTypes).indexOf(_annotation.getAnnotationType().id) !== -1; |
| 900 | 769 |
}); |
770 |
} else { |
|
| 970 | 771 |
return new Model.List(this.source.directory) |
| 900 | 772 |
} |
773 |
} |
|
774 |
||
| 970 | 775 |
Model.Mashup.prototype.getAnnotationAtTime = function(_time) { |
| 903 | 776 |
var _list = this.segments.filter(function(_annotation) { |
777 |
return _annotation.begin <= _time && _annotation.end > _time; |
|
778 |
}); |
|
779 |
if (_list.length) { |
|
780 |
return _list[0]; |
|
781 |
} else { |
|
782 |
return undefined; |
|
783 |
} |
|
784 |
} |
|
785 |
||
| 970 | 786 |
Model.Mashup.prototype.getMediaAtTime = function(_time) { |
| 903 | 787 |
var _annotation = this.getAnnotationAtTime(_time); |
788 |
if (typeof _annotation !== "undefined") { |
|
789 |
return _annotation.getMedia(); |
|
790 |
} else { |
|
791 |
return undefined; |
|
792 |
} |
|
793 |
} |
|
794 |
||
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
795 |
/* */ |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
796 |
|
| 970 | 797 |
Model.Source = function(_config) { |
798 |
this.status = Model._SOURCE_STATUS_EMPTY; |
|
|
969
353b0881a0b9
Added On-the-fly (file-less) metadata generation test
veltr
parents:
965
diff
changeset
|
799 |
this.elementType = "source"; |
| 860 | 800 |
if (typeof _config !== "undefined") { |
801 |
var _this = this; |
|
| 970 | 802 |
ns._(_config).forEach(function(_v, _k) { |
| 860 | 803 |
_this[_k] = _v; |
804 |
}) |
|
805 |
this.callbackQueue = []; |
|
806 |
this.contents = {}; |
|
807 |
this.get(); |
|
808 |
} |
|
809 |
} |
|
810 |
||
| 970 | 811 |
Model.Source.prototype = new Model.Element(); |
|
969
353b0881a0b9
Added On-the-fly (file-less) metadata generation test
veltr
parents:
965
diff
changeset
|
812 |
|
| 970 | 813 |
Model.Source.prototype.addList = function(_listId, _contents) { |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
814 |
if (typeof this.contents[_listId] === "undefined") { |
| 970 | 815 |
this.contents[_listId] = new Model.List(this.directory); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
816 |
} |
| 866 | 817 |
this.contents[_listId].addElements(_contents); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
818 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
819 |
|
| 970 | 820 |
Model.Source.prototype.getList = function(_listId, _global) { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
821 |
_global = (typeof _global !== "undefined" && _global); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
822 |
if (_global || typeof this.contents[_listId] === "undefined") { |
| 860 | 823 |
return this.directory.getGlobalList().filter(function(_e) { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
824 |
return (_e.elementType === _listId); |
| 858 | 825 |
}); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
826 |
} else { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
827 |
return this.contents[_listId]; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
828 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
829 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
830 |
|
| 970 | 831 |
Model.Source.prototype.forEach = function(_callback) { |
| 860 | 832 |
var _this = this; |
| 970 | 833 |
ns._(this.contents).forEach(function(_value, _key) { |
| 860 | 834 |
_callback.call(_this, _value, _key); |
835 |
}) |
|
836 |
} |
|
837 |
||
| 970 | 838 |
Model.Source.prototype.getElement = function(_elId) { |
| 916 | 839 |
return this.directory.getElement(_elId); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
840 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
841 |
|
| 970 | 842 |
Model.Source.prototype.get = function() { |
843 |
this.status = Model._SOURCE_STATUS_WAITING; |
|
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
844 |
this.handleCallbacks(); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
845 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
846 |
|
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
847 |
/* We defer the callbacks calls so they execute after the queue is cleared */ |
| 970 | 848 |
Model.Source.prototype.deferCallback = function(_callback) { |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
849 |
var _this = this; |
| 970 | 850 |
ns._.defer(function() { |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
851 |
_callback.call(_this); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
852 |
}); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
853 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
854 |
|
| 970 | 855 |
Model.Source.prototype.handleCallbacks = function() { |
856 |
this.status = Model._SOURCE_STATUS_READY; |
|
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
857 |
while (this.callbackQueue.length) { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
858 |
this.deferCallback(this.callbackQueue.splice(0,1)[0]); |
| 858 | 859 |
} |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
860 |
} |
| 970 | 861 |
Model.Source.prototype.onLoad = function(_callback) { |
862 |
if (this.status === Model._SOURCE_STATUS_READY) { |
|
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
863 |
this.deferCallback(_callback); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
864 |
} else { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
865 |
this.callbackQueue.push(_callback); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
866 |
} |
| 854 | 867 |
} |
868 |
||
| 970 | 869 |
Model.Source.prototype.serialize = function() { |
| 860 | 870 |
return this.serializer.serialize(this); |
871 |
} |
|
872 |
||
| 970 | 873 |
Model.Source.prototype.deSerialize = function(_data) { |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
874 |
this.serializer.deSerialize(_data, this); |
| 854 | 875 |
} |
876 |
||
| 970 | 877 |
Model.Source.prototype.getAnnotations = function(_global) { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
878 |
_global = (typeof _global !== "undefined" && _global); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
879 |
return this.getList("annotation", _global); |
| 854 | 880 |
} |
881 |
||
| 970 | 882 |
Model.Source.prototype.getMedias = function(_global) { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
883 |
_global = (typeof _global !== "undefined" && _global); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
884 |
return this.getList("media", _global); |
| 864 | 885 |
} |
886 |
||
| 970 | 887 |
Model.Source.prototype.getTags = function(_global) { |
| 904 | 888 |
_global = (typeof _global !== "undefined" && _global); |
889 |
return this.getList("tag", _global); |
|
890 |
} |
|
891 |
||
| 970 | 892 |
Model.Source.prototype.getMashups = function(_global) { |
| 900 | 893 |
_global = (typeof _global !== "undefined" && _global); |
894 |
return this.getList("mashup", _global); |
|
895 |
} |
|
896 |
||
| 970 | 897 |
Model.Source.prototype.getAnnotationTypes = function(_global) { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
898 |
_global = (typeof _global !== "undefined" && _global); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
899 |
return this.getList("annotationType", _global); |
| 864 | 900 |
} |
901 |
||
| 970 | 902 |
Model.Source.prototype.getAnnotationsByTypeTitle = function(_title, _global) { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
903 |
_global = (typeof _global !== "undefined" && _global); |
| 970 | 904 |
var _res = new Model.List(this.directory), |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
905 |
_annTypes = this.getAnnotationTypes(_global).searchByTitle(_title); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
906 |
_annTypes.forEach(function(_annType) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
907 |
_res.addElements(_annType.getAnnotations(_global)); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
908 |
}) |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
909 |
return _res; |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
910 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
911 |
|
| 970 | 912 |
Model.Source.prototype.getDuration = function() { |
| 866 | 913 |
var _m = this.currentMedia; |
914 |
if (typeof _m !== "undefined") { |
|
915 |
return this.currentMedia.duration; |
|
916 |
} |
|
| 858 | 917 |
} |
918 |
||
| 970 | 919 |
Model.Source.prototype.getCurrentMedia = function(_opts) { |
| 959 | 920 |
if (typeof this.currentMedia === "undefined") { |
921 |
if (_opts.is_mashup) { |
|
| 957 | 922 |
var _mashups = this.getMashups(); |
923 |
if (_mashups.length) { |
|
924 |
this.currentMedia = _mashups[0]; |
|
925 |
} |
|
926 |
} else { |
|
927 |
var _medias = this.getMedias(); |
|
928 |
if (_medias.length) { |
|
|
969
353b0881a0b9
Added On-the-fly (file-less) metadata generation test
veltr
parents:
965
diff
changeset
|
929 |
this.currentMedia = _medias[0]; |
| 957 | 930 |
} |
931 |
} |
|
932 |
} |
|
933 |
return this.currentMedia; |
|
934 |
} |
|
935 |
||
| 970 | 936 |
Model.Source.prototype.merge = function(_source) { |
|
908
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
937 |
var _this = this; |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
938 |
_source.forEach(function(_value, _key) { |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
939 |
_this.getList(_key).addElements(_value); |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
940 |
}); |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
941 |
} |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
942 |
|
| 858 | 943 |
/* */ |
944 |
||
| 970 | 945 |
Model.RemoteSource = function(_config) { |
946 |
Model.Source.call(this, _config); |
|
| 858 | 947 |
} |
948 |
||
| 970 | 949 |
Model.RemoteSource.prototype = new Model.Source(); |
| 858 | 950 |
|
| 970 | 951 |
Model.RemoteSource.prototype.get = function() { |
952 |
this.status = Model._SOURCE_STATUS_WAITING; |
|
| 858 | 953 |
var _this = this; |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
954 |
this.serializer.loadData(this.url, function(_result) { |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
955 |
_this.deSerialize(_result); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
956 |
_this.handleCallbacks(); |
| 858 | 957 |
}); |
| 854 | 958 |
} |
959 |
||
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
960 |
/* */ |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
961 |
|
| 970 | 962 |
Model.Directory = function() { |
| 858 | 963 |
this.remoteSources = {}; |
964 |
this.elements = {}; |
|
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
965 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
966 |
|
| 970 | 967 |
Model.Directory.prototype.remoteSource = function(_properties) { |
| 917 | 968 |
if (typeof _properties !== "object" || typeof _properties.url === "undefined") { |
| 970 | 969 |
throw "Error : Model.Directory.remoteSource(configuration): configuration.url is undefined"; |
| 917 | 970 |
} |
| 970 | 971 |
var _config = ns._({ directory: this }).extend(_properties); |
| 858 | 972 |
if (typeof this.remoteSources[_properties.url] === "undefined") { |
| 970 | 973 |
this.remoteSources[_properties.url] = new Model.RemoteSource(_config); |
| 858 | 974 |
} |
975 |
return this.remoteSources[_properties.url]; |
|
| 854 | 976 |
} |
977 |
||
| 970 | 978 |
Model.Directory.prototype.newLocalSource = function(_properties) { |
979 |
var _config = ns._({ directory: this }).extend(_properties), |
|
980 |
_res = new Model.Source(_config); |
|
| 860 | 981 |
return _res; |
982 |
} |
|
983 |
||
| 970 | 984 |
Model.Directory.prototype.getElement = function(_id) { |
| 900 | 985 |
return this.elements[_id]; |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
986 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
987 |
|
| 970 | 988 |
Model.Directory.prototype.addElement = function(_element) { |
| 858 | 989 |
this.elements[_element.id] = _element; |
990 |
} |
|
991 |
||
| 970 | 992 |
Model.Directory.prototype.getGlobalList = function() { |
993 |
var _res = new Model.List(this); |
|
994 |
_res.addIds(ns._(this.elements).keys()); |
|
| 858 | 995 |
return _res; |
| 854 | 996 |
} |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
997 |
|
| 972 | 998 |
return Model; |
| 970 | 999 |
|
1000 |
})(IriSP); |