src/widgets/AnnotationsList.js
author veltr
Wed, 19 Sep 2012 14:59:35 +0900
changeset 963 d58d0dcdb640
parent 959 ee11ed1b739e
child 965 eadb7290c325
permissions -rw-r--r--
Bugfixes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
875
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
     1
IriSP.Widgets.AnnotationsList = function(player, config) {
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
     2
    IriSP.Widgets.Widget.call(this, player, config);
870
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 852
diff changeset
     3
    this.searchString = false;
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 852
diff changeset
     4
    this.lastIds = [];
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 852
diff changeset
     5
    var _this = this;
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 852
diff changeset
     6
    this.throttledRefresh = IriSP._.throttle(function() {
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 852
diff changeset
     7
        _this.refresh(false);
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 852
diff changeset
     8
    }, 1500);
585
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
     9
};
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
    10
875
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
    11
IriSP.Widgets.AnnotationsList.prototype = new IriSP.Widgets.Widget();
585
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
    12
875
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
    13
IriSP.Widgets.AnnotationsList.prototype.defaults = {
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
    14
    /* URL when the annotations are to be reloaded from an LDT-like segment API
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
    15
     * e.g. http://ldt.iri.centrepompidou.fr/ldtplatform/api/ldt/segments/{{media}}/{{begin}}/{{end}}?callback=?
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
    16
     */
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
    17
    ajax_url : false,
909
aa0e42229784 Started reworking on documentation
veltr
parents: 908
diff changeset
    18
    /* number of milliseconds before/after the current timecode when calling the segment API
875
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
    19
     */
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
    20
    ajax_granularity : 300000, 
925
28efc97b5d78 Corrected MAJOR bug in search results
veltr
parents: 924
diff changeset
    21
    default_thumbnail : "",
875
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
    22
    /* URL when the annotation is not in the current project,
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
    23
     * e.g. http://ldt.iri.centrepompidou.fr/ldtplatform/ldt/front/player/{{media}}/{{project}}/{{annotationType}}#id={{annotation}}
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
    24
     */
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
    25
    foreign_url : "",
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
    26
    annotation_type : false,
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
    27
    refresh_interval : 0,
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
    28
    limit_count : 10,
924
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents: 923
diff changeset
    29
    newest_first : false,
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents: 923
diff changeset
    30
    polemics : [{
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents: 923
diff changeset
    31
        keyword: "++",
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents: 923
diff changeset
    32
        background_color: "#c9ecc6"
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents: 923
diff changeset
    33
    },{
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents: 923
diff changeset
    34
        keyword: "--",
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents: 923
diff changeset
    35
        background_color: "#f9c5c6"
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents: 923
diff changeset
    36
    },{
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents: 923
diff changeset
    37
        keyword: "??",
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents: 923
diff changeset
    38
        background_color: "#cec5f9"
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents: 923
diff changeset
    39
    },{
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents: 923
diff changeset
    40
        keyword: "==",
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents: 923
diff changeset
    41
        background_color: "#f9f4c6"
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents: 923
diff changeset
    42
    }]
585
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
    43
};
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
    44
875
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
    45
IriSP.Widgets.AnnotationsList.prototype.template =
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
    46
    '<div class="Ldt-AnnotationsListWidget">'
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
    47
    + '<ul class="Ldt-AnnotationsList-ul">'
937
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
    48
    + '</ul>'
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
    49
    + '</div>';
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
    50
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
    51
IriSP.Widgets.AnnotationsList.prototype.annotationTemplate = 
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
    52
    '<li class="Ldt-AnnotationsList-li Ldt-TraceMe" trace-info="annotation-id:{{id}}, media-id:{{media_id}}" style="{{specific_style}}">'
