src/widgets/CreateAnnotation.js
changeset 966 c1c762ad1697
parent 965 eadb7290c325
child 970 b1c3bf6eca78
equal deleted inserted replaced
965:eadb7290c325 966:c1c762ad1697
    11     show_creator_field : true,
    11     show_creator_field : true,
    12     start_visible : true,
    12     start_visible : true,
    13     always_visible : false,
    13     always_visible : false,
    14     show_slice : true,
    14     show_slice : true,
    15     show_arrow : true,
    15     show_arrow : true,
       
    16     show_mic_record: false,
       
    17     show_mic_play: false,
    16     minimize_annotation_widget : true,
    18     minimize_annotation_widget : true,
    17     creator_name : "",
    19     creator_name : "",
    18     creator_avatar : "",
    20     creator_avatar : "",
    19     tags : false,
    21     tags : false,
    20     tag_titles : false,
    22     tag_titles : false,
    97     + '<div class="Ldt-CreateAnnotation"><div class="Ldt-CreateAnnotation-Inner">'
    99     + '<div class="Ldt-CreateAnnotation"><div class="Ldt-CreateAnnotation-Inner">'
    98     + '<form class="Ldt-CreateAnnotation-Screen Ldt-CreateAnnotation-Main">'
   100     + '<form class="Ldt-CreateAnnotation-Screen Ldt-CreateAnnotation-Main">'
    99     + '<h3><span class="Ldt-CreateAnnotation-h3Left">{{#show_title_field}}<input class="Ldt-CreateAnnotation-Title" placeholder="{{l10n.type_title}}" />{{/show_title_field}}'
   101     + '<h3><span class="Ldt-CreateAnnotation-h3Left">{{#show_title_field}}<input class="Ldt-CreateAnnotation-Title" placeholder="{{l10n.type_title}}" />{{/show_title_field}}'
   100     + '{{^show_title_field}}<span class="Ldt-CreateAnnotation-NoTitle">{{l10n.no_title}} </span>{{/show_title_field}}'
   102     + '{{^show_title_field}}<span class="Ldt-CreateAnnotation-NoTitle">{{l10n.no_title}} </span>{{/show_title_field}}'
   101     + ' <span class="Ldt-CreateAnnotation-Times">{{#show_slice}}{{l10n.from_time}} {{/show_slice}}{{^show_slice}}{{l10n.at_time}} {{/show_slice}} <span class="Ldt-CreateAnnotation-Begin">00:00</span>'
   103     + ' <span class="Ldt-CreateAnnotation-Times">{{#show_slice}}{{l10n.from_time}} {{/show_slice}}{{^show_slice}}{{l10n.at_time}} {{/show_slice}} <span class="Ldt-CreateAnnotation-Begin">00:00</span>'
   102     + '{{#show_slice}} {{l10n.to_time}} <span class="Ldt-CreateAnnotation-End">00:00</span>{{/show_slice}}</span></span>'
   104     + '{{#show_slice}} {{l10n.to_time}} <span class="Ldt-CreateAnnotation-End">{{end}}</span>{{/show_slice}}</span></span>'
   103     + '{{#show_creator_field}}{{l10n.your_name_}} <input class="Ldt-CreateAnnotation-Creator" value="{{creator_name}}" /></h3>{{/show_creator_field}}'
   105     + '{{#show_creator_field}}{{l10n.your_name_}} <input class="Ldt-CreateAnnotation-Creator" value="{{creator_name}}" /></h3>{{/show_creator_field}}'
   104     + '<textarea class="Ldt-CreateAnnotation-Description" placeholder="{{l10n.type_description}}"></textarea>'
   106     + '<textarea class="Ldt-CreateAnnotation-Description" placeholder="{{l10n.type_description}}"></textarea>'
   105     + '<div class="Ldt-CreateAnnotation-Avatar"><img src="{{creator_avatar}}" title="{{creator_name}}"></img></div>'
   107     + '<div class="Ldt-CreateAnnotation-Avatar"><img src="{{creator_avatar}}" title="{{creator_name}}"></img></div>'
   106     + '<input type="submit" class="Ldt-CreateAnnotation-Submit" value="{{l10n.submit}}" />'
   108     + '<input type="submit" class="Ldt-CreateAnnotation-Submit" value="{{l10n.submit}}" />'
       
   109     + '{{#show_mic_record}}<div class="Ldt-CreateAnnotation-RecBlock"><div class="Ldt-CreateAnnotation-RecLabel">Add voice annotation</div>'
       
   110     + '    <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="220" height="160">'
       
   111     + '        <param name="movie" value="{{record_swf}}" />'
       
   112     + '        <param name="quality" value="high" />'
       
   113     + '        <param name="bgcolor" value="#ffffff" />'
       
   114     + '        <param name="play" value="true" />'
       
   115     + '        <param name="loop" value="true" />'
       
   116     + '        <param name="wmode" value="transparent" />'
       
   117     + '        <param name="scale" value="showall" />'
       
   118     + '        <param name="menu" value="true" />'
       
   119     + '        <param name="devicefont" value="false" />'
       
   120     + '        <param name="salign" value="" />'
       
   121     + '        <param name="allowScriptAccess" value="always" />'
       
   122     + '        <param name="allowFullScreen" value="true" />'
       
   123     + '        <param name="flashvars" value="playVisible={{show_mic_play}}">'
       
   124     + '        <embed src="{{record_swf}}"" quality="high" bgcolor="#ffffff"'
       
   125     + '             width="220" height="160" name="ExternalInterfaceExample" align="middle"'
       
   126     + '             play="true" loop="false" quality="high" allowScriptAccess="always" '
       
   127     + '             type="application/x-shockwave-flash" allowFullScreen="true" wmode="transparent" '
       
   128     + '             flashvars="playVisible={{show_mic_play}}"'
       
   129     + '             pluginspage="http://www.macromedia.com/go/getflashplayer">'
       
   130     + '        </embed>'
       
   131     + '    </object>'
       
   132     + '</div>{{/show_mic_record}}' 
   107     + '{{#tags.length}}<div class="Ldt-CreateAnnotation-Tags"><div class="Ldt-CreateAnnotation-TagTitle">{{l10n.add_keywords_}}</div><ul class="Ldt-CreateAnnotation-TagList">'
   133     + '{{#tags.length}}<div class="Ldt-CreateAnnotation-Tags"><div class="Ldt-CreateAnnotation-TagTitle">{{l10n.add_keywords_}}</div><ul class="Ldt-CreateAnnotation-TagList">'
   108     + '{{#tags}}<li class="Ldt-CreateAnnotation-TagLi" tag-id="{{id}}"><span class="Ldt-CreateAnnotation-TagButton">{{title}}</span></li>{{/tags}}</ul></div>{{/tags.length}}'
   134     + '{{#tags}}<li class="Ldt-CreateAnnotation-TagLi" tag-id="{{id}}"><span class="Ldt-CreateAnnotation-TagButton">{{title}}</span></li>{{/tags}}</ul></div>{{/tags.length}}'
   109     + '{{#polemics.length}}<div class="Ldt-CreateAnnotation-Polemics"><div class="Ldt-CreateAnnotation-PolemicTitle">{{l10n.add_polemic_keywords_}}</div><ul class="Ldt-CreateAnnotation-PolemicList">'
   135     + '{{#polemics.length}}<div class="Ldt-CreateAnnotation-Polemics"><div class="Ldt-CreateAnnotation-PolemicTitle">{{l10n.add_polemic_keywords_}}</div><ul class="Ldt-CreateAnnotation-PolemicList">'
   110     + '{{#polemics}}<li class="Ldt-CreateAnnotation-PolemicLi" style="background-color: {{background_color}}; color: {{text_color}}">{{keyword}}</li>{{/polemics}}</ul></div>{{/polemics.length}}'
   136     + '{{#polemics}}<li class="Ldt-CreateAnnotation-PolemicLi" style="background-color: {{background_color}}; color: {{text_color}}">{{keyword}}</li>{{/polemics}}</ul></div>{{/polemics.length}}'
   111     + '<div style="clear: both;"></div></form>'
   137     + '<div style="clear: both;"></div></form>'
   114     + '<div class="Ldt-CreateAnnotation-Screen Ldt-CreateAnnotation-Saved">{{^always_visible}}<a title="{{l10n.close_widget}}" class="Ldt-CreateAnnotation-Close" href="#"></a>{{/always_visible}}<div class="Ldt-CreateAnnotation-InnerBox">{{l10n.annotation_saved}}</div></div>'
   140     + '<div class="Ldt-CreateAnnotation-Screen Ldt-CreateAnnotation-Saved">{{^always_visible}}<a title="{{l10n.close_widget}}" class="Ldt-CreateAnnotation-Close" href="#"></a>{{/always_visible}}<div class="Ldt-CreateAnnotation-InnerBox">{{l10n.annotation_saved}}</div></div>'
   115     + '</div></div>';
   141     + '</div></div>';
   116     
   142     
   117 IriSP.Widgets.CreateAnnotation.prototype.draw = function() {
   143 IriSP.Widgets.CreateAnnotation.prototype.draw = function() {
   118     var _this = this;
   144     var _this = this;
       
   145     
       
   146     this.begin = new IriSP.Model.Time();
       
   147     this.end = this.source.getDuration();
       
   148     
   119     if (this.tag_titles && !this.tags) {
   149     if (this.tag_titles && !this.tags) {
   120         this.tags = IriSP._(this.tag_titles).map(function(_tag_title) {
   150         this.tags = IriSP._(this.tag_titles).map(function(_tag_title) {
   121             var _tag,
   151             var _tag,
   122                 _tags = _this.source.getTags().searchByTitle(_tag_title);
   152                 _tags = _this.source.getTags().searchByTitle(_tag_title);
   123             if (_tags.length) {
   153             if (_tags.length) {
   138             .map(function(_tag) {
   168             .map(function(_tag) {
   139                 return _tag;
   169                 return _tag;
   140             });
   170             });
   141         /* We have to use the map function because Mustache doesn't like our tags object */
   171         /* We have to use the map function because Mustache doesn't like our tags object */
   142     }
   172     }
       
   173     this.record_swf = IriSP.getLib("recordMicSwf");
   143     this.renderTemplate();
   174     this.renderTemplate();
       
   175     if (this.show_mic_record) {
       
   176         this.recorder = this.$.find("embed")[0];
       
   177         
       
   178         window.setAudioUrl = function(_url) {
       
   179             _this.audio_url = _url;
       
   180         }
       
   181     }
   144     if (this.show_slice) {
   182     if (this.show_slice) {
   145         this.insertSubwidget(
   183         this.insertSubwidget(
   146             this.$.find(".Ldt-CreateAnnotation-Slice"),
   184             this.$.find(".Ldt-CreateAnnotation-Slice"),
   147             {
   185             {
   148                 type: "Slice",
   186                 type: "Slice",
   194         this.$.hide();
   232         this.$.hide();
   195         this.hide();
   233         this.hide();
   196     }
   234     }
   197     
   235     
   198     this.onMdpEvent("CreateAnnotation.toggle","toggle");
   236     this.onMdpEvent("CreateAnnotation.toggle","toggle");
   199     this.begin = new IriSP.Model.Time();
       
   200     this.end = this.source.getDuration();
       
   201     this.$.find("form").submit(this.functionWrapper("onSubmit"));
   237     this.$.find("form").submit(this.functionWrapper("onSubmit"));
   202 }
   238 }
   203 
   239 
   204 IriSP.Widgets.CreateAnnotation.prototype.showScreen = function(_screenName) {
   240 IriSP.Widgets.CreateAnnotation.prototype.showScreen = function(_screenName) {
   205     this.$.find('.Ldt-CreateAnnotation-' + _screenName).show()
   241     this.$.find('.Ldt-CreateAnnotation-' + _screenName).show()
   222         this.player.trigger("Annotation.minimize");
   258         this.player.trigger("Annotation.minimize");
   223     }
   259     }
   224 }
   260 }
   225 
   261 
   226 IriSP.Widgets.CreateAnnotation.prototype.hide = function() {
   262 IriSP.Widgets.CreateAnnotation.prototype.hide = function() {
       
   263     if (this.recorder) {
       
   264         this.recorder.stopRecord();
       
   265     }
   227     if (!this.always_visible) {
   266     if (!this.always_visible) {
   228         this.visible = false;
   267         this.visible = false;
   229         this.$.slideUp();
   268         this.$.slideUp();
   230         if (this.minimize_annotation_widget) {
   269         if (this.minimize_annotation_widget) {
   231             this.player.trigger("Annotation.maximize");
   270             this.player.trigger("Annotation.maximize");
   297 /* Fonction effectuant l'envoi des annotations */
   336 /* Fonction effectuant l'envoi des annotations */
   298 IriSP.Widgets.CreateAnnotation.prototype.onSubmit = function() {
   337 IriSP.Widgets.CreateAnnotation.prototype.onSubmit = function() {
   299     /* Si les champs obligatoires sont vides, on annule l'envoi */
   338     /* Si les champs obligatoires sont vides, on annule l'envoi */
   300     if (!this.onDescriptionChange() || (this.show_title_field && !this.onTitleChange()) || (this.show_creator_field && !this.onCreatorChange())) {
   339     if (!this.onDescriptionChange() || (this.show_title_field && !this.onTitleChange()) || (this.show_creator_field && !this.onCreatorChange())) {
   301         return;
   340         return;
       
   341     }
       
   342     
       
   343     if (this.recorder) {
       
   344         this.recorder.stopRecord();
   302     }
   345     }
   303     
   346     
   304     var _exportedAnnotations = new IriSP.Model.List(this.player.sourceManager), /* Création d'une liste d'annotations contenant une annotation afin de l'envoyer au serveur */
   347     var _exportedAnnotations = new IriSP.Model.List(this.player.sourceManager), /* Création d'une liste d'annotations contenant une annotation afin de l'envoyer au serveur */
   305         _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 */
   348         _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 */
   306         _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) */
   349         _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) */
   331     }
   374     }
   332     _annotation.created = new Date(); /* Date de création de l'annotation */
   375     _annotation.created = new Date(); /* Date de création de l'annotation */
   333     _annotation.description = this.$.find(".Ldt-CreateAnnotation-Description").val(); /* Champ description */
   376     _annotation.description = this.$.find(".Ldt-CreateAnnotation-Description").val(); /* Champ description */
   334     _annotation.setTags(this.$.find(".Ldt-CreateAnnotation-TagLi.selected")
   377     _annotation.setTags(this.$.find(".Ldt-CreateAnnotation-TagLi.selected")
   335         .map(function() { return IriSP.jQuery(this).attr("tag-id")})); /*Liste des ids de tags */
   378         .map(function() { return IriSP.jQuery(this).attr("tag-id")})); /*Liste des ids de tags */
       
   379     
       
   380     if (this.audio_url) {
       
   381         _annotation.audio = {
       
   382             src: "mic",
       
   383             mimetype: "audio/mp3",
       
   384             href: this.audio_url
       
   385         };
       
   386     }
   336     
   387     
   337     /* Les données créateur/date de création sont envoyées non pas dans l'annotation, mais dans le projet */
   388     /* Les données créateur/date de création sont envoyées non pas dans l'annotation, mais dans le projet */
   338     if (this.show_creator_field) {
   389     if (this.show_creator_field) {
   339         _export.creator = this.$.find(".Ldt-CreateAnnotation-Creator").val();
   390         _export.creator = this.$.find(".Ldt-CreateAnnotation-Creator").val();
   340     } else {
   391     } else {