diff -r 4b6e154ae8de -r f56199193fad src/widgets/CreateAnnotation.js
--- a/src/widgets/CreateAnnotation.js Tue May 22 16:49:48 2012 +0200
+++ b/src/widgets/CreateAnnotation.js Wed May 30 17:07:01 2012 +0200
@@ -1,3 +1,5 @@
+/* TODO: Add Social Network Sharing and from field */
+
IriSP.Widgets.CreateAnnotation = function(player, config) {
IriSP.Widgets.Widget.call(this, player, config);
this.lastAnnotation = false;
@@ -7,7 +9,8 @@
IriSP.Widgets.CreateAnnotation.prototype.defaults = {
show_title_field : false,
- user_avatar : "https://si0.twimg.com/sticky/default_profile_images/default_profile_1_normal.png",
+ creator_name : "",
+ creator_avatar : "https://si0.twimg.com/sticky/default_profile_images/default_profile_1_normal.png",
tags : false,
max_tags : 8,
polemics : [{
@@ -28,35 +31,10 @@
text_color: "#000000"
}],
annotation_type: "Contributions",
- creator_name: "",
- api_serializer: "ldt_annotate"
-/*
-
- remote_tags : false,
- random_tags : false,
- show_from_field : false,
- disable_share : false,
- polemic_mode : true, // enable polemics
- polemics : [{
- className: "positive",
- keyword: "++"
- }, {
- className: "negative",
- keyword: "--"
- }, {
- className: "reference",
- keyword: "=="
- }, {
- className: "question",
- keyword: "??"
- }],
- cinecast_version : false, // put to false to enable the platform version, true for the festival cinecast one.
-
- // where does the widget PUT the annotations - this is a mustache template. id refers to the id of the media and is filled by the widget.
-
- api_endpoint_template : "", // platform_url + "/ldtplatform/api/ldt/annotations/{{id}}.json",
- api_method : "PUT"
- */
+ api_serializer: "ldt_annotate",
+ api_endpoint_template: "",
+ api_method: "PUT",
+ close_widget_timeout: 0
}
IriSP.Widgets.CreateAnnotation.prototype.messages = {
@@ -77,7 +55,8 @@
share_annotation: "Would you like to share it on social networks ?",
share_on: "Share on",
more_tags: "More tags",
- cancel: "Cancel"
+ cancel: "Cancel",
+ close_widget: "Cacher la zone de création d'annotations"
},
fr: {
from_time: "de",
@@ -96,7 +75,8 @@
share_annotation: "Souhaitez-vous la partager sur les réseaux sociaux ?",
share_on: "Partager sur",
more_tags: "Plus de mots-clés",
- cancel: "Cancel"
+ cancel: "Cancel",
+ close_widget: "Hide the annotation creating block"
}
}
@@ -108,14 +88,17 @@
+ ' {{l10n.from_time}} '
+ ' {{l10n.to_time}} '
+ ''
- + '

