src/js/widgets/annotationsListWidget.js
branchpopcorn-port
changeset 607 0b94ae49efbd
parent 605 e1a6f73038b4
child 615 7eb41c26a8b7
equal deleted inserted replaced
606:13675511a01a 607:0b94ae49efbd
    12 
    12 
    13 IriSP.AnnotationsListWidget.prototype.clearWidget = function() {
    13 IriSP.AnnotationsListWidget.prototype.clearWidget = function() {
    14 };
    14 };
    15 
    15 
    16 /** draw the annotation list */
    16 /** draw the annotation list */
    17 IriSP.AnnotationsListWidget.prototype.drawList = function() {
    17 IriSP.AnnotationsListWidget.prototype.drawList = function(force_redraw) {
    18   var _this = this;
    18   var _this = this;
    19 
    19 
    20   var view_type = this._serializer.getContributions();
    20   var view_type = this._serializer.getContributions();
    21   var annotations = this._serializer._data.annotations;
    21   var annotations = this._serializer._data.annotations;
    22   var currentTime = this._Popcorn.currentTime();
    22   var currentTime = this._Popcorn.currentTime();
    51     obj["begin"] = IriSP.msToTime(annotation.begin);
    51     obj["begin"] = IriSP.msToTime(annotation.begin);
    52     obj["end"] = IriSP.msToTime(annotation.end);
    52     obj["end"] = IriSP.msToTime(annotation.end);
    53 
    53 
    54     list.push(obj);
    54     list.push(obj);
    55   }
    55   }
    56 
    56   
    57   var idList = IriSP.underscore.pluck(list, "id").sort();
    57   var idList = IriSP.underscore.pluck(list, "id").sort();
    58   
    58   
    59   if (idList.length !== this.__oldList.length) {
    59   if (idList.length !== this.__oldList.length) {
    60     var widgetMarkup = IriSP.templToHTML(IriSP.annotationsListWidget_template, {annotations: list});
    60     var widgetMarkup = IriSP.templToHTML(IriSP.annotationsListWidget_template, {annotations: list});
    61     this.selector.html(widgetMarkup);
    61     this.selector.html(widgetMarkup);
    67       res = 0;
    67       res = 0;
    68       break;
    68       break;
    69   }
    69   }
    70   
    70   
    71   this.__oldList = idList; /* save for next call */
    71   this.__oldList = idList; /* save for next call */
       
    72 
       
    73   if (typeof(force_redraw) !== "undefined") {
       
    74     console.log("forced redraw");
       
    75     var widgetMarkup = IriSP.templToHTML(IriSP.annotationsListWidget_template, {annotations: list});
       
    76     this.selector.html(widgetMarkup);
       
    77   }
    72   
    78   
    73   /* the two lists are equal, no need to redraw */
    79   /* the two lists are equal, no need to redraw */
    74   if (res === 1) {
    80   if (res === 1) {
    75     return;
    81     return;
    76   } else {
    82   } else {
    81 };
    87 };
    82 
    88 
    83 IriSP.AnnotationsListWidget.prototype.draw = function() {
    89 IriSP.AnnotationsListWidget.prototype.draw = function() {
    84 
    90 
    85   this.drawList();
    91   this.drawList();
    86   this._Popcorn.listen("IriSP.createAnnotationWidget.addedAnnotation", IriSP.wrap(this, this.drawList));
    92   this._Popcorn.listen("IriSP.createAnnotationWidget.addedAnnotation", IriSP.wrap(this, function() { this.redraw(true); }));
    87   this._Popcorn.listen("timeupdate", IriSP.wrap(this, this.redraw));
    93   this._Popcorn.listen("timeupdate", IriSP.wrap(this, this.redraw));
    88 };
    94 };
    89 
    95 
    90 IriSP.AnnotationsListWidget.prototype.redraw = function() {
    96 IriSP.AnnotationsListWidget.prototype.redraw = function() {
    91   /* we use some kind of counter to mitigate the fact that the function
       
    92      is supposed to be called at every timeupdate */
       
    93 /*  if (this.__counter < 4) {
       
    94     this.__counter++;
       
    95   } else {
       
    96     this.drawList();
       
    97     this.__counter = 0;
       
    98   }*/
       
    99   
       
   100   this.drawList();
    97   this.drawList();
   101 };
    98 };