| author | hamidouk |
| Wed, 18 Jan 2012 17:22:19 +0100 | |
| branch | popcorn-port |
| changeset 674 | 835f5f454595 |
| parent 642 | 37693f217f8c |
| child 698 | 329333e07267 |
| permissions | -rw-r--r-- |
| 585 | 1 |
IriSP.AnnotationsListWidget = function(Popcorn, config, Serializer) { |
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 | 5 |
|
6 |
this.ajax_mode = IriSP.widgetsDefaults["AnnotationsListWidget"].ajax_mode; |
|
| 585 | 7 |
}; |
8 |
||
9 |
||
10 |
IriSP.AnnotationsListWidget.prototype = new IriSP.Widget(); |
|
11 |
||
12 |
IriSP.AnnotationsListWidget.prototype.clear = function() { |
|
13 |
}; |
|
14 |
||
| 588 | 15 |
IriSP.AnnotationsListWidget.prototype.clearWidget = function() { |
| 585 | 16 |
}; |
17 |
||
| 629 | 18 |
/** effectively redraw the widget - called by drawList */ |
19 |
IriSP.AnnotationsListWidget.prototype.do_redraw = function(list) { |
|
20 |
var widgetMarkup = IriSP.templToHTML(IriSP.annotationsListWidget_template, {annotations: list}); |
|
21 |
this.selector.html(widgetMarkup); |
|
22 |
}; |
|
23 |
||
| 599 | 24 |
/** 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
|
25 |
IriSP.AnnotationsListWidget.prototype.drawList = function(force_redraw) { |
| 585 | 26 |
var _this = this; |
| 674 | 27 |
|
|
595
29d86e6c61a6
finished going through the widgets to add stricter line checking.
hamidouk
parents:
588
diff
changeset
|
28 |
var view_type = this._serializer.getContributions(); |
| 585 | 29 |
var annotations = this._serializer._data.annotations; |
| 602 | 30 |
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
|
31 |
|
| 585 | 32 |
var list = []; |
| 588 | 33 |
|
| 621 | 34 |
if (typeof(view_type) === "undefined") { |
| 585 | 35 |
return; |
36 |
} |
|
| 588 | 37 |
|
| 585 | 38 |
for (i = 0; i < annotations.length; i++) { |
39 |
var annotation = annotations[i]; |
|
40 |
||
41 |
/* filter the annotations whose type is not the one we want */ |
|
42 |
if (typeof(annotation.meta) !== "undefined" && typeof(annotation.meta["id-ref"]) !== "undefined" |
|
| 615 | 43 |
&& annotation.meta["id-ref"] !== view_type) { |
| 585 | 44 |
continue; |
45 |
} |
|
46 |
||
| 602 | 47 |
/* only get the annotations happening in the current chapter */ |
| 603 | 48 |
if (!(annotation.begin <= currentTime * 1000 && annotation.end > currentTime * 1000)) { |
| 602 | 49 |
continue; |
50 |
} |
|
| 603 | 51 |
|
| 585 | 52 |
var a = annotation; |
53 |
var obj = {}; |
|
| 588 | 54 |
|
| 585 | 55 |
obj["id"] = a.id; |
56 |
obj["title"] = a.content.title; |
|
57 |
obj["desc"] = a.content.description; |
|
| 603 | 58 |
obj["begin"] = IriSP.msToTime(annotation.begin); |
59 |
obj["end"] = IriSP.msToTime(annotation.end); |
|
| 588 | 60 |
|
| 585 | 61 |
list.push(obj); |
62 |
} |
|
|
607
0b94ae49efbd
added an option to force the redraw of a list, even if the cached lists are the
hamidouk
parents:
605
diff
changeset
|
63 |
|
|
605
e1a6f73038b4
made the listWidget redraw at every timeupdate event (added a small optimization though,
hamidouk
parents:
603
diff
changeset
|
64 |
var idList = IriSP.underscore.pluck(list, "id").sort(); |
| 642 | 65 |
|
|
605
e1a6f73038b4
made the listWidget redraw at every timeupdate event (added a small optimization though,
hamidouk
parents:
603
diff
changeset
|
66 |
if (idList.length !== this.__oldList.length) { |
| 629 | 67 |
this.do_redraw(list); |
|
605
e1a6f73038b4
made the listWidget redraw at every timeupdate event (added a small optimization though,
hamidouk
parents:
603
diff
changeset
|
68 |
} |
|
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 |
var res = 1; |
|
e1a6f73038b4
made the listWidget redraw at every timeupdate event (added a small optimization though,
hamidouk
parents:
603
diff
changeset
|
71 |
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
|
72 |
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
|
73 |
res = 0; |
|
e1a6f73038b4
made the listWidget redraw at every timeupdate event (added a small optimization though,
hamidouk
parents:
603
diff
changeset
|
74 |
break; |
|
e1a6f73038b4
made the listWidget redraw at every timeupdate event (added a small optimization though,
hamidouk
parents:
603
diff
changeset
|
75 |
} |
|
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 |
this.__oldList = idList; /* save for next call */ |
|
607
0b94ae49efbd
added an option to force the redraw of a list, even if the cached lists are the
hamidouk
parents:
605
diff
changeset
|
78 |
|
|
0b94ae49efbd
added an option to force the redraw of a list, even if the cached lists are the
hamidouk
parents:
605
diff
changeset
|
79 |
if (typeof(force_redraw) !== "undefined") { |
|
0b94ae49efbd
added an option to force the redraw of a list, even if the cached lists are the
hamidouk
parents:
605
diff
changeset
|
80 |
console.log("forced redraw"); |
| 629 | 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 | 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 | 91 |
}; |
92 |
||
| 674 | 93 |
IriSP.AnnotationsListWidget.prototype.ajaxRedraw = function(timecode) { |
94 |
var pre_url = IriSP.widgetsDefaults["AnnotationsListWidget"].ajax_url; |
|
95 |
var templ = "{{pre_url}}/{{content_id}}/{{begin_timecode}}/{{end_timecode}}/"; |
|
96 |
}; |
|
97 |
||
| 599 | 98 |
IriSP.AnnotationsListWidget.prototype.draw = function() { |
99 |
||
100 |
this.drawList(); |
|
| 674 | 101 |
|
102 |
if (!this._ajax_mode) { |
|
103 |
this._Popcorn.listen("IriSP.createAnnotationWidget.addedAnnotation", IriSP.wrap(this, function() { this.drawList(true); })); |
|
104 |
} else { |
|
105 |
this._Popcorn.listen("IriSP.StackGraphWidget.mouseOver", IriSP.wrap(this, this.ajaxRedraw)); |
|
106 |
} |
|
|
605
e1a6f73038b4
made the listWidget redraw at every timeupdate event (added a small optimization though,
hamidouk
parents:
603
diff
changeset
|
107 |
this._Popcorn.listen("timeupdate", IriSP.wrap(this, this.redraw)); |
| 599 | 108 |
}; |
109 |
||
110 |
IriSP.AnnotationsListWidget.prototype.redraw = function() { |
|
111 |
this.drawList(); |
|
| 585 | 112 |
}; |