245 this.editing = true; |
245 this.editing = true; |
246 } |
246 } |
247 |
247 |
248 IriSP.Widgets.Markers.prototype.cancelEdit = function(){ |
248 IriSP.Widgets.Markers.prototype.cancelEdit = function(){ |
249 if (this.selectedMarker){ |
249 if (this.selectedMarker){ |
250 // Clic sur "cancel" pendant édition d'un marqueur = retour à l'état visualisation |
250 // Click on "cancel" while editing a marker: back to visualization state |
251 _divHtml = Mustache.to_html(this.infoTemplate, { |
251 _divHtml = Mustache.to_html(this.infoTemplate, { |
252 edit: false, |
252 edit: false, |
253 marker_info: this.selectedMarker.description, |
253 marker_info: this.selectedMarker.description, |
254 }) |
254 }) |
255 this.$.find(".Ldt-Markers-Info").html(_divHtml); |
255 this.$.find(".Ldt-Markers-Info").html(_divHtml); |
256 if (!this.preview_mode){ |
256 if (!this.preview_mode){ |
257 this.$.find(".Ldt-Markers-MarkerDescription").click(this.functionWrapper("startEdit")); |
257 this.$.find(".Ldt-Markers-MarkerDescription").click(this.functionWrapper("startEdit")); |
258 } |
258 } |
259 } |
259 } |
260 else { |
260 else { |
261 // Clic sur "cancel" pendant la création d'un marqueur = retour à l'état initial |
261 // Click on "cancel" while editing a marker: back to initial state |
262 this.hidePlaceholder(); |
262 this.hidePlaceholder(); |
263 this.$.find(".Ldt-Markers-Info").html(""); |
263 this.$.find(".Ldt-Markers-Info").html(""); |
264 this.$.find(".Ldt-Markers-RoundButton").hide() |
264 this.$.find(".Ldt-Markers-RoundButton").hide() |
265 this.$.find(".Ldt-Markers-Create").show() |
265 this.$.find(".Ldt-Markers-Create").show() |
266 this.updateCreateButtonState(this.media.getCurrentTime()) |
266 this.updateCreateButtonState(this.media.getCurrentTime()) |
438 } |
438 } |
439 |
439 |
440 |
440 |
441 IriSP.Widgets.Markers.prototype.onSubmit = function(){ |
441 IriSP.Widgets.Markers.prototype.onSubmit = function(){ |
442 |
442 |
443 /* Si les champs obligatoires sont vides, on annule l'envoi */ |
443 /* If mandatory fields are empty, we cancel the sending */ |
444 if (!this.allow_empty_markers && !this.onDescriptionChange()){ |
444 if (!this.allow_empty_markers && !this.onDescriptionChange()){ |
445 return false; |
445 return false; |
446 } |
446 } |
447 |
447 |
448 /* On pause la vidéo si elle est encore en train de tourner */ |
448 /* We pause the video if it's still playing */ |
449 if (!this.media.getPaused()){ |
449 if (!this.media.getPaused()){ |
450 this.media.pause(); |
450 this.media.pause(); |
451 } |
451 } |
452 |
452 |
453 var _this = this, |
453 var _this = this, |
454 _exportedAnnotations = new IriSP.Model.List(this.player.sourceManager); /* Création d'une liste d'annotations contenant une annotation afin de l'envoyer au serveur */ |
454 _exportedAnnotations = new IriSP.Model.List(this.player.sourceManager), /* We create a List to send to the server that will contains the annotation */ |
|
455 _export = this.player.sourceManager.newLocalSource({serializer: IriSP.serializers[this.api_serializer]}), /* We create a source object using a specific serializer for export */ |
|
456 _annotationTypes = this.source.getAnnotationTypes().searchByTitle(this.annotation_type, true), /* We get the AnnotationType in which the annotation will be added */ |
|
457 _annotationType = (_annotationTypes.length ? _annotationTypes[0] : new IriSP.Model.AnnotationType(false, _export)); /* If it doesn't already exists, we create it */ |
455 if (this.selectedMarker){ |
458 if (this.selectedMarker){ |
456 var _export = this.player.sourceManager.newLocalSource({serializer: IriSP.serializers[this.api_serializer]}) |
459 var _annotation = this.selectedMarker, |
457 _annotation = this.selectedMarker, |
|
458 _url = Mustache.to_html(this.api_endpoint_template_edit, {annotation_id: this.selectedMarker ? this.selectedMarker.id : ""}); |
460 _url = Mustache.to_html(this.api_endpoint_template_edit, {annotation_id: this.selectedMarker ? this.selectedMarker.id : ""}); |
459 _annotation.source = _export |
461 _annotation.source = _export |
460 _annotation.description = this.$.find(".Ldt-Markers-MarkerTextArea").val(), /* Champ description */ |
462 _annotation.description = this.$.find(".Ldt-Markers-MarkerTextArea").val(), /* Description field */ |
461 _annotationTypes = this.source.getAnnotationTypes().searchByTitle(this.annotation_type, true), /* Récupération du type d'annotation dans lequel l'annotation doit être ajoutée */ |
463 } |
462 _annotationType = (_annotationTypes.length ? _annotationTypes[0] : new IriSP.Model.AnnotationType(false, _export)); /* Si le Type d'Annotation n'existe pas, il est créé à la volée */ |
464 else { |
463 } |
465 var _annotation = new IriSP.Model.Annotation(false, _export), |
464 else { |
|
465 var _export = this.player.sourceManager.newLocalSource({serializer: IriSP.serializers[this.api_serializer]}), /* Création d'un objet source utilisant un sérialiseur spécifique pour l'export */ |
|
466 _annotation = new IriSP.Model.Annotation(false, _export); /* Création d'une annotation dans cette source avec un ID généré à la volée (param. false) */ |
|
467 _annotationTypes = this.source.getAnnotationTypes().searchByTitle(this.annotation_type, true), /* Récupération du type d'annotation dans lequel l'annotation doit être ajoutée */ |
|
468 _annotationType = (_annotationTypes.length ? _annotationTypes[0] : new IriSP.Model.AnnotationType(false, _export)), /* Si le Type d'Annotation n'existe pas, il est créé à la volée */ |
|
469 _url = Mustache.to_html(this.api_endpoint_template_create); |
466 _url = Mustache.to_html(this.api_endpoint_template_create); |
470 /* Si nous avons dû générer un ID d'annotationType à la volée... */ |
467 |
|
468 /* If we created an AnnotationType on the spot ... */ |
471 if (!_annotationTypes.length) { |
469 if (!_annotationTypes.length) { |
472 /* Il ne faudra pas envoyer l'ID généré au serveur */ |
470 /* ... We must not send its id to the server ... */ |
473 _annotationType.dont_send_id = true; |
471 _annotationType.dont_send_id = true; |
474 /* Il faut inclure le titre dans le type d'annotation */ |
472 /* ... And we must include its title. */ |
475 _annotationType.title = this.annotation_type; |
473 _annotationType.title = this.annotation_type; |
476 } |
474 } |
477 |
475 |
478 _annotation.setMedia(this.source.currentMedia.id); /* Id du média annoté */ |
476 _annotation.setMedia(this.source.currentMedia.id); /* Annotated media ID */ |
479 if (!this.selectedMarker){ |
477 if (!this.selectedMarker){ |
480 _annotation.setBegin(this.newMarkerCurrentTime); |
478 _annotation.setBegin(this.newMarkerCurrentTime); |
481 _annotation.setEnd(this.newMarkerCurrentTime); |
479 _annotation.setEnd(this.newMarkerCurrentTime); |
482 } |
480 } |
483 _annotation.setAnnotationType(_annotationType.id); /* Id du type d'annotation */ |
481 _annotation.setAnnotationType(_annotationType.id); /* AnnotationType ID */ |
484 if (this.project_id != ""){ |
482 if (this.project_id != ""){ |
485 /* Champ id projet, seulement si on l'a renseigné dans la config */ |
483 /* Project id, only if it's been specifiec in the config */ |
486 _annotation.project_id = this.project_id; |
484 _annotation.project_id = this.project_id; |
487 } |
485 } |
488 _annotation.created = new Date(); /* Date de création de l'annotation */ |
486 _annotation.created = new Date(); /* Creation date */ |
489 _annotation.description = this.$.find(".Ldt-Markers-MarkerTextArea").val(); /* Champ description */ |
487 _annotation.description = this.$.find(".Ldt-Markers-MarkerTextArea").val(); /* Description field */ |
490 _annotation.creator = this.creator_name; |
488 _annotation.creator = this.creator_name; |
491 } |
489 } |
492 _annotation.project_id = this.project_id; |
490 _annotation.project_id = this.project_id; |
493 |
491 |
494 /* |
492 _exportedAnnotations.push(_annotation); /* We add the annotation in the list to export */ |
495 * Nous remplissons les données de l'annotation générée à la volée |
493 _export.addList("annotation",_exportedAnnotations); /* We add the list to the source object */ |
496 * ATTENTION: Si nous sommes sur un MASHUP, ces éléments doivent se référer AU MEDIA D'ORIGINE |
494 |
497 * */ |
495 /* We send the AJAX request to the server ! */ |
498 |
|
499 _exportedAnnotations.push(_annotation); /* Ajout de l'annotation à la liste à exporter */ |
|
500 _export.addList("annotation",_exportedAnnotations); /* Ajout de la liste à exporter à l'objet Source */ |
|
501 |
|
502 /* Envoi de l'annotation via AJAX au serveur ! */ |
|
503 IriSP.jQuery.ajax({ |
496 IriSP.jQuery.ajax({ |
504 url: _url, |
497 url: _url, |
505 type: this.selectedMarker ? this.api_method_edit : this.api_method_create, |
498 type: this.selectedMarker ? this.api_method_edit : this.api_method_create, |
506 contentType: 'application/json', |
499 contentType: 'application/json', |
507 data: _export.serialize(), /* L'objet Source est sérialisé */ |
500 data: _export.serialize(), |
508 success: function(_data) { |
501 success: function(_data) { |
509 _this.showScreen('Success'); /* Si l'appel a fonctionné, on affiche l'écran "Annotation enregistrée" */ |
502 _this.showScreen('Success'); |
510 window.setTimeout(_this.functionWrapper("revertToMainScreen"),(_this.after_send_timeout || 5000)); |
503 window.setTimeout(_this.functionWrapper("revertToMainScreen"),(_this.after_send_timeout || 5000)); |
511 _export.getAnnotations().removeElement(_annotation, true); /* Pour éviter les doublons, on supprime l'annotation qui a été envoyée */ |
504 _export.getAnnotations().removeElement(_annotation, true); /* We delete the sent annotation to avoid redundancy */ |
512 _export.deSerialize(_data); /* On désérialise les données reçues pour les réinjecter */ |
505 _export.deSerialize(_data); /* Data deserialization */ |
513 _annotation.id = _data.id; |
506 _annotation.id = _data.id; |
514 _this.source.merge(_export); /* On récupère les données réimportées dans l'espace global des données */ |
507 _this.source.merge(_export); /* We merge the deserialized data with the current source data */ |
515 if (_this.pause_on_write && _this.media.getPaused() && _this.play_on_submit) { |
508 if (_this.pause_on_write && _this.media.getPaused() && _this.play_on_submit) { |
516 _this.media.play(); |
509 _this.media.play(); |
517 } |
510 } |
518 _this.markers.push(_annotation); |
511 _this.markers.push(_annotation); |
519 _this.selectedMarker = _annotation; |
512 _this.selectedMarker = _annotation; |
520 _this.drawMarkers(); |
513 _this.drawMarkers(); |
521 _this.player.trigger("AnnotationsList.refresh"); /* On force le rafraîchissement du widget AnnotationsList */ |
514 _this.player.trigger("AnnotationsList.refresh"); |
522 _this.player.trigger("Markers.refresh"); |
515 _this.player.trigger("Markers.refresh"); |
523 }, |
516 }, |
524 error: function(_xhr, _error, _thrown) { |
517 error: function(_xhr, _error, _thrown) { |
525 IriSP.log("Error when sending annotation", _thrown); |
518 IriSP.log("Error when sending annotation", _thrown); |
526 _export.getAnnotations().removeElement(_annotation, true); |
519 _export.getAnnotations().removeElement(_annotation, true); |
539 IriSP.jQuery.ajax({ |
532 IriSP.jQuery.ajax({ |
540 url: _url, |
533 url: _url, |
541 type: this.api_method_delete, |
534 type: this.api_method_delete, |
542 contentType: 'application/json', |
535 contentType: 'application/json', |
543 success: function(_data) { |
536 success: function(_data) { |
544 _this.showScreen('DeleteSuccess'); /* Si l'appel a fonctionné, on affiche l'écran "Annotation enregistrée" */ |
537 _this.showScreen('DeleteSuccess'); |
545 window.setTimeout(_this.functionWrapper("revertToMainScreen"),(_this.after_send_timeout || 5000)); |
538 window.setTimeout(_this.functionWrapper("revertToMainScreen"),(_this.after_send_timeout || 5000)); |
546 if (_this.pause_on_write && _this.media.getPaused() && _this.play_on_submit) { |
539 if (_this.pause_on_write && _this.media.getPaused() && _this.play_on_submit) { |
547 _this.media.play(); |
540 _this.media.play(); |
548 } |
541 } |
549 _this.markers.removeElement(_this.selectedMarker); |
542 _this.markers.removeElement(_this.selectedMarker); |
550 _this.selectedMarker = false |
543 _this.selectedMarker = false |
551 _this.player.trigger("AnnotationsList.refresh"); /* On force le rafraîchissement du widget AnnotationsList */ |
544 _this.player.trigger("AnnotationsList.refresh"); |
552 _this.player.trigger("Markers.refresh"); |
545 _this.player.trigger("Markers.refresh"); |
553 }, |
546 }, |
554 error: function(_xhr, _error, _thrown) { |
547 error: function(_xhr, _error, _thrown) { |
555 IriSP.log("Error when sending annotation", _thrown); |
548 IriSP.log("Error when sending annotation", _thrown); |
556 _this.showScreen('Failure'); |
549 _this.showScreen('Failure'); |