# HG changeset patch # User hamidouk # Date 1326465942 -3600 # Node ID b13bcfd2f9b1873c6ed069bf02e7937d8fc49598 # Parent 55282f5ef4778a171356181e6f0fa40491e38914 DRYied the code. diff -r 55282f5ef477 -r b13bcfd2f9b1 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); } };