| author | veltr |
| Wed, 29 Aug 2012 18:34:11 +0200 | |
| branch | new-model |
| changeset 937 | eb3c442cec50 |
| parent 930 | 165f236e42f2 |
| child 940 | 9698ad710824 |
| 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 |
|
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
270 |
IriSP.Model.List.prototype.trigger = function(_event, _data) { |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
271 |
var _list = this; |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
272 |
IriSP._(this.__events[_event]).each(function(_callback) { |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
273 |
_callback.call(_list, _data); |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
274 |
}); |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
275 |
} |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
276 |
|
| 868 | 277 |
/* A simple time management object, that helps converting millisecs to seconds and strings, |
278 |
* without the clumsiness of the original Date object. |
|
279 |
*/ |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
280 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
281 |
IriSP.Model.Time = function(_milliseconds) { |
| 900 | 282 |
this.milliseconds = 0; |
283 |
this.setMilliseconds(_milliseconds); |
|
284 |
} |
|
285 |
||
286 |
IriSP.Model.Time.prototype.setMilliseconds = function(_milliseconds) { |
|
287 |
var _ante = _milliseconds; |
|
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
288 |
switch(typeof _milliseconds) { |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
289 |
case "string": |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
290 |
this.milliseconds = parseFloat(_milliseconds); |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
291 |
break; |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
292 |
case "number": |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
293 |
this.milliseconds = _milliseconds; |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
294 |
break; |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
295 |
case "object": |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
296 |
this.milliseconds = parseFloat(_milliseconds.valueOf()); |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
297 |
break; |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
298 |
default: |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
299 |
this.milliseconds = 0; |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
300 |
} |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
301 |
if (this.milliseconds === NaN) { |
| 900 | 302 |
this.milliseconds = _ante; |
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
303 |
} |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
304 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
305 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
306 |
IriSP.Model.Time.prototype.setSeconds = function(_seconds) { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
307 |
this.milliseconds = 1000 * _seconds; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
308 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
309 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
310 |
IriSP.Model.Time.prototype.getSeconds = function() { |
| 917 | 311 |
return this.milliseconds / 1000; |
|
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.getHMS = function() { |
| 917 | 315 |
var _totalSeconds = Math.abs(Math.floor(this.getSeconds())); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
316 |
return { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
317 |
hours : Math.floor(_totalSeconds / 3600), |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
318 |
minutes : (Math.floor(_totalSeconds / 60) % 60), |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
319 |
seconds : _totalSeconds % 60 |
|
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 |
|
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
323 |
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
|
324 |
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
|
325 |
} |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
326 |
|
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
327 |
IriSP.Model.Time.prototype.valueOf = function() { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
328 |
return this.milliseconds; |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
329 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
330 |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
331 |
IriSP.Model.Time.prototype.toString = function() { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
332 |
function pad(_n) { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
333 |
var _res = _n.toString(); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
334 |
while (_res.length < 2) { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
335 |
_res = '0' + _res; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
336 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
337 |
return _res; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
338 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
339 |
var _hms = this.getHMS(), |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
340 |
_res = ''; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
341 |
if (_hms.hours) { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
342 |
_res += pad(_hms.hours) + ':' |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
343 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
344 |
_res += pad(_hms.minutes) + ':' + pad(_hms.seconds); |
|
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 |
|
| 868 | 348 |
/* IriSP.Model.Reference handles references between elements |
349 |
*/ |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
350 |
|
| 860 | 351 |
IriSP.Model.Reference = function(_source, _idRef) { |
352 |
this.source = _source; |
|
| 916 | 353 |
this.id = _idRef; |
| 858 | 354 |
if (typeof _idRef === "object") { |
355 |
this.isList = true; |
|
356 |
} else { |
|
357 |
this.isList = false; |
|
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
358 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
359 |
this.refresh(); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
360 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
361 |
|
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
362 |
IriSP.Model.Reference.prototype.refresh = function() { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
363 |
if (this.isList) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
364 |
this.contents = new IriSP.Model.List(this.source.directory); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
365 |
this.contents.addIds(this.id); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
366 |
} else { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
367 |
this.contents = this.source.directory.getElement(this.id); |
|
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 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
371 |
|
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
372 |
IriSP.Model.Reference.prototype.getContents = function() { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
373 |
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
|
374 |
this.refresh(); |
|
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 |
return this.contents; |
|
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 |
IriSP.Model.Reference.prototype.isOrHasId = function(_idRef) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
380 |
if (this.isList) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
381 |
return (IriSP._(this.id).indexOf(_idRef) !== -1) |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
382 |
} else { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
383 |
return (this.id == _idRef); |
| 858 | 384 |
} |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
385 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
386 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
387 |
/* */ |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
388 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
389 |
IriSP.Model.Element = function(_id, _source) { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
390 |
this.elementType = 'element'; |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
391 |
if (typeof _source === "undefined") { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
392 |
return; |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
393 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
394 |
if (typeof _id === "undefined" || !_id) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
395 |
_id = IriSP.Model.getUID(); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
396 |
} |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
397 |
this.source = _source; |
| 916 | 398 |
this.id = _id; |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
399 |
this.title = ""; |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
400 |
this.description = ""; |
|
937
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
401 |
this.__events = {} |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
402 |
this.source.directory.addElement(this); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
403 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
404 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
405 |
IriSP.Model.Element.prototype.toString = function() { |
| 858 | 406 |
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
|
407 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
408 |
|
| 858 | 409 |
IriSP.Model.Element.prototype.setReference = function(_elementType, _idRef) { |
| 860 | 410 |
this[_elementType] = new IriSP.Model.Reference(this.source, _idRef); |
| 854 | 411 |
} |
412 |
||
| 858 | 413 |
IriSP.Model.Element.prototype.getReference = function(_elementType) { |
414 |
if (typeof this[_elementType] !== "undefined") { |
|
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
415 |
return this[_elementType].getContents(); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
416 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
417 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
418 |
|
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
419 |
IriSP.Model.Element.prototype.getRelated = function(_elementType, _global) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
420 |
_global = (typeof _global !== "undefined" && _global); |
| 864 | 421 |
var _this = this; |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
422 |
return this.source.getList(_elementType, _global).filter(function(_el) { |
| 864 | 423 |
var _ref = _el[_this.elementType]; |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
424 |
return _ref.isOrHasId(_this.id); |
| 864 | 425 |
}); |
426 |
} |
|
427 |
||
|
937
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
428 |
IriSP.Model.Element.prototype.on = function(_event, _callback) { |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
429 |
if (typeof this.__events[_event] === "undefined") { |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
430 |
this.__events[_event] = []; |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
431 |
} |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
432 |
this.__events[_event].push(_callback); |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
433 |
} |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
434 |
|
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
435 |
IriSP.Model.Element.prototype.trigger = function(_event, _data) { |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
436 |
var _element = this; |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
437 |
IriSP._(this.__events[_event]).each(function(_callback) { |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
438 |
_callback.call(_element, _data); |
|
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 |
} |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
441 |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
442 |
/* */ |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
443 |
|
| 864 | 444 |
IriSP.Model.Media = function(_id, _source) { |
445 |
IriSP.Model.Element.call(this, _id, _source); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
446 |
this.elementType = 'media'; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
447 |
this.duration = new IriSP.Model.Time(); |
| 866 | 448 |
this.video = ''; |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
449 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
450 |
|
| 858 | 451 |
IriSP.Model.Media.prototype = new IriSP.Model.Element(); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
452 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
453 |
IriSP.Model.Media.prototype.setDuration = function(_durationMs) { |
| 900 | 454 |
this.duration.setMilliseconds(_durationMs); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
455 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
456 |
|
| 864 | 457 |
IriSP.Model.Media.prototype.getAnnotations = function() { |
458 |
return this.getRelated("annotation"); |
|
459 |
} |
|
460 |
||
| 900 | 461 |
IriSP.Model.Media.prototype.getAnnotationsByTypeTitle = function(_title) { |
462 |
var _annTypes = this.source.getAnnotationTypes().searchByTitle(_title).pluck("id"); |
|
463 |
if (_annTypes.length) { |
|
464 |
return this.getAnnotations().filter(function(_annotation) { |
|
465 |
return IriSP._(_annTypes).indexOf(_annotation.getAnnotationType().id) !== -1; |
|
466 |
}); |
|
467 |
} else { |
|
468 |
return new IriSP.Model.List(this.source.directory) |
|
469 |
} |
|
470 |
} |
|
471 |
||
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
472 |
/* */ |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
473 |
|
| 864 | 474 |
IriSP.Model.Tag = function(_id, _source) { |
475 |
IriSP.Model.Element.call(this, _id, _source); |
|
| 858 | 476 |
this.elementType = 'tag'; |
477 |
} |
|
478 |
||
479 |
IriSP.Model.Tag.prototype = new IriSP.Model.Element(); |
|
480 |
||
| 864 | 481 |
IriSP.Model.Tag.prototype.getAnnotations = function() { |
482 |
return this.getRelated("annotation"); |
|
483 |
} |
|
484 |
||
| 858 | 485 |
/* */ |
486 |
||
| 864 | 487 |
IriSP.Model.AnnotationType = function(_id, _source) { |
488 |
IriSP.Model.Element.call(this, _id, _source); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
489 |
this.elementType = 'annotationType'; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
490 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
491 |
|
| 858 | 492 |
IriSP.Model.AnnotationType.prototype = new IriSP.Model.Element(); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
493 |
|
| 864 | 494 |
IriSP.Model.AnnotationType.prototype.getAnnotations = function() { |
495 |
return this.getRelated("annotation"); |
|
496 |
} |
|
497 |
||
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
498 |
/* Annotation |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
499 |
* */ |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
500 |
|
| 864 | 501 |
IriSP.Model.Annotation = function(_id, _source) { |
502 |
IriSP.Model.Element.call(this, _id, _source); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
503 |
this.elementType = 'annotation'; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
504 |
this.begin = new IriSP.Model.Time(); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
505 |
this.end = new IriSP.Model.Time(); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
506 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
507 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
508 |
IriSP.Model.Annotation.prototype = new IriSP.Model.Element(null); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
509 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
510 |
IriSP.Model.Annotation.prototype.setBegin = function(_beginMs) { |
| 900 | 511 |
this.begin.setMilliseconds(_beginMs); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
512 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
513 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
514 |
IriSP.Model.Annotation.prototype.setEnd = function(_beginMs) { |
| 900 | 515 |
this.end.setMilliseconds(_beginMs); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
516 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
517 |
|
| 858 | 518 |
IriSP.Model.Annotation.prototype.setMedia = function(_idRef) { |
519 |
this.setReference("media", _idRef); |
|
|
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 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
522 |
IriSP.Model.Annotation.prototype.getMedia = function() { |
| 858 | 523 |
return this.getReference("media"); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
524 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
525 |
|
| 858 | 526 |
IriSP.Model.Annotation.prototype.setAnnotationType = function(_idRef) { |
527 |
this.setReference("annotationType", _idRef); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
528 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
529 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
530 |
IriSP.Model.Annotation.prototype.getAnnotationType = function() { |
| 858 | 531 |
return this.getReference("annotationType"); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
532 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
533 |
|
| 858 | 534 |
IriSP.Model.Annotation.prototype.setTags = function(_idRefs) { |
535 |
this.setReference("tag", _idRefs); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
536 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
537 |
|
| 858 | 538 |
IriSP.Model.Annotation.prototype.getTags = function() { |
539 |
return this.getReference("tag"); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
540 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
541 |
|
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
542 |
IriSP.Model.Annotation.prototype.getTagTexts = function() { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
543 |
return this.getTags().getTitles(); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
544 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
545 |
|
| 900 | 546 |
IriSP.Model.Annotation.prototype.getDuration = function() { |
547 |
return new IriSP.Model.Time(this.end.milliseconds - this.begin.milliseconds) |
|
548 |
} |
|
549 |
||
| 858 | 550 |
/* */ |
551 |
||
| 902 | 552 |
IriSP.Model.MashedAnnotation = function(_mashup, _annotation) { |
| 916 | 553 |
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
|
554 |
this.elementType = 'mashedAnnotation'; |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
555 |
this.annotation = _annotation; |
| 902 | 556 |
this.begin = new IriSP.Model.Time(_mashup.duration); |
557 |
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
|
558 |
this.title = this.annotation.title; |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
559 |
this.description = this.annotation.description; |
| 900 | 560 |
this.color = this.annotation.color; |
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
561 |
} |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
562 |
|
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
563 |
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
|
564 |
|
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
565 |
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
|
566 |
return this.annotation.getReference("media"); |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
567 |
} |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
568 |
|
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
569 |
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
|
570 |
return this.annotation.getReference("annotationType"); |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
571 |
} |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
572 |
|
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
573 |
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
|
574 |
return this.annotation.getReference("tag"); |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
575 |
} |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
576 |
|
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
577 |
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
|
578 |
return this.annotation.getTags().getTitles(); |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
579 |
} |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
580 |
|
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
581 |
/* */ |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
582 |
|
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
583 |
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
|
584 |
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
|
585 |
this.elementType = 'mashup'; |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
586 |
this.duration = new IriSP.Model.Time(); |
| 900 | 587 |
this.segments = new IriSP.Model.List(_source.directory); |
588 |
this.medias = new IriSP.Model.List(_source.directory); |
|
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
589 |
} |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
590 |
|
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
591 |
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
|
592 |
|
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
593 |
IriSP.Model.Mashup.prototype.addSegment = function(_annotation) { |
| 902 | 594 |
var _mashedAnnotation = new IriSP.Model.MashedAnnotation(this, _annotation); |
| 900 | 595 |
this.duration.setMilliseconds(_mashedAnnotation.end); |
596 |
this.segments.push(_mashedAnnotation); |
|
597 |
this.medias.push(_annotation.getMedia()); |
|
598 |
} |
|
599 |
||
600 |
IriSP.Model.Mashup.prototype.addSegmentById = function(_elId) { |
|
601 |
var _annotation = this.source.getElement(_elId); |
|
602 |
if (typeof _annotation !== "undefined") { |
|
603 |
this.addSegment(_annotation); |
|
604 |
} |
|
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
605 |
} |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
606 |
|
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
607 |
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
|
608 |
return this.segments; |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
609 |
} |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
610 |
|
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
611 |
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
|
612 |
return this.medias; |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
613 |
} |
| 900 | 614 |
|
615 |
IriSP.Model.Mashup.prototype.getAnnotationsByTypeTitle = function(_title) { |
|
616 |
var _annTypes = this.source.getAnnotationTypes().searchByTitle(_title).pluck("id"); |
|
617 |
if (_annTypes.length) { |
|
618 |
return this.getAnnotations().filter(function(_annotation) { |
|
619 |
return IriSP._(_annTypes).indexOf(_annotation.getAnnotationType().id) !== -1; |
|
620 |
}); |
|
621 |
} else { |
|
622 |
return new IriSP.Model.List(this.source.directory) |
|
623 |
} |
|
624 |
} |
|
625 |
||
| 903 | 626 |
IriSP.Model.Mashup.prototype.getAnnotationAtTime = function(_time) { |
627 |
var _list = this.segments.filter(function(_annotation) { |
|
628 |
return _annotation.begin <= _time && _annotation.end > _time; |
|
629 |
}); |
|
630 |
if (_list.length) { |
|
631 |
return _list[0]; |
|
632 |
} else { |
|
633 |
return undefined; |
|
634 |
} |
|
635 |
} |
|
636 |
||
637 |
IriSP.Model.Mashup.prototype.getMediaAtTime = function(_time) { |
|
638 |
var _annotation = this.getAnnotationAtTime(_time); |
|
639 |
if (typeof _annotation !== "undefined") { |
|
640 |
return _annotation.getMedia(); |
|
641 |
} else { |
|
642 |
return undefined; |
|
643 |
} |
|
644 |
} |
|
645 |
||
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
646 |
/* */ |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
647 |
|
| 860 | 648 |
IriSP.Model.Source = function(_config) { |
| 868 | 649 |
this.status = IriSP.Model._SOURCE_STATUS_EMPTY; |
| 860 | 650 |
if (typeof _config !== "undefined") { |
651 |
var _this = this; |
|
| 866 | 652 |
IriSP._(_config).forEach(function(_v, _k) { |
| 860 | 653 |
_this[_k] = _v; |
654 |
}) |
|
655 |
this.callbackQueue = []; |
|
656 |
this.contents = {}; |
|
657 |
this.get(); |
|
658 |
} |
|
659 |
} |
|
660 |
||
| 858 | 661 |
IriSP.Model.Source.prototype.addList = function(_listId, _contents) { |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
662 |
if (typeof this.contents[_listId] === "undefined") { |
| 860 | 663 |
this.contents[_listId] = new IriSP.Model.List(this.directory); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
664 |
} |
| 866 | 665 |
this.contents[_listId].addElements(_contents); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
666 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
667 |
|
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
668 |
IriSP.Model.Source.prototype.getList = function(_listId, _global) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
669 |
_global = (typeof _global !== "undefined" && _global); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
670 |
if (_global || typeof this.contents[_listId] === "undefined") { |
| 860 | 671 |
return this.directory.getGlobalList().filter(function(_e) { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
672 |
return (_e.elementType === _listId); |
| 858 | 673 |
}); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
674 |
} else { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
675 |
return this.contents[_listId]; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
676 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
677 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
678 |
|
| 866 | 679 |
IriSP.Model.Source.prototype.forEach = function(_callback) { |
| 860 | 680 |
var _this = this; |
| 866 | 681 |
IriSP._(this.contents).forEach(function(_value, _key) { |
| 860 | 682 |
_callback.call(_this, _value, _key); |
683 |
}) |
|
684 |
} |
|
685 |
||
| 866 | 686 |
IriSP.Model.Source.prototype.getElement = function(_elId) { |
| 916 | 687 |
return this.directory.getElement(_elId); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
688 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
689 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
690 |
IriSP.Model.Source.prototype.get = function() { |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
691 |
this.status = IriSP.Model._SOURCE_STATUS_WAITING; |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
692 |
this.handleCallbacks(); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
693 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
694 |
|
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
695 |
/* We defer the callbacks calls so they execute after the queue is cleared */ |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
696 |
IriSP.Model.Source.prototype.deferCallback = function(_callback) { |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
697 |
var _this = this; |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
698 |
IriSP._.defer(function() { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
699 |
_callback.call(_this); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
700 |
}); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
701 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
702 |
|
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
703 |
IriSP.Model.Source.prototype.handleCallbacks = function() { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
704 |
this.status = IriSP.Model._SOURCE_STATUS_READY; |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
705 |
while (this.callbackQueue.length) { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
706 |
this.deferCallback(this.callbackQueue.splice(0,1)[0]); |
| 858 | 707 |
} |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
708 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
709 |
IriSP.Model.Source.prototype.onLoad = function(_callback) { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
710 |
if (this.status === IriSP.Model._SOURCE_STATUS_READY) { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
711 |
this.deferCallback(_callback); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
712 |
} else { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
713 |
this.callbackQueue.push(_callback); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
714 |
} |
| 854 | 715 |
} |
716 |
||
| 860 | 717 |
IriSP.Model.Source.prototype.serialize = function() { |
718 |
return this.serializer.serialize(this); |
|
719 |
} |
|
720 |
||
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
721 |
IriSP.Model.Source.prototype.deSerialize = function(_data) { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
722 |
this.serializer.deSerialize(_data, this); |
| 854 | 723 |
} |
724 |
||
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
725 |
IriSP.Model.Source.prototype.getAnnotations = function(_global) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
726 |
_global = (typeof _global !== "undefined" && _global); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
727 |
return this.getList("annotation", _global); |
| 854 | 728 |
} |
729 |
||
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
730 |
IriSP.Model.Source.prototype.getMedias = function(_global) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
731 |
_global = (typeof _global !== "undefined" && _global); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
732 |
return this.getList("media", _global); |
| 864 | 733 |
} |
734 |
||
| 904 | 735 |
IriSP.Model.Source.prototype.getTags = function(_global) { |
736 |
_global = (typeof _global !== "undefined" && _global); |
|
737 |
return this.getList("tag", _global); |
|
738 |
} |
|
739 |
||
| 900 | 740 |
IriSP.Model.Source.prototype.getMashups = function(_global) { |
741 |
_global = (typeof _global !== "undefined" && _global); |
|
742 |
return this.getList("mashup", _global); |
|
743 |
} |
|
744 |
||
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
745 |
IriSP.Model.Source.prototype.getAnnotationTypes = function(_global) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
746 |
_global = (typeof _global !== "undefined" && _global); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
747 |
return this.getList("annotationType", _global); |
| 864 | 748 |
} |
749 |
||
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
750 |
IriSP.Model.Source.prototype.getAnnotationsByTypeTitle = function(_title, _global) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
751 |
_global = (typeof _global !== "undefined" && _global); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
752 |
var _res = new IriSP.Model.List(this.directory), |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
753 |
_annTypes = this.getAnnotationTypes(_global).searchByTitle(_title); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
754 |
_annTypes.forEach(function(_annType) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
755 |
_res.addElements(_annType.getAnnotations(_global)); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
756 |
}) |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
757 |
return _res; |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
758 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
759 |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
760 |
IriSP.Model.Source.prototype.getDuration = function() { |
| 866 | 761 |
var _m = this.currentMedia; |
762 |
if (typeof _m !== "undefined") { |
|
763 |
return this.currentMedia.duration; |
|
764 |
} |
|
| 858 | 765 |
} |
766 |
||
|
908
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
767 |
IriSP.Model.Source.prototype.merge = function(_source) { |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
768 |
var _this = this; |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
769 |
_source.forEach(function(_value, _key) { |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
770 |
_this.getList(_key).addElements(_value); |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
771 |
}); |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
772 |
} |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
773 |
|
| 858 | 774 |
/* */ |
775 |
||
| 860 | 776 |
IriSP.Model.RemoteSource = function(_config) { |
777 |
IriSP.Model.Source.call(this, _config); |
|
| 858 | 778 |
} |
779 |
||
780 |
IriSP.Model.RemoteSource.prototype = new IriSP.Model.Source(); |
|
781 |
||
782 |
IriSP.Model.RemoteSource.prototype.get = function() { |
|
| 868 | 783 |
this.status = IriSP.Model._SOURCE_STATUS_WAITING; |
| 858 | 784 |
var _this = this; |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
785 |
this.serializer.loadData(this.url, function(_result) { |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
786 |
_this.deSerialize(_result); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
787 |
_this.handleCallbacks(); |
| 858 | 788 |
}); |
| 854 | 789 |
} |
790 |
||
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
791 |
/* */ |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
792 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
793 |
IriSP.Model.Directory = function() { |
| 858 | 794 |
this.remoteSources = {}; |
795 |
this.elements = {}; |
|
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
796 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
797 |
|
| 858 | 798 |
IriSP.Model.Directory.prototype.remoteSource = function(_properties) { |
| 917 | 799 |
if (typeof _properties !== "object" || typeof _properties.url === "undefined") { |
800 |
throw "Error : IriSP.Model.Directory.remoteSource(configuration): configuration.url is undefined"; |
|
801 |
} |
|
| 860 | 802 |
var _config = IriSP._({ directory: this }).extend(_properties); |
| 858 | 803 |
if (typeof this.remoteSources[_properties.url] === "undefined") { |
| 860 | 804 |
this.remoteSources[_properties.url] = new IriSP.Model.RemoteSource(_config); |
| 858 | 805 |
} |
806 |
return this.remoteSources[_properties.url]; |
|
| 854 | 807 |
} |
808 |
||
| 860 | 809 |
IriSP.Model.Directory.prototype.newLocalSource = function(_properties) { |
810 |
var _config = IriSP._({ directory: this }).extend(_properties), |
|
811 |
_res = new IriSP.Model.Source(_config); |
|
812 |
return _res; |
|
813 |
} |
|
814 |
||
| 858 | 815 |
IriSP.Model.Directory.prototype.getElement = function(_id) { |
| 900 | 816 |
return this.elements[_id]; |
|
856
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 |
|
| 858 | 819 |
IriSP.Model.Directory.prototype.addElement = function(_element) { |
820 |
this.elements[_element.id] = _element; |
|
821 |
} |
|
822 |
||
823 |
IriSP.Model.Directory.prototype.getGlobalList = function() { |
|
824 |
var _res = new IriSP.Model.List(this); |
|
| 866 | 825 |
_res.addIds(IriSP._(this.elements).keys()); |
| 858 | 826 |
return _res; |
| 854 | 827 |
} |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
828 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
829 |
/* */ |