src/widgets/AnnotationsList.js
changeset 1046 eb77616c245f
parent 1037 5c0416e8bba1
child 1053 149a4ea20ea7
equal deleted inserted replaced
1045:b06345320ffb 1046:eb77616c245f
    35     newest_first : false,
    35     newest_first : false,
    36     always_visible : false,
    36     always_visible : false,
    37     start_visible: true,
    37     start_visible: true,
    38     show_audio : true,
    38     show_audio : true,
    39     show_filters : false,
    39     show_filters : false,
       
    40     show_header : false,
       
    41     custom_header : false,
    40     show_creation_date : false,
    42     show_creation_date : false,
    41     show_timecode : true, 
    43     show_timecode : true,
    42     /*
    44     /*
    43      * Only annotation in the current segment will be displayed. Designed to work with the Segments Widget.
    45      * Only annotation in the current segment will be displayed. Designed to work with the Segments Widget.
    44      */
    46      */
    45     filter_by_segments: false,
    47     filter_by_segments: false,
    46     segments_annotation_type: "chap",
    48     segments_annotation_type: "chap",
    69 };
    71 };
    70 
    72 
    71 IriSP.Widgets.AnnotationsList.prototype.messages = {
    73 IriSP.Widgets.AnnotationsList.prototype.messages = {
    72     en: {
    74     en: {
    73         voice_annotation: "Voice Annotation",
    75         voice_annotation: "Voice Annotation",
    74         now_playing: "Now playing..."
    76         now_playing: "Now playing...",
       
    77         everyone: "Everyone",
       
    78         header: "Annotations for this content"
    75     },
    79     },
    76     fr: {
    80     fr: {
    77         voice_annotation: "Annotation Vocale",
    81         voice_annotation: "Annotation Vocale",
    78         now_playing: "Lecture en cours..."
    82         now_playing: "Lecture en cours...",
       
    83         everyone: "Tous",
       
    84         header: "Annotations sur ce contenu"
    79     }
    85     }
    80 };
    86 };
    81 
    87 
    82 IriSP.Widgets.AnnotationsList.prototype.template =
    88 IriSP.Widgets.AnnotationsList.prototype.template =
    83     '<div class="Ldt-AnnotationsListWidget">'
    89     '{{#show_header}}<p class="Ldt-AnnotationsList-header">'
       
    90     +     '{{#custom_header}}{{custom_header}}{{/custom_header}}'
       
    91     +     '{{^custom_header}}{{l10n.header}}{{/custom_header}}'
       
    92     + '</p>{{/show_header}}'
       
    93     + '<div class="Ldt-AnnotationsListWidget">'
    84     + '{{#show_filters}}'
    94     + '{{#show_filters}}'
    85     + '<div class="Ldt-AnnotationsList-Filters">'
    95     + '<div class="Ldt-AnnotationsList-Filters">'
    86     +    '<input class="Ldt-AnnotationsList-filter-text" type="text" value="Mot-clés"></input>'
    96     +    '<input class="Ldt-AnnotationsList-filter-text" id="Ldt-AnnotationsList-keywordsFilter" type="text" value=""></input>'
    87     +    '<select class="Ldt-AnnotationsList-filter-dropdown"></select>'
    97     +    '<select class="Ldt-AnnotationsList-filter-dropdown" id="Ldt-AnnotationsList-userFilter"><option selected value="">{{l10n.everyone}}</option></select>'
    88     +    '<label class="Ldt-AnnotationsList-filter-checkbox"><input type="checkbox">Toutes annotations</label>'
    98     +    '<label class="Ldt-AnnotationsList-filter-date">Date: <input id="Ldt-AnnotationsList-dateFilter" type="text"></input></label>'
       
    99     +    '<label class="Ldt-AnnotationsList-filter-checkbox"><input type="checkbox" id="Ldt-AnnotationsList-ignoreSegmentsFilter">Toutes annotations</label>'
    89     + '</div>'
   100     + '</div>'
    90     + '{{/show_filters}}'
   101     + '{{/show_filters}}'
    91     + '{{#show_audio}}<div class="Ldt-AnnotationsList-Audio"></div>{{/show_audio}}'
   102     + '{{#show_audio}}<div class="Ldt-AnnotationsList-Audio"></div>{{/show_audio}}'
    92     + '<ul class="Ldt-AnnotationsList-ul">'
   103     + '<ul class="Ldt-AnnotationsList-ul">'
    93     + '</ul>'
   104     + '</ul>'
   175         }
   186         }
   176     }
   187     }
   177     _list = _list.filter(function(_annotation) {
   188     _list = _list.filter(function(_annotation) {
   178         return _annotation.found !== false;
   189         return _annotation.found !== false;
   179     });
   190     });
   180     if (this.filter_by_segments) {
   191     
       
   192     if ((this.filter_by_segments)&&(!(this.show_filters && this.ignoresegmentcheckbox_$[0].checked))) {
   181         /*
   193         /*
   182          *  A given annotation is considered "in" segment if the middle of it is between the segment beginning and the segment end. 
   194          *  A given annotation is considered "in" segment if the middle of it is between the segment beginning and the segment end. 
   183          *  Note this is meant to be used for "markings" annotations (not segments)
   195          *  Note this is meant to be used for "markings" annotations (not segments)
   184          */
   196          */
   185         _segmentsAnnotation = this.currentSource.getAnnotationsByTypeTitle(this.segments_annotation_type)
   197         _segmentsAnnotation = this.currentSource.getAnnotationsByTypeTitle(this.segments_annotation_type)
   186         _currentSegments = _segmentsAnnotation.filter(function(_segment){
   198         if (this.media.getTimeRange()){
   187             return (_currentTime >= _segment.begin && _currentTime <= _segment.end)
   199             _currentSegments = _segmentsAnnotation.filter(function(_segment){
   188         });
   200                 return (_this.media.getTimeRange()[0] == _segment.begin && _this.media.getTimeRange()[1] == _segment.end)
       
   201             });
       
   202         }
       
   203         else {
       
   204             _currentSegments = _segmentsAnnotation.filter(function(_segment){
       
   205                 return (_currentTime >= _segment.begin && _currentTime <= _segment.end)
       
   206             });
       
   207         }
   189         if (_currentSegments.length == 0) {
   208         if (_currentSegments.length == 0) {
   190             _list = _list.filter(function(_annotation){
   209             _list = _list.filter(function(_annotation){
   191                 return false;
   210                 return false;
   192             });
   211             });
   193         }
   212         }
   207         /* Get the n annotations closest to current timecode */
   226         /* Get the n annotations closest to current timecode */
   208         _list = _list.sortBy(function(_annotation) {
   227         _list = _list.sortBy(function(_annotation) {
   209             return Math.abs((_annotation.begin + _annotation.end) / 2 - _currentTime);
   228             return Math.abs((_annotation.begin + _annotation.end) / 2 - _currentTime);
   210         }).slice(0, this.limit_count);
   229         }).slice(0, this.limit_count);
   211     }
   230     }
       
   231     
   212     if (this.newest_first) {
   232     if (this.newest_first) {
   213         _list = _list.sortBy(function(_annotation) {
   233         _list = _list.sortBy(function(_annotation) {
   214             return -_annotation.created.valueOf();
   234             return -_annotation.created.valueOf();
   215         });
   235         });
   216     } else {
   236     } else {
   217         _list = _list.sortBy(function(_annotation) {
   237         _list = _list.sortBy(function(_annotation) {
   218             return _annotation.begin;
   238             return _annotation.begin;
   219         });
   239         });
       
   240     }
       
   241     
       
   242     if (this.show_filters){
       
   243         _username = this.userselect_$[0].options[this.userselect_$[0].selectedIndex].value;
       
   244         if (_username != "false")
       
   245         {
       
   246             _list = _list.filter(function(_annotation){
       
   247                 return _annotation.creator == _username
       
   248             })
       
   249         }
       
   250         _keyword = this.keywordinput_$[0].value;
       
   251         if (_keyword != ""){
       
   252             _list = _list.filter(function(_annotation){
       
   253                return _annotation.description.toLowerCase().match(_keyword.toLowerCase());
       
   254             });
       
   255         }
       
   256         
       
   257         
       
   258         if(this.datefilterinput_$[0].value != ""){
       
   259             _date = this.datefilterinput_$.datepicker("getDate");
       
   260             _list = _list.filter(function(_annotation){
       
   261                 return ((_annotation.created.getDate() == _date.getDate())&&(_annotation.created.getMonth() == _date.getMonth())&&(_annotation.created.getFullYear() == _date.getFullYear()))
       
   262             });
       
   263         }
       
   264         
   220     }
   265     }
   221     
   266     
   222     var _ids = _list.idIndex;
   267     var _ids = _list.idIndex;
   223     
   268     
   224     if (_forceRedraw || !IriSP._.isEqual(_ids, this.lastIds) || this.searchString !== this.lastSearch) {
   269     if (_forceRedraw || !IriSP._.isEqual(_ids, this.lastIds) || this.searchString !== this.lastSearch) {
   244                     : document.location.href.replace(/#.*$/,'') + '#id=' + _annotation.id
   289                     : document.location.href.replace(/#.*$/,'') + '#id=' + _annotation.id
   245                     )
   290                     )
   246             );
   291             );
   247             var _title = "",
   292             var _title = "",
   248                 _description = _annotation.description,
   293                 _description = _annotation.description,
   249                 _thumbnail = (typeof _annotation.thumbnail !== "undefined" && _annotation.thumbnail ? _annotation.thumbnail : _this.default_thumbnail);
   294                 _thumbnail = (typeof _annotation.thumbnail !== "undefined" && _annotation.thumbnail ? _annotation.thumbnail : _this.default_thumbnail)
       
   295             
   250             // Update : display creator
   296             // Update : display creator
   251             if (_annotation.creator) {
   297             if (_annotation.creator) {
   252                 _title = _annotation.creator;
   298                 _title = _annotation.creator;
   253             }
   299             }
   254             if (_annotation.title) {
   300             if (_annotation.title) {
   332                     _annotation.trigger("select");
   378                     _annotation.trigger("select");
   333                 })
   379                 })
   334                 .mouseout(function() {
   380                 .mouseout(function() {
   335                     _annotation.trigger("unselect");
   381                     _annotation.trigger("unselect");
   336                 })
   382                 })
       
   383                 .click(function() {
       
   384                     _annotation.trigger("click");
       
   385                 })
   337                 .appendTo(_this.list_$);
   386                 .appendTo(_this.list_$);
   338             IriSP.attachDndData(_el.find("[draggable]"), {
   387             IriSP.attachDndData(_el.find("[draggable]"), {
   339                 title: _title,
   388                 title: _title,
   340                 description: _description,
   389                 description: _description,
   341                 uri: _url,
   390                 uri: _url,
   391     
   440     
   392     return _list.length;
   441     return _list.length;
   393 };
   442 };
   394 
   443 
   395 IriSP.Widgets.AnnotationsList.prototype.hide = function() {
   444 IriSP.Widgets.AnnotationsList.prototype.hide = function() {
       
   445     var _this = this;
   396     if (this.visible){
   446     if (this.visible){
   397         this.visible = false;
   447         this.visible = false;
   398         this.widget_$.slideUp()
   448         this.widget_$.slideUp(function(){
       
   449             _this.$.find('.Ldt-AnnotationsList-header').hide();            
       
   450         });
   399     }
   451     }
   400 }
   452 }
   401 
   453 
   402 IriSP.Widgets.AnnotationsList.prototype.show = function() {
   454 IriSP.Widgets.AnnotationsList.prototype.show = function() {
   403     if(!this.visible){
   455     if(!this.visible){
   404         this.visible = true;
   456         this.visible = true;
   405         this.widget_$.slideDown()
   457         this.$.find('.Ldt-AnnotationsList-header').show();
       
   458         this.widget_$.slideDown();
   406     }
   459     }
   407 }
   460 }
   408 
   461 
   409 
   462 
   410 IriSP.Widgets.AnnotationsList.prototype.toggle = function() {
   463 IriSP.Widgets.AnnotationsList.prototype.toggle = function() {
   426     
   479     
   427     var _this = this;
   480     var _this = this;
   428         
   481         
   429     this.list_$ = this.$.find(".Ldt-AnnotationsList-ul");
   482     this.list_$ = this.$.find(".Ldt-AnnotationsList-ul");
   430     this.widget_$ = this.$.find(".Ldt-AnnotationsListWidget");
   483     this.widget_$ = this.$.find(".Ldt-AnnotationsListWidget");
   431     
   484     this.userselect_$ = this.$.find("#Ldt-AnnotationsList-userFilter");
       
   485     this.userselect_$.change(function(){
       
   486         _this.player.trigger("AnnotationsList.refresh");
       
   487     });
       
   488     this.keywordinput_$ = this.$.find("#Ldt-AnnotationsList-keywordsFilter");
       
   489     this.keywordinput_$.keyup(function(){
       
   490         _this.player.trigger("AnnotationsList.refresh");
       
   491     });
       
   492     this.ignoresegmentcheckbox_$ = this.$.find("#Ldt-AnnotationsList-ignoreSegmentsFilter");
       
   493     this.ignoresegmentcheckbox_$.click(function(){
       
   494         _this.player.trigger("AnnotationsList.refresh");
       
   495     });
       
   496     this.datefilterinput_$ = this.$.find("#Ldt-AnnotationsList-dateFilter");
       
   497     this.datefilterinput_$.datepicker({ dateFormat: 'dd/mm/yy' });
       
   498     this.datefilterinput_$.change(function(){
       
   499         _this.player.trigger("AnnotationsList.refresh")
       
   500     })
   432     
   501     
   433     this.source.getAnnotations().on("search", function(_text) {
   502     this.source.getAnnotations().on("search", function(_text) {
   434         _this.searchString = _text;
   503         _this.searchString = _text;
   435         if (_this.source !== _this.currentSource) {
   504         if (_this.source !== _this.currentSource) {
   436             _this.currentSource.getAnnotations().search(_text);
   505             _this.currentSource.getAnnotations().search(_text);
   450         }
   519         }
   451     });
   520     });
   452     this.source.getAnnotations().on("search-cleared", function() {
   521     this.source.getAnnotations().on("search-cleared", function() {
   453         _this.throttledRefresh();
   522         _this.throttledRefresh();
   454     });
   523     });
       
   524     
       
   525     if (this.show_filters){
       
   526         _usernames = Array();
       
   527         _list = this.getWidgetAnnotations()
       
   528         _list.forEach(function(_annotation){
       
   529             if(_usernames.indexOf(_annotation.creator) == -1){
       
   530                 _usernames.push(_annotation.creator);
       
   531             }
       
   532         });
       
   533         this.userselect_$.html("<option selected value='false'>"+this.l10n.everyone+"</option>");
       
   534         _usernames.forEach(function(_user){
       
   535             _this.userselect_$.append("<option value='"+_user+"'>"+_user+"</option>");
       
   536         });
       
   537     }
   455     
   538     
   456     this.onMdpEvent("AnnotationsList.refresh", function() {
   539     this.onMdpEvent("AnnotationsList.refresh", function() {
   457         if (_this.ajax_url) {
   540         if (_this.ajax_url) {
   458             if (_this.mashupMode) {
   541             if (_this.mashupMode) {
   459                 _this.ajaxMashup();
   542                 _this.ajaxMashup();
   482     
   565     
   483     this.onMdpEvent("AnnotationsList.toggle","toggle");
   566     this.onMdpEvent("AnnotationsList.toggle","toggle");
   484     this.onMdpEvent("AnnotationsList.hide", "hide");
   567     this.onMdpEvent("AnnotationsList.hide", "hide");
   485     this.onMdpEvent("AnnotationsList.show", "show");
   568     this.onMdpEvent("AnnotationsList.show", "show");
   486     
   569     
   487     this.onMdpEvent("createAnnotationWidget.addedAnnotation", "refresh");
   570     this.onMdpEvent("createAnnotationWidget.addedAnnotation", this.throttledRefresh);
   488     var _events = [
   571     var _events = [
   489         "timeupdate",
   572         "timeupdate",
   490         "seeked",
   573         "seeked",
   491         "loadedmetadata"
   574         "loadedmetadata",
       
   575         "settimerange"
   492     ];
   576     ];
   493     for (var _i = 0; _i < _events.length; _i++) {
   577     for (var _i = 0; _i < _events.length; _i++) {
   494         this.onMediaEvent(_events[_i], this.throttledRefresh);
   578         this.onMediaEvent(_events[_i], this.throttledRefresh);
   495     }
   579     }
   496     
   580