|
1 /* TODO: Add Social Network Sharing and from field */ |
|
2 |
1 IriSP.Widgets.CreateAnnotation = function(player, config) { |
3 IriSP.Widgets.CreateAnnotation = function(player, config) { |
2 IriSP.Widgets.Widget.call(this, player, config); |
4 IriSP.Widgets.Widget.call(this, player, config); |
3 this.lastAnnotation = false; |
5 this.lastAnnotation = false; |
4 }; |
6 }; |
5 |
7 |
6 IriSP.Widgets.CreateAnnotation.prototype = new IriSP.Widgets.Widget(); |
8 IriSP.Widgets.CreateAnnotation.prototype = new IriSP.Widgets.Widget(); |
7 |
9 |
8 IriSP.Widgets.CreateAnnotation.prototype.defaults = { |
10 IriSP.Widgets.CreateAnnotation.prototype.defaults = { |
9 show_title_field : false, |
11 show_title_field : false, |
10 user_avatar : "https://si0.twimg.com/sticky/default_profile_images/default_profile_1_normal.png", |
12 creator_name : "", |
|
13 creator_avatar : "https://si0.twimg.com/sticky/default_profile_images/default_profile_1_normal.png", |
11 tags : false, |
14 tags : false, |
12 max_tags : 8, |
15 max_tags : 8, |
13 polemics : [{ |
16 polemics : [{ |
14 keyword: "++", |
17 keyword: "++", |
15 background_color: "#00a000", |
18 background_color: "#00a000", |
26 keyword: "==", |
29 keyword: "==", |
27 background_color: "#f0e000", |
30 background_color: "#f0e000", |
28 text_color: "#000000" |
31 text_color: "#000000" |
29 }], |
32 }], |
30 annotation_type: "Contributions", |
33 annotation_type: "Contributions", |
31 creator_name: "", |
34 api_serializer: "ldt_annotate", |
32 api_serializer: "ldt_annotate" |
35 api_endpoint_template: "", |
33 /* |
36 api_method: "PUT", |
34 |
37 close_widget_timeout: 0 |
35 remote_tags : false, |
|
36 random_tags : false, |
|
37 show_from_field : false, |
|
38 disable_share : false, |
|
39 polemic_mode : true, // enable polemics |
|
40 polemics : [{ |
|
41 className: "positive", |
|
42 keyword: "++" |
|
43 }, { |
|
44 className: "negative", |
|
45 keyword: "--" |
|
46 }, { |
|
47 className: "reference", |
|
48 keyword: "==" |
|
49 }, { |
|
50 className: "question", |
|
51 keyword: "??" |
|
52 }], |
|
53 cinecast_version : false, // put to false to enable the platform version, true for the festival cinecast one. |
|
54 |
|
55 // where does the widget PUT the annotations - this is a mustache template. id refers to the id of the media and is filled by the widget. |
|
56 |
|
57 api_endpoint_template : "", // platform_url + "/ldtplatform/api/ldt/annotations/{{id}}.json", |
|
58 api_method : "PUT" |
|
59 */ |
|
60 } |
38 } |
61 |
39 |
62 IriSP.Widgets.CreateAnnotation.prototype.messages = { |
40 IriSP.Widgets.CreateAnnotation.prototype.messages = { |
63 en: { |
41 en: { |
64 from_time: "from", |
42 from_time: "from", |
94 empty_annotation: "Votre annotation est vide. Merci de rédiger un texte avant de l'envoyer.", |
73 empty_annotation: "Votre annotation est vide. Merci de rédiger un texte avant de l'envoyer.", |
95 annotation_saved: "Merci, votre annotation a été enregistrée.", |
74 annotation_saved: "Merci, votre annotation a été enregistrée.", |
96 share_annotation: "Souhaitez-vous la partager sur les réseaux sociaux ?", |
75 share_annotation: "Souhaitez-vous la partager sur les réseaux sociaux ?", |
97 share_on: "Partager sur", |
76 share_on: "Partager sur", |
98 more_tags: "Plus de mots-clés", |
77 more_tags: "Plus de mots-clés", |
99 cancel: "Cancel" |
78 cancel: "Cancel", |
|
79 close_widget: "Hide the annotation creating block" |
100 } |
80 } |
101 } |
81 } |
102 |
82 |
103 IriSP.Widgets.CreateAnnotation.prototype.template = |
83 IriSP.Widgets.CreateAnnotation.prototype.template = |
104 '<div class="Ldt-CreateAnnotation"><div class="Ldt-CreateAnnotation-Inner">' |
84 '<div class="Ldt-CreateAnnotation"><div class="Ldt-CreateAnnotation-Inner">' |
106 + '<h3>{{#show_title_field}}<input class="Ldt-CreateAnnotation-Title" placeholder="{{l10n.type_title}}" />{{/show_title_field}}' |
86 + '<h3>{{#show_title_field}}<input class="Ldt-CreateAnnotation-Title" placeholder="{{l10n.type_title}}" />{{/show_title_field}}' |
107 + '{{^show_title_field}}<span class="Ldt-CreateAnnotation-NoTitle">{{l10n.no_title}} </span>{{/show_title_field}}' |
87 + '{{^show_title_field}}<span class="Ldt-CreateAnnotation-NoTitle">{{l10n.no_title}} </span>{{/show_title_field}}' |
108 + ' <span class="Ldt-CreateAnnotation-Times">{{l10n.from_time}} <span class="Ldt-CreateAnnotation-Begin"></span>' |
88 + ' <span class="Ldt-CreateAnnotation-Times">{{l10n.from_time}} <span class="Ldt-CreateAnnotation-Begin"></span>' |
109 + ' {{l10n.to_time}} <span class="Ldt-CreateAnnotation-End"></span></span></h3>' |
89 + ' {{l10n.to_time}} <span class="Ldt-CreateAnnotation-End"></span></span></h3>' |
110 + '<textarea class="Ldt-CreateAnnotation-Description" placeholder="{{l10n.type_description}}"></textarea>' |
90 + '<textarea class="Ldt-CreateAnnotation-Description" placeholder="{{l10n.type_description}}"></textarea>' |
111 + '<div class="Ldt-CreateAnnotation-Avatar"><img src="{{user_avatar}}"></img></div>' |
91 + '<div class="Ldt-CreateAnnotation-Avatar"><img src="{{creator_avatar}}" title="{{creator_name}}"></img></div>' |
112 + '<input type="submit" class="Ldt-CreateAnnotation-Submit" value="{{l10n.submit}}" />' |
92 + '<input type="submit" class="Ldt-CreateAnnotation-Submit" value="{{l10n.submit}}" />' |
113 + '{{#tags.length}}<div class="Ldt-CreateAnnotation-Tags"><div class="Ldt-CreateAnnotation-TagTitle">{{l10n.add_keywords_}}</div><ul class="Ldt-CreateAnnotation-TagList">' |
93 + '{{#tags.length}}<div class="Ldt-CreateAnnotation-Tags"><div class="Ldt-CreateAnnotation-TagTitle">{{l10n.add_keywords_}}</div><ul class="Ldt-CreateAnnotation-TagList">' |
114 + '{{#tags}}<li class="Ldt-CreateAnnotation-TagLi" tag-id="{{id}}"><span class="Ldt-CreateAnnotation-TagButton">{{title}}</span></li>{{/tags}}</ul></div>{{/tags.length}}' |
94 + '{{#tags}}<li class="Ldt-CreateAnnotation-TagLi" tag-id="{{id}}"><span class="Ldt-CreateAnnotation-TagButton">{{title}}</span></li>{{/tags}}</ul></div>{{/tags.length}}' |
115 + '{{#polemics.length}}<div class="Ldt-CreateAnnotation-Polemics"><div class="Ldt-CreateAnnotation-PolemicTitle">{{l10n.add_polemic_keywords_}}</div><ul class="Ldt-CreateAnnotation-PolemicList">' |
95 + '{{#polemics.length}}<div class="Ldt-CreateAnnotation-Polemics"><div class="Ldt-CreateAnnotation-PolemicTitle">{{l10n.add_polemic_keywords_}}</div><ul class="Ldt-CreateAnnotation-PolemicList">' |
116 + '{{#polemics}}<li class="Ldt-CreateAnnotation-PolemicLi" style="background-color: {{background_color}}; color: {{text_color}}">{{keyword}}</li>{{/polemics}}</ul></div>{{/polemics.length}}' |
96 + '{{#polemics}}<li class="Ldt-CreateAnnotation-PolemicLi" style="background-color: {{background_color}}; color: {{text_color}}">{{keyword}}</li>{{/polemics}}</ul></div>{{/polemics.length}}' |
117 + '</form>' |
97 + '<div style="clear: both;"></div></form>' |
118 + '<div style="clear: both;"></div></div></div>'; |
98 + '<div class="Ldt-CreateAnnotation-Screen Ldt-CreateAnnotation-Wait"><div class="Ldt-CreateAnnotation-InnerBox">{{l10n.wait_while_processing}}</div></div>' |
|
99 + '<div class="Ldt-CreateAnnotation-Screen Ldt-CreateAnnotation-Error"><a title="{{l10n.close_widget}}" class="Ldt-CreateAnnotation-Close" href="#"></a><div class="Ldt-CreateAnnotation-InnerBox">{{l10n.error_while_contacting}}</div></div>' |
|
100 + '<div class="Ldt-CreateAnnotation-Screen Ldt-CreateAnnotation-Saved"><a title="{{l10n.close_widget}}" class="Ldt-CreateAnnotation-Close" href="#"></a><div class="Ldt-CreateAnnotation-InnerBox">{{l10n.annotation_saved}}</div></div>' |
|
101 + '</div></div>'; |
119 |
102 |
120 IriSP.Widgets.CreateAnnotation.prototype.draw = function() { |
103 IriSP.Widgets.CreateAnnotation.prototype.draw = function() { |
121 if (!this.tags) { |
104 if (!this.tags) { |
122 this.tags = this.source.getTags() |
105 this.tags = this.source.getTags() |
123 .sortBy(function (_tag) { |
106 .sortBy(function (_tag) { |
147 this.begin = new IriSP.Model.Time(); |
134 this.begin = new IriSP.Model.Time(); |
148 this.end = this.source.getDuration(); |
135 this.end = this.source.getDuration(); |
149 this.$.find("form").submit(this.functionWrapper("onSubmit")); |
136 this.$.find("form").submit(this.functionWrapper("onSubmit")); |
150 } |
137 } |
151 |
138 |
|
139 IriSP.Widgets.CreateAnnotation.prototype.showScreen = function(_screenName) { |
|
140 this.$.find('.Ldt-CreateAnnotation-' + _screenName).show() |
|
141 .siblings().hide(); |
|
142 } |
|
143 |
152 IriSP.Widgets.CreateAnnotation.prototype.show = function() { |
144 IriSP.Widgets.CreateAnnotation.prototype.show = function() { |
153 this.visible = true; |
145 this.visible = true; |
|
146 this.showScreen('Main'); |
|
147 this.$.find(".Ldt-CreateAnnotation-Description").val("").css("border-color", "#666666"); |
|
148 this.$.find(".Ldt-CreateAnnotation-Title").val("").css("border-color", "#666666"); |
|
149 this.$.find(".Ldt-CreateAnnotation-TagLi, .Ldt-CreateAnnotation-PolemicLi").removeClass("selected"); |
154 this.$.slideDown(); |
150 this.$.slideDown(); |
155 this.player.popcorn.trigger("IriSP.Annotation.minimize"); |
151 this.player.popcorn.trigger("IriSP.Annotation.minimize"); |
156 this.player.popcorn.trigger("IriSP.Slice.show"); |
152 this.player.popcorn.trigger("IriSP.Slice.show"); |
157 } |
153 } |
158 |
154 |
191 } |
187 } |
192 |
188 |
193 IriSP.Widgets.CreateAnnotation.prototype.onDescriptionChange = function() { |
189 IriSP.Widgets.CreateAnnotation.prototype.onDescriptionChange = function() { |
194 var _field = this.$.find(".Ldt-CreateAnnotation-Description"), |
190 var _field = this.$.find(".Ldt-CreateAnnotation-Description"), |
195 _contents = _field.val(); |
191 _contents = _field.val(); |
196 _field.css("border-color", !!_contents ? "#666666" : "#c00000"); |
192 _field.css("border-color", !!_contents ? "#666666" : "#ff0000"); |
197 this.$.find(".Ldt-CreateAnnotation-TagLi, .Ldt-CreateAnnotation-PolemicLi").each(function() { |
193 this.$.find(".Ldt-CreateAnnotation-TagLi, .Ldt-CreateAnnotation-PolemicLi").each(function() { |
198 var _rx = IriSP.Model.regexpFromTextOrArray(IriSP.jQuery(this).text().replace(/(^\s+|\s+$)/g,'')); |
194 var _rx = IriSP.Model.regexpFromTextOrArray(IriSP.jQuery(this).text().replace(/(^\s+|\s+$)/g,'')); |
199 if (_rx.test(_contents)) { |
195 if (_rx.test(_contents)) { |
200 IriSP.jQuery(this).addClass("selected"); |
196 IriSP.jQuery(this).addClass("selected"); |
201 } else { |
197 } else { |
218 } |
214 } |
219 |
215 |
220 var _exportedAnnotations = new IriSP.Model.List(this.player.sourceManager); |
216 var _exportedAnnotations = new IriSP.Model.List(this.player.sourceManager); |
221 _export = this.player.sourceManager.newLocalSource({serializer: IriSP.serializers[this.api_serializer]}), |
217 _export = this.player.sourceManager.newLocalSource({serializer: IriSP.serializers[this.api_serializer]}), |
222 _annotation = new IriSP.Model.Annotation(false, _export), |
218 _annotation = new IriSP.Model.Annotation(false, _export), |
223 _annotationType = new IriSP.Model.AnnotationType(false, _export); |
219 _annotationType = new IriSP.Model.AnnotationType(false, _export), |
|
220 _url = Mustache.to_html(this.api_endpoint_template, {id: this.source.projectId}); |
224 |
221 |
225 _annotationType.title = this.annotation_type; |
222 _annotationType.title = this.annotation_type; |
226 _annotation.setBegin(this.begin); |
223 _annotation.setBegin(this.begin); |
227 _annotation.setEnd(this.end); |
224 _annotation.setEnd(this.end); |
228 _annotation.setMedia(this.source.currentMedia.id); |
225 _annotation.setMedia(this.source.currentMedia.id); |
232 } |
229 } |
233 _annotation.created = new Date(); |
230 _annotation.created = new Date(); |
234 _annotation.description = this.$.find(".Ldt-CreateAnnotation-Description").val(); |
231 _annotation.description = this.$.find(".Ldt-CreateAnnotation-Description").val(); |
235 _annotation.setTags(this.$.find(".Ldt-CreateAnnotation-TagLi.selected").map(function() { return IriSP.jQuery(this).attr("tag-id")})); |
232 _annotation.setTags(this.$.find(".Ldt-CreateAnnotation-TagLi.selected").map(function() { return IriSP.jQuery(this).attr("tag-id")})); |
236 |
233 |
237 _export.creator = this.creator; |
234 _export.creator = this.creator_name; |
238 _export.created = new Date(); |
235 _export.created = new Date(); |
239 _exportedAnnotations.push(_annotation); |
236 _exportedAnnotations.push(_annotation); |
240 _export.addList("annotation",_exportedAnnotations); |
237 _export.addList("annotation",_exportedAnnotations); |
241 console.log(_export.serialize()); |
238 |
|
239 var _this = this; |
|
240 IriSP.jQuery.ajax({ |
|
241 url: _url, |
|
242 type: this.api_method, |
|
243 contentType: 'application/json', |
|
244 data: _export.serialize(), |
|
245 success: function(_data) { |
|
246 _this.showScreen('Saved'); |
|
247 if (_this.close_widget_timeout) { |
|
248 window.setTimeout(_this.functionWrapper("hide"),_this.close_widget_timeout); |
|
249 } |
|
250 _export.getAnnotations().removeElement(_annotation, true); |
|
251 _export.deSerialize(_data); |
|
252 _this.source.merge(_export); |
|
253 _this.player.popcorn.trigger("IriSP.AnnotationsList.refresh"); |
|
254 }, |
|
255 error: function(_xhr, _error, _thrown) { |
|
256 IriSP.log("Error when sending annotation", _thrown); |
|
257 _this.showScreen('Error'); |
|
258 window.setTimeout(function(){ |
|
259 _this.showScreen("Main") |
|
260 }, |
|
261 (_this.close_widget_timeout || 5000)); |
|
262 } |
|
263 }); |
|
264 this.showScreen('Wait'); |
242 |
265 |
243 return false; |
266 return false; |
244 } |
267 } |
245 |
268 |
246 /* |
|
247 + ' <div class="Ldt-CreateAnnotation-Screen Ldt-createAnnotation-startScreen">' |
|
248 + ' <div style="margin-bottom: 7px; overflow: auto;">' |
|
249 + ' <div class="Ldt-createAnnotation-Title"></div>' |
|
250 + ' <div class="Ldt-createAnnotation-TimeFrame"></div>' |
|
251 + ' {{^cinecast_version}} <div class="Ldt-createAnnotation-Minimize Ldt-TraceMe" title="Cancel"></div>' |
|
252 + ' {{/cinecast_version}}' |
|
253 + ' </div>' |
|
254 + ' <div class="Ldt-createAnnotation-Container">' |
|
255 + ' {{#show_from_field}}' |
|
256 + ' <label>{{l10n.your_name}} : </label><input class="Ldt-createAnnotation-userName Ldt-TraceMe" value="{{user_name}}" />' |
|
257 + ' {{/show_from_field}}' |
|
258 + ' <textarea class="Ldt-createAnnotation-Description Ldt-TraceMe"></textarea>' |
|
259 + ' <div class="Ldt-createAnnotation-userAvatar Ldt-TraceMe">' |
|
260 + ' {{^user_avatar}} <img src="https://si0.twimg.com/sticky/default_profile_images/default_profile_1_normal.png"></img>' |
|
261 + ' {{/user_avatar}}' |
|
262 + ' {{#user_avatar}} <img src="{{ user_avatar }}"></img>' |
|
263 + ' {{/user_avatar}}' |
|
264 + ' </div>' |
|
265 + ' <div class="Ldt-createAnnotation-profileArrow"></div>' |
|
266 + ' </div>' |
|
267 + ' <button class="Ldt-createAnnotation-submitButton Ldt-TraceMe">{{l10n.submit}}</button>' |
|
268 + ' {{#tags.length}}' |
|
269 + ' <div class="Ldt-createAnnotation-btnblock Ldt-createAnnotation-keywords">' |
|
270 + ' <label>{{l10n.add_keywords}} :</label>' |
|
271 + ' <ul class="Ldt-floatList">' |
|
272 + ' {{#tags}}' |
|
273 + ' <li><button class="Ldt-createAnnotation-keyword-button Ldt-TraceMe" tag-id="{{id}}">{{meta.description}}</button></li>' |
|
274 + ' {{/tags}}' |
|
275 + ' </ul>' |
|
276 + ' </div>' |
|
277 + ' {{#random_tags}}' |
|
278 + ' <button class="Ldt-createAnnotation-moar-keywordz">{{l10n.more_tags}}</button>' |
|
279 + ' {{/random_tags}}' |
|
280 + ' {{/tags.length}}' |
|
281 + ' {{#polemic_mode}}' |
|
282 + ' {{#polemics.length}}' |
|
283 + ' <div class="Ldt-createAnnotation-btnblock Ldt-createAnnotation-polemics">' |
|
284 + ' <label>{{l10n.add_polemic_keywords}} :</label>' |
|
285 + ' <ul class="Ldt-floatList">' |
|
286 + ' {{#polemics}}' |
|
287 + ' <li><button class="Ldt-createAnnotation-polemic-{{className}} Ldt-createAnnotation-polemic-button Ldt-TraceMe">{{keyword}}</button></li>' |
|
288 + ' {{/polemics}}' |
|
289 + ' </ul>' |
|
290 + ' </div>' |
|
291 + ' {{/polemics.length}}' |
|
292 + ' {{/polemic_mode}}' |
|
293 + ' </div>' |
|
294 + ' <div class="Ldt-createAnnotation-screen Ldt-createAnnotation-waitScreen" style="display: none; text-align: center">' |
|
295 + ' <div class="Ldt-createAnnotation-spinner"></div>' |
|
296 + ' {{l10n.wait_while_processed}}' |
|
297 + ' </div>' |
|
298 + ' <div class="Ldt-createAnnotation-screen Ldt-createAnnotation-errorScreen" style="display: none; text-align: center">' |
|
299 + ' <div class="Ldt-createAnnotation-Minimize" title="Hide"></div>' |
|
300 + ' {{l10n.error_while_contacting}}' |
|
301 + ' </div>' |
|
302 + ' <div class="Ldt-createAnnotation-screen Ldt-createAnnotation-endScreen" style="display: none">' |
|
303 + ' <div class="Ldt-createAnnotation-Minimize" title="Hide"></div>' |
|
304 + ' {{l10n.annotation_saved}}' |
|
305 + ' <br>' |
|
306 + ' {{^disable_share}}' |
|
307 + ' {{l10n.share_annotation}}' |
|
308 + ' <div style="margin-top: 12px; text-align: center;">' |
|
309 + ' <a target="_blank" class="Ldt-createAnnotation-endScreen-TweetLink Ldt-TraceMe"></a>' |
|
310 + ' <a target="_blank" class="Ldt-createAnnotation-endScreen-FbLink Ldt-TraceMe"></a>' |
|
311 + ' <a target="_blank" class="Ldt-createAnnotation-endScreen-GplusLink Ldt-TraceMe"></a>' |
|
312 + ' </div>' |
|
313 + ' {{/disable_share}}' |
|
314 + ' </div>' |
|
315 + ' <div class="Ldt-floatClear"></div>' |
|
316 */ |
|
317 |
|