5 |
5 |
6 this.checkOption('ajax_mode'); |
6 this.checkOption('ajax_mode'); |
7 this.checkOption('project_url'); |
7 this.checkOption('project_url'); |
8 this.checkOption('default_thumbnail'); |
8 this.checkOption('default_thumbnail'); |
9 this.checkOption("cinecast_version", false); |
9 this.checkOption("cinecast_version", false); |
|
10 this.checkOption("ajax_url"); |
10 this.searchRe = null; |
11 this.searchRe = null; |
11 this._ajax_cache = []; |
12 this._ajax_cache = []; |
12 var _this = this; |
13 var _this = this; |
13 |
14 |
14 this._Popcorn.listen("IriSP.search", function(searchString) { |
15 this._Popcorn.listen("IriSP.search", function(searchString) { |
71 }) |
72 }) |
72 } |
73 } |
73 }; |
74 }; |
74 |
75 |
75 IriSP.AnnotationsListWidget.prototype.transformAnnotation = function(a) { |
76 IriSP.AnnotationsListWidget.prototype.transformAnnotation = function(a) { |
76 var _this = this |
77 var _this = this; |
77 return { |
78 return { |
78 "id" : a.id, |
79 "id" : a.id, |
79 "title": this.cinecast_version ? IriSP.get_aliased(a.meta, ['creator_name', 'creator']) : a.content.title, |
80 "title": this.cinecast_version ? IriSP.get_aliased(a.meta, ['creator_name', 'creator']) : a.content.title, |
80 "desc" : this.cinecast_version ? a.content.data : a.content.description, |
81 "desc" : this.cinecast_version ? a.content.data : a.content.description, |
81 "begin": IriSP.msToTime(a.begin), |
82 "begin": IriSP.msToTime(a.begin), |
82 "end" : IriSP.msToTime(a.end), |
83 "end" : IriSP.msToTime(a.end), |
83 "thumbnail" : (typeof a.meta == "object" && typeof a.meta.thumbnail == "string") ? a.meta.thumbnail : this.default_thumbnail, |
84 "thumbnail" : (typeof a.meta == "object" && typeof a.meta.thumbnail == "string") ? a.meta.thumbnail : this.default_thumbnail, |
84 "url" : (typeof a.meta == "object" && typeof a.meta.url == "string") ? a.meta.url : null, |
85 "url" : (typeof a.meta == "object" && typeof a.meta.url == "string") ? a.meta.url : null, |
|
86 "created_at" :(typeof a.meta == "object" && typeof a.meta.created == "string") ? Date.parse(a.meta.created.replace(/^(\d{4})-(\d{2})-(\d{2})T(\d{2}\:\d{2}\:\d{2}).*$/,"$2/$3/$1 $4 UTC+0000")) : null, |
85 "tags": typeof a.tags == "object" |
87 "tags": typeof a.tags == "object" |
86 ? IriSP.underscore(a.tags) |
88 ? IriSP.underscore(a.tags) |
87 .chain() |
89 .chain() |
88 .map(function(_t) { |
90 .map(function(_t) { |
89 if (typeof _t == "string") { |
91 if (typeof _t == "string") { |
138 this._Popcorn.trigger("IriSP.search.matchFound"); |
140 this._Popcorn.trigger("IriSP.search.matchFound"); |
139 } else { |
141 } else { |
140 this._Popcorn.trigger("IriSP.search.noMatchFound"); |
142 this._Popcorn.trigger("IriSP.search.noMatchFound"); |
141 } |
143 } |
142 } |
144 } |
143 |
|
144 list = IriSP.underscore(list) |
145 list = IriSP.underscore(list) |
145 .chain() |
146 .chain() |
146 .sortBy(function(_o) { |
147 .sortBy(function(_o) { |
147 return _o.distance; |
148 return _o.distance; |
148 }) |
149 }) |
149 .first(10) |
150 .first(10) |
150 .sortBy(function(_o) { |
151 .sortBy(function(_o) { |
151 return _o.iterator; |
152 return (_this.cinecast_version ? - _o.created_at : _o.iterator); |
152 }) |
153 }) |
153 .value(); |
154 .value(); |
154 |
|
155 var idList = IriSP.underscore.pluck(list, "id").sort(); |
155 var idList = IriSP.underscore.pluck(list, "id").sort(); |
156 |
156 |
157 |
157 |
158 if (!IriSP.underscore.isEqual(this.__oldList, idList) || typeof(force_redraw) !== "undefined") { |
158 if (!IriSP.underscore.isEqual(this.__oldList, idList) || typeof(force_redraw) !== "undefined") { |
159 this.do_redraw(list); |
159 this.do_redraw(list); |
174 } else { |
174 } else { |
175 var tcode = timecode; |
175 var tcode = timecode; |
176 } |
176 } |
177 |
177 |
178 |
178 |
179 /* the platform gives us a special url - of the type : http://path/{media}/{begin}/{end} |
179 /* the platform gives us a special url - of the type : http://path/{{media}}/{{begin}}/{{end}} |
180 we double the braces using regexps and we feed it to mustache to build the correct url |
180 we double the braces using regexps and we feed it to mustache to build the correct url |
181 we have to do that because the platform only knows at run time what view it's displaying. |
181 we have to do that because the platform only knows at run time what view it's displaying. |
182 */ |
182 */ |
183 |
183 |
184 var platf_url = IriSP.widgetsDefaults.AnnotationsListWidget.ajax_url |
|
185 .replace(/\{/g, '{{').replace(/\}/g, '}}'); |
|
186 var media_id = this._serializer.currentMedia()["id"]; |
184 var media_id = this._serializer.currentMedia()["id"]; |
187 var duration = this._serializer.getDuration(); |
185 var duration = this._serializer.getDuration(); |
188 |
186 |
189 var begin_timecode = (Math.floor(tcode) - 300) * 1000; |
187 var begin_timecode = (Math.floor(tcode) - 300) * 1000; |
190 if (begin_timecode < 0) |
188 if (begin_timecode < 0) |
192 |
190 |
193 var end_timecode = (Math.floor(tcode) + 300) * 1000; |
191 var end_timecode = (Math.floor(tcode) + 300) * 1000; |
194 if (end_timecode > duration) |
192 if (end_timecode > duration) |
195 end_timecode = duration; |
193 end_timecode = duration; |
196 |
194 |
197 var templ = Mustache.to_html(platf_url, {media: media_id, begin: begin_timecode, |
195 var templ = Mustache.to_html(this.ajax_url, {media: media_id, begin: begin_timecode, |
198 end: end_timecode}); |
196 end: end_timecode}); |
199 |
197 |
200 /* we create on the fly a serializer to get the ajax */ |
198 /* we create on the fly a serializer to get the ajax */ |
201 var serializer = new IriSP.JSONSerializer(IriSP.__dataloader, templ); |
199 var serializer = new IriSP.JSONSerializer(IriSP.__dataloader, templ); |
202 serializer.sync(IriSP.wrap(this, function(json) { this.processJson(json, serializer) })); |
200 serializer.sync(IriSP.wrap(this, function(json) { this.processJson(json, serializer) })); |