DRYied the code. popcorn-port
authorhamidouk
Fri, 13 Jan 2012 15:45:42 +0100
branchpopcorn-port
changeset 629 b13bcfd2f9b1
parent 628 55282f5ef477
child 630 7c53857650b1
DRYied the code.
src/js/widgets/annotationsListWidget.js
--- a/src/js/widgets/annotationsListWidget.js	Fri Jan 13 15:45:29 2012 +0100
+++ b/src/js/widgets/annotationsListWidget.js	Fri Jan 13 15:45:42 2012 +0100
@@ -13,6 +13,12 @@
 IriSP.AnnotationsListWidget.prototype.clearWidget = function() {
 };
 
+/** effectively redraw the widget - called by drawList */
+IriSP.AnnotationsListWidget.prototype.do_redraw = function(list) {
+    var widgetMarkup = IriSP.templToHTML(IriSP.annotationsListWidget_template, {annotations: list});
+    this.selector.html(widgetMarkup);
+};
+
 /** draw the annotation list */
 IriSP.AnnotationsListWidget.prototype.drawList = function(force_redraw) {
   var _this = this;
@@ -56,8 +62,7 @@
   var idList = IriSP.underscore.pluck(list, "id").sort();
   
   if (idList.length !== this.__oldList.length) {
-    var widgetMarkup = IriSP.templToHTML(IriSP.annotationsListWidget_template, {annotations: list});
-    this.selector.html(widgetMarkup);
+    this.do_redraw(list);
   }
     
   var res = 1;
@@ -71,16 +76,14 @@
 
   if (typeof(force_redraw) !== "undefined") {
     console.log("forced redraw");
-    var widgetMarkup = IriSP.templToHTML(IriSP.annotationsListWidget_template, {annotations: list});
-    this.selector.html(widgetMarkup);
+    this.do_redraw(list);
   }
   
   /* the two lists are equal, no need to redraw */
   if (res === 1) {
     return;
   } else {
-    var widgetMarkup = IriSP.templToHTML(IriSP.annotationsListWidget_template, {annotations: list});
-    this.selector.html(widgetMarkup);
+    this.do_redraw(list);
   }
   
 };