875
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
    53
    + '<div class="Ldt-AnnotationsList-ThumbContainer">'
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
    54
    + '<a href="{{url}}">'
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
    55
    + '<img class="Ldt-AnnotationsList-Thumbnail" src="{{thumbnail}}" />'
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
    56
    + '</a>'
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
    57
    + '</div>'
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
    58
    + '<div class="Ldt-AnnotationsList-Duration">{{begin}} - {{end}}</div>'
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
    59
    + '<h3 class="Ldt-AnnotationsList-Title">'
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
    60
    + '<a href="{{url}}">{{title}}</a>'
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
    61
    + '</h3>'
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
    62
    + '<p class="Ldt-AnnotationsList-Description">{{description}}</p>'
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
    63
    + '{{#tags.length}}'
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
    64
    + '<ul class="Ldt-AnnotationsList-Tags">'
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
    65
    + '{{#tags}}'
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
    66
    + '{{#.}}'
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
    67
    + '<li class="Ldt-AnnotationsList-Tag-Li">'
902
14022f1d49ab Added MediaList widget for mashup
veltr
parents: 876
diff changeset
    68
    + '<span>{{.}}</span>'
875
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
    69
    + '</li>'
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
    70
    + '{{/.}}'
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
    71
    + '{{/tags}}'
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
    72
    + '</ul>'
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
    73
    + '{{/tags.length}}'
937
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
    74
    + '</li>';
875
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
    75
876
03967b6ada7c ArrowWidget, AnnotationWidget
veltr
parents: 875
diff changeset
    76
IriSP.Widgets.AnnotationsList.prototype.onSearch = function(searchString) {
870
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 852
diff changeset
    77
    this.searchString = typeof searchString !== "undefined" ? searchString : '';
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 852
diff changeset
    78
    var _n = this.refresh(true);
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 852
diff changeset
    79
    if (this.searchString) {
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 852
diff changeset
    80
        if (_n) {
957
4da0a5740b6c Starting 'players-as-widgets' branch
veltr
parents: 944
diff changeset
    81
            this.player.trigger("search.matchFound");
870
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 852
diff changeset
    82
        } else {
957
4da0a5740b6c Starting 'players-as-widgets' branch
veltr
parents: 944
diff changeset
    83
            this.player.trigger("search.noMatchFound");
870
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 852
diff changeset
    84
        }
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 852
diff changeset
    85
    }
838
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 836
diff changeset
    86
}
870
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 852
diff changeset
    87
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
    88
//obj.url = this.project_url + "/" + media + "/" + annotations[i].meta.project + "/" + annotations[i].meta["id-ref"] + '#id=' + annotations[i].id;
870
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 852
diff changeset
    89
875
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
    90
IriSP.Widgets.AnnotationsList.prototype.ajaxSource = function() {
957
4da0a5740b6c Starting 'players-as-widgets' branch
veltr
parents: 944
diff changeset
    91
    var _currentTime = this.media.getCurrentTime(),
4da0a5740b6c Starting 'players-as-widgets' branch
veltr
parents: 944
diff changeset
    92
        _duration = this.media.duration;
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
    93
    this.lastAjaxQuery = _currentTime;
870
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 852
diff changeset
    94
    var _url = Mustache.to_html(this.ajax_url, {
916
ec6849bbbdcc Removed Namespacing before rewrite
veltr
parents: 909
diff changeset
    95
        media : this.source.currentMedia.id,
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
    96
        begin : Math.max(0, _currentTime - this.ajax_granularity),
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
    97
        end : Math.min(_duration.milliseconds, _currentTime + this.ajax_granularity)
870
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 852
diff changeset
    98
    });
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
    99
    this.currentSource = this.player.loadMetadata(IriSP._.defaults({
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   100
        "url" : _url
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   101
    }, this.metadata));
870
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 852
diff changeset
   102
}
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 852
diff changeset
   103
903
d9da52e20f7f AnnotationsList now updated to work with mashups
veltr
parents: 902
diff changeset
   104
