| author | veltr |
| Thu, 12 Apr 2012 15:54:33 +0200 | |
| branch | new-model |
| changeset 858 | ad1ffe0c0955 |
| parent 856 | 41c574c807d1 |
| child 860 | 7fd843e0dc4e |
| 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, |
| 858 | 7 |
ID_AUTO_INCREMENT : 0 |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
8 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
9 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
10 |
/* */ |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
11 |
|
| 858 | 12 |
IriSP.Model.List = function(_directory) { |
13 |
this.contents = []; |
|
14 |
this.directory = _directory; |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
15 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
16 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
17 |
IriSP.Model.List.prototype.toString = function() { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
18 |
return 'List of Elements, length=' + this.length(); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
19 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
20 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
21 |
IriSP.Model.List.prototype.length = function() { |
| 858 | 22 |
return this.contents.length; |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
23 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
24 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
25 |
IriSP.Model.List.prototype.getElement = function(_id) { |
| 858 | 26 |
return this.directory.getElement(_id); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
27 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
28 |
|
| 858 | 29 |
IriSP.Model.List.prototype.getElementAt = function(_pos) { |
30 |
if (_pos >= 0 && _pos < this.length()) { |
|
31 |
return this.getElement(this.contents[_pos]); |
|
32 |
} |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
33 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
34 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
35 |
IriSP.Model.List.prototype.each = function(_callback) { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
36 |
var _this = this; |
| 858 | 37 |
IriSP._(this.contents).each(function(_id) { |
38 |
_callback.call(_this, _this.getElement(_id), _id); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
39 |
}); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
40 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
41 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
42 |
IriSP.Model.List.prototype.map = function(_callback) { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
43 |
var _this = this; |
| 858 | 44 |
return IriSP._(this.contents).map(function(_id) { |
45 |
return _callback.call(_this, _this.getElement(_id), _id); |
|
46 |
}); |
|
47 |
} |
|
48 |
||
49 |
IriSP.Model.List.prototype.filter = function(_callback) { |
|
50 |
var _this = this, |
|
51 |
_res = new IriSP.Model.List(this.directory); |
|
52 |
_res.contents = IriSP._(this.contents).filter(function(_id) { |
|
53 |
return _callback.call(_this, _this.getElement(_id), _id); |
|
54 |
}); |
|
55 |
return _res; |
|
56 |
} |
|
57 |
||
58 |
IriSP.Model.List.prototype.searchByTitle = function(_text) { |
|
59 |
var _rgxp = new RegExp('(' + _text.replace(/(\W)/gm,'\\$1') + ')','gim'); |
|
60 |
return this.filter(function(_element) { |
|
61 |
return _rgxp.test(_element.text); |
|
62 |
}); |
|
63 |
} |
|
64 |
||
65 |
IriSP.Model.List.prototype.searchByDescription = function(_text) { |
|
66 |
var _rgxp = new RegExp('(' + _text.replace(/(\W)/gm,'\\$1') + ')','gim'); |
|
67 |
return this.filter(function(_element) { |
|
68 |
return _rgxp.test(_element.description); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
69 |
}); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
70 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
71 |
|
| 858 | 72 |
IriSP.Model.List.prototype.searchByTextFields = function(_text) { |
73 |
var _rgxp = new RegExp('(' + _text.replace(/(\W)/gm,'\\$1') + ')','gim'); |
|
74 |
return this.filter(function(_element) { |
|
75 |
return _rgxp.test(_element.description); |
|
76 |
}); |
|
77 |
} |
|
78 |
||
79 |
IriSP.Model.List.prototype.addId = function(_id) { |
|
80 |
if (this.contents.indexOf(_id) === -1) { |
|
81 |
this.contents.push(_id); |
|
|
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 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
84 |
|
| 858 | 85 |
IriSP.Model.List.prototype.addElement = function(_el) { |
86 |
this.addId(_el.id); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
87 |
} |
| 858 | 88 |
|
89 |
IriSP.Model.List.prototype.addIdsFromArray = function(_array) { |
|
90 |
var _l = _array.length; |
|
91 |
for (var _i = 0; _i < _l; _i++) { |
|
92 |
this.addId(_array[_i]); |
|
93 |
} |
|
94 |
} |
|
95 |
||
96 |
IriSP.Model.List.prototype.addIdsFromList = function(_list) { |
|
97 |
this.addIdsFromArray(_list.contents); |
|
98 |
} |
|
99 |
||
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
100 |
/* */ |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
101 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
102 |
IriSP.Model.Time = function(_milliseconds) { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
103 |
this.milliseconds = parseInt(typeof _milliseconds !== "undefined" ? _milliseconds : 0); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
104 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
105 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
106 |
IriSP.Model.Time.prototype.setSeconds = function(_seconds) { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
107 |
this.milliseconds = 1000 * _seconds; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
108 |
} |
|
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 |
IriSP.Model.Time.prototype.getSeconds = function() { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
111 |
return Math.floor(this.milliseconds / 1000); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
112 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
113 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
114 |
IriSP.Model.Time.prototype.getHMS = function() { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
115 |
var _totalSeconds = Math.abs(this.getSeconds()); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
116 |
return { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
117 |
hours : Math.floor(_totalSeconds / 3600), |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
118 |
minutes : (Math.floor(_totalSeconds / 60) % 60), |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
119 |
seconds : _totalSeconds % 60 |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
120 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
121 |
} |
|
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 |
IriSP.Model.Time.prototype.toString = function() { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
124 |
function pad(_n) { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
125 |
var _res = _n.toString(); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
126 |
while (_res.length < 2) { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
127 |
_res = '0' + _res; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
128 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
129 |
return _res; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
130 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
131 |
var _hms = this.getHMS(), |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
132 |
_res = ''; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
133 |
if (_hms.hours) { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
134 |
_res += pad(_hms.hours) + ':' |
|
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 |
_res += pad(_hms.minutes) + ':' + pad(_hms.seconds); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
137 |
return _res; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
138 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
139 |
|
| 858 | 140 |
/* */ |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
141 |
|
| 858 | 142 |
IriSP.Model.Reference = function(_directory, _idRef) { |
143 |
this.directory = _directory; |
|
144 |
if (typeof _idRef === "object") { |
|
145 |
this.isList = true; |
|
146 |
this.contents = new IriSP.Model.List(this.directory); |
|
147 |
this.contents.addIdsFromArray(_idRef); |
|
148 |
} else { |
|
149 |
this.isList = false; |
|
150 |
this.contents = _idRef; |
|
151 |
} |
|
|
856
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 |
|
| 858 | 154 |
IriSP.Model.Reference.prototype.getContents = function() { |
155 |
return (this.isList ? this.contents : this.directory.getElement(this.contents)); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
156 |
} |
|
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 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
160 |
IriSP.Model.Element = function(_id, _source) { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
161 |
this.elementType = 'element'; |
| 858 | 162 |
if (typeof _id !== "undefined" && typeof _source !== "undefined") { |
163 |
this.source = _source; |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
164 |
this.id = _id; |
| 858 | 165 |
this.title = ""; |
166 |
this.description = ""; |
|
167 |
this.source.directory.addElement(this); |
|
|
856
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 |
} |
|
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 |
IriSP.Model.Element.prototype.toString = function() { |
| 858 | 172 |
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
|
173 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
174 |
|
| 858 | 175 |
IriSP.Model.Element.prototype.setReference = function(_elementType, _idRef) { |
176 |
this[_elementType] = new IriSP.Model.Reference(this.source.directory, _idRef); |
|
| 854 | 177 |
} |
178 |
||
| 858 | 179 |
IriSP.Model.Element.prototype.getReference = function(_elementType) { |
180 |
if (typeof this[_elementType] !== "undefined") { |
|
181 |
return this[_elementType].getContents(); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
182 |
} |
|
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 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
185 |
/* */ |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
186 |
|
| 858 | 187 |
IriSP.Model.Media = function(_id, _directory) { |
188 |
IriSP.Model.Element.call(this, _id, _directory); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
189 |
this.elementType = 'media'; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
190 |
this.duration = new IriSP.Model.Time(); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
191 |
this.url = ''; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
192 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
193 |
|
| 858 | 194 |
IriSP.Model.Media.prototype = new IriSP.Model.Element(); |
|
856
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.Media.prototype.setDuration = function(_durationMs) { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
197 |
this.duration.milliseconds = _durationMs; |
|
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 |
|
| 858 | 202 |
IriSP.Model.Tag = function(_id, _directory) { |
203 |
IriSP.Model.Element.call(this, _id, _directory); |
|
204 |
this.elementType = 'tag'; |
|
205 |
} |
|
206 |
||
207 |
IriSP.Model.Tag.prototype = new IriSP.Model.Element(); |
|
208 |
||
209 |
/* */ |
|
210 |
||
211 |
IriSP.Model.AnnotationType = function(_id, _directory) { |
|
212 |
IriSP.Model.Element.call(this, _id, _directory); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
213 |
this.elementType = 'annotationType'; |
|
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 |
|
| 858 | 216 |
IriSP.Model.AnnotationType.prototype = new IriSP.Model.Element(); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
217 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
218 |
/* Annotation |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
219 |
* */ |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
220 |
|
| 858 | 221 |
IriSP.Model.Annotation = function(_id, _directory) { |
222 |
IriSP.Model.Element.call(this, _id, _directory); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
223 |
this.elementType = 'annotation'; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
224 |
this.begin = new IriSP.Model.Time(); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
225 |
this.end = new IriSP.Model.Time(); |
|
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 |
IriSP.Model.Annotation.prototype = new IriSP.Model.Element(null); |
|
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 |
IriSP.Model.Annotation.prototype.setBegin = function(_beginMs) { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
231 |
this.begin.milliseconds = _beginMs; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
232 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
233 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
234 |
IriSP.Model.Annotation.prototype.setEnd = function(_beginMs) { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
235 |
this.end.milliseconds = _beginMs; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
236 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
237 |
|
| 858 | 238 |
IriSP.Model.Annotation.prototype.setMedia = function(_idRef) { |
239 |
this.setReference("media", _idRef); |
|
|
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 |
IriSP.Model.Annotation.prototype.getMedia = function() { |
| 858 | 243 |
return this.getReference("media"); |
|
856
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 |
|
| 858 | 246 |
IriSP.Model.Annotation.prototype.setAnnotationType = function(_idRef) { |
247 |
this.setReference("annotationType", _idRef); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
248 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
249 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
250 |
IriSP.Model.Annotation.prototype.getAnnotationType = function() { |
| 858 | 251 |
return this.getReference("annotationType"); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
252 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
253 |
|
| 858 | 254 |
IriSP.Model.Annotation.prototype.setTags = function(_idRefs) { |
255 |
this.setReference("tag", _idRefs); |
|
|
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 |
|
| 858 | 258 |
IriSP.Model.Annotation.prototype.getTags = function() { |
259 |
return this.getReference("tag"); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
260 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
261 |
|
| 858 | 262 |
/* */ |
263 |
||
264 |
IriSP.Model.Source = function(_properties) { |
|
265 |
this.status = IriSP.Model.SOURCE_STATUS_EMPTY; |
|
266 |
this.config = _properties; |
|
267 |
this.callbackQueue = []; |
|
268 |
this.contents = {}; |
|
269 |
this.get(); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
270 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
271 |
|
| 858 | 272 |
IriSP.Model.Source.prototype.addList = function(_listId, _contents) { |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
273 |
if (typeof this.contents[_listId] === "undefined") { |
| 858 | 274 |
this.contents[_listId] = new IriSP.Model.List(this.config.directory); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
275 |
} |
| 858 | 276 |
this.contents[_listId].addIdsFromList(_contents); |
|
856
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 |
|
| 858 | 279 |
IriSP.Model.Source.prototype.getList = function(_listId) { |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
280 |
if (typeof this.contents[_listId] === "undefined") { |
| 858 | 281 |
return this.config.directory.getGlobalList.filter(function(_e) { |
282 |
return (_e.elType === _listId); |
|
283 |
}); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
284 |
} else { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
285 |
return this.contents[_listId]; |
|
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 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
288 |
|
| 858 | 289 |
IriSP.Model.Source.prototype.getElement = function(_listId, _elId) { |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
290 |
var _list = this.getList(_listId); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
291 |
return (typeof _list !== "undefined" ? _list.getElement(_elId) : undefined); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
292 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
293 |
|
| 858 | 294 |
IriSP.Model.Source.prototype.setCurrentMediaId = function(_idRef) { |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
295 |
if (typeof _idRef !== "undefined") { |
| 858 | 296 |
this.currentMedia = _idRef; |
|
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 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
299 |
|
| 858 | 300 |
IriSP.Model.Source.prototype.setDefaultCurrentMedia = function() { |
301 |
if (typeof this.currentMedia === "undefined") { |
|
302 |
this.currentMedia = this.getList("media")[0]; |
|
| 854 | 303 |
} |
304 |
} |
|
305 |
||
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
306 |
IriSP.Model.Source.prototype.get = function() { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
307 |
this.status = IriSP.Model.SOURCE_STATUS_WAITING; |
| 858 | 308 |
this.status = IriSP.Model.SOURCE_STATUS_READY; |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
309 |
var _this = this; |
| 858 | 310 |
if (_this.callbackQueue.length) { |
311 |
IriSP._.each(_this.callbackQueue, function(_callback) { |
|
312 |
_callback.call(_this); |
|
313 |
}); |
|
314 |
} |
|
315 |
_this.callbackQueue = []; |
|
| 854 | 316 |
} |
317 |
||
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
318 |
IriSP.Model.Source.prototype.addCallback = function(_callback) { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
319 |
if (this.status === IriSP.Model.SOURCE_STATUS_READY) { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
320 |
callback.call(this); |
| 854 | 321 |
} else { |
322 |
this.callbackQueue.push(_callback); |
|
323 |
} |
|
324 |
} |
|
325 |
||
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
326 |
IriSP.Model.Source.prototype.getAnnotations = function() { |
| 858 | 327 |
return this.getList("annotation"); |
| 854 | 328 |
} |
329 |
||
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
330 |
IriSP.Model.Source.prototype.getMedias = function() { |
| 858 | 331 |
return this.getList("media"); |
|
856
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 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
334 |
IriSP.Model.Source.prototype.getDuration = function() { |
| 858 | 335 |
return this.currentMedia.duration; |
336 |
} |
|
337 |
||
338 |
/* */ |
|
339 |
||
340 |
IriSP.Model.RemoteSource = function() { |
|
341 |
IriSP.Model.Element.call(this, _id, _directory); |
|
342 |
this.elementType = 'tag'; |
|
343 |
} |
|
344 |
||
345 |
IriSP.Model.RemoteSource.prototype = new IriSP.Model.Source(); |
|
346 |
||
347 |
IriSP.Model.RemoteSource.prototype.get = function() { |
|
348 |
this.status = IriSP.Model.SOURCE_STATUS_WAITING; |
|
349 |
var _this = this; |
|
350 |
IriSP.jQuery.getJSON(this.url, function(_result) { |
|
351 |
_this.serializer.deSerialize(_result, _this); |
|
352 |
if (_this.callbackQueue.length) { |
|
353 |
IriSP._.each(_this.callbackQueue, function(_callback) { |
|
354 |
_callback.call(_this); |
|
355 |
}); |
|
356 |
} |
|
357 |
_this.callbackQueue = []; |
|
358 |
_this.status = IriSP.Model.SOURCE_STATUS_READY; |
|
359 |
}); |
|
| 854 | 360 |
} |
361 |
||
|
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 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
364 |
IriSP.Model.Directory = function() { |
| 858 | 365 |
this.remoteSources = {}; |
366 |
this.localSource = []; |
|
367 |
this.elements = {}; |
|
368 |
this.nameSpaces = {}; |
|
369 |
} |
|
370 |
||
371 |
IriSP.Model.Directory.prototype.remoteSource = function(_properties) { |
|
372 |
if (typeof this.remoteSources[_properties.url] === "undefined") { |
|
373 |
this.remoteSources[_properties.url] = new IriSP.Model.RemoteSource(_properties); |
|
374 |
} |
|
375 |
return this.remoteSources[_properties.url]; |
|
| 854 | 376 |
} |
377 |
||
| 858 | 378 |
IriSP.Model.Directory.prototype.getElement = function(_id) { |
379 |
return this.elements[_id]; |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
380 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
381 |
|
| 858 | 382 |
IriSP.Model.Directory.prototype.addElement = function(_element) { |
383 |
this.elements[_element.id] = _element; |
|
384 |
} |
|
385 |
||
386 |
IriSP.Model.Directory.prototype.getGlobalList = function() { |
|
387 |
var _res = new IriSP.Model.List(this); |
|
388 |
_res.addIdsFromArray(IriSP._(this.elements).keys()); |
|
389 |
return _res; |
|
| 854 | 390 |
} |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
391 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
392 |
/* */ |