| author | veltr |
| Thu, 26 Apr 2012 19:18:57 +0200 | |
| branch | new-model |
| changeset 880 | 4c7b33bf2795 |
| parent 872 | d777d05a16e4 |
| child 881 | f11b234497f7 |
| permissions | -rw-r--r-- |
| 854 | 1 |
/* model.js is where data is stored in a standard form, whatever the serializer */ |
2 |
||
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
3 |
IriSP.Model = { |
| 868 | 4 |
_SOURCE_STATUS_EMPTY : 0, |
5 |
_SOURCE_STATUS_WAITING : 1, |
|
6 |
_SOURCE_STATUS_READY : 2, |
|
7 |
_ID_AUTO_INCREMENT : 0, |
|
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
8 |
getUID : function() { |
| 868 | 9 |
return "autoid-" + (++this._ID_AUTO_INCREMENT); |
| 860 | 10 |
}, |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
11 |
regexpFromTextOrArray : function(_textOrArray) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
12 |
function escapeText(_text) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
13 |
return _text.replace(/([\\\*\+\?\|\{\[\}\]\(\)\^\$\.\#\/])/gm, '\\$1'); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
14 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
15 |
return new RegExp( '(' |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
16 |
+ ( |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
17 |
typeof _textOrArray === "string" |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
18 |
? escapeText(_textOrArray) |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
19 |
: IriSP._(_textOrArray).map(escapeText).join("|") |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
20 |
) |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
21 |
+ ')', |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
22 |
'gim' |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
23 |
); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
24 |
}, |
| 860 | 25 |
isoToDate : function(_str) { |
26 |
// http://delete.me.uk/2005/03/iso8601.html |
|
27 |
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})))?)?)?)?"; |
|
28 |
var d = _str.match(new RegExp(regexp)); |
|
29 |
|
|
30 |
var offset = 0; |
|
31 |
var date = new Date(d[1], 0, 1); |
|
32 |
|
|
33 |
if (d[3]) { date.setMonth(d[3] - 1); } |
|
34 |
if (d[5]) { date.setDate(d[5]); } |
|
35 |
if (d[7]) { date.setHours(d[7]); } |
|
36 |
if (d[8]) { date.setMinutes(d[8]); } |
|
37 |
if (d[10]) { date.setSeconds(d[10]); } |
|
38 |
if (d[12]) { date.setMilliseconds(Number("0." + d[12]) * 1000); } |
|
39 |
if (d[14]) { |
|
40 |
offset = (Number(d[16]) * 60) + Number(d[17]); |
|
41 |
offset *= ((d[15] == '-') ? 1 : -1); |
|
42 |
} |
|
43 |
|
|
44 |
offset -= date.getTimezoneOffset(); |
|
45 |
time = (Number(date) + (offset * 60 * 1000)); |
|
46 |
var _res = new Date(); |
|
47 |
_res.setTime(Number(time)); |
|
48 |
return _res; |
|
49 |
}, |
|
50 |
dateToIso : function(d) { |
|
51 |
function pad(n){return n<10 ? '0'+n : n} |
|
52 |
return d.getUTCFullYear()+'-' |
|
53 |
+ pad(d.getUTCMonth()+1)+'-' |
|
54 |
+ pad(d.getUTCDate())+'T' |
|
55 |
+ pad(d.getUTCHours())+':' |
|
56 |
+ pad(d.getUTCMinutes())+':' |
|
57 |
+ pad(d.getUTCSeconds())+'Z' |
|
58 |
} |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
59 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
60 |
|
| 868 | 61 |
/* |
62 |
* IriSP.Model.List is a class for a list of elements (e.g. annotations, medias, etc. that each have a distinct ID) |
|
63 |
*/ |
|
| 858 | 64 |
IriSP.Model.List = function(_directory) { |
| 866 | 65 |
Array.call(this); |
| 858 | 66 |
this.directory = _directory; |
| 866 | 67 |
this.idIndex = []; |
| 860 | 68 |
if (typeof _directory == "undefined") { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
69 |
throw "Error : new IriSP.Model.List(directory): directory is undefined"; |
| 860 | 70 |
} |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
71 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
72 |
|
| 866 | 73 |
IriSP.Model.List.prototype = new Array(); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
74 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
75 |
IriSP.Model.List.prototype.getElement = function(_id) { |
| 880 | 76 |
var _index = (IriSP._(this.idIndex).indexOf(this.source.getNamespaced(_id).fullName)); |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
77 |
if (_index !== -1) { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
78 |
return this[_index]; |
| 858 | 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 |
|
| 864 | 82 |
IriSP.Model.List.prototype.hasId = function(_id) { |
| 866 | 83 |
return (IriSP._(this.idIndex).indexOf(_id) !== -1); |
| 864 | 84 |
} |
85 |
||
| 868 | 86 |
/* On recent browsers, forEach and map are defined and do what we want. |
87 |
* Otherwise, we'll use the Underscore.js functions |
|
88 |
*/ |
|
| 866 | 89 |
if (typeof Array.prototype.forEach === "undefined") { |
90 |
IriSP.Model.List.prototype.forEach = function(_callback) { |
|
91 |
var _this = this; |
|
92 |
IriSP._(this).forEach(function(_value, _key) { |
|
93 |
_callback(_value, _key, _this); |
|
94 |
}); |
|
95 |
} |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
96 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
97 |
|
| 866 | 98 |
if (typeof Array.prototype.map === "undefined") { |
99 |
IriSP.Model.List.prototype.map = function(_callback) { |
|
100 |
var _this = this; |
|
101 |
return IriSP._(this).map(function(_value, _key) { |
|
102 |
return _callback(_value, _key, _this); |
|
103 |
}); |
|
104 |
} |
|
| 858 | 105 |
} |
106 |
||
| 868 | 107 |
/* We override Array's filter function because it doesn't return an IriSP.Model.List |
108 |
*/ |
|
| 858 | 109 |
IriSP.Model.List.prototype.filter = function(_callback) { |
110 |
var _this = this, |
|
111 |
_res = new IriSP.Model.List(this.directory); |
|
| 866 | 112 |
_res.addElements(IriSP._(this).filter(function(_value, _key) { |
113 |
return _callback(_value, _key, _this); |
|
114 |
})); |
|
| 858 | 115 |
return _res; |
116 |
} |
|
117 |
||
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
118 |
IriSP.Model.List.prototype.slice = function(_start, _end) { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
119 |
var _res = new IriSP.Model.List(this.directory); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
120 |
_res.addElements(Array.prototype.slice.call(this, _start, _end)); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
121 |
return _res; |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
122 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
123 |
|
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
124 |
IriSP.Model.List.prototype.splice = function(_start, _end) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
125 |
var _res = new IriSP.Model.List(this.directory); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
126 |
_res.addElements(Array.prototype.splice.call(this, _start, _end)); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
127 |
this.idIndex.splice(_start, _end); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
128 |
return _res; |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
129 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
130 |
|
| 868 | 131 |
/* Array has a sort function, but it's not as interesting as Underscore.js's sortBy |
132 |
* and won't return a new IriSP.Model.List |
|
133 |
*/ |
|
| 864 | 134 |
IriSP.Model.List.prototype.sortBy = function(_callback) { |
135 |
var _this = this, |
|
136 |
_res = new IriSP.Model.List(this.directory); |
|
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
137 |
_res.addElements(IriSP._(this).sortBy(function(_value, _key) { |
| 866 | 138 |
return _callback(_value, _key, _this); |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
139 |
})); |
| 864 | 140 |
return _res; |
141 |
} |
|
142 |
||
| 868 | 143 |
/* Title and Description are basic information for (almost) all element types, |
144 |
* here we can search by these criteria |
|
145 |
*/ |
|
| 858 | 146 |
IriSP.Model.List.prototype.searchByTitle = function(_text) { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
147 |
var _rgxp = IriSP.Model.regexpFromTextOrArray(_text); |
| 858 | 148 |
return this.filter(function(_element) { |
| 864 | 149 |
return _rgxp.test(_element.title); |
| 858 | 150 |
}); |
151 |
} |
|
152 |
||
153 |
IriSP.Model.List.prototype.searchByDescription = function(_text) { |
|
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
154 |
var _rgxp = IriSP.Model.regexpFromTextOrArray(_text); |
| 858 | 155 |
return this.filter(function(_element) { |
156 |
return _rgxp.test(_element.description); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
157 |
}); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
158 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
159 |
|
| 858 | 160 |
IriSP.Model.List.prototype.searchByTextFields = function(_text) { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
161 |
var _rgxp = IriSP.Model.regexpFromTextOrArray(_text); |
| 858 | 162 |
return this.filter(function(_element) { |
| 864 | 163 |
return _rgxp.test(_element.description) || _rgxp.test(_element.title); |
| 858 | 164 |
}); |
165 |
} |
|
166 |
||
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
167 |
IriSP.Model.List.prototype.getTitles = function() { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
168 |
return this.map(function(_el) { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
169 |
return _el.title; |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
170 |
}); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
171 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
172 |
|
| 858 | 173 |
IriSP.Model.List.prototype.addId = function(_id) { |
| 866 | 174 |
var _el = this.directory.getElement(_id) |
175 |
if (!this.hasId(_id) && typeof _el !== "undefined") { |
|
176 |
this.idIndex.push(_id); |
|
177 |
Array.prototype.push.call(this, _el); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
178 |
} |
|
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 |
|
| 866 | 181 |
IriSP.Model.List.prototype.push = function(_el) { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
182 |
if (typeof _el === "undefined") { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
183 |
return; |
| 866 | 184 |
} |
| 868 | 185 |
var _index = (IriSP._(this.idIndex).indexOf(_el.id)); |
186 |
if (_index === -1) { |
|
187 |
this.idIndex.push(_el.id); |
|
188 |
Array.prototype.push.call(this, _el); |
|
189 |
} else { |
|
190 |
this[_index] = _el; |
|
191 |
} |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
192 |
} |
| 858 | 193 |
|
| 866 | 194 |
IriSP.Model.List.prototype.addIds = function(_array) { |
195 |
var _l = _array.length, |
|
196 |
_this = this; |
|
197 |
IriSP._(_array).forEach(function(_id) { |
|
198 |
_this.addId(_id); |
|
199 |
}); |
|
| 858 | 200 |
} |
201 |
||
| 866 | 202 |
IriSP.Model.List.prototype.addElements = function(_array) { |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
203 |
var _this = this; |
| 866 | 204 |
IriSP._(_array).forEach(function(_el) { |
205 |
_this.push(_el); |
|
206 |
}); |
|
| 858 | 207 |
} |
208 |
||
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
209 |
IriSP.Model.List.prototype.removeId = function(_id) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
210 |
var _index = (IriSP._(this.idIndex).indexOf(_id)); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
211 |
if (_index !== -1) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
212 |
this.splice(_index,1); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
213 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
214 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
215 |
|
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
216 |
IriSP.Model.List.prototype.removeElement = function(_el) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
217 |
this.removeId(_el.id); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
218 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
219 |
|
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
220 |
IriSP.Model.List.prototype.removeIds = function(_list) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
221 |
var _this = this; |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
222 |
IriSP._(_list).forEach(function(_id) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
223 |
_this.removeId(_id); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
224 |
}); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
225 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
226 |
|
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
227 |
IriSP.Model.List.prototype.removeElements = function(_list) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
228 |
var _this = this; |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
229 |
IriSP._(_list).forEach(function(_el) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
230 |
_this.removeElement(_el); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
231 |
}); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
232 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
233 |
|
| 868 | 234 |
/* A simple time management object, that helps converting millisecs to seconds and strings, |
235 |
* without the clumsiness of the original Date object. |
|
236 |
*/ |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
237 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
238 |
IriSP.Model.Time = function(_milliseconds) { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
239 |
this.milliseconds = parseInt(typeof _milliseconds !== "undefined" ? _milliseconds : 0); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
240 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
241 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
242 |
IriSP.Model.Time.prototype.setSeconds = function(_seconds) { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
243 |
this.milliseconds = 1000 * _seconds; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
244 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
245 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
246 |
IriSP.Model.Time.prototype.getSeconds = function() { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
247 |
return Math.floor(this.milliseconds / 1000); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
248 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
249 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
250 |
IriSP.Model.Time.prototype.getHMS = function() { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
251 |
var _totalSeconds = Math.abs(this.getSeconds()); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
252 |
return { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
253 |
hours : Math.floor(_totalSeconds / 3600), |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
254 |
minutes : (Math.floor(_totalSeconds / 60) % 60), |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
255 |
seconds : _totalSeconds % 60 |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
256 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
257 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
258 |
|
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
259 |
IriSP.Model.Time.prototype.valueOf = function() { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
260 |
return this.milliseconds; |
|
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 |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
263 |
IriSP.Model.Time.prototype.toString = function() { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
264 |
function pad(_n) { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
265 |
var _res = _n.toString(); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
266 |
while (_res.length < 2) { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
267 |
_res = '0' + _res; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
268 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
269 |
return _res; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
270 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
271 |
var _hms = this.getHMS(), |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
272 |
_res = ''; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
273 |
if (_hms.hours) { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
274 |
_res += pad(_hms.hours) + ':' |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
275 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
276 |
_res += pad(_hms.minutes) + ':' + pad(_hms.seconds); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
277 |
return _res; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
278 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
279 |
|
| 868 | 280 |
/* IriSP.Model.Reference handles references between elements |
281 |
*/ |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
282 |
|
| 860 | 283 |
IriSP.Model.Reference = function(_source, _idRef) { |
284 |
this.source = _source; |
|
| 858 | 285 |
if (typeof _idRef === "object") { |
286 |
this.isList = true; |
|
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
287 |
this.id = IriSP._(_idRef).map(function(_id) { |
| 860 | 288 |
return _source.getNamespaced(_id).fullname; |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
289 |
}); |
| 858 | 290 |
} else { |
291 |
this.isList = false; |
|
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
292 |
this.id = _source.getNamespaced(_idRef).fullname; |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
293 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
294 |
this.refresh(); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
295 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
296 |
|
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
297 |
IriSP.Model.Reference.prototype.refresh = function() { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
298 |
if (this.isList) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
299 |
this.contents = new IriSP.Model.List(this.source.directory); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
300 |
this.contents.addIds(this.id); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
301 |
} else { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
302 |
this.contents = this.source.directory.getElement(this.id); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
303 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
304 |
|
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
305 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
306 |
|
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
307 |
IriSP.Model.Reference.prototype.getContents = function() { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
308 |
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
|
309 |
this.refresh(); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
310 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
311 |
return this.contents; |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
312 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
313 |
|
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
314 |
IriSP.Model.Reference.prototype.isOrHasId = function(_idRef) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
315 |
if (this.isList) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
316 |
return (IriSP._(this.id).indexOf(_idRef) !== -1) |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
317 |
} else { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
318 |
return (this.id == _idRef); |
| 858 | 319 |
} |
|
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 |
/* */ |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
323 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
324 |
IriSP.Model.Element = function(_id, _source) { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
325 |
this.elementType = 'element'; |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
326 |
if (typeof _source === "undefined") { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
327 |
return; |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
328 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
329 |
if (typeof _id === "undefined" || !_id) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
330 |
_id = IriSP.Model.getUID(); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
331 |
} |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
332 |
this.source = _source; |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
333 |
this.namespacedId = _source.getNamespaced(_id) |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
334 |
this.id = this.namespacedId.fullname; |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
335 |
this.title = ""; |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
336 |
this.description = ""; |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
337 |
this.source.directory.addElement(this); |
|
856
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 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
340 |
IriSP.Model.Element.prototype.toString = function() { |
| 858 | 341 |
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
|
342 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
343 |
|
| 858 | 344 |
IriSP.Model.Element.prototype.setReference = function(_elementType, _idRef) { |
| 860 | 345 |
this[_elementType] = new IriSP.Model.Reference(this.source, _idRef); |
| 854 | 346 |
} |
347 |
||
| 858 | 348 |
IriSP.Model.Element.prototype.getReference = function(_elementType) { |
349 |
if (typeof this[_elementType] !== "undefined") { |
|
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
350 |
return this[_elementType].getContents(); |
|
856
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 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
353 |
|
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
354 |
IriSP.Model.Element.prototype.getRelated = function(_elementType, _global) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
355 |
_global = (typeof _global !== "undefined" && _global); |
| 864 | 356 |
var _this = this; |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
357 |
return this.source.getList(_elementType, _global).filter(function(_el) { |
| 864 | 358 |
var _ref = _el[_this.elementType]; |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
359 |
return _ref.isOrHasId(_this.id); |
| 864 | 360 |
}); |
361 |
} |
|
362 |
||
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
363 |
/* */ |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
364 |
|
| 864 | 365 |
IriSP.Model.Media = function(_id, _source) { |
366 |
IriSP.Model.Element.call(this, _id, _source); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
367 |
this.elementType = 'media'; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
368 |
this.duration = new IriSP.Model.Time(); |
| 866 | 369 |
this.video = ''; |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
370 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
371 |
|
| 858 | 372 |
IriSP.Model.Media.prototype = new IriSP.Model.Element(); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
373 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
374 |
IriSP.Model.Media.prototype.setDuration = function(_durationMs) { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
375 |
this.duration.milliseconds = _durationMs; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
376 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
377 |
|
| 864 | 378 |
IriSP.Model.Media.prototype.getAnnotations = function() { |
379 |
return this.getRelated("annotation"); |
|
380 |
} |
|
381 |
||
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
382 |
/* */ |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
383 |
|
| 864 | 384 |
IriSP.Model.Tag = function(_id, _source) { |
385 |
IriSP.Model.Element.call(this, _id, _source); |
|
| 858 | 386 |
this.elementType = 'tag'; |
387 |
} |
|
388 |
||
389 |
IriSP.Model.Tag.prototype = new IriSP.Model.Element(); |
|
390 |
||
| 864 | 391 |
IriSP.Model.Tag.prototype.getAnnotations = function() { |
392 |
return this.getRelated("annotation"); |
|
393 |
} |
|
394 |
||
| 858 | 395 |
/* */ |
396 |
||
| 864 | 397 |
IriSP.Model.AnnotationType = function(_id, _source) { |
398 |
IriSP.Model.Element.call(this, _id, _source); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
399 |
this.elementType = 'annotationType'; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
400 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
401 |
|
| 858 | 402 |
IriSP.Model.AnnotationType.prototype = new IriSP.Model.Element(); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
403 |
|
| 864 | 404 |
IriSP.Model.AnnotationType.prototype.getAnnotations = function() { |
405 |
return this.getRelated("annotation"); |
|
406 |
} |
|
407 |
||
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
408 |
/* Annotation |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
409 |
* */ |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
410 |
|
| 864 | 411 |
IriSP.Model.Annotation = function(_id, _source) { |
412 |
IriSP.Model.Element.call(this, _id, _source); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
413 |
this.elementType = 'annotation'; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
414 |
this.begin = new IriSP.Model.Time(); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
415 |
this.end = new IriSP.Model.Time(); |
|
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 |
IriSP.Model.Annotation.prototype = new IriSP.Model.Element(null); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
419 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
420 |
IriSP.Model.Annotation.prototype.setBegin = function(_beginMs) { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
421 |
this.begin.milliseconds = _beginMs; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
422 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
423 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
424 |
IriSP.Model.Annotation.prototype.setEnd = function(_beginMs) { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
425 |
this.end.milliseconds = _beginMs; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
426 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
427 |
|
| 858 | 428 |
IriSP.Model.Annotation.prototype.setMedia = function(_idRef) { |
429 |
this.setReference("media", _idRef); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
430 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
431 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
432 |
IriSP.Model.Annotation.prototype.getMedia = function() { |
| 858 | 433 |
return this.getReference("media"); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
434 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
435 |
|
| 858 | 436 |
IriSP.Model.Annotation.prototype.setAnnotationType = function(_idRef) { |
437 |
this.setReference("annotationType", _idRef); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
438 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
439 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
440 |
IriSP.Model.Annotation.prototype.getAnnotationType = function() { |
| 858 | 441 |
return this.getReference("annotationType"); |
|
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 |
|
| 858 | 444 |
IriSP.Model.Annotation.prototype.setTags = function(_idRefs) { |
445 |
this.setReference("tag", _idRefs); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
446 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
447 |
|
| 858 | 448 |
IriSP.Model.Annotation.prototype.getTags = function() { |
449 |
return this.getReference("tag"); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
450 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
451 |
|
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
452 |
IriSP.Model.Annotation.prototype.getTagTexts = function() { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
453 |
return this.getTags().getTitles(); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
454 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
455 |
|
| 858 | 456 |
/* */ |
457 |
||
| 860 | 458 |
IriSP.Model.Source = function(_config) { |
| 868 | 459 |
this.status = IriSP.Model._SOURCE_STATUS_EMPTY; |
| 860 | 460 |
if (typeof _config !== "undefined") { |
461 |
var _this = this; |
|
| 866 | 462 |
IriSP._(_config).forEach(function(_v, _k) { |
| 860 | 463 |
_this[_k] = _v; |
464 |
}) |
|
465 |
this.callbackQueue = []; |
|
466 |
this.contents = {}; |
|
467 |
if (typeof this.namespace === "undefined") { |
|
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
468 |
this.namespace = "metadataplayer"; |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
469 |
} else { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
470 |
if (typeof this.namespaceUrl === "undefined" && typeof this.url !== "undefined") { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
471 |
var _matches = this.url.match(/(^[^?&]+|[^?&][a-zA-Z0-9_%=?]+)/g), |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
472 |
_url = _matches[0]; |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
473 |
if (_matches.length > 1) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
474 |
_matches = IriSP._(_matches.slice(1)).reject(function(_txt) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
475 |
return /\?$/.test(_txt); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
476 |
}); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
477 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
478 |
if (_matches.length > 0) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
479 |
_url += '?' + _matches.join('&'); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
480 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
481 |
this.namespaceUrl = _url; |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
482 |
} |
| 860 | 483 |
} |
484 |
if (typeof this.namespaceUrl === "undefined") { |
|
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
485 |
this.namespaceUrl = "http://ldt.iri.centrepompidou.fr/"; |
| 860 | 486 |
} |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
487 |
this.directory.addNamespace(this.namespace, this.namespaceUrl); |
| 860 | 488 |
this.get(); |
489 |
} |
|
490 |
} |
|
491 |
||
492 |
IriSP.Model.Source.prototype.getNamespaced = function(_id) { |
|
493 |
var _tab = _id.split(':'); |
|
494 |
if (_tab.length > 1) { |
|
495 |
return { |
|
496 |
namespace : _tab[0], |
|
497 |
name : _tab[1], |
|
498 |
fullname : _id |
|
499 |
} |
|
500 |
} else { |
|
501 |
return { |
|
502 |
namespace : this.namespace, |
|
503 |
name : _id, |
|
504 |
fullname : this.namespace + ':' + _id |
|
505 |
} |
|
506 |
} |
|
507 |
} |
|
508 |
|
|
509 |
IriSP.Model.Source.prototype.unNamespace = function(_id) { |
|
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
510 |
if (typeof _id !== "undefined") { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
511 |
return _id.replace(this.namespace + ':', ''); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
512 |
} |
|
856
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 |
|
| 858 | 515 |
IriSP.Model.Source.prototype.addList = function(_listId, _contents) { |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
516 |
if (typeof this.contents[_listId] === "undefined") { |
| 860 | 517 |
this.contents[_listId] = new IriSP.Model.List(this.directory); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
518 |
} |
| 866 | 519 |
this.contents[_listId].addElements(_contents); |
|
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 |
|
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
522 |
IriSP.Model.Source.prototype.getList = function(_listId, _global) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
523 |
_global = (typeof _global !== "undefined" && _global); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
524 |
if (_global || typeof this.contents[_listId] === "undefined") { |
| 860 | 525 |
return this.directory.getGlobalList().filter(function(_e) { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
526 |
return (_e.elementType === _listId); |
| 858 | 527 |
}); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
528 |
} else { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
529 |
return this.contents[_listId]; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
530 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
531 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
532 |
|
| 866 | 533 |
IriSP.Model.Source.prototype.forEach = function(_callback) { |
| 860 | 534 |
var _this = this; |
| 866 | 535 |
IriSP._(this.contents).forEach(function(_value, _key) { |
| 860 | 536 |
_callback.call(_this, _value, _key); |
537 |
}) |
|
538 |
} |
|
539 |
||
| 866 | 540 |
IriSP.Model.Source.prototype.getElement = function(_elId) { |
| 880 | 541 |
return this.directory.getElement(_this.getNamespaced(_elId).fullname); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
542 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
543 |
|
| 858 | 544 |
IriSP.Model.Source.prototype.setCurrentMediaId = function(_idRef) { |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
545 |
if (typeof _idRef !== "undefined") { |
| 866 | 546 |
this.currentMedia = this.getMedias().getElement(this.getNamespaced(_idRef).fullname); |
|
856
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 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
549 |
|
| 858 | 550 |
IriSP.Model.Source.prototype.setDefaultCurrentMedia = function() { |
| 866 | 551 |
if (typeof this.currentMedia === "undefined" && this.getMedias().length) { |
552 |
this.currentMedia = this.getMedias()[0]; |
|
| 854 | 553 |
} |
554 |
} |
|
555 |
||
| 864 | 556 |
IriSP.Model.Source.prototype.listNamespaces = function(_excludeSelf) { |
| 860 | 557 |
var _this = this, |
| 864 | 558 |
_nsls = [], |
559 |
_excludeSelf = (typeof _excludeSelf !== "undefined" && _excludeSelf); |
|
| 866 | 560 |
this.forEach(function(_list) { |
561 |
IriSP._(_list).forEach(function(_el) { |
|
562 |
var _ns = _el.id.replace(/:.*$/,''); |
|
| 864 | 563 |
if (IriSP._(_nsls).indexOf(_ns) === -1 && (!_excludeSelf || _ns !== _this.namespace)) { |
| 860 | 564 |
_nsls.push(_ns); |
565 |
} |
|
566 |
}) |
|
567 |
}); |
|
568 |
return _nsls; |
|
569 |
} |
|
570 |
||
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
571 |
IriSP.Model.Source.prototype.get = function() { |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
572 |
this.status = IriSP.Model._SOURCE_STATUS_WAITING; |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
573 |
this.handleCallbacks(); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
574 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
575 |
|
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
576 |
/* We defer the callbacks calls so they execute after the queue is cleared */ |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
577 |
IriSP.Model.Source.prototype.deferCallback = function(_callback) { |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
578 |
var _this = this; |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
579 |
IriSP._.defer(function() { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
580 |
_callback.call(_this); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
581 |
}); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
582 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
583 |
|
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
584 |
IriSP.Model.Source.prototype.handleCallbacks = function() { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
585 |
this.status = IriSP.Model._SOURCE_STATUS_READY; |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
586 |
while (this.callbackQueue.length) { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
587 |
this.deferCallback(this.callbackQueue.splice(0,1)[0]); |
| 858 | 588 |
} |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
589 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
590 |
|
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
591 |
IriSP.Model.Source.prototype.onLoad = function(_callback) { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
592 |
if (this.status === IriSP.Model._SOURCE_STATUS_READY) { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
593 |
this.deferCallback(_callback); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
594 |
} else { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
595 |
this.callbackQueue.push(_callback); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
596 |
} |
| 854 | 597 |
} |
598 |
||
| 860 | 599 |
IriSP.Model.Source.prototype.serialize = function() { |
600 |
return this.serializer.serialize(this); |
|
601 |
} |
|
602 |
||
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
603 |
IriSP.Model.Source.prototype.deSerialize = function(_data) { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
604 |
this.serializer.deSerialize(_data, this); |
| 854 | 605 |
} |
606 |
||
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
607 |
IriSP.Model.Source.prototype.getAnnotations = function(_global) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
608 |
_global = (typeof _global !== "undefined" && _global); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
609 |
return this.getList("annotation", _global); |
| 854 | 610 |
} |
611 |
||
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
612 |
IriSP.Model.Source.prototype.getMedias = function(_global) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
613 |
_global = (typeof _global !== "undefined" && _global); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
614 |
return this.getList("media", _global); |
| 864 | 615 |
} |
616 |
||
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
617 |
IriSP.Model.Source.prototype.getAnnotationTypes = function(_global) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
618 |
_global = (typeof _global !== "undefined" && _global); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
619 |
return this.getList("annotationType", _global); |
| 864 | 620 |
} |
621 |
||
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
622 |
IriSP.Model.Source.prototype.getAnnotationsByTypeTitle = function(_title, _global) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
623 |
_global = (typeof _global !== "undefined" && _global); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
624 |
var _res = new IriSP.Model.List(this.directory), |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
625 |
_annTypes = this.getAnnotationTypes(_global).searchByTitle(_title); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
626 |
_annTypes.forEach(function(_annType) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
627 |
_res.addElements(_annType.getAnnotations(_global)); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
628 |
}) |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
629 |
return _res; |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
630 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
631 |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
632 |
IriSP.Model.Source.prototype.getDuration = function() { |
| 866 | 633 |
var _m = this.currentMedia; |
634 |
if (typeof _m !== "undefined") { |
|
635 |
return this.currentMedia.duration; |
|
636 |
} |
|
| 858 | 637 |
} |
638 |
||
639 |
/* */ |
|
640 |
||
| 860 | 641 |
IriSP.Model.RemoteSource = function(_config) { |
642 |
IriSP.Model.Source.call(this, _config); |
|
| 858 | 643 |
} |
644 |
||
645 |
IriSP.Model.RemoteSource.prototype = new IriSP.Model.Source(); |
|
646 |
||
647 |
IriSP.Model.RemoteSource.prototype.get = function() { |
|
| 868 | 648 |
this.status = IriSP.Model._SOURCE_STATUS_WAITING; |
| 858 | 649 |
var _this = this; |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
650 |
this.serializer.loadData(this.url, function(_result) { |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
651 |
_this.deSerialize(_result); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
652 |
_this.handleCallbacks(); |
| 858 | 653 |
}); |
| 854 | 654 |
} |
655 |
||
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
656 |
/* */ |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
657 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
658 |
IriSP.Model.Directory = function() { |
| 858 | 659 |
this.remoteSources = {}; |
660 |
this.elements = {}; |
|
| 860 | 661 |
this.namespaces = {}; |
| 858 | 662 |
} |
663 |
||
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
664 |
IriSP.Model.Directory.prototype.addNamespace = function(_namespace, _url) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
665 |
this.namespaces[_namespace] = _url; |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
666 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
667 |
|
| 858 | 668 |
IriSP.Model.Directory.prototype.remoteSource = function(_properties) { |
| 860 | 669 |
var _config = IriSP._({ directory: this }).extend(_properties); |
| 858 | 670 |
if (typeof this.remoteSources[_properties.url] === "undefined") { |
| 860 | 671 |
this.remoteSources[_properties.url] = new IriSP.Model.RemoteSource(_config); |
| 858 | 672 |
} |
673 |
return this.remoteSources[_properties.url]; |
|
| 854 | 674 |
} |
675 |
||
| 860 | 676 |
IriSP.Model.Directory.prototype.newLocalSource = function(_properties) { |
677 |
var _config = IriSP._({ directory: this }).extend(_properties), |
|
678 |
_res = new IriSP.Model.Source(_config); |
|
679 |
return _res; |
|
680 |
} |
|
681 |
||
| 858 | 682 |
IriSP.Model.Directory.prototype.getElement = function(_id) { |
683 |
return this.elements[_id]; |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
684 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
685 |
|
| 858 | 686 |
IriSP.Model.Directory.prototype.addElement = function(_element) { |
687 |
this.elements[_element.id] = _element; |
|
688 |
} |
|
689 |
||
690 |
IriSP.Model.Directory.prototype.getGlobalList = function() { |
|
691 |
var _res = new IriSP.Model.List(this); |
|
| 866 | 692 |
_res.addIds(IriSP._(this.elements).keys()); |
| 858 | 693 |
return _res; |
| 854 | 694 |
} |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
695 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
696 |
/* */ |