src/js/widgets/annotationsListWidget.js
author hamidouk
Mon, 09 Jan 2012 17:23:08 +0100
branchpopcorn-port
changeset 602 b35862f9b0b0
parent 599 a5a5e70d46a7
child 603 58dfdafb5410
permissions -rw-r--r--
WIP - working on the autoupdate of the widget.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
585
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
     1
IriSP.AnnotationsListWidget = function(Popcorn, config, Serializer) {
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
     2
  IriSP.Widget.call(this, Popcorn, config, Serializer);
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
     3
};
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
     4
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
     5
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
     6
IriSP.AnnotationsListWidget.prototype = new IriSP.Widget();
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
     7
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
     8
IriSP.AnnotationsListWidget.prototype.clear = function() {
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
     9
};
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
    10
588
78cf49152d4a got a decent-looking list.
hamidouk
parents: 585
diff changeset
    11
IriSP.AnnotationsListWidget.prototype.clearWidget = function() {
585
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
    12
};
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
    13
599
a5a5e70d46a7 added support for widget redrawing.
hamidouk
parents: 595
diff changeset
    14
/** draw the annotation list */
a5a5e70d46a7 added support for widget redrawing.
hamidouk
parents: 595
diff changeset
    15
IriSP.AnnotationsListWidget.prototype.drawList = function() {
585
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
    16
  var _this = this;
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
    17
595
29d86e6c61a6 finished going through the widgets to add stricter line checking.
hamidouk
parents: 588
diff changeset
    18
  var view_type = this._serializer.getContributions();
585
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
    19
  var annotations = this._serializer._data.annotations;
602
b35862f9b0b0 WIP - working on the autoupdate of the widget.
hamidouk
parents: 599
diff changeset
    20
  var currentTime = this._Popcorn.currentTime();
b35862f9b0b0 WIP - working on the autoupdate of the widget.
hamidouk
parents: 599
diff changeset
    21
  
b35862f9b0b0 WIP - working on the autoupdate of the widget.
hamidouk
parents: 599
diff changeset
    22
  /* happens when the player hasn't yet loaded */
b35862f9b0b0 WIP - working on the autoupdate of the widget.
hamidouk
parents: 599
diff changeset
    23
  if (typeof(currentTime) === "undefined") {
b35862f9b0b0 WIP - working on the autoupdate of the widget.
hamidouk
parents: 599
diff changeset
    24
    window.setTimeout(IriSP.wrap(this, this.drawList), 4000);
b35862f9b0b0 WIP - working on the autoupdate of the widget.
hamidouk
parents: 599
diff changeset
    25
    return;
b35862f9b0b0 WIP - working on the autoupdate of the widget.
hamidouk
parents: 599
diff changeset
    26
  }
b35862f9b0b0 WIP - working on the autoupdate of the widget.
hamidouk
parents: 599
diff changeset
    27
  
585
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
    28
  var list = [];
588
78cf49152d4a got a decent-looking list.
hamidouk
parents: 585
diff changeset
    29
585
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
    30
  if (typeof(view_type) === "undefined") {
602
b35862f9b0b0 WIP - working on the autoupdate of the widget.
hamidouk
parents: 599
diff changeset
    31
    console.log("no type suitable for display");
585
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
    32
    return;
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
    33
  }
588
78cf49152d4a got a decent-looking list.
hamidouk
parents: 585
diff changeset
    34
602
b35862f9b0b0 WIP - working on the autoupdate of the widget.
hamidouk
parents: 599
diff changeset
    35
  console.log(currentTime);
585
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
    36
  for (i = 0; i < annotations.length; i++) {
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
    37
    var annotation = annotations[i];
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
    38
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
    39
    /* filter the annotations whose type is not the one we want */
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
    40
    if (typeof(annotation.meta) !== "undefined" && typeof(annotation.meta["id-ref"]) !== "undefined"
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
    41
          && annotation.meta["id-ref"] != view_type) {
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
    42
        continue;
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
    43
    }
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
    44
602
b35862f9b0b0 WIP - working on the autoupdate of the widget.
hamidouk
parents: 599
diff changeset
    45
    /* only get the annotations happening in the current chapter */
b35862f9b0b0 WIP - working on the autoupdate of the widget.
hamidouk
parents: 599
diff changeset
    46
    if (annotation.begin > currentTime || annotation.end <= currentTime) {
b35862f9b0b0 WIP - working on the autoupdate of the widget.
hamidouk
parents: 599
diff changeset
    47
        continue;
b35862f9b0b0 WIP - working on the autoupdate of the widget.
hamidouk
parents: 599
diff changeset
    48
    }
b35862f9b0b0 WIP - working on the autoupdate of the widget.
hamidouk
parents: 599
diff changeset
    49
    
585
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
    50
    var a = annotation;
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
    51
    var obj = {};
588
78cf49152d4a got a decent-looking list.
hamidouk
parents: 585
diff changeset
    52
585
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
    53
    obj["id"] = a.id;
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
    54
    obj["title"] = a.content.title;
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
    55
    obj["desc"] = a.content.description;
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
    56
    obj["begin"] = IriSP.msToTime(a.begin);
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
    57
    obj["end"] = IriSP.msToTime(a.end);
588
78cf49152d4a got a decent-looking list.
hamidouk
parents: 585
diff changeset
    58
585
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
    59
    list.push(obj);
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
    60
  }
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
    61
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
    62
  var widgetMarkup = IriSP.templToHTML(IriSP.annotationsListWidget_template, {annotations: list});
599
a5a5e70d46a7 added support for widget redrawing.
hamidouk
parents: 595
diff changeset
    63
  this.selector.html(widgetMarkup);
a5a5e70d46a7 added support for widget redrawing.
hamidouk
parents: 595
diff changeset
    64
};
a5a5e70d46a7 added support for widget redrawing.
hamidouk
parents: 595
diff changeset
    65
a5a5e70d46a7 added support for widget redrawing.
hamidouk
parents: 595
diff changeset
    66
IriSP.AnnotationsListWidget.prototype.draw = function() {
a5a5e70d46a7 added support for widget redrawing.
hamidouk
parents: 595
diff changeset
    67
a5a5e70d46a7 added support for widget redrawing.
hamidouk
parents: 595
diff changeset
    68
  this.drawList();
a5a5e70d46a7 added support for widget redrawing.
hamidouk
parents: 595
diff changeset
    69
  this._Popcorn.listen("IriSP.createAnnotationWidget.addedAnnotation", IriSP.wrap(this, this.redraw));
602
b35862f9b0b0 WIP - working on the autoupdate of the widget.
hamidouk
parents: 599
diff changeset
    70
  this._Popcorn.listen("seeked", IriSP.wrap(this, this.redraw));
599
a5a5e70d46a7 added support for widget redrawing.
hamidouk
parents: 595
diff changeset
    71
};
a5a5e70d46a7 added support for widget redrawing.
hamidouk
parents: 595
diff changeset
    72
a5a5e70d46a7 added support for widget redrawing.
hamidouk
parents: 595
diff changeset
    73
IriSP.AnnotationsListWidget.prototype.redraw = function() {
a5a5e70d46a7 added support for widget redrawing.
hamidouk
parents: 595
diff changeset
    74
  this.drawList();
585
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
    75
};