IriSP.Widgets.AnnotationsList.prototype.ajaxMashup = function() {
957
4da0a5740b6c Starting 'players-as-widgets' branch
veltr
parents: 944
diff changeset
   105
    var _currentTime = this.media.getCurrentTime();
4da0a5740b6c Starting 'players-as-widgets' branch
veltr
parents: 944
diff changeset
   106
    var _currentAnnotation = this.source.currentMedia.getAnnotationAtTime(_currentTime);
916
ec6849bbbdcc Removed Namespacing before rewrite
veltr
parents: 909
diff changeset
   107
    if (typeof _currentAnnotation !== "undefined" && _currentAnnotation.id !== this.lastMashupAnnotation) {
ec6849bbbdcc Removed Namespacing before rewrite
veltr
parents: 909
diff changeset
   108
        this.lastMashupAnnotation = _currentAnnotation.id;
903
d9da52e20f7f AnnotationsList now updated to work with mashups
veltr
parents: 902
diff changeset
   109
        var _currentMedia = _currentAnnotation.getMedia(),
d9da52e20f7f AnnotationsList now updated to work with mashups
veltr
parents: 902
diff changeset
   110
            _url = Mustache.to_html(this.ajax_url, {
916
ec6849bbbdcc Removed Namespacing before rewrite
veltr
parents: 909
diff changeset
   111
                media : _currentMedia.id,
903
d9da52e20f7f AnnotationsList now updated to work with mashups
veltr
parents: 902
diff changeset
   112
                begin : Math.max(0, _currentAnnotation.annotation.begin.milliseconds - this.ajax_granularity),
d9da52e20f7f AnnotationsList now updated to work with mashups
veltr
parents: 902
diff changeset
   113
                end : Math.min(_currentMedia.duration.milliseconds, _currentAnnotation.annotation.end.milliseconds + this.ajax_granularity)
d9da52e20f7f AnnotationsList now updated to work with mashups
veltr
parents: 902
diff changeset
   114
            });
d9da52e20f7f AnnotationsList now updated to work with mashups
veltr
parents: 902
diff changeset
   115
        this.currentSource = this.player.loadMetadata(IriSP._.defaults({
d9da52e20f7f AnnotationsList now updated to work with mashups
veltr
parents: 902
diff changeset
   116
            "url" : _url
d9da52e20f7f AnnotationsList now updated to work with mashups
veltr
parents: 902
diff changeset
   117
        }, this.metadata));
d9da52e20f7f AnnotationsList now updated to work with mashups
veltr
parents: 902
diff changeset
   118
    }
d9da52e20f7f AnnotationsList now updated to work with mashups
veltr
parents: 902
diff changeset
   119
}
d9da52e20f7f AnnotationsList now updated to work with mashups
veltr
parents: 902
diff changeset
   120
875
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
   121
