added an option to force the redraw of a list, even if the cached lists are the popcorn-port
authorhamidouk
Tue, 10 Jan 2012 16:46:47 +0100
branchpopcorn-port
changeset 607 0b94ae49efbd
parent 606 13675511a01a
child 608 2fb4eda4dcd2
added an option to force the redraw of a list, even if the cached lists are the same (which is the case when we just added another annotation)
src/js/widgets/annotationsListWidget.js
--- a/src/js/widgets/annotationsListWidget.js	Tue Jan 10 16:45:20 2012 +0100
+++ b/src/js/widgets/annotationsListWidget.js	Tue Jan 10 16:46:47 2012 +0100
@@ -14,7 +14,7 @@
 };
 
 /** draw the annotation list */
-IriSP.AnnotationsListWidget.prototype.drawList = function() {
+IriSP.AnnotationsListWidget.prototype.drawList = function(force_redraw) {
   var _this = this;
 
   var view_type = this._serializer.getContributions();
@@ -53,7 +53,7 @@
 
     list.push(obj);
   }
-
+  
   var idList = IriSP.underscore.pluck(list, "id").sort();
   
   if (idList.length !== this.__oldList.length) {
@@ -69,6 +69,12 @@
   }
   
   this.__oldList = idList; /* save for next call */
+
+  if (typeof(force_redraw) !== "undefined") {
+    console.log("forced redraw");
+    var widgetMarkup = IriSP.templToHTML(IriSP.annotationsListWidget_template, {annotations: list});
+    this.selector.html(widgetMarkup);
+  }
   
   /* the two lists are equal, no need to redraw */
   if (res === 1) {
@@ -83,19 +89,10 @@
 IriSP.AnnotationsListWidget.prototype.draw = function() {
 
   this.drawList();
-  this._Popcorn.listen("IriSP.createAnnotationWidget.addedAnnotation", IriSP.wrap(this, this.drawList));
+  this._Popcorn.listen("IriSP.createAnnotationWidget.addedAnnotation", IriSP.wrap(this, function() { this.redraw(true); }));
   this._Popcorn.listen("timeupdate", IriSP.wrap(this, this.redraw));
 };
 
 IriSP.AnnotationsListWidget.prototype.redraw = function() {
-  /* we use some kind of counter to mitigate the fact that the function
-     is supposed to be called at every timeupdate */
-/*  if (this.__counter < 4) {
-    this.__counter++;
-  } else {
-    this.drawList();
-    this.__counter = 0;
-  }*/
-  
   this.drawList();
 };
\ No newline at end of file