| author | veltr |
| Tue, 22 May 2012 16:49:48 +0200 | |
| branch | new-model |
| changeset 906 | 4b6e154ae8de |
| parent 904 | 510ebab76fa3 |
| child 908 | f56199193fad |
| permissions | -rw-r--r-- |
| 880 | 1 |
IriSP.Widgets.CreateAnnotation = function(player, config) { |
2 |
IriSP.Widgets.Widget.call(this, player, config); |
|
3 |
this.lastAnnotation = false; |
|
4 |
}; |
|
5 |
||
6 |
IriSP.Widgets.CreateAnnotation.prototype = new IriSP.Widgets.Widget(); |
|
7 |
||
8 |
IriSP.Widgets.CreateAnnotation.prototype.defaults = { |
|
| 904 | 9 |
show_title_field : false, |
10 |
user_avatar : "https://si0.twimg.com/sticky/default_profile_images/default_profile_1_normal.png", |
|
11 |
tags : false, |
|
12 |
max_tags : 8, |
|
13 |
polemics : [{ |
|
14 |
keyword: "++", |
|
15 |
background_color: "#00a000", |
|
16 |
text_color: "#ffffff" |
|
17 |
},{ |
|
18 |
keyword: "--", |
|
19 |
background_color: "#c00000", |
|
20 |
text_color: "#ffffff" |
|
21 |
},{ |
|
22 |
keyword: "??", |
|
23 |
background_color: "#0000e0", |
|
24 |
text_color: "#ffffff" |
|
25 |
},{ |
|
26 |
keyword: "==", |
|
27 |
background_color: "#f0e000", |
|
28 |
text_color: "#000000" |
|
29 |
}], |
|
30 |
annotation_type: "Contributions", |
|
31 |
creator_name: "", |
|
32 |
api_serializer: "ldt_annotate" |
|
| 882 | 33 |
/* |
| 904 | 34 |
|
| 882 | 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 |
*/ |
|
| 880 | 60 |
} |
61 |
||
62 |
IriSP.Widgets.CreateAnnotation.prototype.messages = { |
|
| 882 | 63 |
en: { |
64 |
from_time: "from", |
|
65 |
to_time: "to", |
|
66 |
submit: "Submit", |
|
| 904 | 67 |
add_keywords_: "Add keywords:", |
68 |
add_polemic_keywords_: "Add polemic keywords:", |
|
| 882 | 69 |
your_name: "Your name", |
70 |
no_title: "Annotate this video", |
|
71 |
type_title: "Annotation title", |
|
72 |
type_description: "Type the full description of your annotation here.", |
|
73 |
wait_while_processing: "Please wait while your request is being processed...", |
|
74 |
error_while_contacting: "An error happened while contacting the server. Your annotation has not been saved.", |
|
75 |
empty_annotation: "Your annotation is empty. Please write something before submitting.", |
|
76 |
annotation_saved: "Thank you, your annotation has been saved.", |
|
77 |
share_annotation: "Would you like to share it on social networks ?", |
|
78 |
share_on: "Share on", |
|
79 |
more_tags: "More tags", |
|
80 |
cancel: "Cancel" |
|
| 880 | 81 |
}, |
| 882 | 82 |
fr: { |
| 904 | 83 |
from_time: "de", |
| 882 | 84 |
to_time: "Ã ", |
85 |
submit: "Envoyer", |
|
| 904 | 86 |
add_keywords_: "Ajouter des mots-clés :", |
87 |
add_polemic_keywords_: "Ajouter des mots-clés polémiques :", |
|
| 882 | 88 |
your_name: "Votre nom", |
89 |
no_title: "Annoter cette vidéo", |
|
90 |
type_title: "Titre de l'annotation", |
|
91 |
type_description: "Rédigez le contenu de votre annotation ici.", |
|
92 |
wait_while_processing: "Veuillez patienter pendant le traitement de votre requête...", |
|
93 |
error_while_contacting: "Une erreur s'est produite en contactant le serveur. Votre annotation n'a pas été enregistrée", |
|
94 |
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.", |
|
96 |
share_annotation: "Souhaitez-vous la partager sur les réseaux sociaux ?", |
|
97 |
share_on: "Partager sur", |
|
98 |
more_tags: "Plus de mots-clés", |
|
99 |
cancel: "Cancel" |
|
| 880 | 100 |
} |
101 |
} |
|
102 |
||
103 |
IriSP.Widgets.CreateAnnotation.prototype.template = |
|
| 881 | 104 |
'<div class="Ldt-CreateAnnotation"><div class="Ldt-CreateAnnotation-Inner">' |
105 |
+ '<form class="Ldt-CreateAnnotation-Screen Ldt-CreateAnnotation-Main">' |
|
106 |
+ '<h3>{{#show_title_field}}<input class="Ldt-CreateAnnotation-Title" placeholder="{{l10n.type_title}}" />{{/show_title_field}}' |
|
| 904 | 107 |
+ '{{^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>' |
|
109 |
+ ' {{l10n.to_time}} <span class="Ldt-CreateAnnotation-End"></span></span></h3>' |
|
110 |
+ '<textarea class="Ldt-CreateAnnotation-Description" placeholder="{{l10n.type_description}}"></textarea>' |
|
111 |
+ '<div class="Ldt-CreateAnnotation-Avatar"><img src="{{user_avatar}}"></img></div>' |
|
112 |
+ '<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">' |
|
114 |
+ '{{#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">' |
|
116 |
+ '{{#polemics}}<li class="Ldt-CreateAnnotation-PolemicLi" style="background-color: {{background_color}}; color: {{text_color}}">{{keyword}}</li>{{/polemics}}</ul></div>{{/polemics.length}}' |
|
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
882
diff
changeset
|
117 |
+ '</form>' |
| 904 | 118 |
+ '<div style="clear: both;"></div></div></div>'; |
| 880 | 119 |
|
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
882
diff
changeset
|
120 |
IriSP.Widgets.CreateAnnotation.prototype.draw = function() { |
| 904 | 121 |
if (!this.tags) { |
122 |
this.tags = this.source.getTags() |
|
123 |
.sortBy(function (_tag) { |
|
124 |
return -_tag.getAnnotations().length; |
|
125 |
}) |
|
126 |
.slice(0, this.max_tags) |
|
127 |
.map(function(_tag) { |
|
128 |
return _tag; |
|
129 |
}); |
|
130 |
// We have to use the map function because Mustache doesn't like our tags object |
|
131 |
} |
|
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
882
diff
changeset
|
132 |
this.renderTemplate(); |
| 904 | 133 |
var _this = this; |
134 |
this.$.find(".Ldt-CreateAnnotation-TagLi, .Ldt-CreateAnnotation-PolemicLi").click(function() { |
|
135 |
_this.addKeyword(IriSP.jQuery(this).text().replace(/(^\s+|\s+$)/g,'')); |
|
136 |
return false; |
|
137 |
}); |
|
138 |
this.$.find(".Ldt-CreateAnnotation-Description").bind("change keyup input paste", this.functionWrapper("onDescriptionChange")); |
|
139 |
if (this.show_title_field) { |
|
140 |
this.$.find(".Ldt-CreateAnnotation-Title").bind("change keyup input paste", this.functionWrapper("onTitleChange")); |
|
141 |
} |
|
142 |
|
|
143 |
this.$.hide(); |
|
144 |
this.hide(); |
|
145 |
this.bindPopcorn("IriSP.CreateAnnotation.toggle","toggle"); |
|
146 |
this.bindPopcorn("IriSP.Slice.boundsChanged","onBoundsChanged"); |
|
147 |
this.begin = new IriSP.Model.Time(); |
|
148 |
this.end = this.source.getDuration(); |
|
149 |
this.$.find("form").submit(this.functionWrapper("onSubmit")); |
|
150 |
} |
|
151 |
||
152 |
IriSP.Widgets.CreateAnnotation.prototype.show = function() { |
|
153 |
this.visible = true; |
|
154 |
this.$.slideDown(); |
|
155 |
this.player.popcorn.trigger("IriSP.Annotation.minimize"); |
|
156 |
this.player.popcorn.trigger("IriSP.Slice.show"); |
|
157 |
} |
|
158 |
||
159 |
IriSP.Widgets.CreateAnnotation.prototype.hide = function() { |
|
160 |
this.visible = false; |
|
161 |
this.$.slideUp(); |
|
162 |
this.player.popcorn.trigger("IriSP.Annotation.maximize"); |
|
163 |
this.player.popcorn.trigger("IriSP.Slice.hide"); |
|
164 |
} |
|
165 |
||
166 |
IriSP.Widgets.CreateAnnotation.prototype.toggle = function() { |
|
167 |
if (this.visible) { |
|
168 |
this.hide(); |
|
169 |
} else { |
|
170 |
this.show(); |
|
171 |
} |
|
172 |
} |
|
173 |
||
174 |
IriSP.Widgets.CreateAnnotation.prototype.onBoundsChanged = function(_values) { |
|
175 |
this.begin = new IriSP.Model.Time(_values[0]); |
|
176 |
this.end = new IriSP.Model.Time(_values[1]); |
|
177 |
this.$.find(".Ldt-CreateAnnotation-Begin").html(this.begin.toString()); |
|
178 |
this.$.find(".Ldt-CreateAnnotation-End").html(this.end.toString()); |
|
179 |
} |
|
180 |
||
181 |
IriSP.Widgets.CreateAnnotation.prototype.addKeyword = function(_keyword) { |
|
182 |
var _field = this.$.find(".Ldt-CreateAnnotation-Description"), |
|
183 |
_rx = IriSP.Model.regexpFromTextOrArray(_keyword), |
|
184 |
_contents = _field.val(); |
|
185 |
_contents = ( _rx.test(_contents) |
|
186 |
? _contents.replace(_rx,"") |
|
187 |
: _contents + " " + _keyword |
|
188 |
); |
|
189 |
_field.val(_contents.replace(/\s{2,}/g,' ').replace(/(^\s+|\s+$)/g,'')); |
|
190 |
this.onDescriptionChange(); |
|
191 |
} |
|
192 |
||
193 |
IriSP.Widgets.CreateAnnotation.prototype.onDescriptionChange = function() { |
|
194 |
var _field = this.$.find(".Ldt-CreateAnnotation-Description"), |
|
195 |
_contents = _field.val(); |
|
196 |
_field.css("border-color", !!_contents ? "#666666" : "#c00000"); |
|
197 |
this.$.find(".Ldt-CreateAnnotation-TagLi, .Ldt-CreateAnnotation-PolemicLi").each(function() { |
|
198 |
var _rx = IriSP.Model.regexpFromTextOrArray(IriSP.jQuery(this).text().replace(/(^\s+|\s+$)/g,'')); |
|
199 |
if (_rx.test(_contents)) { |
|
200 |
IriSP.jQuery(this).addClass("selected"); |
|
201 |
} else { |
|
202 |
IriSP.jQuery(this).removeClass("selected"); |
|
203 |
} |
|
204 |
}); |
|
205 |
return !!_contents; |
|
206 |
} |
|
207 |
||
208 |
IriSP.Widgets.CreateAnnotation.prototype.onTitleChange = function() { |
|
209 |
var _field = this.$.find(".Ldt-CreateAnnotation-Title"), |
|
210 |
_contents = _field.val(); |
|
211 |
_field.css("border-color", !!_contents ? "#666666" : "#c00000"); |
|
212 |
return !!_contents; |
|
213 |
} |
|
214 |
||
215 |
IriSP.Widgets.CreateAnnotation.prototype.onSubmit = function() { |
|
216 |
if (!this.onDescriptionChange() || (!this.onTitleChange() && this.show_title_field)) { |
|
217 |
return; |
|
218 |
} |
|
219 |
|
|
220 |
var _exportedAnnotations = new IriSP.Model.List(this.player.sourceManager); |
|
221 |
_export = this.player.sourceManager.newLocalSource({serializer: IriSP.serializers[this.api_serializer]}), |
|
222 |
_annotation = new IriSP.Model.Annotation(false, _export), |
|
223 |
_annotationType = new IriSP.Model.AnnotationType(false, _export); |
|
224 |
||
225 |
_annotationType.title = this.annotation_type; |
|
226 |
_annotation.setBegin(this.begin); |
|
227 |
_annotation.setEnd(this.end); |
|
228 |
_annotation.setMedia(this.source.currentMedia.id); |
|
229 |
_annotation.setAnnotationType(_annotationType.id); |
|
230 |
if (this.show_title_field) { |
|
231 |
_annotation.title = this.$.find(".Ldt-CreateAnnotation-Title").val() |
|
232 |
} |
|
233 |
_annotation.created = new Date(); |
|
234 |
_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")})); |
|
236 |
|
|
237 |
_export.creator = this.creator; |
|
238 |
_export.created = new Date(); |
|
239 |
_exportedAnnotations.push(_annotation); |
|
240 |
_export.addList("annotation",_exportedAnnotations); |
|
241 |
console.log(_export.serialize()); |
|
242 |
|
|
243 |
return false; |
|
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
882
diff
changeset
|
244 |
} |
| 880 | 245 |
|
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 |