src/widgets/AnnotationsList.js
changeset 1053 149a4ea20ea7
parent 1046 eb77616c245f
child 1055 b45522b1b2af
equal deleted inserted replaced
1052:c8fd9dbf3804 1053:149a4ea20ea7
    10 };
    10 };
    11 
    11 
    12 IriSP.Widgets.AnnotationsList.prototype = new IriSP.Widgets.Widget();
    12 IriSP.Widgets.AnnotationsList.prototype = new IriSP.Widgets.Widget();
    13 
    13 
    14 IriSP.Widgets.AnnotationsList.prototype.defaults = {
    14 IriSP.Widgets.AnnotationsList.prototype.defaults = {
       
    15     pre_draw_callback: function(){
       
    16         return this.importUsers();
       
    17     },
    15     /*
    18     /*
    16      * URL when the annotations are to be reloaded from an LDT-like segment API
    19      * URL when the annotations are to be reloaded from an LDT-like segment API
    17      * e.g.
    20      * e.g.
    18      * http://ldt.iri.centrepompidou.fr/ldtplatform/api/ldt/segments/{{media}}/{{begin}}/{{end}}?callback=?
    21      * http://ldt.iri.centrepompidou.fr/ldtplatform/api/ldt/segments/{{media}}/{{begin}}/{{end}}?callback=?
    19      */
    22      */
    35     newest_first : false,
    38     newest_first : false,
    36     always_visible : false,
    39     always_visible : false,
    37     start_visible: true,
    40     start_visible: true,
    38     show_audio : true,
    41     show_audio : true,
    39     show_filters : false,
    42     show_filters : false,
       
    43     keyword_filter: true,
       
    44     date_filter: true,
       
    45     user_filter: true,
       
    46     segment_filter: true,
       
    47     latest_contributions_filter: false,
       
    48     current_day_filter: true,
    40     show_header : false,
    49     show_header : false,
    41     custom_header : false,
    50     custom_header : false,
       
    51     annotations_count_header : true,
    42     show_creation_date : false,
    52     show_creation_date : false,
    43     show_timecode : true,
    53     show_timecode : true,
    44     /*
    54     /*
    45      * Only annotation in the current segment will be displayed. Designed to work with the Segments Widget.
    55      * Only annotation in the current segment will be displayed. Designed to work with the Segments Widget.
    46      */
    56      */
       
    57     allow_annotations_deletion: false,
       
    58     /*
       
    59      * URL to call when deleting annotation. Expects a mustache template with {{annotation_id}}, ex /api/anotations/{{annotation_id}}/
       
    60      */
       
    61     api_delete_endpoint : "",
       
    62     api_delete_method: "DELETE",
       
    63     api_users_endpoint: "",
       
    64     api_users_method: "GET",
       
    65     make_name_string_function: function(params){
       
    66         return params.username ? params.username : "Anonymous";
       
    67     },
    47     filter_by_segments: false,
    68     filter_by_segments: false,
       
    69     segment_filter: true,
    48     segments_annotation_type: "chap",
    70     segments_annotation_type: "chap",
    49     /*
    71     /*
    50      * Set to a username if you only want to display annotations from a given user
    72      * Set to a username if you only want to display annotations from a given user
    51      */
    73      */
    52     show_only_annotation_from_user: false,
    74     show_only_annotation_from_user: false,
    53     /*
    75     /*
    54      * Show a text field that filter annotations by username
    76      * Show a text field that filter annotations by username
    55      */
    77      */
    56     filter_by_user: false,
       
    57     tags : true,
    78     tags : true,
    58     polemics : [{
    79     polemics : [{
    59         keyword: "++",
    80         keyword: "++",
    60         background_color: "#c9ecc6"
    81         background_color: "#c9ecc6"
    61     },{
    82     },{
    68         keyword: "==",
    89         keyword: "==",
    69         background_color: "#f9f4c6"
    90         background_color: "#f9f4c6"
    70     }]
    91     }]
    71 };
    92 };
    72 
    93 
       
    94 IriSP.Widgets.AnnotationsList.prototype.importUsers = function(){
       
    95     if (!this.source.users_data){
       
    96         this.usernames = Array();
       
    97         var _this = this,
       
    98             _list = this.getWidgetAnnotations(),
       
    99             usernames_list_string = "";
       
   100         
       
   101         _list.forEach(function(_annotation){
       
   102             if(_this.usernames.indexOf(_annotation.creator) == -1){
       
   103                 _this.usernames.push(_annotation.creator);
       
   104             }
       
   105         });
       
   106         this.usernames.forEach(function(_username){
       
   107             usernames_list_string+=_username+","
       
   108         })
       
   109         usernames_list_string = usernames_list_string.substring(0, usernames_list_string.length - 1);
       
   110         _url = Mustache.to_html(this.api_users_endpoint, {usernames_list_string: encodeURIComponent(usernames_list_string), usernames_list_length: this.usernames.length});
       
   111         return IriSP.jQuery.ajax({
       
   112             async: false,
       
   113             url: _url,
       
   114             type: "GET",
       
   115             success: function(_data) {
       
   116                 console.log(_data)
       
   117                 _this.source.users_data = _data.objects
       
   118             },
       
   119             error: function(_xhr, _error, _thrown) {
       
   120                 console.log(_xhr)
       
   121                 console.log(_error)
       
   122                 console.log(_thrown)
       
   123             }
       
   124         })
       
   125     }
       
   126 }
       
   127 
    73 IriSP.Widgets.AnnotationsList.prototype.messages = {
   128 IriSP.Widgets.AnnotationsList.prototype.messages = {
    74     en: {
   129     en: {
    75         voice_annotation: "Voice Annotation",
   130         voice_annotation: "Voice Annotation",
    76         now_playing: "Now playing...",
   131         now_playing: "Now playing...",
    77         everyone: "Everyone",
   132         everyone: "Everyone",
    78         header: "Annotations for this content"
   133         header: "Annotations for this content",
       
   134         segment_filter: "All cuttings",
       
   135         latest_contributions: "Latest contributions",
       
   136         close_widget: "Close",
       
   137         confirm: "Confirm",
       
   138         cancel: "Cancel",
       
   139         annotation_deletion_delete: "You will delete this annotation : ",
       
   140         annotation_deletion_sending: "Your deletion request is being sent ... ",
       
   141         annotation_deletion_success: "The annotation has been deleted.",
       
   142         annotation_deletion_error: "There was an error contacting the server. The annotation has not been deleted."
    79     },
   143     },
    80     fr: {
   144     fr: {
    81         voice_annotation: "Annotation Vocale",
   145         voice_annotation: "Annotation Vocale",
    82         now_playing: "Lecture en cours...",
   146         now_playing: "Lecture en cours...",
    83         everyone: "Tous",
   147         everyone: "Tous",
    84         header: "Annotations sur ce contenu"
   148         header: "Annotations sur ce contenu",
       
   149         segment_filter: "Tous les segments",
       
   150         latest_contributions: "Dernières contributions",
       
   151         close_widget: "Fermer",
       
   152         confirm: "Confirmer",
       
   153         cancel: "Annuler",
       
   154         annotation_deletion_delete: "Vous allez supprimer cette annotation: ",
       
   155         annotation_deletion_sending: "Votre demande de suppression est en cours d'envoi ... ",
       
   156         annotation_deletion_success: "L'annotation a été supprimée.",
       
   157         annotation_deletion_error: "Une erreur s'est produite en contactant le serveur. L'annotation n'a pas été supprimée."
    85     }
   158     }
    86 };
   159 };
    87 
   160 
    88 IriSP.Widgets.AnnotationsList.prototype.template =
   161 IriSP.Widgets.AnnotationsList.prototype.template =
    89     '{{#show_header}}<p class="Ldt-AnnotationsList-header">'
   162     '{{#show_header}}<p class="Ldt-AnnotationsList-header">'
    90     +     '{{#custom_header}}{{custom_header}}{{/custom_header}}'
   163     +     '{{#custom_header}}{{custom_header}}{{/custom_header}}'
    91     +     '{{^custom_header}}{{l10n.header}}{{/custom_header}}'
   164     +     '{{^custom_header}}{{l10n.header}}{{/custom_header}}'
    92     + '</p>{{/show_header}}'
   165     + '</p>{{/show_header}}'
    93     + '<div class="Ldt-AnnotationsListWidget">'
   166     + '<div class="Ldt-AnnotationsListWidget">'
    94     + '{{#show_filters}}'
   167     +     '<div class="Ldt-AnnotationsList-ScreenMain">'
    95     + '<div class="Ldt-AnnotationsList-Filters">'
   168     +         '{{#show_filters}}'
    96     +    '<input class="Ldt-AnnotationsList-filter-text" id="Ldt-AnnotationsList-keywordsFilter" type="text" value=""></input>'
   169     +         '<div class="Ldt-AnnotationsList-Filters">'
    97     +    '<select class="Ldt-AnnotationsList-filter-dropdown" id="Ldt-AnnotationsList-userFilter"><option selected value="">{{l10n.everyone}}</option></select>'
   170     +             '{{#keyword_filter}}<input class="Ldt-AnnotationsList-filter-text" id="Ldt-AnnotationsList-keywordsFilter" type="text" value=""></input>{{/keyword_filter}}'
    98     +    '<label class="Ldt-AnnotationsList-filter-date">Date: <input id="Ldt-AnnotationsList-dateFilter" type="text"></input></label>'
   171     +             '{{#user_filter}}<select class="Ldt-AnnotationsList-filter-dropdown" id="Ldt-AnnotationsList-userFilter"><option selected value="">{{l10n.everyone}}</option></select>{{/user_filter}}'
    99     +    '<label class="Ldt-AnnotationsList-filter-checkbox"><input type="checkbox" id="Ldt-AnnotationsList-ignoreSegmentsFilter">Toutes annotations</label>'
   172     +             '{{#date_filter}}<label class="Ldt-AnnotationsList-filter-date">Date: <input id="Ldt-AnnotationsList-dateFilter" type="text"></input></label>{{/date_filter}}'
   100     + '</div>'
   173     +             '{{#segment_filter}}<label class="Ldt-AnnotationsList-filter-checkbox"><input type="checkbox" id="Ldt-AnnotationsList-ignoreSegmentsFilter">{{l10n.segment_filter}}</label>{{/segment_filter}}'
   101     + '{{/show_filters}}'
   174     +             '{{#latest_contributions_filter}}<label class="Ldt-AnnotationsList-filter-checkbox"><input type="checkbox" id="Ldt-AnnotationsList-latestContributionsFilter">{{l10n.latest_contributions}}</label>{{/latest_contributions_filter}}'
   102     + '{{#show_audio}}<div class="Ldt-AnnotationsList-Audio"></div>{{/show_audio}}'
   175     +         '</div>'
   103     + '<ul class="Ldt-AnnotationsList-ul">'
   176     +         '{{/show_filters}}'
   104     + '</ul>'
   177     +         '{{#show_audio}}<div class="Ldt-AnnotationsList-Audio"></div>{{/show_audio}}'
       
   178     +         '<ul class="Ldt-AnnotationsList-ul">'
       
   179     +         '</ul>'
       
   180     +     '</div>'    
       
   181     +     '{{#allow_annotations_deletion}}'
       
   182     +     '<div id="{{id}}" class="Ldt-AnnotationsList-Screen Ldt-AnnotationsList-ScreenDelete">'
       
   183     +         '<a title="{{l10n.close_widget}}" class="Ldt-AnnotationsList-Close" href="#"></a>' 
       
   184     +         '<ul class="Ldt-AnnotationsList-ul-ToDelete"></ul>'
       
   185     +         '{{l10n.annotation_deletion_delete}} <a class="Ldt-AnnotationsList-ConfirmDelete">{{l10n.confirm}}</a> <a class="Ldt-AnnotationsList-CancelDelete">{{l10n.cancel}}</a>'
       
   186     +     '</div>'
       
   187     +     '<div id="{{id}}" class="Ldt-AnnotationsList-Screen Ldt-AnnotationsList-ScreenSending">'
       
   188     +         '<a title="{{l10n.close_widget}}" class="Ldt-AnnotationsList-Close" href="#"></a>'  
       
   189     +         '{{l10n.annotation_deletion_sending}}'
       
   190     +     '</div>'
       
   191     +     '<div id="{{id}}" class="Ldt-AnnotationsList-Screen Ldt-AnnotationsList-ScreenSuccess">'
       
   192     +         '<a title="{{l10n.close_widget}}" class="Ldt-AnnotationsList-Close" href="#"></a>'  
       
   193     +         '{{l10n.annotation_deletion_success}}'
       
   194     +     '</div>'
       
   195     +     '<div id="{{id}}" class="Ldt-AnnotationsList-Screen Ldt-AnnotationsList-ScreenError">'
       
   196     +         '<a title="{{l10n.close_widget}}" class="Ldt-AnnotationsList-Close" href="#"></a>'  
       
   197     +         '{{l10n.annotation_deletion_error}}'
       
   198     +     '</div>'
       
   199     +     '{{/allow_annotations_deletion}}'
   105     + '</div>';
   200     + '</div>';
   106 
   201 
   107 IriSP.Widgets.AnnotationsList.prototype.annotationTemplate = 
   202 IriSP.Widgets.AnnotationsList.prototype.annotationTemplate = 
   108     '<li class="Ldt-AnnotationsList-li Ldt-TraceMe" trace-info="annotation-id:{{id}}, media-id:{{media_id}}" style="{{specific_style}}">'
   203     '<li class="Ldt-AnnotationsList-li Ldt-TraceMe" trace-info="annotation-id:{{id}}, media-id:{{media_id}}" style="{{specific_style}}">'
   109     + '<div class="Ldt-AnnotationsList-ThumbContainer">'
   204     + '<div id="{{id}}" class="Ldt-AnnotationsList-ThumbContainer Ldt-AnnotationsList-Annotation-Screen Ldt-AnnotationsList-Annotation-ScreenMain">'
   110     + '<a href="{{url}}" draggable="true">'
   205     + '<a href="{{url}}" draggable="true">'
   111     + '<img class="Ldt-AnnotationsList-Thumbnail" src="{{thumbnail}}" />'
   206     + '<img class="Ldt-AnnotationsList-Thumbnail" src="{{thumbnail}}" />'
   112     + '</a>'
   207     + '</a>'
   113     + '</div>'
   208     + '</div>'
       
   209     + '{{#allow_annotations_deletion}}'
       
   210     + '<div id={{id}} class="Ldt-AnnotationsList-DeleteButton">&#10006;</div>'
       
   211     + '{{/allow_annotations_deletion}}'
   114     + '{{#show_timecode}}<div class="Ldt-AnnotationsList-Duration">{{begin}} - {{end}}</div>{{/show_timecode}}'
   212     + '{{#show_timecode}}<div class="Ldt-AnnotationsList-Duration">{{begin}} - {{end}}</div>{{/show_timecode}}'
   115     + '<h3 class="Ldt-AnnotationsList-Title" draggable="true">'
   213     + '<h3 class="Ldt-AnnotationsList-Title" draggable="true">'
   116     + '<a href="{{url}}">{{{htitle}}}</a>'
   214     + '<a {{#url}} href="{{url}}" {{/url}}>{{{htitle}}}</a>'
   117     + '</h3>'
   215     + '</h3>'
   118     + '<p class="Ldt-AnnotationsList-Description">{{{hdescription}}}</p>'
   216     + '<p class="Ldt-AnnotationsList-Description">{{{hdescription}}}</p>'
   119     + '{{#created}}'
   217     + '{{#created}}'
   120     + '<div class="Ldt-AnnotationsList-CreationDate">{{{created}}}</div>'
   218     + '<div class="Ldt-AnnotationsList-CreationDate">{{{created}}}</div>'
   121     + '{{/created}}'
   219     + '{{/created}}'
   128     + '</li>'
   226     + '</li>'
   129     + '{{/.}}'
   227     + '{{/.}}'
   130     + '{{/tags}}'
   228     + '{{/tags}}'
   131     + '</ul>'
   229     + '</ul>'
   132     + '{{/tags.length}}'
   230     + '{{/tags.length}}'
   133     + '{{#audio}}<div class="Ldt-AnnotationsList-Play" data-annotation-id="{{id}}">{{l10n.voice_annotation}}</div>{{/audio}}'
   231     + '{{#audio}}<div class="Ldt-AnnotationsList-Play" data-annotation-id="{{id}}">{{l10n.voice_annotation}}</div>{{/audio}}'    
   134     + '</li>';
   232     + '</li>';
   135 
   233 
   136 // obj.url = this.project_url + "/" + media + "/" + annotations[i].meta.project
   234 // obj.url = this.project_url + "/" + media + "/" + annotations[i].meta.project
   137 // + "/" + annotations[i].meta["id-ref"] + '#id=' + annotations[i].id;
   235 // + "/" + annotations[i].meta["id-ref"] + '#id=' + annotations[i].id;
   138 
   236 
   147     });
   245     });
   148     this.currentSource = this.player.loadMetadata(IriSP._.defaults({
   246     this.currentSource = this.player.loadMetadata(IriSP._.defaults({
   149         "url" : _url
   247         "url" : _url
   150     }, this.metadata));
   248     }, this.metadata));
   151 };
   249 };
       
   250 
       
   251 IriSP.Widgets.AnnotationsList.prototype.showScreen = function(_screenName) {
       
   252     this.$.find('.Ldt-AnnotationsList-Screen' + _screenName).show()
       
   253         .siblings().hide();
       
   254 }
   152 
   255 
   153 IriSP.Widgets.AnnotationsList.prototype.ajaxMashup = function() {
   256 IriSP.Widgets.AnnotationsList.prototype.ajaxMashup = function() {
   154     var _currentTime = this.media.getCurrentTime();
   257     var _currentTime = this.media.getCurrentTime();
   155     var _currentAnnotation = this.source.currentMedia.getAnnotationAtTime(_currentTime);
   258     var _currentAnnotation = this.source.currentMedia.getAnnotationAtTime(_currentTime);
   156     if (typeof _currentAnnotation !== "undefined" && _currentAnnotation.id !== this.lastMashupAnnotation) {
   259     if (typeof _currentAnnotation !== "undefined" && _currentAnnotation.id !== this.lastMashupAnnotation) {
   187     }
   290     }
   188     _list = _list.filter(function(_annotation) {
   291     _list = _list.filter(function(_annotation) {
   189         return _annotation.found !== false;
   292         return _annotation.found !== false;
   190     });
   293     });
   191     
   294     
   192     if ((this.filter_by_segments)&&(!(this.show_filters && this.ignoresegmentcheckbox_$[0].checked))) {
   295     if ((this.filter_by_segments)&&(!(this.show_filters && this.segment_filter && this.ignoresegmentcheckbox_$[0].checked))) {
   193         /*
   296         /*
   194          *  A given annotation is considered "in" segment if the middle of it is between the segment beginning and the segment end. 
   297          *  A given annotation is considered "in" segment if the middle of it is between the segment beginning and the segment end. 
   195          *  Note this is meant to be used for "markings" annotations (not segments)
   298          *  Note this is meant to be used for "markings" annotations (not segments)
   196          */
   299          */
   197         _segmentsAnnotation = this.currentSource.getAnnotationsByTypeTitle(this.segments_annotation_type)
   300         _segmentsAnnotation = this.currentSource.getAnnotationsByTypeTitle(this.segments_annotation_type)
   214             _list = _list.filter(function(_annotation){
   317             _list = _list.filter(function(_annotation){
   215                 _annotation_time = (_annotation.begin+_annotation.end)/2;
   318                 _annotation_time = (_annotation.begin+_annotation.end)/2;
   216                 return (_currentSegments[0].begin <= _annotation_time && _currentSegments[0].end >= _annotation_time)
   319                 return (_currentSegments[0].begin <= _annotation_time && _currentSegments[0].end >= _annotation_time)
   217             });
   320             });
   218         }
   321         }
       
   322         if(this.annotations_count_header && this.annotations_count != _list.length){
       
   323             this.annotations_count = _list.length;
       
   324             this.refreshHeader();
       
   325         }
   219     }
   326     }
   220     if (this.show_only_annotation_from_user){
   327     if (this.show_only_annotation_from_user){
   221         _list = _list.filter(function(_annotation){
   328         _list = _list.filter(function(_annotation){
   222            return _annotation.creator == _this.show_only_annotation_from_user;
   329            return _annotation.creator == _this.show_only_annotation_from_user;
   223         });
   330         });
   238             return _annotation.begin;
   345             return _annotation.begin;
   239         });
   346         });
   240     }
   347     }
   241     
   348     
   242     if (this.show_filters){
   349     if (this.show_filters){
   243         _username = this.userselect_$[0].options[this.userselect_$[0].selectedIndex].value;
   350         if (this.user_filter){
   244         if (_username != "false")
   351             _username = this.userselect_$[0].options[this.userselect_$[0].selectedIndex].value;
   245         {
   352             if (_username != "false")
   246             _list = _list.filter(function(_annotation){
   353             {
   247                 return _annotation.creator == _username
   354                 _list = _list.filter(function(_annotation){
   248             })
   355                     return _annotation.creator == _username
   249         }
   356                 })
       
   357             }
       
   358         }
       
   359         if (this.keyword_filter){
   250         _keyword = this.keywordinput_$[0].value;
   360         _keyword = this.keywordinput_$[0].value;
   251         if (_keyword != ""){
   361             if (_keyword != ""){
   252             _list = _list.filter(function(_annotation){
   362                 _list = _list.filter(function(_annotation){
   253                return _annotation.description.toLowerCase().match(_keyword.toLowerCase());
   363                    return _annotation.description.toLowerCase().match(_keyword.toLowerCase());
   254             });
   364                 });
   255         }
   365             }
   256         
   366         }
   257         
   367         if (this.date_filter){
   258         if(this.datefilterinput_$[0].value != ""){
   368             if(this.datefilterinput_$[0].value != ""){
   259             _date = this.datefilterinput_$.datepicker("getDate");
   369                 _date = this.datefilterinput_$.datepicker("getDate");
   260             _list = _list.filter(function(_annotation){
   370                 _list = _list.filter(function(_annotation){
   261                 return ((_annotation.created.getDate() == _date.getDate())&&(_annotation.created.getMonth() == _date.getMonth())&&(_annotation.created.getFullYear() == _date.getFullYear()))
   371                     return ((_annotation.created.getDate() == _date.getDate())&&(_annotation.created.getMonth() == _date.getMonth())&&(_annotation.created.getFullYear() == _date.getFullYear()));
       
   372                 });
       
   373             }
       
   374         }
       
   375         if (this.latest_contributions_filter && this.latestcontributionscheckbox_$[0].checked){
       
   376             _list = _list.sortBy(function(_annotation) {
       
   377                 return -_annotation.created.valueOf();
       
   378             });
       
   379             this.usernames.forEach(function(_user){
       
   380                 
       
   381                 latest_ann = _list.filter(function(_annotation){
       
   382                     return _annotation.creator == _user;
       
   383                 })[0];
       
   384                 _list = _list.filter(function(_annotation){
       
   385                     return _annotation.id == (latest_ann ? latest_ann.id : false) || _annotation.creator != _user;
       
   386                 });
   262             });
   387             });
   263         }
   388         }
   264         
   389         
   265     }
   390     }
   266     
   391     
   293                 _description = _annotation.description,
   418                 _description = _annotation.description,
   294                 _thumbnail = (typeof _annotation.thumbnail !== "undefined" && _annotation.thumbnail ? _annotation.thumbnail : _this.default_thumbnail)
   419                 _thumbnail = (typeof _annotation.thumbnail !== "undefined" && _annotation.thumbnail ? _annotation.thumbnail : _this.default_thumbnail)
   295             
   420             
   296             // Update : display creator
   421             // Update : display creator
   297             if (_annotation.creator) {
   422             if (_annotation.creator) {
   298                 _title = _annotation.creator;
   423                 var _users = _this.source.users_data.filter(function(_user_data){
       
   424                     return _user_data.username == _annotation.creator
       
   425                 }),
       
   426                     _user = {};
       
   427                 if (_users.length == 0){
       
   428                     _user.username = _annotation.creator
       
   429                 }
       
   430                 else{
       
   431                     _user = _users[0]
       
   432                 }
       
   433                 _title = _this.make_name_string_function(_user);
   299             }
   434             }
   300             if (_annotation.title) {
   435             if (_annotation.title) {
   301                 var tempTitle = _annotation.title;
   436                 var tempTitle = _annotation.title;
   302                 if( tempTitle.substr(0, _title.length + 1) == (_title + ":") ){
   437                 if( tempTitle.substr(0, _title.length + 1) == (_title + ":") ){
   303                     _title = "";
   438                     _title = "";
   332                 show_timecode : _this.show_timecode,
   467                 show_timecode : _this.show_timecode,
   333                 thumbnail : _thumbnail,
   468                 thumbnail : _thumbnail,
   334                 url : _url,
   469                 url : _url,
   335                 tags : _tags,
   470                 tags : _tags,
   336                 specific_style : (typeof _bgcolor !== "undefined" ? "background-color: " + _bgcolor : ""),
   471                 specific_style : (typeof _bgcolor !== "undefined" ? "background-color: " + _bgcolor : ""),
   337                 l10n: _this.l10n
   472                 l10n: _this.l10n,
       
   473                 allow_annotations_deletion: _this.allow_annotations_deletion
   338             };
   474             };
   339             if (_this.show_audio && _annotation.audio && _annotation.audio.href && _annotation.audio.href != "null") {
   475             if (_this.show_audio && _annotation.audio && _annotation.audio.href && _annotation.audio.href != "null") {
   340                 _data.audio = true;
   476                 _data.audio = true;
   341                 if (!_this.jwplayers[_annotation.id]) {
   477                 if (!_this.jwplayers[_annotation.id]) {
   342                     var _audiofile = _annotation.audio.href;
   478                     var _audiofile = _annotation.audio.href;
   424             this.$.find(".Ldt-AnnotationsList-Title a, .Ldt-AnnotationsList-Description").each(function() {
   560             this.$.find(".Ldt-AnnotationsList-Title a, .Ldt-AnnotationsList-Description").each(function() {
   425                 var _$ = IriSP.jQuery(this);
   561                 var _$ = IriSP.jQuery(this);
   426                 _$.html(IriSP.textFieldHtml(_$.text(), rx));
   562                 _$.html(IriSP.textFieldHtml(_$.text(), rx));
   427             });
   563             });
   428         }
   564         }
       
   565 
       
   566         this.$.find(".Ldt-AnnotationsList-DeleteButton").click(_this.functionWrapper("onDeleteClick"))
   429     }
   567     }
   430     
   568     
   431     if (this.ajax_url) {
   569     if (this.ajax_url) {
   432         if (this.mashupMode) {
   570         if (this.mashupMode) {
   433             this.ajaxMashup();
   571             this.ajaxMashup();
   438         }
   576         }
   439     }
   577     }
   440     
   578     
   441     return _list.length;
   579     return _list.length;
   442 };
   580 };
       
   581 
       
   582 IriSP.Widgets.AnnotationsList.prototype.onDeleteClick = function(event){
       
   583     
       
   584     ann_id = event.target.id;
       
   585     console.log(ann_id)
       
   586     delete_preview_$ = this.$.find(".Ldt-AnnotationsList-ul-ToDelete");
       
   587     delete_preview_$.html("");
       
   588     _list = this.getWidgetAnnotations()
       
   589     _list = _list.filter(function(_annotation){
       
   590         return _annotation.id == ann_id
       
   591     })
       
   592     var _annotation = _list[0],
       
   593         _title = "",
       
   594         _this = this;
       
   595     console.log(_annotation)
       
   596     if (_annotation.creator) {
       
   597         var _users = _this.source.users_data.filter(function(_user_data){
       
   598             return _user_data.username == _annotation.creator
       
   599         }),
       
   600             _user = {};
       
   601         if (_users.length == 0){
       
   602             _user.username = _annotation.creator
       
   603         }
       
   604         else{
       
   605             _user = _users[0]
       
   606         }
       
   607         _title = _this.make_name_string_function(_user);
       
   608     }
       
   609     if (_annotation.title) {
       
   610         var tempTitle = _annotation.title;
       
   611         if( tempTitle.substr(0, _title.length + 1) == (_title + ":") ){
       
   612             _title = "";
       
   613         }
       
   614         _title = _title + ( (_title=="") ? "" : ": ") + _annotation.title;
       
   615     }
       
   616     var _created = false;
       
   617     if (this.show_creation_date) {
       
   618         _created = _annotation.created.toLocaleDateString()+", "+_annotation.created.toLocaleTimeString();
       
   619     }
       
   620     var _data = {
       
   621             id : _annotation.id,
       
   622             media_id : _annotation.getMedia().id,
       
   623             htitle : IriSP.textFieldHtml(_title),
       
   624             hdescription : IriSP.textFieldHtml(_annotation.description),
       
   625             begin : _annotation.begin.toString(),
       
   626             end : _annotation.end.toString(),
       
   627             created : _created,
       
   628             show_timecode : this.show_timecode,
       
   629             tags : false,
       
   630             l10n: this.l10n,
       
   631             allow_annotations_deletion: false
       
   632     }
       
   633     _html = Mustache.to_html(this.annotationTemplate, _data)
       
   634     delete_preview_$.html(_html)
       
   635     
       
   636     this.$.find(".Ldt-AnnotationsList-ConfirmDelete").click(function(){
       
   637         _this.sendDelete(ann_id);
       
   638     });
       
   639     
       
   640     this.showScreen("Delete");    
       
   641 }
       
   642 
       
   643 IriSP.Widgets.AnnotationsList.prototype.refreshHeader = function() {
       
   644     var annotation_count_string = " (" + this.annotations_count +" annotations)";
       
   645     this.$.find('.Ldt-AnnotationsList-header').html("");
       
   646     this.$.find('.Ldt-AnnotationsList-header').html(
       
   647         this.custom_header && typeof this.custom_header == "string"? this.custom_header + annotation_count_string : this.l10n.header + annotation_count_string
       
   648     );
       
   649 }
   443 
   650 
   444 IriSP.Widgets.AnnotationsList.prototype.hide = function() {
   651 IriSP.Widgets.AnnotationsList.prototype.hide = function() {
   445     var _this = this;
   652     var _this = this;
   446     if (this.visible){
   653     if (this.visible){
   447         this.visible = false;
   654         this.visible = false;
   448         this.widget_$.slideUp(function(){
   655         this.widget_$.slideUp(function(){
   449             _this.$.find('.Ldt-AnnotationsList-header').hide();            
   656             _this.$.find('.Ldt-AnnotationsList-header').hide();            
   450         });
   657         });
       
   658         this.showScreen("Main")
   451     }
   659     }
   452 }
   660 }
   453 
   661 
   454 IriSP.Widgets.AnnotationsList.prototype.show = function() {
   662 IriSP.Widgets.AnnotationsList.prototype.show = function() {
   455     if(!this.visible){
   663     if(!this.visible){
   456         this.visible = true;
   664         this.visible = true;
   457         this.$.find('.Ldt-AnnotationsList-header').show();
   665         this.$.find('.Ldt-AnnotationsList-header').show();
   458         this.widget_$.slideDown();
   666         this.widget_$.slideDown();
       
   667         this.showScreen("Main")
   459     }
   668     }
   460 }
   669 }
   461 
   670 
   462 
   671 
   463 IriSP.Widgets.AnnotationsList.prototype.toggle = function() {
   672 IriSP.Widgets.AnnotationsList.prototype.toggle = function() {
   468             this.show();
   677             this.show();
   469         }
   678         }
   470     }
   679     }
   471 };
   680 };
   472 
   681 
       
   682 IriSP.Widgets.AnnotationsList.prototype.revertToMainScreen = function(){
       
   683     if (this.$.find(".Ldt-AnnotationsList-ScreenMain").is(":hidden")){
       
   684         this.showScreen("Main");
       
   685     }
       
   686 }
       
   687 
       
   688 IriSP.Widgets.AnnotationsList.prototype.sendDelete = function(id){
       
   689     console.log("deleting "+id)
       
   690     var _this = this,
       
   691         _url = Mustache.to_html(this.api_delete_endpoint, {annotation_id: id})
       
   692     
       
   693     IriSP.jQuery.ajax({
       
   694         url: _url,
       
   695         type: this.api_delete_method,
       
   696         contentType: 'application/json',
       
   697         success: function(_data) {
       
   698             _this.showScreen('Success');
       
   699             window.setTimeout(_this.functionWrapper("revertToMainScreen"),(_this.after_send_timeout || 2000));
       
   700             _this.currentSource.getAnnotations().removeId(id);
       
   701             _this.player.trigger("AnnotationsList.refresh");
       
   702         },
       
   703         error: function(_xhr, _error, _thrown) {
       
   704             IriSP.log("Error when sending annotation", _thrown);
       
   705             _this.showScreen('Error');
       
   706             window.setTimeout(_this.functionWrapper("revertToMainScreen"),(_this.after_send_timeout || 2000));
       
   707         }
       
   708     });
       
   709     this.showScreen('Sending');
       
   710 }
       
   711 
   473 IriSP.Widgets.AnnotationsList.prototype.draw = function() {
   712 IriSP.Widgets.AnnotationsList.prototype.draw = function() {
   474     
       
   475     this.jwplayers = {};
   713     this.jwplayers = {};
   476     this.mashupMode = (this.media.elementType === "mashup");
   714     this.mashupMode = (this.media.elementType === "mashup");
   477     
   715     
   478     this.renderTemplate();
   716     this.renderTemplate();
   479     
   717     
   480     var _this = this;
   718     var _this = this;
   481         
   719     
   482     this.list_$ = this.$.find(".Ldt-AnnotationsList-ul");
   720     this.list_$ = this.$.find(".Ldt-AnnotationsList-ul");
   483     this.widget_$ = this.$.find(".Ldt-AnnotationsListWidget");
   721     this.widget_$ = this.$.find(".Ldt-AnnotationsListWidget");
   484     this.userselect_$ = this.$.find("#Ldt-AnnotationsList-userFilter");
   722     
   485     this.userselect_$.change(function(){
   723     if (this.show_filters){
   486         _this.player.trigger("AnnotationsList.refresh");
   724         if (this.user_filter){
   487     });
   725             this.userselect_$ = this.$.find("#Ldt-AnnotationsList-userFilter");
   488     this.keywordinput_$ = this.$.find("#Ldt-AnnotationsList-keywordsFilter");
   726             this.userselect_$.change(function(){
   489     this.keywordinput_$.keyup(function(){
   727                 _this.player.trigger("AnnotationsList.refresh");
   490         _this.player.trigger("AnnotationsList.refresh");
   728             });
   491     });
   729             this.userselect_$.html("<option selected value='false'>"+this.l10n.everyone+"</option>");
   492     this.ignoresegmentcheckbox_$ = this.$.find("#Ldt-AnnotationsList-ignoreSegmentsFilter");
   730             this.usernames.forEach(function(_user){
   493     this.ignoresegmentcheckbox_$.click(function(){
   731                 _this.userselect_$.append("<option value='"+_user+"'>"+_user+"</option>");
   494         _this.player.trigger("AnnotationsList.refresh");
   732             });
   495     });
   733         }
   496     this.datefilterinput_$ = this.$.find("#Ldt-AnnotationsList-dateFilter");
   734         if (this.keyword_filter){
   497     this.datefilterinput_$.datepicker({ dateFormat: 'dd/mm/yy' });
   735             this.keywordinput_$ = this.$.find("#Ldt-AnnotationsList-keywordsFilter");
   498     this.datefilterinput_$.change(function(){
   736             this.keywordinput_$.keyup(function(){
   499         _this.player.trigger("AnnotationsList.refresh")
   737                 _this.player.trigger("AnnotationsList.refresh");
   500     })
   738             });
       
   739             
       
   740         }
       
   741         if (this.segment_filter){
       
   742             this.ignoresegmentcheckbox_$ = this.$.find("#Ldt-AnnotationsList-ignoreSegmentsFilter");
       
   743             this.ignoresegmentcheckbox_$.click(function(){
       
   744                 _this.player.trigger("AnnotationsList.refresh");
       
   745             });
       
   746         }
       
   747         if(this.date_filter){
       
   748             this.datefilterinput_$ = this.$.find("#Ldt-AnnotationsList-dateFilter");
       
   749             this.datefilterinput_$.datepicker({ dateFormat: 'dd/mm/yy' });
       
   750             this.datefilterinput_$.change(function(){
       
   751                 _this.player.trigger("AnnotationsList.refresh")
       
   752             })
       
   753             if (this.current_day_filter){
       
   754                 currentDate = new Date();
       
   755                 this.datefilterinput_$.datepicker("setDate",currentDate);
       
   756             }
       
   757         }
       
   758         if(this.latest_contributions_filter){
       
   759             this.latestcontributionscheckbox_$ = this.$.find("#Ldt-AnnotationsList-latestContributionsFilter");
       
   760             this.latestcontributionscheckbox_$.click(function(){
       
   761                 _this.player.trigger("AnnotationsList.refresh");
       
   762             });
       
   763         }
       
   764     }
   501     
   765     
   502     this.source.getAnnotations().on("search", function(_text) {
   766     this.source.getAnnotations().on("search", function(_text) {
   503         _this.searchString = _text;
   767         _this.searchString = _text;
   504         if (_this.source !== _this.currentSource) {
   768         if (_this.source !== _this.currentSource) {
   505             _this.currentSource.getAnnotations().search(_text);
   769             _this.currentSource.getAnnotations().search(_text);
   516         _this.searchString = false;
   780         _this.searchString = false;
   517         if (_this.source !== _this.currentSource) {
   781         if (_this.source !== _this.currentSource) {
   518             _this.currentSource.getAnnotations().trigger("clear-search");
   782             _this.currentSource.getAnnotations().trigger("clear-search");
   519         }
   783         }
   520     });
   784     });
       
   785     
       
   786     this.$.find(".Ldt-AnnotationsList-Close").click(function(){
       
   787         _this.showScreen("Main");
       
   788     })
       
   789     
   521     this.source.getAnnotations().on("search-cleared", function() {
   790     this.source.getAnnotations().on("search-cleared", function() {
   522         _this.throttledRefresh();
   791         _this.throttledRefresh();
   523     });
   792     });
   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     }
       
   538     
   793     
   539     this.onMdpEvent("AnnotationsList.refresh", function() {
   794     this.onMdpEvent("AnnotationsList.refresh", function() {
   540         if (_this.ajax_url) {
   795         if (_this.ajax_url) {
   541             if (_this.mashupMode) {
   796             if (_this.mashupMode) {
   542                 _this.ajaxMashup();
   797                 _this.ajaxMashup();
   559     
   814     
   560     if (this.refresh_interval) {
   815     if (this.refresh_interval) {
   561         window.setInterval(function() {
   816         window.setInterval(function() {
   562             _this.currentSource.get();
   817             _this.currentSource.get();
   563         }, this.refresh_interval);
   818         }, this.refresh_interval);
       
   819     }
       
   820     
       
   821     if (this.annotations_count_header){
       
   822         this.annotations_count = false;
   564     }
   823     }
   565     
   824     
   566     this.onMdpEvent("AnnotationsList.toggle","toggle");
   825     this.onMdpEvent("AnnotationsList.toggle","toggle");
   567     this.onMdpEvent("AnnotationsList.hide", "hide");
   826     this.onMdpEvent("AnnotationsList.hide", "hide");
   568     this.onMdpEvent("AnnotationsList.show", "show");
   827     this.onMdpEvent("AnnotationsList.show", "show");
   578         this.onMediaEvent(_events[_i], this.throttledRefresh);
   837         this.onMediaEvent(_events[_i], this.throttledRefresh);
   579     }
   838     }
   580     
   839     
   581     this.throttledRefresh();
   840     this.throttledRefresh();
   582     
   841     
       
   842     this.showScreen("Main");
       
   843     this.$.find(".Ldt-AnnotationsList-CancelDelete").click(function(){
       
   844         _this.showScreen("Main")
       
   845     });
       
   846     
   583     this.visible = true;
   847     this.visible = true;
   584     if (!this.start_visible){
   848     if (!this.start_visible){
   585         this.hide();
   849         this.hide();
   586     }
   850     }
   587     
       
   588 };
   851 };