| author | veltr |
| Fri, 26 Oct 2012 15:49:29 +0200 | |
| changeset 973 | 638fe8541a2e |
| parent 972 | 58e2db2e9714 |
| child 976 | 4b9ec475026a |
| 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) { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
359 |
_res += pad(_hms.hours) + ':' |
|
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) { |
| 900 | 622 |
this.begin.setMilliseconds(_beginMs); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
623 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
624 |
|
| 970 | 625 |
Model.Annotation.prototype.setEnd = function(_beginMs) { |
| 900 | 626 |
this.end.setMilliseconds(_beginMs); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
627 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
628 |
|
| 970 | 629 |
Model.Annotation.prototype.setMedia = function(_idRef) { |
| 858 | 630 |
this.setReference("media", _idRef); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
631 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
632 |
|
| 970 | 633 |
Model.Annotation.prototype.getMedia = function() { |
| 858 | 634 |
return this.getReference("media"); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
635 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
636 |
|
| 970 | 637 |
Model.Annotation.prototype.setAnnotationType = function(_idRef) { |
| 858 | 638 |
this.setReference("annotationType", _idRef); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
639 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
640 |
|
| 970 | 641 |
Model.Annotation.prototype.getAnnotationType = function() { |
| 858 | 642 |
return this.getReference("annotationType"); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
643 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
644 |
|
| 970 | 645 |
Model.Annotation.prototype.setTags = function(_idRefs) { |
| 858 | 646 |
this.setReference("tag", _idRefs); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
647 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
648 |
|
| 970 | 649 |
Model.Annotation.prototype.getTags = function() { |
| 858 | 650 |
return this.getReference("tag"); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
651 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
652 |
|
| 970 | 653 |
Model.Annotation.prototype.getTagTexts = function() { |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
654 |
return this.getTags().getTitles(); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
655 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
656 |
|
| 970 | 657 |
Model.Annotation.prototype.getDuration = function() { |
658 |
return new Model.Time(this.end.milliseconds - this.begin.milliseconds) |
|
| 900 | 659 |
} |
660 |
||
| 858 | 661 |
/* */ |
662 |
||
| 970 | 663 |
Model.MashedAnnotation = function(_mashup, _annotation) { |
664 |
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
|
665 |
this.elementType = 'mashedAnnotation'; |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
666 |
this.annotation = _annotation; |
| 970 | 667 |
this.begin = new Model.Time(_mashup.duration); |
668 |
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
|
669 |
this.title = this.annotation.title; |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
670 |
this.description = this.annotation.description; |
| 900 | 671 |
this.color = this.annotation.color; |
| 965 | 672 |
var _this = this; |
673 |
this.on("click", function() { |
|
674 |
_mashup.setCurrentTime(_this.begin); |
|
675 |
}); |
|
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
676 |
} |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
677 |
|
| 970 | 678 |
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
|
679 |
|
| 970 | 680 |
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
|
681 |
return this.annotation.getReference("media"); |
|
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.getAnnotationType = function() { |
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
685 |
return this.annotation.getReference("annotationType"); |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
686 |
} |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
687 |
|
| 970 | 688 |
Model.MashedAnnotation.prototype.getTags = function() { |
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
689 |
return this.annotation.getReference("tag"); |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
690 |
} |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
691 |
|
| 970 | 692 |
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
|
693 |
return this.annotation.getTags().getTitles(); |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
694 |
} |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
695 |
|
| 970 | 696 |
Model.MashedAnnotation.prototype.getDuration = function() { |
| 940 | 697 |
return this.annotation.getDuration(); |
698 |
} |
|
699 |
||
|
887
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.Mashup = function(_id, _source) { |
703 |
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
|
704 |
this.elementType = 'mashup'; |
| 970 | 705 |
this.duration = new Model.Time(); |
706 |
this.segments = new Model.List(_source.directory); |
|
707 |
this.medias = new Model.List(_source.directory); |
|
| 965 | 708 |
var _currentMedia = null; |
709 |
var _this = this; |
|
710 |
this.on("timeupdate", function(_time) { |
|
711 |
_this.getAnnotations().filter(function(_a) { |
|
712 |
return (_a.end <= _time || _a.begin > _time) && _a.playing |
|
713 |
}).forEach(function(_a) { |
|
714 |
_a.playing = false; |
|
715 |
_a.trigger("leave"); |
|
716 |
}); |
|
717 |
_this.getAnnotations().filter(function(_a) { |
|
718 |
return _a.begin <= _time && _a.end > _time && !_a.playing |
|
719 |
}).forEach(function(_a) { |
|
720 |
_a.playing = true; |
|
721 |
_a.trigger("enter"); |
|
722 |
var _m = _a.getMedia(); |
|
723 |
if (_m !== _currentMedia) { |
|
724 |
if (_currentMedia) { |
|
725 |
_currentMedia.trigger("leave"); |
|
726 |
} |
|
727 |
_m.trigger("enter"); |
|
728 |
_currentMedia = _m; |
|
729 |
} |
|
730 |
}); |
|
731 |
}); |
|
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
732 |
} |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
733 |
|
| 970 | 734 |
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
|
735 |
|
| 970 | 736 |
Model.Mashup.prototype.addSegment = function(_annotation) { |
737 |
var _mashedAnnotation = new Model.MashedAnnotation(this, _annotation); |
|
| 900 | 738 |
this.duration.setMilliseconds(_mashedAnnotation.end); |
739 |
this.segments.push(_mashedAnnotation); |
|
740 |
this.medias.push(_annotation.getMedia()); |
|
741 |
} |
|
742 |
||
| 970 | 743 |
Model.Mashup.prototype.addSegmentById = function(_elId) { |
| 900 | 744 |
var _annotation = this.source.getElement(_elId); |
745 |
if (typeof _annotation !== "undefined") { |
|
746 |
this.addSegment(_annotation); |
|
747 |
} |
|
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
748 |
} |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
749 |
|
| 970 | 750 |
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
|
751 |
return this.segments; |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
752 |
} |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
753 |
|
| 970 | 754 |
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
|
755 |
return this.medias; |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
756 |
} |
| 900 | 757 |
|
| 970 | 758 |
Model.Mashup.prototype.getAnnotationsByTypeTitle = function(_title) { |
| 900 | 759 |
var _annTypes = this.source.getAnnotationTypes().searchByTitle(_title).pluck("id"); |
760 |
if (_annTypes.length) { |
|
761 |
return this.getAnnotations().filter(function(_annotation) { |
|
| 970 | 762 |
return ns._(_annTypes).indexOf(_annotation.getAnnotationType().id) !== -1; |
| 900 | 763 |
}); |
764 |
} else { |
|
| 970 | 765 |
return new Model.List(this.source.directory) |
| 900 | 766 |
} |
767 |
} |
|
768 |
||
| 970 | 769 |
Model.Mashup.prototype.getAnnotationAtTime = function(_time) { |
| 903 | 770 |
var _list = this.segments.filter(function(_annotation) { |
771 |
return _annotation.begin <= _time && _annotation.end > _time; |
|
772 |
}); |
|
773 |
if (_list.length) { |
|
774 |
return _list[0]; |
|
775 |
} else { |
|
776 |
return undefined; |
|
777 |
} |
|
778 |
} |
|
779 |
||
| 970 | 780 |
Model.Mashup.prototype.getMediaAtTime = function(_time) { |
| 903 | 781 |
var _annotation = this.getAnnotationAtTime(_time); |
782 |
if (typeof _annotation !== "undefined") { |
|
783 |
return _annotation.getMedia(); |
|
784 |
} else { |
|
785 |
return undefined; |
|
786 |
} |
|
787 |
} |
|
788 |
||
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
789 |
/* */ |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
790 |
|
| 970 | 791 |
Model.Source = function(_config) { |
792 |
this.status = Model._SOURCE_STATUS_EMPTY; |
|
|
969
353b0881a0b9
Added On-the-fly (file-less) metadata generation test
veltr
parents:
965
diff
changeset
|
793 |
this.elementType = "source"; |
| 860 | 794 |
if (typeof _config !== "undefined") { |
795 |
var _this = this; |
|
| 970 | 796 |
ns._(_config).forEach(function(_v, _k) { |
| 860 | 797 |
_this[_k] = _v; |
798 |
}) |
|
799 |
this.callbackQueue = []; |
|
800 |
this.contents = {}; |
|
801 |
this.get(); |
|
802 |
} |
|
803 |
} |
|
804 |
||
| 970 | 805 |
Model.Source.prototype = new Model.Element(); |
|
969
353b0881a0b9
Added On-the-fly (file-less) metadata generation test
veltr
parents:
965
diff
changeset
|
806 |
|
| 970 | 807 |
Model.Source.prototype.addList = function(_listId, _contents) { |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
808 |
if (typeof this.contents[_listId] === "undefined") { |
| 970 | 809 |
this.contents[_listId] = new Model.List(this.directory); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
810 |
} |
| 866 | 811 |
this.contents[_listId].addElements(_contents); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
812 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
813 |
|
| 970 | 814 |
Model.Source.prototype.getList = function(_listId, _global) { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
815 |
_global = (typeof _global !== "undefined" && _global); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
816 |
if (_global || typeof this.contents[_listId] === "undefined") { |
| 860 | 817 |
return this.directory.getGlobalList().filter(function(_e) { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
818 |
return (_e.elementType === _listId); |
| 858 | 819 |
}); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
820 |
} else { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
821 |
return this.contents[_listId]; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
822 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
823 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
824 |
|
| 970 | 825 |
Model.Source.prototype.forEach = function(_callback) { |
| 860 | 826 |
var _this = this; |
| 970 | 827 |
ns._(this.contents).forEach(function(_value, _key) { |
| 860 | 828 |
_callback.call(_this, _value, _key); |
829 |
}) |
|
830 |
} |
|
831 |
||
| 970 | 832 |
Model.Source.prototype.getElement = function(_elId) { |
| 916 | 833 |
return this.directory.getElement(_elId); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
834 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
835 |
|
| 970 | 836 |
Model.Source.prototype.get = function() { |
837 |
this.status = Model._SOURCE_STATUS_WAITING; |
|
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
838 |
this.handleCallbacks(); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
839 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
840 |
|
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
841 |
/* We defer the callbacks calls so they execute after the queue is cleared */ |
| 970 | 842 |
Model.Source.prototype.deferCallback = function(_callback) { |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
843 |
var _this = this; |
| 970 | 844 |
ns._.defer(function() { |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
845 |
_callback.call(_this); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
846 |
}); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
847 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
848 |
|
| 970 | 849 |
Model.Source.prototype.handleCallbacks = function() { |
850 |
this.status = Model._SOURCE_STATUS_READY; |
|
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
851 |
while (this.callbackQueue.length) { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
852 |
this.deferCallback(this.callbackQueue.splice(0,1)[0]); |
| 858 | 853 |
} |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
854 |
} |
| 970 | 855 |
Model.Source.prototype.onLoad = function(_callback) { |
856 |
if (this.status === Model._SOURCE_STATUS_READY) { |
|
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
857 |
this.deferCallback(_callback); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
858 |
} else { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
859 |
this.callbackQueue.push(_callback); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
860 |
} |
| 854 | 861 |
} |
862 |
||
| 970 | 863 |
Model.Source.prototype.serialize = function() { |
| 860 | 864 |
return this.serializer.serialize(this); |
865 |
} |
|
866 |
||
| 970 | 867 |
Model.Source.prototype.deSerialize = function(_data) { |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
868 |
this.serializer.deSerialize(_data, this); |
| 854 | 869 |
} |
870 |
||
| 970 | 871 |
Model.Source.prototype.getAnnotations = function(_global) { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
872 |
_global = (typeof _global !== "undefined" && _global); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
873 |
return this.getList("annotation", _global); |
| 854 | 874 |
} |
875 |
||
| 970 | 876 |
Model.Source.prototype.getMedias = function(_global) { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
877 |
_global = (typeof _global !== "undefined" && _global); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
878 |
return this.getList("media", _global); |
| 864 | 879 |
} |
880 |
||
| 970 | 881 |
Model.Source.prototype.getTags = function(_global) { |
| 904 | 882 |
_global = (typeof _global !== "undefined" && _global); |
883 |
return this.getList("tag", _global); |
|
884 |
} |
|
885 |
||
| 970 | 886 |
Model.Source.prototype.getMashups = function(_global) { |
| 900 | 887 |
_global = (typeof _global !== "undefined" && _global); |
888 |
return this.getList("mashup", _global); |
|
889 |
} |
|
890 |
||
| 970 | 891 |
Model.Source.prototype.getAnnotationTypes = function(_global) { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
892 |
_global = (typeof _global !== "undefined" && _global); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
893 |
return this.getList("annotationType", _global); |
| 864 | 894 |
} |
895 |
||
| 970 | 896 |
Model.Source.prototype.getAnnotationsByTypeTitle = function(_title, _global) { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
897 |
_global = (typeof _global !== "undefined" && _global); |
| 970 | 898 |
var _res = new Model.List(this.directory), |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
899 |
_annTypes = this.getAnnotationTypes(_global).searchByTitle(_title); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
900 |
_annTypes.forEach(function(_annType) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
901 |
_res.addElements(_annType.getAnnotations(_global)); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
902 |
}) |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
903 |
return _res; |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
904 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
905 |
|
| 970 | 906 |
Model.Source.prototype.getDuration = function() { |
| 866 | 907 |
var _m = this.currentMedia; |
908 |
if (typeof _m !== "undefined") { |
|
909 |
return this.currentMedia.duration; |
|
910 |
} |
|
| 858 | 911 |
} |
912 |
||
| 970 | 913 |
Model.Source.prototype.getCurrentMedia = function(_opts) { |
| 959 | 914 |
if (typeof this.currentMedia === "undefined") { |
915 |
if (_opts.is_mashup) { |
|
| 957 | 916 |
var _mashups = this.getMashups(); |
917 |
if (_mashups.length) { |
|
918 |
this.currentMedia = _mashups[0]; |
|
919 |
} |
|
920 |
} else { |
|
921 |
var _medias = this.getMedias(); |
|
922 |
if (_medias.length) { |
|
|
969
353b0881a0b9
Added On-the-fly (file-less) metadata generation test
veltr
parents:
965
diff
changeset
|
923 |
this.currentMedia = _medias[0]; |
| 957 | 924 |
} |
925 |
} |
|
926 |
} |
|
927 |
return this.currentMedia; |
|
928 |
} |
|
929 |
||
| 970 | 930 |
Model.Source.prototype.merge = function(_source) { |
|
908
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
931 |
var _this = this; |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
932 |
_source.forEach(function(_value, _key) { |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
933 |
_this.getList(_key).addElements(_value); |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
934 |
}); |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
935 |
} |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
936 |
|
| 858 | 937 |
/* */ |
938 |
||
| 970 | 939 |
Model.RemoteSource = function(_config) { |
940 |
Model.Source.call(this, _config); |
|
| 858 | 941 |
} |
942 |
||
| 970 | 943 |
Model.RemoteSource.prototype = new Model.Source(); |
| 858 | 944 |
|
| 970 | 945 |
Model.RemoteSource.prototype.get = function() { |
946 |
this.status = Model._SOURCE_STATUS_WAITING; |
|
| 858 | 947 |
var _this = this; |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
948 |
this.serializer.loadData(this.url, function(_result) { |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
949 |
_this.deSerialize(_result); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
950 |
_this.handleCallbacks(); |
| 858 | 951 |
}); |
| 854 | 952 |
} |
953 |
||
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
954 |
/* */ |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
955 |
|
| 970 | 956 |
Model.Directory = function() { |
| 858 | 957 |
this.remoteSources = {}; |
958 |
this.elements = {}; |
|
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
959 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
960 |
|
| 970 | 961 |
Model.Directory.prototype.remoteSource = function(_properties) { |
| 917 | 962 |
if (typeof _properties !== "object" || typeof _properties.url === "undefined") { |
| 970 | 963 |
throw "Error : Model.Directory.remoteSource(configuration): configuration.url is undefined"; |
| 917 | 964 |
} |
| 970 | 965 |
var _config = ns._({ directory: this }).extend(_properties); |
| 858 | 966 |
if (typeof this.remoteSources[_properties.url] === "undefined") { |
| 970 | 967 |
this.remoteSources[_properties.url] = new Model.RemoteSource(_config); |
| 858 | 968 |
} |
969 |
return this.remoteSources[_properties.url]; |
|
| 854 | 970 |
} |
971 |
||
| 970 | 972 |
Model.Directory.prototype.newLocalSource = function(_properties) { |
973 |
var _config = ns._({ directory: this }).extend(_properties), |
|
974 |
_res = new Model.Source(_config); |
|
| 860 | 975 |
return _res; |
976 |
} |
|
977 |
||
| 970 | 978 |
Model.Directory.prototype.getElement = function(_id) { |
| 900 | 979 |
return this.elements[_id]; |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
980 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
981 |
|
| 970 | 982 |
Model.Directory.prototype.addElement = function(_element) { |
| 858 | 983 |
this.elements[_element.id] = _element; |
984 |
} |
|
985 |
||
| 970 | 986 |
Model.Directory.prototype.getGlobalList = function() { |
987 |
var _res = new Model.List(this); |
|
988 |
_res.addIds(ns._(this.elements).keys()); |
|
| 858 | 989 |
return _res; |
| 854 | 990 |
} |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
991 |
|
| 972 | 992 |
return Model; |
| 970 | 993 |
|
994 |
})(IriSP); |