IriSP.Widgets.AnnotationsList.prototype.refresh = function(_forceRedraw) {
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   122
    _forceRedraw = (typeof _forceRedraw !== "undefined" && _forceRedraw);
870
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 852
diff changeset
   123
    if (this.currentSource.status !== IriSP.Model._SOURCE_STATUS_READY) {
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 852
diff changeset
   124
        return 0;
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 852
diff changeset
   125
    }
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 852
diff changeset
   126
    var _this = this,
957
4da0a5740b6c Starting 'players-as-widgets' branch
veltr
parents: 944
diff changeset
   127
        _currentTime = this.media.getCurrentTime();
903
d9da52e20f7f AnnotationsList now updated to work with mashups
veltr
parents: 902
diff changeset
   128
    var _list = this.annotation_type ? this.currentSource.getAnnotationsByTypeTitle(this.annotation_type) : this.currentSource.getAnnotations();
d9da52e20f7f AnnotationsList now updated to work with mashups
veltr
parents: 902
diff changeset
   129
    if (this.mashupMode) {
957
4da0a5740b6c Starting 'players-as-widgets' branch
veltr
parents: 944
diff changeset
   130
        var _currentAnnotation = this.source.currentMedia.getAnnotationAtTime(_currentTime);
903
d9da52e20f7f AnnotationsList now updated to work with mashups
veltr
parents: 902
diff changeset
   131
        if (typeof _currentAnnotation !== "undefined") {
d9da52e20f7f AnnotationsList now updated to work with mashups
veltr
parents: 902
diff changeset
   132
            _currentTime = _currentTime - _currentAnnotation.begin.getSeconds() + _currentAnnotation.annotation.begin.getSeconds();
916
ec6849bbbdcc Removed Namespacing before rewrite
veltr
parents: 909
diff changeset
   133
            var _mediaId = _currentAnnotation.getMedia().id;
903
d9da52e20f7f AnnotationsList now updated to work with mashups
veltr
parents: 902
diff changeset
   134
            _list = _list.filter(function(_annotation) {
916
ec6849bbbdcc Removed Namespacing before rewrite
veltr
parents: 909
diff changeset
   135
                return _annotation.getMedia().id === _mediaId;
903
d9da52e20f7f AnnotationsList now updated to work with mashups
veltr
parents: 902
diff changeset
   136
            });
d9da52e20f7f AnnotationsList now updated to work with mashups
veltr
parents: 902
diff changeset
   137
        }
d9da52e20f7f AnnotationsList now updated to work with mashups
veltr
parents: 902
diff changeset
   138
    }
870
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 852
diff changeset
   139
    if (this.searchString) {
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 852
diff changeset
   140
        _list = _list.searchByTextFields(this.searchString);
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 852
diff changeset
   141
    }
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 852
diff changeset
   142
    if (this.limit_count) {
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 852
diff changeset
   143
        _list = _list.sortBy(function(_annotation) {
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 852
diff changeset
   144
            return Math.abs(_annotation.begin.getSeconds() - _currentTime);
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 852
diff changeset
   145
        }).slice(0, this.limit_count)
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 852
diff changeset
   146
    }
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 852
diff changeset
   147
    if (this.newest_first) {
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 852
diff changeset
   148
        _list = _list.sortBy(function(_annotation) {
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 852
diff changeset
   149
            return -_annotation.created.valueOf();
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 852
diff changeset
   150
        });
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 852
diff changeset
   151
    } else {
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 852
diff changeset
   152
        _list = _list.sortBy(function(_annotation) {
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   153
            return _annotation.begin;
870
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 852
diff changeset
   154
        });
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 852
diff changeset
   155
    }
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 852
diff changeset
   156
    
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   157
    var _ids = _list.idIndex;
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   158
    
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   159
    if (_forceRedraw || !IriSP._.isEqual(_ids, this.lastIds)) {
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   160
        /* This part only gets executed if the list needs updating */
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   161
        this.lastIds = _ids;
937
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   162
        this.list_$.html("");
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   163
        _list.forEach(function(_annotation) {
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   164
            var _url = (
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   165
                ( typeof _annotation.url !== "undefined" && _annotation.url)
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   166
                ? _annotation.url
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   167
                : (
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   168
                    ( typeof _this.source.projectId !== "undefined" && typeof _annotation.project !== "undefined" && _annotation.project && _this.source.projectId !== _annotation.project )
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   169
                    ? Mustache.to_html(
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   170
                        _this.foreign_url,
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   171
                        {
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   172
                            project : _annotation.project,
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   173
                            media : _annotation.media.id,
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   174
                            annotation : _annotation.id,
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   175
                            annotationType : _annotation.annotationType.id
924
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents: 923
diff changeset
   176
                        }
937
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   177
                    )
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   178
                    : '#id=' + _annotation.id
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   179
                    )
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   180
            );
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   181
            var _title = (_annotation.title || "").replace(_annotation.description,''),
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   182
                _description = _annotation.description;
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   183
            if (!_annotation.title) {
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   184
                _title = _annotation.creator;
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   185
            }
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   186
            if (!_annotation.description && _annotation.creator) {
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   187
                _description = _annotation.title;
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   188
                _title = _annotation.creator;
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   189
            }
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   190
            var _bgcolor;
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   191
            IriSP._(_this.polemics).each(function(_polemic) {
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   192
                var _rgxp = IriSP.Model.regexpFromTextOrArray(_polemic.keyword, true);
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   193
                if (_rgxp.test(_title + " " + _description)) {
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   194
                    _bgcolor = _polemic.background_color;
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   195
                }
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   196
            });
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   197
            var _data = {
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   198
                id : _annotation.id,
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   199
                media_id : _annotation.getMedia().id,
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   200
                title : _title,
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   201
                description : _description,
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   202
                begin : _annotation.begin.toString(),
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   203
                end : _annotation.end.toString(),
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   204
                thumbnail : typeof _annotation.thumbnail !== "undefined" && _annotation.thumbnail ? _annotation.thumbnail : _this.default_thumbnail,
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   205
                url : _url,
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   206
                tags : _annotation.getTagTexts(),
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   207
                specific_style : (typeof _bgcolor !== "undefined" ? "background-color: " + _bgcolor : "")
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   208
            };
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   209
            var _html = Mustache.to_html(_this.annotationTemplate, _data);
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   210
            var _el = IriSP.jQuery(_html);
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   211
            _el.mouseover(function() {
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   212
                    _annotation.trigger("select");
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   213
                })
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   214
                .mouseout(function() {
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   215
                    _annotation.trigger("unselect");
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   216
                })
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   217
                .appendTo(_this.list_$);
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   218
            _annotation.on("select", function() {
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   219
                _this.annotations_$.removeClass("selected");
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   220
                _el.addClass("selected");
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   221
            });
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   222
            _annotation.on("unselect", function() {
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   223
                _this.annotations_$.removeClass("selected");
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   224
            });;
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   225
        });
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   226
        
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   227
        this.annotations_$ = this.$.find('.Ldt-AnnotationsList-li');
903
d9da52e20f7f AnnotationsList now updated to work with mashups
veltr
parents: 902
diff changeset
   228
        
d9da52e20f7f AnnotationsList now updated to work with mashups
veltr
parents: 902
diff changeset
   229
        /* Correct the empty tag bug */
d9da52e20f7f AnnotationsList now updated to work with mashups
veltr
parents: 902
diff changeset
   230
        this.$.find('.Ldt-AnnotationsList-Tag-Li').each(function() {
d9da52e20f7f AnnotationsList now updated to work with mashups
veltr
parents: 902
diff changeset
   231
            var _el = IriSP.jQuery(this);
d9da52e20f7f AnnotationsList now updated to work with mashups
veltr
parents: 902
diff changeset
   232
            if (!_el.text().replace(/(^\s+|\s+$)/g,'')) {
d9da52e20f7f AnnotationsList now updated to work with mashups
veltr
parents: 902
diff changeset
   233
                _el.detach();
d9da52e20f7f AnnotationsList now updated to work with mashups
veltr
parents: 902
diff changeset
   234
            }
d9da52e20f7f AnnotationsList now updated to work with mashups
veltr
parents: 902
diff changeset
   235
        });
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   236
    
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   237
        this.$.find('.Ldt-AnnotationsList-Tag-Li').click(function() {
957
4da0a5740b6c Starting 'players-as-widgets' branch
veltr
parents: 944
diff changeset
   238
            _this.player.trigger("search.triggeredSearch", IriSP.jQuery(this).text().replace(/(^\s+|\s+$)/g,''));
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   239
        })
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   240
        
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   241
        if(this.searchString) {
925
28efc97b5d78 Corrected MAJOR bug in search results
veltr
parents: 924
diff changeset
   242
            var _searchRe = IriSP.Model.regexpFromTextOrArray(this.searchString);
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   243
            this.$.find(".Ldt-AnnotationsList-Title a, .Ldt-AnnotationsList-Description").each(function() {
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   244
                var _$ = IriSP.jQuery(this);
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   245
                _$.html(_$.text().replace(/(^\s+|\s+$)/g,'').replace(_searchRe, '<span class="Ldt-AnnotationsList-highlight">$1</span>'))
870
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 852
diff changeset
   246
            })
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   247
        }
870
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 852
diff changeset
   248
    }
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 852
diff changeset
   249
    
903
d9da52e20f7f AnnotationsList now updated to work with mashups
veltr
parents: 902
diff changeset
   250
    if (this.ajax_url) {
d9da52e20f7f AnnotationsList now updated to work with mashups
veltr
parents: 902
diff changeset
   251
        if (this.mashupMode) {
d9da52e20f7f AnnotationsList now updated to work with mashups
veltr
parents: 902
diff changeset
   252
            this.ajaxMashup();
d9da52e20f7f AnnotationsList now updated to work with mashups
veltr
parents: 902
diff changeset
   253
        } else {
963
d58d0dcdb640 Bugfixes
veltr
parents: 959
diff changeset
   254
            if (Math.abs(_currentTime - this.lastAjaxQuery) > (this.ajax_granularity)) {
903
d9da52e20f7f AnnotationsList now updated to work with mashups
veltr
parents: 902
diff changeset
   255
                this.ajaxSource();
d9da52e20f7f AnnotationsList now updated to work with mashups
veltr
parents: 902
diff changeset
   256
            }
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   257
        }
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   258
    }
870
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 852
diff changeset
   259
    return _list.length;
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 852
diff changeset
   260
}
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 852
diff changeset
   261
