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