|
2
|
1 |
IriSP.Widgets.MusitagAnnotator = function(player, config) { |
|
|
2 |
IriSP.Widgets.Widget.call(this, player, config); |
|
|
3 |
}; |
|
|
4 |
|
|
|
5 |
IriSP.Widgets.MusitagAnnotator.prototype = new IriSP.Widgets.Widget(); |
|
|
6 |
|
|
|
7 |
IriSP.Widgets.MusitagAnnotator.prototype.defaults = { |
|
|
8 |
min_left: -90, |
|
|
9 |
max_right: 900, |
|
38
|
10 |
width: 870, |
|
|
11 |
record_swf: "", |
|
|
12 |
show_play_arrow: false, |
|
|
13 |
api_serializer: "ldt_annotate", |
|
|
14 |
api_endpoint_template: "", |
|
|
15 |
api_method: "PUT", |
|
40
|
16 |
close_widget_timeout: 4000, |
|
|
17 |
annotation_type: "contributions", |
|
54
|
18 |
creator_name: "musitag", |
|
|
19 |
emoticons: [ |
|
|
20 |
{ tag: "happy", name: "content"}, |
|
|
21 |
{ tag: "unhappy", name: "mécontent"}, |
|
|
22 |
{ tag: "laughing", name: "rigolard"}, |
|
|
23 |
{ tag: "surprised", name: "étonné"} |
|
|
24 |
], |
|
|
25 |
colors: [ |
|
|
26 |
{ tag: "red", name: "rouge"}, |
|
|
27 |
{ tag: "yellow", name: "jaune"}, |
|
|
28 |
{ tag: "green", name: "vert"}, |
|
|
29 |
{ tag: "blue", name: "bleu"} |
|
|
30 |
], |
|
2
|
31 |
}; |
|
|
32 |
|
|
|
33 |
IriSP.Widgets.MusitagAnnotator.prototype.template = |
|
|
34 |
'<div class="Musitag-Annotator-PositionBar"></div><div class="Musitag-Annotator-Main">' |
|
38
|
35 |
+ '<div class="Musitag-Annotator-MainScreen">' |
|
2
|
36 |
+ '<div class="Musitag-Annotator-section"><h2>1</h2>' |
|
|
37 |
+ ' <h3>Choisis<br />une couleur</h3>' |
|
|
38 |
+ ' <div class="Musitag-Annotator-selector">' |
|
54
|
39 |
+ '{{#colors}}' |
|
|
40 |
+ ' <div class="Musitag-container-80 Musitag-Annotator-tagInSelector" title="{{name}}">' |
|
2
|
41 |
+ ' <div class="Musitag-shadow"></div>' |
|
|
42 |
+ ' <div class="Musitag-color"></div>' |
|
54
|
43 |
+ ' <div class="Musitag-color Musitag-{{tag}}"></div>' |
|
2
|
44 |
+ ' </div>' |
|
54
|
45 |
+ '{{/colors}}' |
|
2
|
46 |
+ ' </div>' |
|
|
47 |
+ '</div>' |
|
|
48 |
+ '<div class="Musitag-Annotator-separator"></div>' |
|
|
49 |
+ '<div class="Musitag-Annotator-section">' |
|
|
50 |
+ ' <h2>2</h2>' |
|
|
51 |
+ ' <h3>Choisis<br />une émotion</h3>' |
|
|
52 |
+ ' <div class="Musitag-Annotator-selector">' |
|
54
|
53 |
+ '{{#emoticons}}' |
|
|
54 |
+ ' <div class="Musitag-container-80 Musitag-Annotator-tagInSelector" title="{{name}}">' |
|
2
|
55 |
+ ' <div class="Musitag-shadow"></div>' |
|
|
56 |
+ ' <div class="Musitag-color"></div>' |
|
54
|
57 |
+ ' <div class="Musitag-emoticon Musitag-{{tag}}"></div>' |
|
2
|
58 |
+ ' </div>' |
|
54
|
59 |
+ '{{/emoticons}}' |
|
2
|
60 |
+ ' </div>' |
|
|
61 |
+ '</div>' |
|
|
62 |
+ '<div class="Musitag-Annotator-separator"></div>' |
|
|
63 |
+ '<div class="Musitag-Annotator-section">' |
|
|
64 |
+ ' <h2>3</h2>' |
|
|
65 |
+ ' <h3>Enregistre<br />ta voix</h3>' |
|
13
|
66 |
+ ' <div class="Musitag-Annotator-record">' |
|
|
67 |
|
|
38
|
68 |
+ ' <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="220" height="160" id="record_mic" align="middle">' |
|
|
69 |
+ ' <param name="movie" value="{{record_swf}}" />' |
|
13
|
70 |
+ ' <param name="quality" value="high" />' |
|
|
71 |
+ ' <param name="bgcolor" value="#ffffff" />' |
|
|
72 |
+ ' <param name="play" value="true" />' |
|
|
73 |
+ ' <param name="loop" value="true" />' |
|
|
74 |
+ ' <param name="wmode" value="transparent" />' |
|
|
75 |
+ ' <param name="scale" value="showall" />' |
|
|
76 |
+ ' <param name="menu" value="true" />' |
|
|
77 |
+ ' <param name="devicefont" value="false" />' |
|
|
78 |
+ ' <param name="salign" value="" />' |
|
|
79 |
+ ' <param name="allowScriptAccess" value="always" />' |
|
|
80 |
+ ' <param name="allowFullScreen" value="true" />' |
|
38
|
81 |
+ ' <param name="flashvars" value="playVisible={{show_play_arrow}}">' |
|
|
82 |
+ ' <embed src="{{record_swf}}"" quality="high" bgcolor="#ffffff"' |
|
|
83 |
+ ' width="220" height="160" name="ExternalInterfaceExample" align="middle"' |
|
13
|
84 |
+ ' play="true" loop="false" quality="high" allowScriptAccess="always" ' |
|
|
85 |
+ ' type="application/x-shockwave-flash" allowFullScreen="true" wmode="transparent" ' |
|
38
|
86 |
+ ' flashvars="playVisible={{show_play_arrow}}"' |
|
13
|
87 |
+ ' pluginspage="http://www.macromedia.com/go/getflashplayer">' |
|
|
88 |
+ ' </embed>' |
|
|
89 |
+ ' </object>' |
|
|
90 |
|
|
|
91 |
|
|
|
92 |
+'</div>' |
|
2
|
93 |
+ '</div>' |
|
|
94 |
+ '<div class="Musitag-Annotator-separator"></div>' |
|
|
95 |
+ '<div class="Musitag-Annotator-section">' |
|
|
96 |
+ ' <h2>4</h2>' |
|
|
97 |
+ ' <h3>Envoie<br />ton Musitag</h3>' |
|
|
98 |
+ ' <div class="Musitag-Annotator-Note">' |
|
|
99 |
+ ' <div class="Musitag-container-80 Musitag-Annotator-tagInSend">' |
|
|
100 |
+ ' <div class="Musitag-shadow"></div>' |
|
|
101 |
+ ' <div class="Musitag-color"></div>' |
|
10
|
102 |
+ ' <div class="Musitag-emoticon"></div>' |
|
2
|
103 |
+ ' </div>' |
|
|
104 |
+ ' </div>' |
|
|
105 |
+ '</div>' |
|
|
106 |
+ '<div class="Musitag-Annotator-close"></div>' |
|
38
|
107 |
+ '</div><div class="Musitag-Annotator-EndScreen Musitag-Annotator-TextMessage">Ton Musitag a bien été enregistré :-)</div>' |
|
|
108 |
+ '<div class="Musitag-Annotator-ErrorScreen Musitag-Annotator-TextMessage">Nous n\'avons pas réussi à envoyer ton Musitag :-(</div>' |
|
|
109 |
+ '<div class="Musitag-Annotator-WaitScreen Musitag-Annotator-TextMessage">Nous sommes en train d\'envoyer ton Musitag</div>' |
|
2
|
110 |
+ '</div></div>'; |
|
|
111 |
|
|
|
112 |
IriSP.Widgets.MusitagAnnotator.prototype.draw = function() { |
|
|
113 |
this.renderTemplate(); |
|
|
114 |
this.position_bar = this.$.find(".Musitag-Annotator-PositionBar"); |
|
|
115 |
this.position_bar.hide(); |
|
|
116 |
this.position_width = this.position_bar.outerWidth(); |
|
|
117 |
this.main_div = this.$.find(".Musitag-Annotator-Main"); |
|
|
118 |
this.$.hide(); |
|
|
119 |
this.main_width = this.main_div.outerWidth(); |
|
|
120 |
this.bindPopcorn("timeupdate","onTimeupdate"); |
|
|
121 |
this.bindPopcorn("IriSP.MusitagAnnotator.hide","hide"); |
|
|
122 |
this.bindPopcorn("IriSP.MusitagAnnotator.show","show"); |
|
15
|
123 |
this.recorder = this.$.find("embed")[0]; |
|
|
124 |
|
|
|
125 |
var _this = this; |
|
|
126 |
|
|
2
|
127 |
this.$.find('.Musitag-Annotator-tagInSelector').click(function() { |
|
|
128 |
var _class = IriSP.jQuery(this).children(':last-child').attr('class'), |
|
15
|
129 |
_classes = _class.split(' '), |
|
|
130 |
_type = _classes[0].replace(/^\w+-/,""), |
|
|
131 |
_value = _classes[1].replace(/^\w+-/,""); |
|
|
132 |
_this.annotation[_type] = _value; |
|
|
133 |
_this.checkAnnotation(); |
|
2
|
134 |
IriSP.jQuery('.Musitag-Annotator-tagInSend .' + _classes[0]).attr('class',_class); |
|
|
135 |
IriSP.jQuery(this).siblings().removeClass('down') |
|
|
136 |
.children(':last-child').css('opacity',.35); |
|
|
137 |
IriSP.jQuery(this).addClass('down') |
|
|
138 |
.children(':last-child').css('opacity',1); |
|
|
139 |
}); |
|
15
|
140 |
|
|
2
|
141 |
this.$.find('.Musitag-Annotator-close').click(function() { |
|
15
|
142 |
_this.recorder.stopRecord(); |
|
2
|
143 |
_this.hide(); |
|
15
|
144 |
}); |
|
|
145 |
|
|
|
146 |
this.$.find('.Musitag-Annotator-Note').click(function() { |
|
38
|
147 |
if (_this.checkAnnotation) { |
|
|
148 |
_this.recorder.stopRecord(); |
|
|
149 |
_this.sendAnnotation(); |
|
|
150 |
} |
|
15
|
151 |
}); |
|
|
152 |
|
|
|
153 |
window.setAudioUrl = function(_url) { |
|
|
154 |
_this.annotation.audio_url = _url; |
|
|
155 |
} |
|
2
|
156 |
} |
|
|
157 |
|
|
|
158 |
IriSP.Widgets.MusitagAnnotator.prototype.onTimeupdate = function() { |
|
|
159 |
var _x = Math.floor(this.width * this.player.popcorn.currentTime() / this.source.getDuration().getSeconds()); |
|
|
160 |
this.position_bar.css("margin-left", (_x - this.position_width / 2)+"px"); |
|
|
161 |
this.main_div.css("margin-left",Math.max(this.min_left, Math.min(this.max_right - this.main_width, _x - this.main_width / 2))+"px"); |
|
|
162 |
} |
|
|
163 |
|
|
15
|
164 |
IriSP.Widgets.MusitagAnnotator.prototype.checkAnnotation = function() { |
|
|
165 |
var _res = this.annotation.emoticon && this.annotation.color; |
|
|
166 |
this.$.find('.Musitag-Annotator-Note').css("opacity", _res ? 1 : .5); |
|
|
167 |
return _res; |
|
|
168 |
} |
|
|
169 |
|
|
38
|
170 |
IriSP.Widgets.MusitagAnnotator.prototype.showScreen = function(_screenName) { |
|
|
171 |
this.$.find('.Musitag-Annotator-' + _screenName + 'Screen').show() |
|
|
172 |
.siblings().hide(); |
|
|
173 |
} |
|
|
174 |
|
|
2
|
175 |
IriSP.Widgets.MusitagAnnotator.prototype.show = function() { |
|
45
|
176 |
if (!this.player.popcorn.media.paused) { |
|
|
177 |
this.player.popcorn.pause(); |
|
|
178 |
} |
|
2
|
179 |
this.$.show(); |
|
38
|
180 |
this.showScreen('Main'); |
|
10
|
181 |
this.$.find('.Musitag-Annotator-tagInSelector').removeClass("down"); |
|
|
182 |
this.$.find(".Musitag-Annotator-tagInSend .Musitag-color").attr("class","Musitag-color"); |
|
|
183 |
this.$.find(".Musitag-Annotator-tagInSend .Musitag-emoticon").attr("class","Musitag-emoticon hidden"); |
|
15
|
184 |
this.annotation = { |
|
38
|
185 |
timecode: Math.floor(this.player.popcorn.currentTime() * 1000), |
|
15
|
186 |
audio_url: false, |
|
|
187 |
emoticon: false, |
|
|
188 |
color: false |
|
|
189 |
}; |
|
|
190 |
this.checkAnnotation(); |
|
2
|
191 |
this.position_bar.slideDown(200); |
|
|
192 |
} |
|
|
193 |
|
|
|
194 |
IriSP.Widgets.MusitagAnnotator.prototype.hide = function() { |
|
|
195 |
var _this = this; |
|
45
|
196 |
this.player.popcorn.trigger("IriSP.MusitagAndYou.show"); |
|
2
|
197 |
this.position_bar.slideUp(200, function() { |
|
|
198 |
_this.$.hide(); |
|
|
199 |
}); |
|
|
200 |
} |
|
38
|
201 |
|
|
|
202 |
IriSP.Widgets.MusitagAnnotator.prototype.sendAnnotation = function() { |
|
|
203 |
var _exportedAnnotations = new IriSP.Model.List(this.player.sourceManager); |
|
|
204 |
_export = this.player.sourceManager.newLocalSource({serializer: IriSP.serializers[this.api_serializer]}), |
|
|
205 |
_annotation = new IriSP.Model.Annotation(false, _export), |
|
|
206 |
_annotationTypes = this.source.getAnnotationTypes().searchByTitle(this.annotation_type), |
|
|
207 |
_annotationType = (_annotationTypes.length ? _annotationTypes[0] : new IriSP.Model.AnnotationType(false, _export)), |
|
|
208 |
_color = new IriSP.Model.Tag(false, _export), |
|
|
209 |
_emoticon = new IriSP.Model.Tag(false, _export), |
|
|
210 |
_url = Mustache.to_html(this.api_endpoint_template, {id: this.source.projectId}); |
|
|
211 |
|
|
40
|
212 |
if (!_annotationTypes.length) { |
|
|
213 |
_annotationType.dont_send_id = true; |
|
|
214 |
} |
|
|
215 |
|
|
38
|
216 |
_color.title = this.annotation.color; |
|
|
217 |
_emoticon.title = this.annotation.emoticon; |
|
|
218 |
|
|
|
219 |
_annotationType.title = this.annotation_type; |
|
|
220 |
_annotation.setBegin(this.annotation.timecode); |
|
|
221 |
_annotation.setEnd(this.annotation.timecode); |
|
|
222 |
_annotation.setMedia(this.source.currentMedia.id); |
|
|
223 |
_annotation.setAnnotationType(_annotationType.id); |
|
|
224 |
_annotation.created = new Date(); |
|
|
225 |
_annotation.description = this.annotation.color + " " + this.annotation.emoticon; |
|
|
226 |
_annotation.setTags([_color.id, _emoticon.id]); |
|
|
227 |
|
|
|
228 |
if (this.annotation.audio_url) { |
|
|
229 |
_annotation.audio = { |
|
|
230 |
src: "mic", |
|
|
231 |
mimetype: "audio/mp3", |
|
|
232 |
href: this.annotation.audio_url |
|
|
233 |
}; |
|
|
234 |
} |
|
|
235 |
|
|
|
236 |
_export.creator = this.creator_name; |
|
|
237 |
_export.created = new Date(); |
|
|
238 |
_exportedAnnotations.push(_annotation); |
|
|
239 |
_export.addList("annotation",_exportedAnnotations); |
|
|
240 |
|
|
|
241 |
var _this = this; |
|
|
242 |
IriSP.jQuery.ajax({ |
|
|
243 |
url: _url, |
|
|
244 |
type: this.api_method, |
|
|
245 |
contentType: 'application/json', |
|
|
246 |
data: _export.serialize(), |
|
|
247 |
success: function(_data) { |
|
|
248 |
_this.showScreen('End'); |
|
|
249 |
window.setTimeout(_this.functionWrapper("hide"),_this.close_widget_timeout); |
|
|
250 |
_export.getAnnotations().removeElement(_annotation, true); |
|
|
251 |
_export.deSerialize(_data); |
|
|
252 |
_this.source.merge(_export); |
|
|
253 |
_this.player.popcorn.trigger("IriSP.MusitagAnnotations.redraw"); |
|
|
254 |
}, |
|
|
255 |
error: function(_xhr, _error, _thrown) { |
|
|
256 |
IriSP.log("Error when sending annotation", _thrown); |
|
62
|
257 |
_export.getAnnotations().removeElement(_annotation, true); |
|
38
|
258 |
_this.showScreen('Error'); |
|
|
259 |
window.setTimeout(function(){ |
|
|
260 |
_this.showScreen("Main"); |
|
|
261 |
}, |
|
|
262 |
_this.close_widget_timeout); |
|
|
263 |
} |
|
|
264 |
}); |
|
|
265 |
this.showScreen('Wait'); |
|
|
266 |
} |