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