src/js/widgets/annotationsListWidget.js
author hamidouk
Tue, 31 Jan 2012 15:33:59 +0100
branchpopcorn-port
changeset 752 ebc72cbc35f4
parent 748 ec1f7aa873f4
child 753 72eecd7250e5
permissions -rw-r--r--
same thing, for the annotationsListWidget
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);
605
e1a6f73038b4 made the listWidget redraw at every timeupdate event (added a small optimization though,
hamidouk
parents: 603
diff changeset
     3
  this.__counter = 0;
e1a6f73038b4 made the listWidget redraw at every timeupdate event (added a small optimization though,
hamidouk
parents: 603
diff changeset
     4
  this.__oldList = [];
674
835f5f454595 WIP - working on ajax autoupdate of the widget.
hamidouk
parents: 642
diff changeset
     5
  
835f5f454595 WIP - working on ajax autoupdate of the widget.
hamidouk
parents: 642
diff changeset
     6
  this.ajax_mode = IriSP.widgetsDefaults["AnnotationsListWidget"].ajax_mode;
714
9056928c46de WIP - making links to only annotations which are not present in the opened
hamidouk
parents: 703
diff changeset
     7
  this.project_url = IriSP.widgetsDefaults["AnnotationsListWidget"].project_url;  
585
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
     8
};
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
     9
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
    10
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
    11
IriSP.AnnotationsListWidget.prototype = new IriSP.Widget();
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
    12
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
    13
IriSP.AnnotationsListWidget.prototype.clear = function() {
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
    14
};
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
    15
588
78cf49152d4a got a decent-looking list.
hamidouk
parents: 585
diff changeset
    16
IriSP.AnnotationsListWidget.prototype.clearWidget = function() {
585
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
    17
};
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
    18
629
b13bcfd2f9b1 DRYied the code.
hamidouk
parents: 621
diff changeset
    19
/** effectively redraw the widget - called by drawList */
b13bcfd2f9b1 DRYied the code.
hamidouk
parents: 621
diff changeset
    20
IriSP.AnnotationsListWidget.prototype.do_redraw = function(list) {
b13bcfd2f9b1 DRYied the code.
hamidouk
parents: 621
diff changeset
    21
    var widgetMarkup = IriSP.templToHTML(IriSP.annotationsListWidget_template, {annotations: list});
b13bcfd2f9b1 DRYied the code.
hamidouk
parents: 621
diff changeset
    22
    this.selector.html(widgetMarkup);
b13bcfd2f9b1 DRYied the code.
hamidouk
parents: 621
diff changeset
    23
};
b13bcfd2f9b1 DRYied the code.
hamidouk
parents: 621
diff changeset
    24
599
a5a5e70d46a7 added support for widget redrawing.
hamidouk
parents: 595
diff changeset
    25
/** draw the annotation list */
607
0b94ae49efbd added an option to force the redraw of a list, even if the cached lists are the
hamidouk
parents: 605
diff changeset
    26
IriSP.AnnotationsListWidget.prototype.drawList = function(force_redraw) {
585
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
    27
  var _this = this;
674
835f5f454595 WIP - working on ajax autoupdate of the widget.
hamidouk
parents: 642
diff changeset
    28
  
595
29d86e6c61a6 finished going through the widgets to add stricter line checking.
hamidouk
parents: 588
diff changeset
    29
  var view_type = this._serializer.getContributions();
585
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
    30
  var annotations = this._serializer._data.annotations;
602
b35862f9b0b0 WIP - working on the autoupdate of the widget.
hamidouk
parents: 599
diff changeset
    31
  var currentTime = this._Popcorn.currentTime();
605
e1a6f73038b4 made the listWidget redraw at every timeupdate event (added a small optimization though,
hamidouk
parents: 603
diff changeset
    32
    
585
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
    33
  var list = [];
588
78cf49152d4a got a decent-looking list.
hamidouk
parents: 585
diff changeset
    34
621
170a8cd859d5 remove error message.
hamidouk
parents: 615
diff changeset
    35
  if (typeof(view_type) === "undefined") {    
585
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
    36
    return;
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
    37
  }
588
78cf49152d4a got a decent-looking list.
hamidouk
parents: 585
diff changeset
    38
585
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
    39
  for (i = 0; i < annotations.length; i++) {
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
    40
    var annotation = annotations[i];
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
    41
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
    42
    /* filter the annotations whose type is not the one we want */
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
    43
    if (typeof(annotation.meta) !== "undefined" && typeof(annotation.meta["id-ref"]) !== "undefined"
615
7eb41c26a8b7 stricter equality check.
hamidouk
parents: 607
diff changeset
    44
          && annotation.meta["id-ref"] !== view_type) {
585
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
    45
        continue;
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
    46
    }
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
    47
602
b35862f9b0b0 WIP - working on the autoupdate of the widget.
hamidouk
parents: 599
diff changeset
    48
    /* only get the annotations happening in the current chapter */
603
58dfdafb5410 fixed stupid ms/s bug.
hamidouk
parents: 602
diff changeset
    49
    if (!(annotation.begin <= currentTime * 1000 && annotation.end > currentTime * 1000)) {        
602
b35862f9b0b0 WIP - working on the autoupdate of the widget.
hamidouk
parents: 599
diff changeset
    50
        continue;
b35862f9b0b0 WIP - working on the autoupdate of the widget.
hamidouk
parents: 599
diff changeset
    51
    }
603
58dfdafb5410 fixed stupid ms/s bug.
hamidouk
parents: 602
diff changeset
    52
585
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
    53
    var a = annotation;
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
    54
    var obj = {};
588
78cf49152d4a got a decent-looking list.
hamidouk
parents: 585
diff changeset
    55
585
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
    56
    obj["id"] = a.id;
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
    57
    obj["title"] = a.content.title;
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
    58
    obj["desc"] = a.content.description;
603
58dfdafb5410 fixed stupid ms/s bug.
hamidouk
parents: 602
diff changeset
    59
    obj["begin"] = IriSP.msToTime(annotation.begin);
58dfdafb5410 fixed stupid ms/s bug.
hamidouk
parents: 602
diff changeset
    60
    obj["end"] = IriSP.msToTime(annotation.end);
588
78cf49152d4a got a decent-looking list.
hamidouk
parents: 585
diff changeset
    61
585
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
    62
    list.push(obj);
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
    63
  }
607
0b94ae49efbd added an option to force the redraw of a list, even if the cached lists are the
hamidouk
parents: 605
diff changeset
    64
  
605
e1a6f73038b4 made the listWidget redraw at every timeupdate event (added a small optimization though,
hamidouk
parents: 603
diff changeset
    65
  var idList = IriSP.underscore.pluck(list, "id").sort();
642
37693f217f8c redraw the list when a new annotation is added.
hamidouk
parents: 629
diff changeset
    66
605
e1a6f73038b4 made the listWidget redraw at every timeupdate event (added a small optimization though,
hamidouk
parents: 603
diff changeset
    67
  if (idList.length !== this.__oldList.length) {
629
b13bcfd2f9b1 DRYied the code.
hamidouk
parents: 621
diff changeset
    68
    this.do_redraw(list);
605
e1a6f73038b4 made the listWidget redraw at every timeupdate event (added a small optimization though,
hamidouk
parents: 603
diff changeset
    69
  }
e1a6f73038b4 made the listWidget redraw at every timeupdate event (added a small optimization though,
hamidouk
parents: 603
diff changeset
    70
    
e1a6f73038b4 made the listWidget redraw at every timeupdate event (added a small optimization though,
hamidouk
parents: 603
diff changeset
    71
  var res = 1;
e1a6f73038b4 made the listWidget redraw at every timeupdate event (added a small optimization though,
hamidouk
parents: 603
diff changeset
    72
  for (var i = 0; i < idList.length; i++) {
e1a6f73038b4 made the listWidget redraw at every timeupdate event (added a small optimization though,
hamidouk
parents: 603
diff changeset
    73
    if (idList[i] !== this.__oldList[i])
e1a6f73038b4 made the listWidget redraw at every timeupdate event (added a small optimization though,
hamidouk
parents: 603
diff changeset
    74
      res = 0;
e1a6f73038b4 made the listWidget redraw at every timeupdate event (added a small optimization though,
hamidouk
parents: 603
diff changeset
    75
      break;
e1a6f73038b4 made the listWidget redraw at every timeupdate event (added a small optimization though,
hamidouk
parents: 603
diff changeset
    76
  }
e1a6f73038b4 made the listWidget redraw at every timeupdate event (added a small optimization though,
hamidouk
parents: 603
diff changeset
    77
  
e1a6f73038b4 made the listWidget redraw at every timeupdate event (added a small optimization though,
hamidouk
parents: 603
diff changeset
    78
  this.__oldList = idList; /* save for next call */
698
329333e07267 lot of work on the ajax update front.
hamidouk
parents: 674
diff changeset
    79
  
607
0b94ae49efbd added an option to force the redraw of a list, even if the cached lists are the
hamidouk
parents: 605
diff changeset
    80
  if (typeof(force_redraw) !== "undefined") {
629
b13bcfd2f9b1 DRYied the code.
hamidouk
parents: 621
diff changeset
    81
    this.do_redraw(list);
607
0b94ae49efbd added an option to force the redraw of a list, even if the cached lists are the
hamidouk
parents: 605
diff changeset
    82
  }
605
e1a6f73038b4 made the listWidget redraw at every timeupdate event (added a small optimization though,
hamidouk
parents: 603
diff changeset
    83
  
e1a6f73038b4 made the listWidget redraw at every timeupdate event (added a small optimization though,
hamidouk
parents: 603
diff changeset
    84
  /* the two lists are equal, no need to redraw */
e1a6f73038b4 made the listWidget redraw at every timeupdate event (added a small optimization though,
hamidouk
parents: 603
diff changeset
    85
  if (res === 1) {
e1a6f73038b4 made the listWidget redraw at every timeupdate event (added a small optimization though,
hamidouk
parents: 603
diff changeset
    86
    return;
e1a6f73038b4 made the listWidget redraw at every timeupdate event (added a small optimization though,
hamidouk
parents: 603
diff changeset
    87
  } else {
629
b13bcfd2f9b1 DRYied the code.
hamidouk
parents: 621
diff changeset
    88
    this.do_redraw(list);
605
e1a6f73038b4 made the listWidget redraw at every timeupdate event (added a small optimization though,
hamidouk
parents: 603
diff changeset
    89
  }
e1a6f73038b4 made the listWidget redraw at every timeupdate event (added a small optimization though,
hamidouk
parents: 603
diff changeset
    90
  
599
a5a5e70d46a7 added support for widget redrawing.
hamidouk
parents: 595
diff changeset
    91
};
a5a5e70d46a7 added support for widget redrawing.
hamidouk
parents: 595
diff changeset
    92
674
835f5f454595 WIP - working on ajax autoupdate of the widget.
hamidouk
parents: 642
diff changeset
    93
IriSP.AnnotationsListWidget.prototype.ajaxRedraw = function(timecode) {
748
ec1f7aa873f4 parse the url received by the platform.
hamidouk
parents: 745
diff changeset
    94
752
ebc72cbc35f4 same thing, for the annotationsListWidget
hamidouk
parents: 748
diff changeset
    95
  /* the seeked signal sometimes passes an argument - depending on if we're using
ebc72cbc35f4 same thing, for the annotationsListWidget
hamidouk
parents: 748
diff changeset
    96
     our popcorn lookalike or the real thing - if it's the case, use it as it's
ebc72cbc35f4 same thing, for the annotationsListWidget
hamidouk
parents: 748
diff changeset
    97
     more precise than currentTime which sometimes contains the place we where at */
ebc72cbc35f4 same thing, for the annotationsListWidget
hamidouk
parents: 748
diff changeset
    98
  if (IriSP.null_or_undefined(timecode) || typeof(timecode) != "number") {
ebc72cbc35f4 same thing, for the annotationsListWidget
hamidouk
parents: 748
diff changeset
    99
     var tcode = this._Popcorn.currentTime();     
ebc72cbc35f4 same thing, for the annotationsListWidget
hamidouk
parents: 748
diff changeset
   100
   } else {
ebc72cbc35f4 same thing, for the annotationsListWidget
hamidouk
parents: 748
diff changeset
   101
     var tcode = timecode;     
ebc72cbc35f4 same thing, for the annotationsListWidget
hamidouk
parents: 748
diff changeset
   102
  }
ebc72cbc35f4 same thing, for the annotationsListWidget
hamidouk
parents: 748
diff changeset
   103
   
ebc72cbc35f4 same thing, for the annotationsListWidget
hamidouk
parents: 748
diff changeset
   104
  
748
ec1f7aa873f4 parse the url received by the platform.
hamidouk
parents: 745
diff changeset
   105
  /* the platform gives us a special url - of the type : http://path/{media}/{begin}/{end}
ec1f7aa873f4 parse the url received by the platform.
hamidouk
parents: 745
diff changeset
   106
     we double the braces using regexps and we feed it to mustache to build the correct url
ec1f7aa873f4 parse the url received by the platform.
hamidouk
parents: 745
diff changeset
   107
     we have to do that because the platform only knows at run time what view it's displaying.
ec1f7aa873f4 parse the url received by the platform.
hamidouk
parents: 745
diff changeset
   108
  */
ec1f7aa873f4 parse the url received by the platform.
hamidouk
parents: 745
diff changeset
   109
     
ec1f7aa873f4 parse the url received by the platform.
hamidouk
parents: 745
diff changeset
   110
  var platf_url = IriSP.widgetsDefaults["AnnotationsListWidget"].ajax_url
ec1f7aa873f4 parse the url received by the platform.
hamidouk
parents: 745
diff changeset
   111
                                      .replace(/\{/g, '{{').replace(/\}/g, '}}');
698
329333e07267 lot of work on the ajax update front.
hamidouk
parents: 674
diff changeset
   112
  var media_id = this._serializer.currentMedia()["id"];
329333e07267 lot of work on the ajax update front.
hamidouk
parents: 674
diff changeset
   113
  var duration = +this._serializer.currentMedia().meta["dc:duration"];
329333e07267 lot of work on the ajax update front.
hamidouk
parents: 674
diff changeset
   114
  
752
ebc72cbc35f4 same thing, for the annotationsListWidget
hamidouk
parents: 748
diff changeset
   115
  var begin_timecode = (Math.floor(tcode) - 300) * 1000;
698
329333e07267 lot of work on the ajax update front.
hamidouk
parents: 674
diff changeset
   116
  if (begin_timecode < 0)
329333e07267 lot of work on the ajax update front.
hamidouk
parents: 674
diff changeset
   117
    begin_timecode = 0;
329333e07267 lot of work on the ajax update front.
hamidouk
parents: 674
diff changeset
   118
    
752
ebc72cbc35f4 same thing, for the annotationsListWidget
hamidouk
parents: 748
diff changeset
   119
  var end_timecode = (Math.floor(tcode) + 300) * 1000;
698
329333e07267 lot of work on the ajax update front.
hamidouk
parents: 674
diff changeset
   120
  if (end_timecode > duration)
329333e07267 lot of work on the ajax update front.
hamidouk
parents: 674
diff changeset
   121
    end_timecode = duration;
329333e07267 lot of work on the ajax update front.
hamidouk
parents: 674
diff changeset
   122
  
752
ebc72cbc35f4 same thing, for the annotationsListWidget
hamidouk
parents: 748
diff changeset
   123
  console.log("b, e:", begin_timecode, end_timecode);
748
ec1f7aa873f4 parse the url received by the platform.
hamidouk
parents: 745
diff changeset
   124
  var templ = Mustache.to_html(platf_url, {media: media_id, begin: begin_timecode,
ec1f7aa873f4 parse the url received by the platform.
hamidouk
parents: 745
diff changeset
   125
                                 end: end_timecode});
ec1f7aa873f4 parse the url received by the platform.
hamidouk
parents: 745
diff changeset
   126
698
329333e07267 lot of work on the ajax update front.
hamidouk
parents: 674
diff changeset
   127
  /* we create on the fly a serializer to get the ajax */
329333e07267 lot of work on the ajax update front.
hamidouk
parents: 674
diff changeset
   128
  var serializer = new IriSP.JSONSerializer(IriSP.__dataloader, templ);
329333e07267 lot of work on the ajax update front.
hamidouk
parents: 674
diff changeset
   129
  serializer.sync(IriSP.wrap(this, function(json) { this.processJson(json, serializer) }));                  
674
835f5f454595 WIP - working on ajax autoupdate of the widget.
hamidouk
parents: 642
diff changeset
   130
};
835f5f454595 WIP - working on ajax autoupdate of the widget.
hamidouk
parents: 642
diff changeset
   131
698
329333e07267 lot of work on the ajax update front.
hamidouk
parents: 674
diff changeset
   132
/** process the received json - it's a bit hackish */
329333e07267 lot of work on the ajax update front.
hamidouk
parents: 674
diff changeset
   133
IriSP.AnnotationsListWidget.prototype.processJson = function(json, serializer) {
329333e07267 lot of work on the ajax update front.
hamidouk
parents: 674
diff changeset
   134
  /* FIXME: DRY the whole thing */
329333e07267 lot of work on the ajax update front.
hamidouk
parents: 674
diff changeset
   135
  var annotations = serializer._data.annotations;
329333e07267 lot of work on the ajax update front.
hamidouk
parents: 674
diff changeset
   136
  if (IriSP.null_or_undefined(annotations))
329333e07267 lot of work on the ajax update front.
hamidouk
parents: 674
diff changeset
   137
    return;
329333e07267 lot of work on the ajax update front.
hamidouk
parents: 674
diff changeset
   138
  
329333e07267 lot of work on the ajax update front.
hamidouk
parents: 674
diff changeset
   139
  var view_types = serializer.getIds("Contributions");
329333e07267 lot of work on the ajax update front.
hamidouk
parents: 674
diff changeset
   140
  var l = [];
329333e07267 lot of work on the ajax update front.
hamidouk
parents: 674
diff changeset
   141
  
714
9056928c46de WIP - making links to only annotations which are not present in the opened
hamidouk
parents: 703
diff changeset
   142
  var media = this._serializer.currentMedia()["id"];
9056928c46de WIP - making links to only annotations which are not present in the opened
hamidouk
parents: 703
diff changeset
   143
  
698
329333e07267 lot of work on the ajax update front.
hamidouk
parents: 674
diff changeset
   144
  for (i = 0; i < annotations.length; i++) {
329333e07267 lot of work on the ajax update front.
hamidouk
parents: 674
diff changeset
   145
      var annotation = annotations[i];
703
9341d858bf8e removed useless printfs.
hamidouk
parents: 698
diff changeset
   146
698
329333e07267 lot of work on the ajax update front.
hamidouk
parents: 674
diff changeset
   147
      /* filter the annotations whose type is not the one we want */
329333e07267 lot of work on the ajax update front.
hamidouk
parents: 674
diff changeset
   148
      /* We want _all_ the annotations.
329333e07267 lot of work on the ajax update front.
hamidouk
parents: 674
diff changeset
   149
      if (typeof(annotation.meta) !== "undefined" && typeof(annotation.meta["id-ref"]) !== "undefined"
329333e07267 lot of work on the ajax update front.
hamidouk
parents: 674
diff changeset
   150
            && !IriSP.underscore.include(view_types, annotation.meta["id-ref"])) {
329333e07267 lot of work on the ajax update front.
hamidouk
parents: 674
diff changeset
   151
          continue;
329333e07267 lot of work on the ajax update front.
hamidouk
parents: 674
diff changeset
   152
      }
329333e07267 lot of work on the ajax update front.
hamidouk
parents: 674
diff changeset
   153
      */
329333e07267 lot of work on the ajax update front.
hamidouk
parents: 674
diff changeset
   154
      var a = annotation;
329333e07267 lot of work on the ajax update front.
hamidouk
parents: 674
diff changeset
   155
      var obj = {};
329333e07267 lot of work on the ajax update front.
hamidouk
parents: 674
diff changeset
   156
329333e07267 lot of work on the ajax update front.
hamidouk
parents: 674
diff changeset
   157
      obj["id"] = a.id;
329333e07267 lot of work on the ajax update front.
hamidouk
parents: 674
diff changeset
   158
      obj["title"] = a.content.title;
329333e07267 lot of work on the ajax update front.
hamidouk
parents: 674
diff changeset
   159
      obj["desc"] = a.content.description;
329333e07267 lot of work on the ajax update front.
hamidouk
parents: 674
diff changeset
   160
      obj["begin"] = IriSP.msToTime(annotation.begin);
329333e07267 lot of work on the ajax update front.
hamidouk
parents: 674
diff changeset
   161
      obj["end"] = IriSP.msToTime(annotation.end);
714
9056928c46de WIP - making links to only annotations which are not present in the opened
hamidouk
parents: 703
diff changeset
   162
9056928c46de WIP - making links to only annotations which are not present in the opened
hamidouk
parents: 703
diff changeset
   163
      /* only if the annotation isn't present in the document create an
9056928c46de WIP - making links to only annotations which are not present in the opened
hamidouk
parents: 703
diff changeset
   164
         external link */
9056928c46de WIP - making links to only annotations which are not present in the opened
hamidouk
parents: 703
diff changeset
   165
      if (!this.annotations_ids.hasOwnProperty(obj["id"])) {
9056928c46de WIP - making links to only annotations which are not present in the opened
hamidouk
parents: 703
diff changeset
   166
        // braindead url; jacques didn't want to create a new one in the platform,
9056928c46de WIP - making links to only annotations which are not present in the opened
hamidouk
parents: 703
diff changeset
   167
        // so we append the cutting id to the url.
9056928c46de WIP - making links to only annotations which are not present in the opened
hamidouk
parents: 703
diff changeset
   168
        obj["url"] = this.project_url + "/" + media + "/" + 
9056928c46de WIP - making links to only annotations which are not present in the opened
hamidouk
parents: 703
diff changeset
   169
                     annotation.meta["project"] + "/" +
745
a996a24e07d6 fixed url generation bug.
hamidouk
parents: 730
diff changeset
   170
                     annotation.meta["id-ref"];
714
9056928c46de WIP - making links to only annotations which are not present in the opened
hamidouk
parents: 703
diff changeset
   171
        
9056928c46de WIP - making links to only annotations which are not present in the opened
hamidouk
parents: 703
diff changeset
   172
        // obj["url"] = document.location.href.split("#")[0] + "/" + annotation.meta["project"];
9056928c46de WIP - making links to only annotations which are not present in the opened
hamidouk
parents: 703
diff changeset
   173
      }
716
16d61d539cbf fixed stupid bug.
hamidouk
parents: 714
diff changeset
   174
      
16d61d539cbf fixed stupid bug.
hamidouk
parents: 714
diff changeset
   175
      l.push(obj);
698
329333e07267 lot of work on the ajax update front.
hamidouk
parents: 674
diff changeset
   176
  }
703
9341d858bf8e removed useless printfs.
hamidouk
parents: 698
diff changeset
   177
698
329333e07267 lot of work on the ajax update front.
hamidouk
parents: 674
diff changeset
   178
  this.do_redraw(l);
329333e07267 lot of work on the ajax update front.
hamidouk
parents: 674
diff changeset
   179
};
599
a5a5e70d46a7 added support for widget redrawing.
hamidouk
parents: 595
diff changeset
   180
IriSP.AnnotationsListWidget.prototype.draw = function() {
714
9056928c46de WIP - making links to only annotations which are not present in the opened
hamidouk
parents: 703
diff changeset
   181
  
9056928c46de WIP - making links to only annotations which are not present in the opened
hamidouk
parents: 703
diff changeset
   182
  /* build a table of the annotations present in the document for faster 
9056928c46de WIP - making links to only annotations which are not present in the opened
hamidouk
parents: 703
diff changeset
   183
     lookup
9056928c46de WIP - making links to only annotations which are not present in the opened
hamidouk
parents: 703
diff changeset
   184
  */
9056928c46de WIP - making links to only annotations which are not present in the opened
hamidouk
parents: 703
diff changeset
   185
  this.annotations_ids = {};
9056928c46de WIP - making links to only annotations which are not present in the opened
hamidouk
parents: 703
diff changeset
   186
  
9056928c46de WIP - making links to only annotations which are not present in the opened
hamidouk
parents: 703
diff changeset
   187
  var annotations = this._serializer._data.annotations;
9056928c46de WIP - making links to only annotations which are not present in the opened
hamidouk
parents: 703
diff changeset
   188
  var i = 0;
9056928c46de WIP - making links to only annotations which are not present in the opened
hamidouk
parents: 703
diff changeset
   189
  for(i = 0; i < annotations.length; i++) {
9056928c46de WIP - making links to only annotations which are not present in the opened
hamidouk
parents: 703
diff changeset
   190
    this.annotations_ids[annotations[i]["id"]] = 1;
9056928c46de WIP - making links to only annotations which are not present in the opened
hamidouk
parents: 703
diff changeset
   191
  }
9056928c46de WIP - making links to only annotations which are not present in the opened
hamidouk
parents: 703
diff changeset
   192
  
599
a5a5e70d46a7 added support for widget redrawing.
hamidouk
parents: 595
diff changeset
   193
  this.drawList();
674
835f5f454595 WIP - working on ajax autoupdate of the widget.
hamidouk
parents: 642
diff changeset
   194
    
698
329333e07267 lot of work on the ajax update front.
hamidouk
parents: 674
diff changeset
   195
  if (!this.ajax_mode) {    
674
835f5f454595 WIP - working on ajax autoupdate of the widget.
hamidouk
parents: 642
diff changeset
   196
    this._Popcorn.listen("IriSP.createAnnotationWidget.addedAnnotation", IriSP.wrap(this, function() { this.drawList(true); }));
698
329333e07267 lot of work on the ajax update front.
hamidouk
parents: 674
diff changeset
   197
    this._Popcorn.listen("timeupdate", IriSP.wrap(this, this.redraw));
674
835f5f454595 WIP - working on ajax autoupdate of the widget.
hamidouk
parents: 642
diff changeset
   198
  } else {
729
7ba63d0315ad load the widget when the video has finished loading.
hamidouk
parents: 716
diff changeset
   199
    /* update the widget when the video has finished loading and when it's seeked and paused */
698
329333e07267 lot of work on the ajax update front.
hamidouk
parents: 674
diff changeset
   200
    this._Popcorn.listen("seeked", IriSP.wrap(this, this.ajaxRedraw));
729
7ba63d0315ad load the widget when the video has finished loading.
hamidouk
parents: 716
diff changeset
   201
    this._Popcorn.listen("loadedmetadata", IriSP.wrap(this, this.ajaxRedraw));
698
329333e07267 lot of work on the ajax update front.
hamidouk
parents: 674
diff changeset
   202
    this._Popcorn.listen("paused", IriSP.wrap(this, this.ajaxRedraw));
730
357fc047503b redraw the widget after that an annotation has been added.
hamidouk
parents: 729
diff changeset
   203
    
357fc047503b redraw the widget after that an annotation has been added.
hamidouk
parents: 729
diff changeset
   204
    this._Popcorn.listen("IriSP.createAnnotationWidget.addedAnnotation", IriSP.wrap(this, this.ajaxRedraw));
674
835f5f454595 WIP - working on ajax autoupdate of the widget.
hamidouk
parents: 642
diff changeset
   205
  }
698
329333e07267 lot of work on the ajax update front.
hamidouk
parents: 674
diff changeset
   206
599
a5a5e70d46a7 added support for widget redrawing.
hamidouk
parents: 595
diff changeset
   207
};
a5a5e70d46a7 added support for widget redrawing.
hamidouk
parents: 595
diff changeset
   208
a5a5e70d46a7 added support for widget redrawing.
hamidouk
parents: 595
diff changeset
   209
IriSP.AnnotationsListWidget.prototype.redraw = function() {
a5a5e70d46a7 added support for widget redrawing.
hamidouk
parents: 595
diff changeset
   210
  this.drawList();
585
44a4a4a179c1 first version of the AnnotationListWidget.
hamidouk
parents:
diff changeset
   211
};