875
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
   262
IriSP.Widgets.AnnotationsList.prototype.draw = function() {
876
03967b6ada7c ArrowWidget, AnnotationWidget
veltr
parents: 875
diff changeset
   263
    
959
ee11ed1b739e Mashup Player and Dailymotion are now widgets
veltr
parents: 957
diff changeset
   264
    this.mashupMode = (this.media.elementType === "mashup");
ee11ed1b739e Mashup Player and Dailymotion are now widgets
veltr
parents: 957
diff changeset
   265
    
937
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   266
    this.renderTemplate();
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   267
    
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   268
    this.list_$ = this.$.find(".Ldt-AnnotationsList-ul");
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   269
    
957
4da0a5740b6c Starting 'players-as-widgets' branch
veltr
parents: 944
diff changeset
   270
    this.onMdpEvent("search", "onSearch");
4da0a5740b6c Starting 'players-as-widgets' branch
veltr
parents: 944
diff changeset
   271
    this.onMdpEvent("search.closed", "onSearch");
4da0a5740b6c Starting 'players-as-widgets' branch
veltr
parents: 944
diff changeset
   272
    this.onMdpEvent("search.cleared", "onSearch");
4da0a5740b6c Starting 'players-as-widgets' branch
veltr
parents: 944
diff changeset
   273
    this.onMdpEvent("AnnotationsList.refresh","refresh");
876
03967b6ada7c ArrowWidget, AnnotationWidget
veltr
parents: 875
diff changeset
   274
    
870
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 852
diff changeset
   275
    var _this = this;
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 852
diff changeset
   276
    
903
d9da52e20f7f AnnotationsList now updated to work with mashups
veltr
parents: 902
diff changeset
   277
    if (this.ajax_url) {
d9da52e20f7f AnnotationsList now updated to work with mashups
veltr
parents: 902
diff changeset
   278
        if (this.mashupMode) {
d9da52e20f7f AnnotationsList now updated to work with mashups
veltr
parents: 902
diff changeset
   279
            this.ajaxMashup();
d9da52e20f7f AnnotationsList now updated to work with mashups
veltr
parents: 902
diff changeset
   280
        } else {
d9da52e20f7f AnnotationsList now updated to work with mashups
veltr
parents: 902
diff changeset
   281
            this.ajaxSource();
d9da52e20f7f AnnotationsList now updated to work with mashups
veltr
parents: 902
diff changeset
   282
        }
870
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 852
diff changeset
   283
    } else {
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 852
diff changeset
   284
        this.currentSource = this.source;
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 852
diff changeset
   285
    }
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 852
diff changeset
   286
    
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 852
diff changeset
   287
    if (this.refresh_interval) {
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 852
diff changeset
   288
        window.setInterval(function() {
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 852
diff changeset
   289
            _this.currentSource.get()
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 852
diff changeset
   290
        }, this.refresh_interval);
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 852
diff changeset
   291
    }
674
835f5f454595 WIP - working on ajax autoupdate of the widget.
hamidouk
parents: 642
diff changeset
   292
    
957
4da0a5740b6c Starting 'players-as-widgets' branch
veltr
parents: 944
diff changeset
   293
    this.onMdpEvent("createAnnotationWidget.addedAnnotation");
870
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 852
diff changeset
   294
    var _events = [
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 852
diff changeset
   295
        "timeupdate",
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 852
diff changeset
   296
        "seeked",
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 852
diff changeset
   297
        "loadedmetadata"
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 852
diff changeset
   298
    ];
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 852
diff changeset
   299
    for (var _i = 0; _i < _events.length; _i++) {
957
4da0a5740b6c Starting 'players-as-widgets' branch
veltr
parents: 944
diff changeset
   300
        this.onMediaEvent(_events[_i], this.throttledRefresh);
870
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 852
diff changeset
   301
    }
730
357fc047503b redraw the widget after that an annotation has been added.
hamidouk
parents: 729
diff changeset
   302
    
870
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 852
diff changeset
   303
    this.throttledRefresh();
698
329333e07267 lot of work on the ajax update front.
hamidouk
parents: 674
diff changeset
   304
870
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 852
diff changeset
   305
};