| author | veltr |
| Mon, 16 Apr 2012 19:10:32 +0200 | |
| branch | new-model |
| changeset 864 | 5e76a06b961c |
| parent 860 | 7fd843e0dc4e |
| child 866 | 3bf7aa8216e5 |
| 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 = { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
4 |
SOURCE_STATUS_EMPTY : 0, |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
5 |
SOURCE_STATUS_WAITING : 1, |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
6 |
SOURCE_STATUS_READY : 2, |
| 860 | 7 |
ID_AUTO_INCREMENT : 0, |
8 |
getAI : function() { |
|
9 |
return "autoid-" + (++this.ID_AUTO_INCREMENT); |
|
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 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
47 |
/* */ |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
48 |
|
| 858 | 49 |
IriSP.Model.List = function(_directory) { |
50 |
this.contents = []; |
|
51 |
this.directory = _directory; |
|
| 860 | 52 |
if (typeof _directory == "undefined") { |
53 |
throw("Error : new IriSP.Model.List(directory): directory is undefined"); |
|
54 |
} |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
55 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
56 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
57 |
IriSP.Model.List.prototype.toString = function() { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
58 |
return 'List of Elements, length=' + this.length(); |
|
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 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
61 |
IriSP.Model.List.prototype.length = function() { |
| 858 | 62 |
return this.contents.length; |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
63 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
64 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
65 |
IriSP.Model.List.prototype.getElement = function(_id) { |
| 858 | 66 |
return this.directory.getElement(_id); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
67 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
68 |
|
| 858 | 69 |
IriSP.Model.List.prototype.getElementAt = function(_pos) { |
70 |
if (_pos >= 0 && _pos < this.length()) { |
|
71 |
return this.getElement(this.contents[_pos]); |
|
72 |
} |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
73 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
74 |
|
| 864 | 75 |
IriSP.Model.List.prototype.hasId = function(_id) { |
76 |
return (IriSP._(this.contents).indexOf(_id) !== -1); |
|
77 |
} |
|
78 |
||
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
79 |
IriSP.Model.List.prototype.each = function(_callback) { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
80 |
var _this = this; |
| 858 | 81 |
IriSP._(this.contents).each(function(_id) { |
82 |
_callback.call(_this, _this.getElement(_id), _id); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
83 |
}); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
84 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
85 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
86 |
IriSP.Model.List.prototype.map = function(_callback) { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
87 |
var _this = this; |
| 858 | 88 |
return IriSP._(this.contents).map(function(_id) { |
89 |
return _callback.call(_this, _this.getElement(_id), _id); |
|
90 |
}); |
|
91 |
} |
|
92 |
||
93 |
IriSP.Model.List.prototype.filter = function(_callback) { |
|
94 |
var _this = this, |
|
95 |
_res = new IriSP.Model.List(this.directory); |
|
96 |
_res.contents = IriSP._(this.contents).filter(function(_id) { |
|
97 |
return _callback.call(_this, _this.getElement(_id), _id); |
|
98 |
}); |
|
99 |
return _res; |
|
100 |
} |
|
101 |
||
| 864 | 102 |
IriSP.Model.List.prototype.sortBy = function(_callback) { |
103 |
var _this = this, |
|
104 |
_res = new IriSP.Model.List(this.directory); |
|
105 |
_res.contents = IriSP._(this.contents).sortBy(function(_id) { |
|
106 |
return _callback.call(_this, _this.getElement(_id), _id); |
|
107 |
}); |
|
108 |
return _res; |
|
109 |
} |
|
110 |
||
| 858 | 111 |
IriSP.Model.List.prototype.searchByTitle = function(_text) { |
112 |
var _rgxp = new RegExp('(' + _text.replace(/(\W)/gm,'\\$1') + ')','gim'); |
|
113 |
return this.filter(function(_element) { |
|
| 864 | 114 |
return _rgxp.test(_element.title); |
| 858 | 115 |
}); |
116 |
} |
|
117 |
||
118 |
IriSP.Model.List.prototype.searchByDescription = function(_text) { |
|
119 |
var _rgxp = new RegExp('(' + _text.replace(/(\W)/gm,'\\$1') + ')','gim'); |
|
120 |
return this.filter(function(_element) { |
|
121 |
return _rgxp.test(_element.description); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
122 |
}); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
123 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
124 |
|
| 858 | 125 |
IriSP.Model.List.prototype.searchByTextFields = 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.description) || _rgxp.test(_element.title); |
| 858 | 129 |
}); |
130 |
} |
|
131 |
||
132 |
IriSP.Model.List.prototype.addId = function(_id) { |
|
| 864 | 133 |
if (!this.hasId(_id)) { |
| 858 | 134 |
this.contents.push(_id); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
135 |
} |
|
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 |
|
| 858 | 138 |
IriSP.Model.List.prototype.addElement = function(_el) { |
139 |
this.addId(_el.id); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
140 |
} |
| 858 | 141 |
|
142 |
IriSP.Model.List.prototype.addIdsFromArray = function(_array) { |
|
143 |
var _l = _array.length; |
|
144 |
for (var _i = 0; _i < _l; _i++) { |
|
145 |
this.addId(_array[_i]); |
|
146 |
} |
|
147 |
} |
|
148 |
||
149 |
IriSP.Model.List.prototype.addIdsFromList = function(_list) { |
|
150 |
this.addIdsFromArray(_list.contents); |
|
151 |
} |
|
152 |
||
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
153 |
/* */ |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
154 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
155 |
IriSP.Model.Time = function(_milliseconds) { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
156 |
this.milliseconds = parseInt(typeof _milliseconds !== "undefined" ? _milliseconds : 0); |
|
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 |
IriSP.Model.Time.prototype.setSeconds = function(_seconds) { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
160 |
this.milliseconds = 1000 * _seconds; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
161 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
162 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
163 |
IriSP.Model.Time.prototype.getSeconds = function() { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
164 |
return Math.floor(this.milliseconds / 1000); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
165 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
166 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
167 |
IriSP.Model.Time.prototype.getHMS = function() { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
168 |
var _totalSeconds = Math.abs(this.getSeconds()); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
169 |
return { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
170 |
hours : Math.floor(_totalSeconds / 3600), |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
171 |
minutes : (Math.floor(_totalSeconds / 60) % 60), |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
172 |
seconds : _totalSeconds % 60 |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
173 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
174 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
175 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
176 |
IriSP.Model.Time.prototype.toString = function() { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
177 |
function pad(_n) { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
178 |
var _res = _n.toString(); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
179 |
while (_res.length < 2) { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
180 |
_res = '0' + _res; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
181 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
182 |
return _res; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
183 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
184 |
var _hms = this.getHMS(), |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
185 |
_res = ''; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
186 |
if (_hms.hours) { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
187 |
_res += pad(_hms.hours) + ':' |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
188 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
189 |
_res += pad(_hms.minutes) + ':' + pad(_hms.seconds); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
190 |
return _res; |
|
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 |
|
| 858 | 193 |
/* */ |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
194 |
|
| 860 | 195 |
IriSP.Model.Reference = function(_source, _idRef) { |
196 |
this.source = _source; |
|
| 858 | 197 |
if (typeof _idRef === "object") { |
198 |
this.isList = true; |
|
| 860 | 199 |
this.contents = new IriSP.Model.List(this.source.directory); |
200 |
this.contents.addIdsFromArray(IriSP._(_idRef).map(function(_id) { |
|
201 |
return _source.getNamespaced(_id).fullname; |
|
202 |
})); |
|
| 858 | 203 |
} else { |
204 |
this.isList = false; |
|
| 860 | 205 |
this.contents = _source.getNamespaced(_idRef).fullname; |
| 858 | 206 |
} |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
207 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
208 |
|
| 858 | 209 |
IriSP.Model.Reference.prototype.getContents = function() { |
| 860 | 210 |
return (this.isList ? this.contents : this.source.directory.getElement(this.contents)); |
|
856
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 |
/* */ |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
214 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
215 |
IriSP.Model.Element = function(_id, _source) { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
216 |
this.elementType = 'element'; |
| 860 | 217 |
if (typeof _source !== "undefined") { |
218 |
if (typeof _id === "undefined" || !_id) { |
|
219 |
_id = IriSP.Model.getAI(); |
|
220 |
} |
|
| 858 | 221 |
this.source = _source; |
| 860 | 222 |
this.id = _source.getNamespaced(_id).fullname; |
| 858 | 223 |
this.title = ""; |
224 |
this.description = ""; |
|
225 |
this.source.directory.addElement(this); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
226 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
227 |
} |
|
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 |
IriSP.Model.Element.prototype.toString = function() { |
| 858 | 230 |
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
|
231 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
232 |
|
| 858 | 233 |
IriSP.Model.Element.prototype.setReference = function(_elementType, _idRef) { |
| 860 | 234 |
this[_elementType] = new IriSP.Model.Reference(this.source, _idRef); |
| 854 | 235 |
} |
236 |
||
| 858 | 237 |
IriSP.Model.Element.prototype.getReference = function(_elementType) { |
238 |
if (typeof this[_elementType] !== "undefined") { |
|
239 |
return this[_elementType].getContents(); |
|
|
856
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 |
|
| 864 | 243 |
IriSP.Model.Element.prototype.getRelated = function(_elementType) { |
244 |
var _this = this; |
|
245 |
return this.source.getList(_elementType).filter(function(_el) { |
|
246 |
var _ref = _el[_this.elementType]; |
|
247 |
if (_ref.isList) { |
|
248 |
return _ref.contents.hasId(_this.id); |
|
249 |
} |
|
250 |
else { |
|
251 |
return _ref.contents === _this.id; |
|
252 |
} |
|
253 |
}); |
|
254 |
} |
|
255 |
||
|
856
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 |
|
| 864 | 258 |
IriSP.Model.Media = function(_id, _source) { |
259 |
IriSP.Model.Element.call(this, _id, _source); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
260 |
this.elementType = 'media'; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
261 |
this.duration = new IriSP.Model.Time(); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
262 |
this.url = ''; |
|
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 |
|
| 858 | 265 |
IriSP.Model.Media.prototype = new IriSP.Model.Element(); |
|
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 |
IriSP.Model.Media.prototype.setDuration = function(_durationMs) { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
268 |
this.duration.milliseconds = _durationMs; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
269 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
270 |
|
| 864 | 271 |
IriSP.Model.Media.prototype.getAnnotations = function() { |
272 |
return this.getRelated("annotation"); |
|
273 |
} |
|
274 |
||
|
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 |
|
| 864 | 277 |
IriSP.Model.Tag = function(_id, _source) { |
278 |
IriSP.Model.Element.call(this, _id, _source); |
|
| 858 | 279 |
this.elementType = 'tag'; |
280 |
} |
|
281 |
||
282 |
IriSP.Model.Tag.prototype = new IriSP.Model.Element(); |
|
283 |
||
| 864 | 284 |
IriSP.Model.Tag.prototype.getAnnotations = function() { |
285 |
return this.getRelated("annotation"); |
|
286 |
} |
|
287 |
||
| 858 | 288 |
/* */ |
289 |
||
| 864 | 290 |
IriSP.Model.AnnotationType = function(_id, _source) { |
291 |
IriSP.Model.Element.call(this, _id, _source); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
292 |
this.elementType = 'annotationType'; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
293 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
294 |
|
| 858 | 295 |
IriSP.Model.AnnotationType.prototype = new IriSP.Model.Element(); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
296 |
|
| 864 | 297 |
IriSP.Model.AnnotationType.prototype.getAnnotations = function() { |
298 |
return this.getRelated("annotation"); |
|
299 |
} |
|
300 |
||
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
301 |
/* Annotation |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
302 |
* */ |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
303 |
|
| 864 | 304 |
IriSP.Model.Annotation = function(_id, _source) { |
305 |
IriSP.Model.Element.call(this, _id, _source); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
306 |
this.elementType = 'annotation'; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
307 |
this.begin = new IriSP.Model.Time(); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
308 |
this.end = new IriSP.Model.Time(); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
309 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
310 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
311 |
IriSP.Model.Annotation.prototype = new IriSP.Model.Element(null); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
312 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
313 |
IriSP.Model.Annotation.prototype.setBegin = function(_beginMs) { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
314 |
this.begin.milliseconds = _beginMs; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
315 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
316 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
317 |
IriSP.Model.Annotation.prototype.setEnd = function(_beginMs) { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
318 |
this.end.milliseconds = _beginMs; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
319 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
320 |
|
| 858 | 321 |
IriSP.Model.Annotation.prototype.setMedia = function(_idRef) { |
322 |
this.setReference("media", _idRef); |
|
|
856
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 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
325 |
IriSP.Model.Annotation.prototype.getMedia = function() { |
| 858 | 326 |
return this.getReference("media"); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
327 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
328 |
|
| 858 | 329 |
IriSP.Model.Annotation.prototype.setAnnotationType = function(_idRef) { |
330 |
this.setReference("annotationType", _idRef); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
331 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
332 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
333 |
IriSP.Model.Annotation.prototype.getAnnotationType = function() { |
| 858 | 334 |
return this.getReference("annotationType"); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
335 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
336 |
|
| 858 | 337 |
IriSP.Model.Annotation.prototype.setTags = function(_idRefs) { |
338 |
this.setReference("tag", _idRefs); |
|
|
856
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 |
|
| 858 | 341 |
IriSP.Model.Annotation.prototype.getTags = function() { |
342 |
return this.getReference("tag"); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
343 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
344 |
|
| 858 | 345 |
/* */ |
346 |
||
| 860 | 347 |
IriSP.Model.Source = function(_config) { |
| 858 | 348 |
this.status = IriSP.Model.SOURCE_STATUS_EMPTY; |
| 860 | 349 |
if (typeof _config !== "undefined") { |
350 |
var _this = this; |
|
351 |
IriSP._(_config).each(function(_v, _k) { |
|
352 |
_this[_k] = _v; |
|
353 |
}) |
|
354 |
this.callbackQueue = []; |
|
355 |
this.contents = {}; |
|
356 |
if (typeof this.namespace === "undefined") { |
|
357 |
this.namespace = IriSP.Model.getAI(); |
|
358 |
} |
|
359 |
if (typeof this.namespaceUrl === "undefined") { |
|
360 |
this.namespaceUrl = (typeof this.url !== "undefined" ? this.url : this.namespaceUrl); |
|
361 |
} |
|
362 |
this.directory.namespaces[this.namespace] = this.namespaceUrl; |
|
363 |
this.get(); |
|
364 |
} |
|
365 |
} |
|
366 |
||
367 |
IriSP.Model.Source.prototype.getNamespaced = function(_id) { |
|
368 |
var _tab = _id.split(':'); |
|
369 |
if (_tab.length > 1) { |
|
370 |
return { |
|
371 |
namespace : _tab[0], |
|
372 |
name : _tab[1], |
|
373 |
fullname : _id |
|
374 |
} |
|
375 |
} else { |
|
376 |
return { |
|
377 |
namespace : this.namespace, |
|
378 |
name : _id, |
|
379 |
fullname : this.namespace + ':' + _id |
|
380 |
} |
|
381 |
} |
|
382 |
} |
|
383 |
|
|
384 |
IriSP.Model.Source.prototype.unNamespace = function(_id) { |
|
385 |
return _id.replace(this.namespace + ':', ''); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
386 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
387 |
|
| 858 | 388 |
IriSP.Model.Source.prototype.addList = function(_listId, _contents) { |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
389 |
if (typeof this.contents[_listId] === "undefined") { |
| 860 | 390 |
this.contents[_listId] = new IriSP.Model.List(this.directory); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
391 |
} |
| 858 | 392 |
this.contents[_listId].addIdsFromList(_contents); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
393 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
394 |
|
| 858 | 395 |
IriSP.Model.Source.prototype.getList = function(_listId) { |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
396 |
if (typeof this.contents[_listId] === "undefined") { |
| 860 | 397 |
return this.directory.getGlobalList().filter(function(_e) { |
| 858 | 398 |
return (_e.elType === _listId); |
399 |
}); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
400 |
} else { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
401 |
return this.contents[_listId]; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
402 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
403 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
404 |
|
| 860 | 405 |
IriSP.Model.Source.prototype.each = function(_callback) { |
406 |
var _this = this; |
|
407 |
IriSP._(this.contents).each(function(_value, _key) { |
|
408 |
_callback.call(_this, _value, _key); |
|
409 |
}) |
|
410 |
} |
|
411 |
||
| 858 | 412 |
IriSP.Model.Source.prototype.getElement = function(_listId, _elId) { |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
413 |
var _list = this.getList(_listId); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
414 |
return (typeof _list !== "undefined" ? _list.getElement(_elId) : undefined); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
415 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
416 |
|
| 858 | 417 |
IriSP.Model.Source.prototype.setCurrentMediaId = function(_idRef) { |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
418 |
if (typeof _idRef !== "undefined") { |
| 860 | 419 |
this.currentMedia = this.getNamespaced(_idRef).fullname; |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
420 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
421 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
422 |
|
| 858 | 423 |
IriSP.Model.Source.prototype.setDefaultCurrentMedia = function() { |
424 |
if (typeof this.currentMedia === "undefined") { |
|
| 864 | 425 |
this.currentMedia = this.getList("media").getElementAt(0); |
| 854 | 426 |
} |
427 |
} |
|
428 |
||
| 864 | 429 |
IriSP.Model.Source.prototype.listNamespaces = function(_excludeSelf) { |
| 860 | 430 |
var _this = this, |
| 864 | 431 |
_nsls = [], |
432 |
_excludeSelf = (typeof _excludeSelf !== "undefined" && _excludeSelf); |
|
| 860 | 433 |
this.each(function(_list) { |
434 |
IriSP._(_list.contents).each(function(_id) { |
|
435 |
var _ns = _id.replace(/:.*$/,''); |
|
| 864 | 436 |
if (IriSP._(_nsls).indexOf(_ns) === -1 && (!_excludeSelf || _ns !== _this.namespace)) { |
| 860 | 437 |
_nsls.push(_ns); |
438 |
} |
|
439 |
}) |
|
440 |
}); |
|
441 |
return _nsls; |
|
442 |
} |
|
443 |
||
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
444 |
IriSP.Model.Source.prototype.get = function() { |
| 858 | 445 |
this.status = IriSP.Model.SOURCE_STATUS_READY; |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
446 |
var _this = this; |
| 858 | 447 |
if (_this.callbackQueue.length) { |
448 |
IriSP._.each(_this.callbackQueue, function(_callback) { |
|
449 |
_callback.call(_this); |
|
450 |
}); |
|
451 |
} |
|
452 |
_this.callbackQueue = []; |
|
| 854 | 453 |
} |
454 |
||
| 860 | 455 |
IriSP.Model.Source.prototype.serialize = function() { |
456 |
return this.serializer.serialize(this); |
|
457 |
} |
|
458 |
||
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
459 |
IriSP.Model.Source.prototype.addCallback = function(_callback) { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
460 |
if (this.status === IriSP.Model.SOURCE_STATUS_READY) { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
461 |
callback.call(this); |
| 854 | 462 |
} else { |
463 |
this.callbackQueue.push(_callback); |
|
464 |
} |
|
465 |
} |
|
466 |
||
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
467 |
IriSP.Model.Source.prototype.getAnnotations = function() { |
| 858 | 468 |
return this.getList("annotation"); |
| 854 | 469 |
} |
470 |
||
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
471 |
IriSP.Model.Source.prototype.getMedias = function() { |
| 858 | 472 |
return this.getList("media"); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
473 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
474 |
|
| 864 | 475 |
IriSP.Model.Source.prototype.getAnnotationTypes = function() { |
476 |
return this.getList("annotationType"); |
|
477 |
} |
|
478 |
||
479 |
IriSP.Model.Source.prototype.getAnnotationTypeByTitle = function(_title) { |
|
480 |
var _res = this.getAnnotationTypes().searchByTitle(_title); |
|
481 |
if (_res.length() > 0) { |
|
482 |
return _res.getElementAt(0); |
|
483 |
} |
|
484 |
} |
|
485 |
||
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
486 |
IriSP.Model.Source.prototype.getDuration = function() { |
| 858 | 487 |
return this.currentMedia.duration; |
488 |
} |
|
489 |
||
490 |
/* */ |
|
491 |
||
| 860 | 492 |
IriSP.Model.RemoteSource = function(_config) { |
493 |
IriSP.Model.Source.call(this, _config); |
|
| 858 | 494 |
} |
495 |
||
496 |
IriSP.Model.RemoteSource.prototype = new IriSP.Model.Source(); |
|
497 |
||
498 |
IriSP.Model.RemoteSource.prototype.get = function() { |
|
499 |
this.status = IriSP.Model.SOURCE_STATUS_WAITING; |
|
500 |
var _this = this; |
|
501 |
IriSP.jQuery.getJSON(this.url, function(_result) { |
|
502 |
_this.serializer.deSerialize(_result, _this); |
|
503 |
if (_this.callbackQueue.length) { |
|
504 |
IriSP._.each(_this.callbackQueue, function(_callback) { |
|
505 |
_callback.call(_this); |
|
506 |
}); |
|
507 |
} |
|
508 |
_this.callbackQueue = []; |
|
509 |
_this.status = IriSP.Model.SOURCE_STATUS_READY; |
|
510 |
}); |
|
| 854 | 511 |
} |
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 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
515 |
IriSP.Model.Directory = function() { |
| 858 | 516 |
this.remoteSources = {}; |
517 |
this.elements = {}; |
|
| 860 | 518 |
this.namespaces = {}; |
| 858 | 519 |
} |
520 |
||
521 |
IriSP.Model.Directory.prototype.remoteSource = function(_properties) { |
|
| 860 | 522 |
var _config = IriSP._({ directory: this }).extend(_properties); |
| 858 | 523 |
if (typeof this.remoteSources[_properties.url] === "undefined") { |
| 860 | 524 |
this.remoteSources[_properties.url] = new IriSP.Model.RemoteSource(_config); |
| 858 | 525 |
} |
526 |
return this.remoteSources[_properties.url]; |
|
| 854 | 527 |
} |
528 |
||
| 860 | 529 |
IriSP.Model.Directory.prototype.newLocalSource = function(_properties) { |
530 |
var _config = IriSP._({ directory: this }).extend(_properties), |
|
531 |
_res = new IriSP.Model.Source(_config); |
|
532 |
return _res; |
|
533 |
} |
|
534 |
||
| 858 | 535 |
IriSP.Model.Directory.prototype.getElement = function(_id) { |
536 |
return this.elements[_id]; |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
537 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
538 |
|
| 858 | 539 |
IriSP.Model.Directory.prototype.addElement = function(_element) { |
540 |
this.elements[_element.id] = _element; |
|
541 |
} |
|
542 |
||
543 |
IriSP.Model.Directory.prototype.getGlobalList = function() { |
|
544 |
var _res = new IriSP.Model.List(this); |
|
545 |
_res.addIdsFromArray(IriSP._(this.elements).keys()); |
|
546 |
return _res; |
|
| 854 | 547 |
} |
|
856
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 |
/* */ |