90 |
89 |
91 }; |
90 }; |
92 |
91 |
93 IriSP.AnnotationsListWidget.prototype.ajaxRedraw = function(timecode) { |
92 IriSP.AnnotationsListWidget.prototype.ajaxRedraw = function(timecode) { |
94 var pre_url = IriSP.widgetsDefaults["AnnotationsListWidget"].ajax_url; |
93 var pre_url = IriSP.widgetsDefaults["AnnotationsListWidget"].ajax_url; |
95 var templ = "{{pre_url}}/{{content_id}}/{{begin_timecode}}/{{end_timecode}}/"; |
94 var media_id = this._serializer.currentMedia()["id"]; |
|
95 var duration = +this._serializer.currentMedia().meta["dc:duration"]; |
|
96 |
|
97 var begin_timecode = (Math.floor(this._Popcorn.currentTime()) - 300) * 1000; |
|
98 if (begin_timecode < 0) |
|
99 begin_timecode = 0; |
|
100 |
|
101 var end_timecode = (Math.floor(this._Popcorn.currentTime()) + 300) * 1000; |
|
102 if (end_timecode > duration) |
|
103 end_timecode = duration; |
|
104 |
|
105 var templ = Mustache.to_html("{{pre_url}}/{{media_id}}/{{begin_timecode}}/{{end_timecode}}", |
|
106 {pre_url: pre_url, media_id: media_id, begin_timecode: begin_timecode, |
|
107 end_timecode: end_timecode}); |
|
108 |
|
109 /* we create on the fly a serializer to get the ajax */ |
|
110 var serializer = new IriSP.JSONSerializer(IriSP.__dataloader, templ); |
|
111 serializer.sync(IriSP.wrap(this, function(json) { this.processJson(json, serializer) })); |
96 }; |
112 }; |
97 |
113 |
|
114 /** process the received json - it's a bit hackish */ |
|
115 IriSP.AnnotationsListWidget.prototype.processJson = function(json, serializer) { |
|
116 /* FIXME: DRY the whole thing */ |
|
117 var annotations = serializer._data.annotations; |
|
118 if (IriSP.null_or_undefined(annotations)) |
|
119 return; |
|
120 |
|
121 var view_types = serializer.getIds("Contributions"); |
|
122 var l = []; |
|
123 |
|
124 for (i = 0; i < annotations.length; i++) { |
|
125 var annotation = annotations[i]; |
|
126 console.log(annotation); |
|
127 console.log(view_types, annotation.meta["id-ref"]); |
|
128 /* filter the annotations whose type is not the one we want */ |
|
129 /* We want _all_ the annotations. |
|
130 if (typeof(annotation.meta) !== "undefined" && typeof(annotation.meta["id-ref"]) !== "undefined" |
|
131 && !IriSP.underscore.include(view_types, annotation.meta["id-ref"])) { |
|
132 continue; |
|
133 } |
|
134 */ |
|
135 var a = annotation; |
|
136 var obj = {}; |
|
137 |
|
138 obj["id"] = a.id; |
|
139 obj["title"] = a.content.title; |
|
140 obj["desc"] = a.content.description; |
|
141 obj["begin"] = IriSP.msToTime(annotation.begin); |
|
142 obj["end"] = IriSP.msToTime(annotation.end); |
|
143 obj["url"] = document.location.href.split("#")[0] + "/" + annotation.meta["project"]; |
|
144 l.push(obj); |
|
145 } |
|
146 console.log(l); |
|
147 this.do_redraw(l); |
|
148 }; |
98 IriSP.AnnotationsListWidget.prototype.draw = function() { |
149 IriSP.AnnotationsListWidget.prototype.draw = function() { |
99 |
150 |
100 this.drawList(); |
151 this.drawList(); |
101 |
152 |
102 if (!this._ajax_mode) { |
153 if (!this.ajax_mode) { |
103 this._Popcorn.listen("IriSP.createAnnotationWidget.addedAnnotation", IriSP.wrap(this, function() { this.drawList(true); })); |
154 this._Popcorn.listen("IriSP.createAnnotationWidget.addedAnnotation", IriSP.wrap(this, function() { this.drawList(true); })); |
|
155 this._Popcorn.listen("timeupdate", IriSP.wrap(this, this.redraw)); |
104 } else { |
156 } else { |
105 this._Popcorn.listen("IriSP.StackGraphWidget.mouseOver", IriSP.wrap(this, this.ajaxRedraw)); |
157 this._Popcorn.listen("seeked", IriSP.wrap(this, this.ajaxRedraw)); |
|
158 this._Popcorn.listen("paused", IriSP.wrap(this, this.ajaxRedraw)); |
106 } |
159 } |
107 this._Popcorn.listen("timeupdate", IriSP.wrap(this, this.redraw)); |
160 |
108 }; |
161 }; |
109 |
162 |
110 IriSP.AnnotationsListWidget.prototype.redraw = function() { |
163 IriSP.AnnotationsListWidget.prototype.redraw = function() { |
111 this.drawList(); |
164 this.drawList(); |
112 }; |
165 }; |