| author | veltr |
| Fri, 13 Apr 2012 18:08:19 +0200 | |
| branch | new-model |
| changeset 860 | 7fd843e0dc4e |
| parent 858 | ad1ffe0c0955 |
| child 864 | 5e76a06b961c |
| 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 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
75 |
IriSP.Model.List.prototype.each = function(_callback) { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
76 |
var _this = this; |
| 858 | 77 |
IriSP._(this.contents).each(function(_id) { |
78 |
_callback.call(_this, _this.getElement(_id), _id); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
79 |
}); |
|
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 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
82 |
IriSP.Model.List.prototype.map = function(_callback) { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
83 |
var _this = this; |
| 858 | 84 |
return IriSP._(this.contents).map(function(_id) { |
85 |
return _callback.call(_this, _this.getElement(_id), _id); |
|
86 |
}); |
|
87 |
} |
|
88 |
||
89 |
IriSP.Model.List.prototype.filter = function(_callback) { |
|
90 |
var _this = this, |
|
91 |
_res = new IriSP.Model.List(this.directory); |
|
92 |
_res.contents = IriSP._(this.contents).filter(function(_id) { |
|
93 |
return _callback.call(_this, _this.getElement(_id), _id); |
|
94 |
}); |
|
95 |
return _res; |
|
96 |
} |
|
97 |
||
98 |
IriSP.Model.List.prototype.searchByTitle = function(_text) { |
|
99 |
var _rgxp = new RegExp('(' + _text.replace(/(\W)/gm,'\\$1') + ')','gim'); |
|
100 |
return this.filter(function(_element) { |
|
101 |
return _rgxp.test(_element.text); |
|
102 |
}); |
|
103 |
} |
|
104 |
||
105 |
IriSP.Model.List.prototype.searchByDescription = function(_text) { |
|
106 |
var _rgxp = new RegExp('(' + _text.replace(/(\W)/gm,'\\$1') + ')','gim'); |
|
107 |
return this.filter(function(_element) { |
|
108 |
return _rgxp.test(_element.description); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
109 |
}); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
110 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
111 |
|
| 858 | 112 |
IriSP.Model.List.prototype.searchByTextFields = function(_text) { |
113 |
var _rgxp = new RegExp('(' + _text.replace(/(\W)/gm,'\\$1') + ')','gim'); |
|
114 |
return this.filter(function(_element) { |
|
115 |
return _rgxp.test(_element.description); |
|
116 |
}); |
|
117 |
} |
|
118 |
||
119 |
IriSP.Model.List.prototype.addId = function(_id) { |
|
120 |
if (this.contents.indexOf(_id) === -1) { |
|
121 |
this.contents.push(_id); |
|
|
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.addElement = function(_el) { |
126 |
this.addId(_el.id); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
127 |
} |
| 858 | 128 |
|
129 |
IriSP.Model.List.prototype.addIdsFromArray = function(_array) { |
|
130 |
var _l = _array.length; |
|
131 |
for (var _i = 0; _i < _l; _i++) { |
|
132 |
this.addId(_array[_i]); |
|
133 |
} |
|
134 |
} |
|
135 |
||
136 |
IriSP.Model.List.prototype.addIdsFromList = function(_list) { |
|
137 |
this.addIdsFromArray(_list.contents); |
|
138 |
} |
|
139 |
||
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
140 |
/* */ |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
141 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
142 |
IriSP.Model.Time = function(_milliseconds) { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
143 |
this.milliseconds = parseInt(typeof _milliseconds !== "undefined" ? _milliseconds : 0); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
144 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
145 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
146 |
IriSP.Model.Time.prototype.setSeconds = function(_seconds) { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
147 |
this.milliseconds = 1000 * _seconds; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
148 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
149 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
150 |
IriSP.Model.Time.prototype.getSeconds = function() { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
151 |
return Math.floor(this.milliseconds / 1000); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
152 |
} |
|
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 |
IriSP.Model.Time.prototype.getHMS = function() { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
155 |
var _totalSeconds = Math.abs(this.getSeconds()); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
156 |
return { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
157 |
hours : Math.floor(_totalSeconds / 3600), |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
158 |
minutes : (Math.floor(_totalSeconds / 60) % 60), |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
159 |
seconds : _totalSeconds % 60 |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
160 |
} |
|
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.toString = function() { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
164 |
function pad(_n) { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
165 |
var _res = _n.toString(); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
166 |
while (_res.length < 2) { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
167 |
_res = '0' + _res; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
168 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
169 |
return _res; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
170 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
171 |
var _hms = this.getHMS(), |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
172 |
_res = ''; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
173 |
if (_hms.hours) { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
174 |
_res += pad(_hms.hours) + ':' |
|
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 |
_res += pad(_hms.minutes) + ':' + pad(_hms.seconds); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
177 |
return _res; |
|
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 |
|
| 858 | 180 |
/* */ |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
181 |
|
| 860 | 182 |
IriSP.Model.Reference = function(_source, _idRef) { |
183 |
this.source = _source; |
|
| 858 | 184 |
if (typeof _idRef === "object") { |
185 |
this.isList = true; |
|
| 860 | 186 |
this.contents = new IriSP.Model.List(this.source.directory); |
187 |
this.contents.addIdsFromArray(IriSP._(_idRef).map(function(_id) { |
|
188 |
return _source.getNamespaced(_id).fullname; |
|
189 |
})); |
|
| 858 | 190 |
} else { |
191 |
this.isList = false; |
|
| 860 | 192 |
this.contents = _source.getNamespaced(_idRef).fullname; |
| 858 | 193 |
} |
|
856
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 |
|
| 858 | 196 |
IriSP.Model.Reference.prototype.getContents = function() { |
| 860 | 197 |
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
|
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 |
/* */ |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
201 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
202 |
IriSP.Model.Element = function(_id, _source) { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
203 |
this.elementType = 'element'; |
| 860 | 204 |
if (typeof _source !== "undefined") { |
205 |
if (typeof _id === "undefined" || !_id) { |
|
206 |
_id = IriSP.Model.getAI(); |
|
207 |
} |
|
| 858 | 208 |
this.source = _source; |
| 860 | 209 |
this.id = _source.getNamespaced(_id).fullname; |
| 858 | 210 |
this.title = ""; |
211 |
this.description = ""; |
|
212 |
this.source.directory.addElement(this); |
|
|
856
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 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
216 |
IriSP.Model.Element.prototype.toString = function() { |
| 858 | 217 |
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
|
218 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
219 |
|
| 858 | 220 |
IriSP.Model.Element.prototype.setReference = function(_elementType, _idRef) { |
| 860 | 221 |
this[_elementType] = new IriSP.Model.Reference(this.source, _idRef); |
| 854 | 222 |
} |
223 |
||
| 858 | 224 |
IriSP.Model.Element.prototype.getReference = function(_elementType) { |
225 |
if (typeof this[_elementType] !== "undefined") { |
|
226 |
return this[_elementType].getContents(); |
|
|
856
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 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
230 |
/* */ |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
231 |
|
| 858 | 232 |
IriSP.Model.Media = function(_id, _directory) { |
233 |
IriSP.Model.Element.call(this, _id, _directory); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
234 |
this.elementType = 'media'; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
235 |
this.duration = new IriSP.Model.Time(); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
236 |
this.url = ''; |
|
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 |
|
| 858 | 239 |
IriSP.Model.Media.prototype = new IriSP.Model.Element(); |
|
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 |
IriSP.Model.Media.prototype.setDuration = function(_durationMs) { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
242 |
this.duration.milliseconds = _durationMs; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
243 |
} |
|
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 |
|
| 858 | 247 |
IriSP.Model.Tag = function(_id, _directory) { |
248 |
IriSP.Model.Element.call(this, _id, _directory); |
|
249 |
this.elementType = 'tag'; |
|
250 |
} |
|
251 |
||
252 |
IriSP.Model.Tag.prototype = new IriSP.Model.Element(); |
|
253 |
||
254 |
/* */ |
|
255 |
||
256 |
IriSP.Model.AnnotationType = function(_id, _directory) { |
|
257 |
IriSP.Model.Element.call(this, _id, _directory); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
258 |
this.elementType = 'annotationType'; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
259 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
260 |
|
| 858 | 261 |
IriSP.Model.AnnotationType.prototype = new IriSP.Model.Element(); |
|
856
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 |
/* Annotation |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
264 |
* */ |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
265 |
|
| 858 | 266 |
IriSP.Model.Annotation = function(_id, _directory) { |
267 |
IriSP.Model.Element.call(this, _id, _directory); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
268 |
this.elementType = 'annotation'; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
269 |
this.begin = new IriSP.Model.Time(); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
270 |
this.end = new IriSP.Model.Time(); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
271 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
272 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
273 |
IriSP.Model.Annotation.prototype = new IriSP.Model.Element(null); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
274 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
275 |
IriSP.Model.Annotation.prototype.setBegin = function(_beginMs) { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
276 |
this.begin.milliseconds = _beginMs; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
277 |
} |
|
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 |
IriSP.Model.Annotation.prototype.setEnd = function(_beginMs) { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
280 |
this.end.milliseconds = _beginMs; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
281 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
282 |
|
| 858 | 283 |
IriSP.Model.Annotation.prototype.setMedia = function(_idRef) { |
284 |
this.setReference("media", _idRef); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
285 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
286 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
287 |
IriSP.Model.Annotation.prototype.getMedia = function() { |
| 858 | 288 |
return this.getReference("media"); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
289 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
290 |
|
| 858 | 291 |
IriSP.Model.Annotation.prototype.setAnnotationType = function(_idRef) { |
292 |
this.setReference("annotationType", _idRef); |
|
|
856
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 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
295 |
IriSP.Model.Annotation.prototype.getAnnotationType = function() { |
| 858 | 296 |
return this.getReference("annotationType"); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
297 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
298 |
|
| 858 | 299 |
IriSP.Model.Annotation.prototype.setTags = function(_idRefs) { |
300 |
this.setReference("tag", _idRefs); |
|
|
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 |
|
| 858 | 303 |
IriSP.Model.Annotation.prototype.getTags = function() { |
304 |
return this.getReference("tag"); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
305 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
306 |
|
| 858 | 307 |
/* */ |
308 |
||
| 860 | 309 |
IriSP.Model.Source = function(_config) { |
| 858 | 310 |
this.status = IriSP.Model.SOURCE_STATUS_EMPTY; |
| 860 | 311 |
if (typeof _config !== "undefined") { |
312 |
var _this = this; |
|
313 |
IriSP._(_config).each(function(_v, _k) { |
|
314 |
_this[_k] = _v; |
|
315 |
}) |
|
316 |
this.callbackQueue = []; |
|
317 |
this.contents = {}; |
|
318 |
if (typeof this.namespace === "undefined") { |
|
319 |
this.namespace = IriSP.Model.getAI(); |
|
320 |
} |
|
321 |
if (typeof this.namespaceUrl === "undefined") { |
|
322 |
this.namespaceUrl = (typeof this.url !== "undefined" ? this.url : this.namespaceUrl); |
|
323 |
} |
|
324 |
this.directory.namespaces[this.namespace] = this.namespaceUrl; |
|
325 |
this.get(); |
|
326 |
} |
|
327 |
} |
|
328 |
||
329 |
IriSP.Model.Source.prototype.getNamespaced = function(_id) { |
|
330 |
var _tab = _id.split(':'); |
|
331 |
if (_tab.length > 1) { |
|
332 |
return { |
|
333 |
namespace : _tab[0], |
|
334 |
name : _tab[1], |
|
335 |
fullname : _id |
|
336 |
} |
|
337 |
} else { |
|
338 |
return { |
|
339 |
namespace : this.namespace, |
|
340 |
name : _id, |
|
341 |
fullname : this.namespace + ':' + _id |
|
342 |
} |
|
343 |
} |
|
344 |
} |
|
345 |
|
|
346 |
IriSP.Model.Source.prototype.unNamespace = function(_id) { |
|
347 |
return _id.replace(this.namespace + ':', ''); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
348 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
349 |
|
| 858 | 350 |
IriSP.Model.Source.prototype.addList = function(_listId, _contents) { |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
351 |
if (typeof this.contents[_listId] === "undefined") { |
| 860 | 352 |
this.contents[_listId] = new IriSP.Model.List(this.directory); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
353 |
} |
| 858 | 354 |
this.contents[_listId].addIdsFromList(_contents); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
355 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
356 |
|
| 858 | 357 |
IriSP.Model.Source.prototype.getList = function(_listId) { |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
358 |
if (typeof this.contents[_listId] === "undefined") { |
| 860 | 359 |
return this.directory.getGlobalList().filter(function(_e) { |
| 858 | 360 |
return (_e.elType === _listId); |
361 |
}); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
362 |
} else { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
363 |
return this.contents[_listId]; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
364 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
365 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
366 |
|
| 860 | 367 |
IriSP.Model.Source.prototype.each = function(_callback) { |
368 |
var _this = this; |
|
369 |
IriSP._(this.contents).each(function(_value, _key) { |
|
370 |
_callback.call(_this, _value, _key); |
|
371 |
}) |
|
372 |
} |
|
373 |
||
| 858 | 374 |
IriSP.Model.Source.prototype.getElement = function(_listId, _elId) { |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
375 |
var _list = this.getList(_listId); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
376 |
return (typeof _list !== "undefined" ? _list.getElement(_elId) : undefined); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
377 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
378 |
|
| 858 | 379 |
IriSP.Model.Source.prototype.setCurrentMediaId = function(_idRef) { |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
380 |
if (typeof _idRef !== "undefined") { |
| 860 | 381 |
this.currentMedia = this.getNamespaced(_idRef).fullname; |
|
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 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
384 |
|
| 858 | 385 |
IriSP.Model.Source.prototype.setDefaultCurrentMedia = function() { |
386 |
if (typeof this.currentMedia === "undefined") { |
|
387 |
this.currentMedia = this.getList("media")[0]; |
|
| 854 | 388 |
} |
389 |
} |
|
390 |
||
| 860 | 391 |
IriSP.Model.Source.prototype.listNamespaces = function() { |
392 |
var _this = this, |
|
393 |
_nsls = []; |
|
394 |
this.each(function(_list) { |
|
395 |
IriSP._(_list.contents).each(function(_id) { |
|
396 |
var _ns = _id.replace(/:.*$/,''); |
|
397 |
if (_nsls.indexOf(_ns) === -1) { |
|
398 |
_nsls.push(_ns); |
|
399 |
} |
|
400 |
}) |
|
401 |
}); |
|
402 |
return _nsls; |
|
403 |
} |
|
404 |
||
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
405 |
IriSP.Model.Source.prototype.get = function() { |
| 858 | 406 |
this.status = IriSP.Model.SOURCE_STATUS_READY; |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
407 |
var _this = this; |
| 858 | 408 |
if (_this.callbackQueue.length) { |
409 |
IriSP._.each(_this.callbackQueue, function(_callback) { |
|
410 |
_callback.call(_this); |
|
411 |
}); |
|
412 |
} |
|
413 |
_this.callbackQueue = []; |
|
| 854 | 414 |
} |
415 |
||
| 860 | 416 |
IriSP.Model.Source.prototype.serialize = function() { |
417 |
return this.serializer.serialize(this); |
|
418 |
} |
|
419 |
||
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
420 |
IriSP.Model.Source.prototype.addCallback = function(_callback) { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
421 |
if (this.status === IriSP.Model.SOURCE_STATUS_READY) { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
422 |
callback.call(this); |
| 854 | 423 |
} else { |
424 |
this.callbackQueue.push(_callback); |
|
425 |
} |
|
426 |
} |
|
427 |
||
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
428 |
IriSP.Model.Source.prototype.getAnnotations = function() { |
| 858 | 429 |
return this.getList("annotation"); |
| 854 | 430 |
} |
431 |
||
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
432 |
IriSP.Model.Source.prototype.getMedias = function() { |
| 858 | 433 |
return this.getList("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 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
436 |
IriSP.Model.Source.prototype.getDuration = function() { |
| 858 | 437 |
return this.currentMedia.duration; |
438 |
} |
|
439 |
||
440 |
/* */ |
|
441 |
||
| 860 | 442 |
IriSP.Model.RemoteSource = function(_config) { |
443 |
IriSP.Model.Source.call(this, _config); |
|
| 858 | 444 |
} |
445 |
||
446 |
IriSP.Model.RemoteSource.prototype = new IriSP.Model.Source(); |
|
447 |
||
448 |
IriSP.Model.RemoteSource.prototype.get = function() { |
|
449 |
this.status = IriSP.Model.SOURCE_STATUS_WAITING; |
|
450 |
var _this = this; |
|
451 |
IriSP.jQuery.getJSON(this.url, function(_result) { |
|
452 |
_this.serializer.deSerialize(_result, _this); |
|
453 |
if (_this.callbackQueue.length) { |
|
454 |
IriSP._.each(_this.callbackQueue, function(_callback) { |
|
455 |
_callback.call(_this); |
|
456 |
}); |
|
457 |
} |
|
458 |
_this.callbackQueue = []; |
|
459 |
_this.status = IriSP.Model.SOURCE_STATUS_READY; |
|
460 |
}); |
|
| 854 | 461 |
} |
462 |
||
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
463 |
/* */ |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
464 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
465 |
IriSP.Model.Directory = function() { |
| 858 | 466 |
this.remoteSources = {}; |
467 |
this.elements = {}; |
|
| 860 | 468 |
this.namespaces = {}; |
| 858 | 469 |
} |
470 |
||
471 |
IriSP.Model.Directory.prototype.remoteSource = function(_properties) { |
|
| 860 | 472 |
var _config = IriSP._({ directory: this }).extend(_properties); |
| 858 | 473 |
if (typeof this.remoteSources[_properties.url] === "undefined") { |
| 860 | 474 |
this.remoteSources[_properties.url] = new IriSP.Model.RemoteSource(_config); |
| 858 | 475 |
} |
476 |
return this.remoteSources[_properties.url]; |
|
| 854 | 477 |
} |
478 |
||
| 860 | 479 |
IriSP.Model.Directory.prototype.newLocalSource = function(_properties) { |
480 |
var _config = IriSP._({ directory: this }).extend(_properties), |
|
481 |
_res = new IriSP.Model.Source(_config); |
|
482 |
return _res; |
|
483 |
} |
|
484 |
||
| 858 | 485 |
IriSP.Model.Directory.prototype.getElement = function(_id) { |
486 |
return this.elements[_id]; |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
487 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
488 |
|
| 858 | 489 |
IriSP.Model.Directory.prototype.addElement = function(_element) { |
490 |
this.elements[_element.id] = _element; |
|
491 |
} |
|
492 |
||
493 |
IriSP.Model.Directory.prototype.getGlobalList = function() { |
|
494 |
var _res = new IriSP.Model.List(this); |
|
495 |
_res.addIdsFromArray(IriSP._(this.elements).keys()); |
|
496 |
return _res; |
|
| 854 | 497 |
} |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
498 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
499 |
/* */ |