2 IriSP.Widget.call(this, Popcorn, config, Serializer); |
2 IriSP.Widget.call(this, Popcorn, config, Serializer); |
3 this._hidden = true; |
3 this._hidden = true; |
4 this.keywords = IriSP.widgetsDefaults["createAnnotationWidget"].keywords; |
4 this.keywords = IriSP.widgetsDefaults["createAnnotationWidget"].keywords; |
5 this.cinecast_version = IriSP.widgetsDefaults["createAnnotationWidget"].cinecast_version; |
5 this.cinecast_version = IriSP.widgetsDefaults["createAnnotationWidget"].cinecast_version; |
6 this.ids = {}; /* a dictionnary linking buttons ids to keywords */ |
6 this.ids = {}; /* a dictionnary linking buttons ids to keywords */ |
|
7 |
|
8 /* variables to save the current position of the slicer */ |
|
9 if (this.cinecast_version) { |
|
10 this.sliceLeft = 0; |
|
11 this.sliceWidth = 0; |
|
12 } |
7 }; |
13 }; |
8 |
14 |
9 |
15 |
10 IriSP.createAnnotationWidget.prototype = new IriSP.Widget(); |
16 IriSP.createAnnotationWidget.prototype = new IriSP.Widget(); |
11 |
17 |
133 this._hidden = false; |
139 this._hidden = false; |
134 var currentTime = this._Popcorn.currentTime(); |
140 var currentTime = this._Popcorn.currentTime(); |
135 |
141 |
136 // block the arrow. |
142 // block the arrow. |
137 this._Popcorn.trigger("IriSP.ArrowWidget.blockArrow"); |
143 this._Popcorn.trigger("IriSP.ArrowWidget.blockArrow"); |
|
144 |
138 var duration = +this._serializer.currentMedia().meta["dc:duration"]; |
145 var duration = +this._serializer.currentMedia().meta["dc:duration"]; |
|
146 |
139 var currentChapter = this._serializer.currentChapitre(currentTime); |
147 var currentChapter = this._serializer.currentChapitre(currentTime); |
140 console.log(currentTime); |
148 if (typeof(currentChapter) === "undefined") { |
141 var left = (currentChapter.begin / duration) * this.selector.width(); |
149 var left = this.selector.width() / 2; |
142 var width = (currentChapter.end / duration) * this.selector.width() - left; |
150 var width = this.selector.width() / 10; |
143 console.log([left, width]); |
151 } else { |
|
152 var left = (currentChapter.begin / duration) * this.selector.width(); |
|
153 var width = (currentChapter.end / duration) * this.selector.width() - left; |
|
154 } |
|
155 |
|
156 this.sliceLeft = left; |
|
157 this.sliceWidth = width; |
144 this._Popcorn.trigger("IriSP.SliceWidget.position", [left, width]); |
158 this._Popcorn.trigger("IriSP.SliceWidget.position", [left, width]); |
|
159 this._Popcorn.listen("IriSP.SliceWidget.zoneChange", IriSP.wrap(this, this.handleSliderChanges)); |
145 this._Popcorn.trigger("IriSP.SliceWidget.show"); |
160 this._Popcorn.trigger("IriSP.SliceWidget.show"); |
146 } |
161 } |
147 }; |
162 }; |
148 |
163 |
149 |
164 |
170 } |
185 } |
171 }; |
186 }; |
172 |
187 |
173 IriSP.createAnnotationWidget.prototype.showStartScreen = function() { |
188 IriSP.createAnnotationWidget.prototype.showStartScreen = function() { |
174 this.selector.find(".Ldt-createAnnotation-DoubleBorder").children().show(); |
189 this.selector.find(".Ldt-createAnnotation-DoubleBorder").children().show(); |
175 this.selector.find("Ldt-createAnnotation-Description").val(""); |
190 this.selector.find("Ldt-createAnnotation-Description").val("Type your annotation here."); |
176 this.selector.find(".Ldt-createAnnotation-endScreen").hide(); |
191 this.selector.find(".Ldt-createAnnotation-endScreen").hide(); |
177 }; |
192 }; |
178 |
193 |
179 IriSP.createAnnotationWidget.prototype.showEndScreen = function() { |
194 IriSP.createAnnotationWidget.prototype.showEndScreen = function() { |
180 this.selector.find(".Ldt-createAnnotation-DoubleBorder").children().hide(); |
195 this.selector.find(".Ldt-createAnnotation-DoubleBorder").children().hide(); |
217 textfield.css("background-color", ""); |
232 textfield.css("background-color", ""); |
218 } |
233 } |
219 })); |
234 })); |
220 } else { |
235 } else { |
221 this.showEndScreen(); |
236 this.showEndScreen(); |
222 |
|
223 if (typeof(this._currentAnnotation) === "undefined") { |
|
224 console.log("this._currentAnnotation undefined"); |
|
225 return; |
|
226 } |
|
227 |
237 |
228 this.sendLdtData(contents, function() { |
238 this.sendLdtData(contents, function() { |
229 if (_this.cinecast_version) { |
239 if (_this.cinecast_version) { |
230 if (_this._Popcorn.media.paused) |
240 if (_this._Popcorn.media.paused) |
231 _this._Popcorn.play(); |
241 _this._Popcorn.play(); |
234 } |
244 } |
235 }); |
245 }); |
236 } |
246 } |
237 }; |
247 }; |
238 |
248 |
|
249 IriSP.createAnnotationWidget.prototype.handleSliderChanges = function(params) { |
|
250 this.sliceLeft = params[0]; |
|
251 this.sliceWidth = params[1]; |
|
252 }; |
|
253 |
239 IriSP.createAnnotationWidget.prototype.sendLdtData = function(contents, callback) { |
254 IriSP.createAnnotationWidget.prototype.sendLdtData = function(contents, callback) { |
240 var _this = this; |
255 var _this = this; |
241 var apiJson = {annotations : [{}], meta: {}}; |
256 var apiJson = {annotations : [{}], meta: {}}; |
242 var annotation = apiJson["annotations"][0]; |
257 var annotation = apiJson["annotations"][0]; |
243 |
258 |
244 annotation["media"] = this._serializer.currentMedia()["id"]; |
259 annotation["media"] = this._serializer.currentMedia()["id"]; |
245 annotation["begin"] = this._currentAnnotation.begin; |
260 |
246 annotation["end"] = this._currentAnnotation.end; |
261 if (this.cinecast_version) { |
|
262 if (typeof(this._currentAnnotation) !== "undefined") { |
|
263 annotation["begin"] = this._currentAnnotation.begin; |
|
264 annotation["end"] = this._currentAnnotation.end; |
|
265 } |
|
266 } else { |
|
267 var duration = +this._serializer.currentMedia().meta["dc:duration"]; |
|
268 annotation["begin"] = duration * (this.sliceLeft / 100); |
|
269 annotation["end"] = duration * ((this.sliceWidth + this.sliceLeft) / 100); |
|
270 console.log(annotation["begin"], annotation["end"]); |
|
271 } |
|
272 |
247 annotation["type"] = this._serializer.getContributions(); |
273 annotation["type"] = this._serializer.getContributions(); |
248 if (typeof(annotation["type"]) === "undefined") |
274 if (typeof(annotation["type"]) === "undefined") |
249 annotation["type"] = ""; |
275 annotation["type"] = ""; |
250 |
276 |
251 annotation["type_title"] = "Contributions"; |
277 annotation["type_title"] = "Contributions"; |
275 type: 'PUT', |
301 type: 'PUT', |
276 contentType: 'application/json', |
302 contentType: 'application/json', |
277 data: jsonString, |
303 data: jsonString, |
278 dataType: 'json', |
304 dataType: 'json', |
279 success: function(json, textStatus, XMLHttpRequest) { |
305 success: function(json, textStatus, XMLHttpRequest) { |
|
306 debugger; |
280 /* add the annotation to the annotations and tell the world */ |
307 /* add the annotation to the annotations and tell the world */ |
281 delete annotation.tags; |
308 delete annotation.tags; |
282 annotation.content.description = annotation.content.data; |
309 annotation.content.description = annotation.content.data; |
283 delete annotation.content.data; |
310 delete annotation.content.data; |
284 annotation.id = json.annotations[0].id; |
311 annotation.id = json.annotations[0].id; |