src/js/widgets/annotationsListWidget.js
author hamidouk
Mon, 09 Jan 2012 15:38:54 +0100
branchpopcorn-port
changeset 599 a5a5e70d46a7
parent 595 29d86e6c61a6
child 602 b35862f9b0b0
permissions -rw-r--r--
added support for widget redrawing.

IriSP.AnnotationsListWidget = function(Popcorn, config, Serializer) {
  IriSP.Widget.call(this, Popcorn, config, Serializer);
};


IriSP.AnnotationsListWidget.prototype = new IriSP.Widget();

IriSP.AnnotationsListWidget.prototype.clear = function() {
};

IriSP.AnnotationsListWidget.prototype.clearWidget = function() {
};

/** draw the annotation list */
IriSP.AnnotationsListWidget.prototype.drawList = function() {
  var _this = this;

  var view_type = this._serializer.getContributions();
  var annotations = this._serializer._data.annotations;
  var list = [];

  if (typeof(view_type) === "undefined") {
    console.log("not type suitable for display");
    return;
  }

  for (i = 0; i < annotations.length; i++) {
    var annotation = annotations[i];

    /* filter the annotations whose type is not the one we want */
    if (typeof(annotation.meta) !== "undefined" && typeof(annotation.meta["id-ref"]) !== "undefined"
          && annotation.meta["id-ref"] != view_type) {
        continue;
    }

    var a = annotation;
    var obj = {};

    obj["id"] = a.id;
    obj["title"] = a.content.title;
    obj["desc"] = a.content.description;
    obj["begin"] = IriSP.msToTime(a.begin);
    obj["end"] = IriSP.msToTime(a.end);

    list.push(obj);
  }

  var widgetMarkup = IriSP.templToHTML(IriSP.annotationsListWidget_template, {annotations: list});
  this.selector.html(widgetMarkup);
};

IriSP.AnnotationsListWidget.prototype.draw = function() {

  this.drawList();
  this._Popcorn.listen("IriSP.createAnnotationWidget.addedAnnotation", IriSP.wrap(this, this.redraw));
};

IriSP.AnnotationsListWidget.prototype.redraw = function() {
  this.drawList();
};