'
+ + '
'
+ ''
+ '{{#tags.length}}{{/tags.length}}'
+ '{{#polemics.length}}{{l10n.add_polemic_keywords_}}
'
+ '{{#polemics}}- {{keyword}}
{{/polemics}}
{{/polemics.length}}'
- + ''
- + '';
+ + ''
+ + '{{l10n.wait_while_processing}}
'
+ + '{{l10n.error_while_contacting}}
'
+ + '{{l10n.annotation_saved}}
'
+ + '';
IriSP.Widgets.CreateAnnotation.prototype.draw = function() {
if (!this.tags) {
@@ -129,8 +112,12 @@
});
// We have to use the map function because Mustache doesn't like our tags object
}
+ var _this = this;
this.renderTemplate();
- var _this = this;
+ this.$.find(".Ldt-CreateAnnotation-Close").click(function() {
+ _this.hide();
+ return false;
+ });
this.$.find(".Ldt-CreateAnnotation-TagLi, .Ldt-CreateAnnotation-PolemicLi").click(function() {
_this.addKeyword(IriSP.jQuery(this).text().replace(/(^\s+|\s+$)/g,''));
return false;
@@ -149,8 +136,17 @@
this.$.find("form").submit(this.functionWrapper("onSubmit"));
}
+IriSP.Widgets.CreateAnnotation.prototype.showScreen = function(_screenName) {
+ this.$.find('.Ldt-CreateAnnotation-' + _screenName).show()
+ .siblings().hide();
+}
+
IriSP.Widgets.CreateAnnotation.prototype.show = function() {
this.visible = true;
+ this.showScreen('Main');
+ this.$.find(".Ldt-CreateAnnotation-Description").val("").css("border-color", "#666666");
+ this.$.find(".Ldt-CreateAnnotation-Title").val("").css("border-color", "#666666");
+ this.$.find(".Ldt-CreateAnnotation-TagLi, .Ldt-CreateAnnotation-PolemicLi").removeClass("selected");
this.$.slideDown();
this.player.popcorn.trigger("IriSP.Annotation.minimize");
this.player.popcorn.trigger("IriSP.Slice.show");
@@ -172,8 +168,8 @@
}
IriSP.Widgets.CreateAnnotation.prototype.onBoundsChanged = function(_values) {
- this.begin = new IriSP.Model.Time(_values[0]);
- this.end = new IriSP.Model.Time(_values[1]);
+ this.begin = new IriSP.Model.Time(_values[0] || 0);
+ this.end = new IriSP.Model.Time(_values[1] || 0);
this.$.find(".Ldt-CreateAnnotation-Begin").html(this.begin.toString());
this.$.find(".Ldt-CreateAnnotation-End").html(this.end.toString());
}
@@ -193,7 +189,7 @@
IriSP.Widgets.CreateAnnotation.prototype.onDescriptionChange = function() {
var _field = this.$.find(".Ldt-CreateAnnotation-Description"),
_contents = _field.val();
- _field.css("border-color", !!_contents ? "#666666" : "#c00000");
+ _field.css("border-color", !!_contents ? "#666666" : "#ff0000");
this.$.find(".Ldt-CreateAnnotation-TagLi, .Ldt-CreateAnnotation-PolemicLi").each(function() {
var _rx = IriSP.Model.regexpFromTextOrArray(IriSP.jQuery(this).text().replace(/(^\s+|\s+$)/g,''));
if (_rx.test(_contents)) {
@@ -208,7 +204,7 @@
IriSP.Widgets.CreateAnnotation.prototype.onTitleChange = function() {
var _field = this.$.find(".Ldt-CreateAnnotation-Title"),
_contents = _field.val();
- _field.css("border-color", !!_contents ? "#666666" : "#c00000");
+ _field.css("border-color", !!_contents ? "#666666" : "#ff0000");
return !!_contents;
}
@@ -220,7 +216,8 @@
var _exportedAnnotations = new IriSP.Model.List(this.player.sourceManager);
_export = this.player.sourceManager.newLocalSource({serializer: IriSP.serializers[this.api_serializer]}),
_annotation = new IriSP.Model.Annotation(false, _export),
- _annotationType = new IriSP.Model.AnnotationType(false, _export);
+ _annotationType = new IriSP.Model.AnnotationType(false, _export),
+ _url = Mustache.to_html(this.api_endpoint_template, {id: this.source.projectId});
_annotationType.title = this.annotation_type;
_annotation.setBegin(this.begin);
@@ -234,84 +231,38 @@
_annotation.description = this.$.find(".Ldt-CreateAnnotation-Description").val();
_annotation.setTags(this.$.find(".Ldt-CreateAnnotation-TagLi.selected").map(function() { return IriSP.jQuery(this).attr("tag-id")}));
- _export.creator = this.creator;
+ _export.creator = this.creator_name;
_export.created = new Date();
_exportedAnnotations.push(_annotation);
_export.addList("annotation",_exportedAnnotations);
- console.log(_export.serialize());
+
+ var _this = this;
+ IriSP.jQuery.ajax({
+ url: _url,
+ type: this.api_method,
+ contentType: 'application/json',
+ data: _export.serialize(),
+ success: function(_data) {
+ _this.showScreen('Saved');
+ if (_this.close_widget_timeout) {
+ window.setTimeout(_this.functionWrapper("hide"),_this.close_widget_timeout);
+ }
+ _export.getAnnotations().removeElement(_annotation, true);
+ _export.deSerialize(_data);
+ _this.source.merge(_export);
+ _this.player.popcorn.trigger("IriSP.AnnotationsList.refresh");
+ },
+ error: function(_xhr, _error, _thrown) {
+ IriSP.log("Error when sending annotation", _thrown);
+ _this.showScreen('Error');
+ window.setTimeout(function(){
+ _this.showScreen("Main")
+ },
+ (_this.close_widget_timeout || 5000));
+ }
+ });
+ this.showScreen('Wait');
return false;
}
-
-/*
- + ' '
- + '
'
- + '
'
- + '
'
- + ' {{^cinecast_version}}
'
- + ' {{/cinecast_version}}'
- + '
'
- + '
'
- + ' {{#show_from_field}}'
- + '
'
- + ' {{/show_from_field}}'
- + '
'
- + '
'
- + ' {{^user_avatar}}

'
- + ' {{/user_avatar}}'
- + ' {{#user_avatar}}

'
- + ' {{/user_avatar}}'
- + '
'
- + '
'
- + '
'
- + '
'
- + ' {{#tags.length}}'
- + '
'
- + '
'
- + '
'
- + ' {{#tags}}'
- + ' '
- + ' {{/tags}}'
- + '
'
- + '
'
- + ' {{#random_tags}}'
- + '
'
- + ' {{/random_tags}}'
- + ' {{/tags.length}}'
- + ' {{#polemic_mode}}'
- + ' {{#polemics.length}}'
- + '
'
- + '
'
- + '
'
- + ' {{#polemics}}'
- + ' '
- + ' {{/polemics}}'
- + '
'
- + '
'
- + ' {{/polemics.length}}'
- + ' {{/polemic_mode}}'
- + '
'
- + ' '
- + '
'
- + ' {{l10n.wait_while_processed}}'
- + '
'
- + ' '
- + '
'
- + ' {{l10n.error_while_contacting}}'
- + '
'
- + ' '
- + '
'
- + ' {{l10n.annotation_saved}}'
- + '
'
- + ' {{^disable_share}}'
- + ' {{l10n.share_annotation}}'
- + '
'
- + ' '
- + '
'
- + '
'
- + '
'
- + ' {{/disable_share}}'
- + '
'
- + ' '
-*/