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