| author | veltr |
| Tue, 04 Dec 2012 19:00:15 +0100 | |
| changeset 105 | 5b753c18e329 |
| parent 104 | 1b84c7b2aeee |
| child 109 | 3034776c1f35 |
| permissions | -rw-r--r-- |
|
41
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
1 |
IriSP.editor = function(options) { |
| 32 | 2 |
|
| 22 | 3 |
/* Load Media List */ |
4 |
|
|
5 |
var directory = new IriSP.Model.Directory(), |
|
| 42 | 6 |
apidirectory = new IriSP.Model.Directory(), |
| 22 | 7 |
project = directory.remoteSource({ |
| 49 | 8 |
url: IriSP.endpoints.content, |
9 |
url_params: _({}).extend(options.filter), |
|
10 |
serializer: IriSP.serializers.content |
|
11 |
}), |
|
| 25 | 12 |
mashup = new IriSP.Model.Mashup(false, project), |
| 45 | 13 |
mediatemplate = _.template( |
14 |
'<li class="item-video media" data-media-id="<%= id %>"><div class="media-count-wrap"><span class="media-count"></span></div>' |
|
15 |
+ '<img class="thumbnail" src="<%= thumbnail %>" alt="<%= title %>" />' |
|
| 43 | 16 |
+ '<div class="video-info"><h3 class="title-video"><%= title %></h3><p class="description"><%= description %></p>' |
| 104 | 17 |
+ '<p class="time-length"><%= gettext("Duration:") %> <span><%= duration.toString() %></span></p></div><div class="media-found-segments"></div></li>' |
| 45 | 18 |
), |
19 |
segmenttemplate = _.template( |
|
20 |
'<li class="item-video annotation" data-segment-id="<%= annotation.id %>" data-media-id="<%= annotation.getMedia().id %>">' |
|
21 |
+ '<img class="thumbnail" src="<%= annotation.thumbnail %>" alt="<%= annotation.getMedia().title %>" />' |
|
| 43 | 22 |
+ '<div class="validate <%= annotation.status %>"><div class="validate-tooltip"><ul><li><%= annotation.status_messages.join("</li><li>") %></li></ul></div></div><div class="video-info"><h3 class="title-video"><%= annotation.getMedia().title %></h3>' |
23 |
+ '<p class="subtitle"><%= annotation.title %></p><p class="duration"><%= annotation.begin.toString() %> - <%= annotation.end.toString() %> (<%= annotation.getDuration().toString() %>)</p>' |
|
| 104 | 24 |
+ '<ul class="tools"><li><a class="edit" href="#" title="<%= gettext("Edit segment") %>"></a></li><li><a class="bottom" href="#" title="<%= gettext("Move segment down") %>"></a></li>' |
25 |
+ '<li><a class="top" href="#" title="<%= gettext("Move segment up") %>"></a></li><li><a class="delete" href="#" title="<%= gettext("Delete segment") %>"></a></li></ul></div></li>' |
|
| 45 | 26 |
), |
27 |
mediasegmenttemplate = _.template( |
|
28 |
'<div class="media-segment">' |
|
| 49 | 29 |
+ '<div class="media-segment-section" style="left:<%= left %>px; width:<%= width %>px; background:<%= color %>; top: <%= top %>px;" data-segment-id="<%= annotation.id %>"></div>' |
| 65 | 30 |
+ '<div class="popin media-segment-popin" style="left:<%= popleft %>px; top: <%= 5+top %>px;"><div style="left:<%= pointerpos %>px;" class="pointer"></div><div class="popin-content">' |
| 104 | 31 |
+ '<h3><%= annotation.title %></h3><a href="#" class="button reprendre-segment" data-segment-id="<%= annotation.id %>"><%= gettext("Clone segment") %></a>' |
32 |
+ '<p><%= gettext("From:") %> <span><%= annotation.begin.toString() %></span> <%= gettext("to:") %> <span><%= annotation.end.toString() %></span> (<%= gettext("duration:") %> <span><%= annotation.getDuration().toString() %></span>)</p>' |
|
| 45 | 33 |
+ '</div></div></div>' |
34 |
), |
|
35 |
mediasegmentlisttemplate = _.template( |
|
36 |
'<div class="media-segment-list" style="height: <%= height %>px"><div class="media-current-section" style="left: <%= left %>px; width: <%= width %>px;"></div><div class="media-segment-list-inner"></div><%= segments %></div>' |
|
37 |
), |
|
38 |
mediafoundtemplate = _.template( |
|
39 |
'<div class="media-segment"><div class="media-segment-section" style="left:<%= left %>px; width:<%= width %>px; background:<%= color %>; top: <%= top %>px;"></div>' |
|
| 65 | 40 |
+ '<div class="popin media-found-popin" style="left:<%= popleft %>px; top: <%= 5+top %>px;"><div style="left:<%= pointerpos %>px;" class="pointer"></div><div class="popin-content">' |
| 104 | 41 |
+ '<h3><%= title %></h3><a href="#" class="button clone-segment" data-segment-id="<%= annotation.id %>"><%= gettext("Clone segment") %></a>' |
| 45 | 42 |
+ '</div></div></div>' |
43 |
), |
|
44 |
mediafoundlisttemplate = _.template( |
|
45 |
'<div class="media-found-list" style="height: <%= height %>px"><div class="media-segment-list-inner"></div><%= segments %></div>' |
|
46 |
), |
|
| 43 | 47 |
mashupstatus = '', |
| 92 | 48 |
mediasegmentscache = {}, |
| 97 | 49 |
mashupModeAfterSave = false, |
50 |
addMode = false, |
|
51 |
currentMedia, currentSegment; |
|
| 45 | 52 |
|
|
41
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
53 |
IriSP.mashupcore(project, mashup); |
| 39 | 54 |
|
55 |
/* Validation of segments and mashup */ |
|
56 |
|
|
57 |
var segmentcritical = [ |
|
58 |
{ |
|
59 |
validate: function(_s) { |
|
|
41
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
60 |
return (_s.getDuration() >= 1000); |
| 39 | 61 |
}, |
| 104 | 62 |
message: gettext("A segment must be at least one second long") |
|
41
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
63 |
}, |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
64 |
{ |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
65 |
validate: function(_s) { |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
66 |
return (_s.getDuration() < 180000); |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
67 |
}, |
| 104 | 68 |
message: gettext("A segment must be at most three minutes long") |
| 39 | 69 |
}, |
70 |
{ |
|
71 |
validate: function(_s) { |
|
| 104 | 72 |
return (!!_s.title && _s.title !== gettext("Untitled segment")); |
| 39 | 73 |
}, |
| 104 | 74 |
message: gettext("A segment must have a title") |
| 39 | 75 |
} |
76 |
]; |
|
77 |
var segmentwarning = [ |
|
78 |
{ |
|
79 |
validate: function(_s) { |
|
|
41
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
80 |
return (!!_s.description); |
| 39 | 81 |
}, |
| 104 | 82 |
message: gettext("A segment should have a description") |
|
41
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
83 |
}, |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
84 |
{ |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
85 |
validate: function(_s) { |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
86 |
return (!!_s.keywords.length); |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
87 |
}, |
| 104 | 88 |
message: gettext("A segment should have tags") |
| 39 | 89 |
} |
90 |
]; |
|
91 |
|
|
92 |
var mashupcritical = [ |
|
93 |
{ |
|
94 |
validate: function(_m) { |
|
95 |
return _m.segments.length > 2; |
|
96 |
}, |
|
| 104 | 97 |
message: gettext("A hashcut must be made from at least three segments") |
| 39 | 98 |
}, |
99 |
{ |
|
100 |
validate: function(_m) { |
|
| 104 | 101 |
return (!!_m.title && _m.title !== gettext("Untitled Hashcut")); |
| 39 | 102 |
}, |
| 104 | 103 |
message: gettext("A hashcut must have a title") |
| 39 | 104 |
} |
105 |
]; |
|
106 |
var mashupwarning = [ |
|
107 |
{ |
|
108 |
validate: function(_m) { |
|
109 |
return !!_m.description |
|
110 |
}, |
|
| 104 | 111 |
message: gettext("A hashcut should have a description") |
| 39 | 112 |
} |
113 |
]; |
|
| 22 | 114 |
|
115 |
/* Fill left column with Media List */ |
|
| 25 | 116 |
|
| 22 | 117 |
project.onLoad(function() { |
118 |
var html = ''; |
|
119 |
project.getMedias().forEach(function(_m) { |
|
| 27 | 120 |
html += mediatemplate(_m); |
| 13 | 121 |
}); |
| 22 | 122 |
$(".col-left .list-video").html(html); |
| 43 | 123 |
project.getMedias().forEach(function(_m) { |
124 |
apidirectory.remoteSource({ |
|
| 49 | 125 |
url: IriSP.endpoints.segment, |
| 43 | 126 |
url_params: { |
127 |
iri_id: _m.id, |
|
128 |
limit: 0 |
|
129 |
}, |
|
130 |
serializer: IriSP.serializers.segmentapi |
|
131 |
}).onLoad(function() { |
|
132 |
var medias = this.getMedias(), |
|
| 92 | 133 |
annotations = this.getAnnotations().filter(function(annotation) { |
134 |
return annotation.getDuration() > 0; |
|
135 |
});; |
|
| 43 | 136 |
if (medias && medias.length) { |
137 |
var mediaid = medias[0].id; |
|
138 |
el = $(".item-video[data-media-id='" + mediaid + "'] .media-count"); |
|
139 |
el.text(annotations.length).parent().show(); |
|
140 |
mediasegmentscache[mediaid] = annotations; |
|
141 |
if (currentMedia && mediaid === currentMedia.id && currentSegment) { |
|
142 |
showOtherSegments(); |
|
143 |
} |
|
144 |
} |
|
145 |
}); |
|
146 |
}); |
|
| 22 | 147 |
}); |
148 |
|
|
149 |
/* Search Media with left column form */ |
|
150 |
|
|
151 |
$(".col-left input").on("keyup change input paste", function() { |
|
152 |
var val = $(this).val(); |
|
153 |
if (val) { |
|
154 |
var find = IriSP.Model.regexpFromTextOrArray(val, true), |
|
155 |
replace = IriSP.Model.regexpFromTextOrArray(val, false); |
|
156 |
} |
|
157 |
$(".col-left .item-video").each(function() { |
|
158 |
var li = $(this), |
|
| 45 | 159 |
mediaid = li.attr("data-media-id"), |
160 |
media = directory.getElement(mediaid); |
|
161 |
if (!val) { |
|
162 |
li.find(".title-video").text(media.title); |
|
163 |
li.find(".description").text(media.description); |
|
164 |
li.find(".media-found-segments").html(""); |
|
| 22 | 165 |
li.show(); |
166 |
} else { |
|
| 45 | 167 |
var apimedia = apidirectory.getElement(mediaid); |
168 |
if (apimedia) { |
|
169 |
var annotations = apimedia.getAnnotations().searchByTextFields(val); |
|
170 |
} else { |
|
171 |
var annotations = []; |
|
172 |
} |
|
173 |
var found = find.test(media.title) || find.test(media.description) || annotations.length; |
|
174 |
if (found) { |
|
175 |
li.find(".title-video").html(media.title.replace(replace, '<span style="background: #fc00ff; color: #ffffff;">$1</span>')); |
|
176 |
li.find(".description").html(media.description.replace(replace, '<span style="background: #fc00ff; color: #ffffff;">$1</span>')); |
|
177 |
var html = '', |
|
178 |
k = 230 / media.duration, |
|
179 |
lines = []; |
|
180 |
_(annotations).each(function(_a, i) { |
|
181 |
var pos = k * (_a.begin + _a.end) / 2, |
|
182 |
corrpos = Math.max(76, Math.min(156, pos)), |
|
183 |
line = IriSP._(lines).find(function(line) { |
|
184 |
return !IriSP._(line.annotations).find(function(ann) { |
|
185 |
return ann.begin < _a.end && ann.end > _a.begin |
|
186 |
}); |
|
187 |
}); |
|
188 |
if (!line) { |
|
189 |
line = { index: lines.length, annotations: []}; |
|
190 |
lines.push(line); |
|
191 |
} |
|
192 |
line.annotations.push(_a); |
|
193 |
vizdata = { |
|
194 |
annotation : _a, |
|
195 |
left : k * _a.begin, |
|
196 |
width : k * _a.getDuration(), |
|
197 |
top: 8 * line.index, |
|
| 50 | 198 |
color: IriSP.vizcolors[i % IriSP.vizcolors.length], |
| 45 | 199 |
title: _a.title.replace(replace, '<span style="background: #fc00ff; color: #ffffff;">$1</span>'), |
200 |
popleft : corrpos, |
|
201 |
pointerpos : (pos - corrpos), |
|
202 |
} |
|
203 |
html += mediafoundtemplate(vizdata); |
|
204 |
}); |
|
205 |
html = mediafoundlisttemplate({ |
|
206 |
height: 8 * lines.length, |
|
207 |
segments: html |
|
208 |
}); |
|
209 |
li.find(".media-found-segments").html(html); |
|
210 |
li.show(); |
|
211 |
} else { |
|
| 22 | 212 |
li.hide(); |
| 13 | 213 |
} |
| 22 | 214 |
} |
215 |
}) |
|
216 |
}); |
|
217 |
|
|
| 25 | 218 |
/* Fill right column when mashup is updated */ |
219 |
|
|
| 27 | 220 |
function updateMashupUI() { |
|
41
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
221 |
var listhtml = '', critical = false, warning = false, messages = []; |
| 27 | 222 |
mashup.segments.forEach(function(_s) { |
223 |
listhtml += segmenttemplate(_s); |
|
| 39 | 224 |
if (_s.annotation.status === "critical") { |
225 |
critical = true; |
|
226 |
} |
|
| 27 | 227 |
}); |
| 39 | 228 |
if (critical) { |
| 49 | 229 |
messages.push("One or more segments are invalid"); |
| 39 | 230 |
} |
231 |
|
|
232 |
_(mashupcritical).each(function(sc) { |
|
233 |
if (!sc.validate(mashup)) { |
|
234 |
critical = true; |
|
235 |
messages.push(sc.message); |
|
236 |
} |
|
237 |
}); |
|
238 |
_(mashupwarning).each(function(sc) { |
|
239 |
if (!sc.validate(mashup)) { |
|
240 |
warning = true; |
|
241 |
messages.push(sc.message); |
|
242 |
} |
|
243 |
}); |
|
244 |
mashup.status = critical ? "critical" : (warning ? "warning" : "valid"); |
|
245 |
if (!messages.length) { |
|
| 49 | 246 |
messages.push("Your hashcut is valid!"); |
| 39 | 247 |
} |
| 104 | 248 |
mashupstatus = ' - ' + _(messages).join('\n - '); |
| 43 | 249 |
|
| 39 | 250 |
$(".publier-button").toggleClass("disable", critical); |
251 |
|
|
252 |
$(".liste-segment .validate").removeClass("critical warning valid").addClass(mashup.status); |
|
253 |
$(".liste-segment .validate-tooltip").html("<ul><li>" + messages.join("</li><li>")+"</li></ul>"); |
|
| 27 | 254 |
|
|
41
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
255 |
$(".col-right .list-video").html(listhtml).find(".item-video:last-child .bottom, .item-video:first-child .top").addClass("disable"); |
| 27 | 256 |
|
|
41
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
257 |
project.trigger("mouseout-annotation"); |
| 22 | 258 |
} |
259 |
|
|
|
41
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
260 |
mashup.on("setcurrent", function() { |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
261 |
currentMedia = mashup; |
| 22 | 262 |
}); |
263 |
|
|
|
41
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
264 |
mashup.on("change",updateMashupUI); |
| 25 | 265 |
|
| 23 | 266 |
/* Slice Widget */ |
| 25 | 267 |
|
| 23 | 268 |
var sliceSlider = $(".Ldt-Slice"), |
|
41
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
269 |
sliceStartTime, |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
270 |
slidersRange = 920; |
| 23 | 271 |
|
272 |
sliceSlider.slider({ |
|
273 |
range: true, |
|
274 |
values: [0, slidersRange], |
|
275 |
min: 0, |
|
276 |
max: slidersRange, |
|
277 |
start: function() { |
|
278 |
if (currentMedia) { |
|
279 |
if (!currentMedia.getPaused()) { |
|
280 |
currentMedia.pause(); |
|
281 |
} |
|
282 |
} |
|
283 |
}, |
|
284 |
slide: function(event, ui) { |
|
| 27 | 285 |
if (currentMedia && currentSegment) { |
| 23 | 286 |
var t = currentMedia.duration * ui.value / slidersRange; |
| 25 | 287 |
if (ui.value === ui.values[0]) { |
| 27 | 288 |
currentSegment.setBegin(t); |
| 25 | 289 |
} else { |
| 27 | 290 |
currentSegment.setEnd(t); |
| 25 | 291 |
} |
| 23 | 292 |
} |
293 |
} |
|
294 |
}); |
|
295 |
|
|
| 25 | 296 |
sliceSlider.find(".ui-slider-handle:first") |
297 |
.addClass("Ldt-Slice-left-handle") |
|
298 |
.click(function() { |
|
| 27 | 299 |
if (currentMedia && currentSegment) { |
300 |
currentMedia.setCurrentTime(currentSegment.begin); |
|
| 25 | 301 |
} |
302 |
}); |
|
303 |
sliceSlider.find(".ui-slider-handle:last") |
|
304 |
.addClass("Ldt-Slice-right-handle") |
|
305 |
.click(function() { |
|
| 27 | 306 |
if (currentMedia && currentSegment) { |
307 |
currentMedia.setCurrentTime(currentSegment.end); |
|
| 25 | 308 |
} |
309 |
}); |
|
| 23 | 310 |
|
311 |
|
|
|
41
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
312 |
/* Update Segment UI */ |
| 22 | 313 |
|
| 39 | 314 |
function updateSegmentUI() { |
| 27 | 315 |
if (currentMedia && currentSegment) { |
316 |
var start = currentSegment.begin, |
|
317 |
end = currentSegment.end, |
|
318 |
dur = currentSegment.getDuration(), |
|
319 |
f = slidersRange / currentMedia.duration, |
|
320 |
tangleStart = $(".tangle-start"), |
|
321 |
tangleEnd = $(".tangle-end"), |
|
| 29 | 322 |
tangleDuration = $(".tangle-duration"), |
323 |
k = 100 / currentMedia.duration, |
|
324 |
p = k * (start + end) / 2; |
|
| 25 | 325 |
sliceSlider.slider( "values", [ f * start, f * end ] ); |
| 27 | 326 |
tangleStart.text(start.toString(tangleStart.hasClass("active"))).attr("data-milliseconds",start.milliseconds); |
327 |
tangleEnd.text(end.toString(tangleEnd.hasClass("active"))).attr("data-milliseconds",end.milliseconds); |
|
328 |
tangleDuration.text(dur.toString(tangleDuration.hasClass("active"))).attr("data-milliseconds",dur.milliseconds); |
|
| 39 | 329 |
$(".segmentation .pointer").css("left", p + "%"); |
| 29 | 330 |
$(".media-current-section").css({ |
331 |
left: (k * start) + "%", |
|
332 |
width: (k * dur) + "%" |
|
| 39 | 333 |
}); |
334 |
var messages = [], |
|
335 |
critical = false, |
|
336 |
warning = false; |
|
337 |
_(segmentcritical).each(function(sc) { |
|
338 |
if (!sc.validate(currentSegment)) { |
|
339 |
critical = true; |
|
340 |
messages.push(sc.message); |
|
341 |
} |
|
342 |
}); |
|
343 |
_(segmentwarning).each(function(sc) { |
|
344 |
if (!sc.validate(currentSegment)) { |
|
345 |
warning = true; |
|
346 |
messages.push(sc.message); |
|
347 |
} |
|
348 |
}); |
|
349 |
currentSegment.status = critical ? "critical" : (warning ? "warning" : "valid"); |
|
350 |
if (!messages.length) { |
|
| 49 | 351 |
messages.push("This segment is valid!") |
| 39 | 352 |
} |
| 104 | 353 |
currentSegment.status_messages = _(messages); |
| 39 | 354 |
|
355 |
$(".segmentation .validate").removeClass("critical warning valid").addClass(currentSegment.status); |
|
356 |
$(".segmentation .validate-tooltip").html("<ul><li>" + currentSegment.status_messages.join("</li><li>")+"</li></ul>"); |
|
| 25 | 357 |
} |
358 |
} |
|
359 |
|
|
| 27 | 360 |
function setMedia(media) { |
| 23 | 361 |
if (currentMedia) { |
362 |
currentMedia.pause(); |
|
363 |
} |
|
| 27 | 364 |
currentMedia = media; |
|
41
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
365 |
project.trigger("set-current", media); |
| 22 | 366 |
if (currentMedia.elementType == "media") { |
| 23 | 367 |
showSegmentation(); |
368 |
$(".tab-media-title").text(currentMedia.title); |
|
| 27 | 369 |
|
370 |
addMode = !(currentSegment && mashup.hasAnnotation(currentSegment)); |
|
371 |
|
|
372 |
if (!currentSegment) { |
|
373 |
currentSegment = new IriSP.Model.Annotation(false, project); |
|
374 |
currentSegment.setMedia(currentMedia.id); |
|
| 45 | 375 |
currentSegment.setBegin(currentMedia.getCurrentTime()); |
376 |
currentSegment.setEnd(Math.min(currentMedia.getCurrentTime() + 180000, currentMedia.duration)); |
|
| 104 | 377 |
currentSegment.title = gettext("Untitled segment"); |
|
41
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
378 |
currentSegment.color = currentMedia.color; |
| 43 | 379 |
currentSegment.thumbnail = currentMedia.thumbnail; |
| 42 | 380 |
currentSegment.created = new Date(); |
|
41
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
381 |
currentSegment.keywords = []; |
| 39 | 382 |
currentSegment.description = ""; |
| 27 | 383 |
currentSegment.on("change-begin", function() { |
384 |
if (currentMedia && currentSegment === this) { |
|
| 25 | 385 |
currentMedia.setCurrentTime(this.begin); |
| 39 | 386 |
updateSegmentUI(); |
| 25 | 387 |
} |
388 |
}); |
|
| 27 | 389 |
currentSegment.on("change-end", function() { |
390 |
if (currentMedia && currentSegment === this) { |
|
| 25 | 391 |
currentMedia.setCurrentTime(this.end); |
| 39 | 392 |
updateSegmentUI(); |
| 25 | 393 |
} |
394 |
}); |
|
395 |
} |
|
| 27 | 396 |
if (currentMedia.loaded) { |
397 |
currentMedia.setCurrentTime(currentSegment.begin); |
|
398 |
} |
|
| 104 | 399 |
$(".add-segment").val(addMode ? gettext("Add segment to hashcut") : gettext("Save segment")); |
400 |
$(".create-or-edit").text(addMode ? gettext("Create new segment") : gettext("Edit existing segment")); |
|
| 27 | 401 |
$("#segment-title").val(currentSegment.title); |
402 |
$("#segment-description").val(currentSegment.description); |
|
|
41
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
403 |
var segment_tags = $("#segment-tags"); |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
404 |
segment_tags.tagit("option","onTagRemoved",function(){}); |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
405 |
segment_tags.tagit("option","onTagAdded",function(){}); |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
406 |
segment_tags.tagit("removeAll"); |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
407 |
_(currentSegment.keywords).each(function(tag) { |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
408 |
segment_tags.tagit("createTag",tag); |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
409 |
}); |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
410 |
segment_tags.tagit("option","onTagRemoved",updateSegmentTags); |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
411 |
segment_tags.tagit("option","onTagAdded",updateSegmentTags); |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
412 |
updateSegmentUI(); |
| 29 | 413 |
var relatedSegments = mashup.segments.filter(function(_s) { |
414 |
return _s.getMedia() === currentMedia && _s.annotation !== currentSegment; |
|
415 |
}); |
|
416 |
if (relatedSegments.length) { |
|
417 |
$(".self-media-segments").show(); |
|
418 |
} else { |
|
419 |
$(".self-media-segments").hide(); |
|
420 |
} |
|
| 45 | 421 |
$(".self-media-segments .media-segments-list").html(mediaSegmentList(_(relatedSegments).pluck("annotation"))); |
| 43 | 422 |
showOtherSegments(); |
423 |
project.trigger("mouseout-annotation"); |
|
| 22 | 424 |
} |
| 27 | 425 |
if (currentMedia.elementType === "mashup") { |
426 |
showPreview(); |
|
427 |
} |
|
| 22 | 428 |
} |
| 43 | 429 |
|
| 45 | 430 |
function mediaSegmentList(_annotations) { |
431 |
var html = '', |
|
432 |
k = $(".Ldt-Slider").width() / currentMedia.duration, |
|
433 |
lines = []; |
|
434 |
_(_annotations).each(function(_a, i) { |
|
435 |
var pos = k * (_a.begin + _a.end) / 2, |
|
436 |
corrpos = Math.max(145, Math.min(305, pos)), |
|
437 |
line = IriSP._(lines).find(function(line) { |
|
438 |
return !IriSP._(line.annotations).find(function(ann) { |
|
439 |
return ann.begin < _a.end && ann.end > _a.begin |
|
440 |
}); |
|
441 |
}); |
|
442 |
if (!line) { |
|
443 |
line = { index: lines.length, annotations: []}; |
|
444 |
lines.push(line); |
|
445 |
} |
|
446 |
line.annotations.push(_a); |
|
447 |
vizdata = { |
|
448 |
annotation : _a, |
|
449 |
popleft : corrpos, |
|
450 |
left : k * _a.begin, |
|
451 |
width : k * _a.getDuration(), |
|
452 |
height: 8, |
|
453 |
top: 8 * line.index, |
|
454 |
pointerpos : (pos - corrpos), |
|
| 50 | 455 |
color: IriSP.vizcolors[i % IriSP.vizcolors.length] |
| 45 | 456 |
} |
457 |
html += mediasegmenttemplate(vizdata); |
|
458 |
}); |
|
459 |
return mediasegmentlisttemplate({ |
|
460 |
height: 8 * lines.length, |
|
461 |
left: k * currentSegment.begin, |
|
462 |
width: k * currentSegment.getDuration(), |
|
463 |
segments: html |
|
464 |
}); |
|
465 |
} |
|
466 |
|
|
| 43 | 467 |
/* Show Related Segments */ |
468 |
|
|
469 |
function showOtherSegments() { |
|
| 45 | 470 |
var annotations = mediasegmentscache[currentMedia.id]; |
471 |
$(".other-media-segments .media-segments-list").html(mediaSegmentList(annotations)); |
|
| 43 | 472 |
if (annotations && annotations.length) { |
473 |
$(".other-media-segments").show(); |
|
474 |
} |
|
475 |
else { |
|
476 |
$(".other-media-segments").hide(); |
|
477 |
} |
|
478 |
} |
|
479 |
/* Set In, Out */ |
|
480 |
|
|
481 |
$(".Ldt-Ctrl-SetIn").click(function() { |
|
482 |
if (currentMedia && currentSegment) { |
|
483 |
currentSegment.setBegin(currentMedia.getCurrentTime()); |
|
484 |
} |
|
485 |
}); |
|
486 |
$(".Ldt-Ctrl-SetOut").click(function() { |
|
487 |
if (currentMedia && currentSegment) { |
|
488 |
currentSegment.setEnd(currentMedia.getCurrentTime()); |
|
489 |
} |
|
490 |
}); |
|
491 |
|
|
| 25 | 492 |
/* Segment Form interaction */ |
493 |
|
|
494 |
$("#segment-title").on("keyup change input paste", function() { |
|
| 27 | 495 |
if (currentMedia && currentSegment) { |
496 |
currentSegment.title = $(this).val(); |
|
| 39 | 497 |
updateSegmentUI(); |
|
41
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
498 |
mashup.trigger("change"); |
| 25 | 499 |
} |
500 |
}); |
|
| 43 | 501 |
$("#segment-title").on("focus click", function() { |
| 104 | 502 |
if ($(this).val() === gettext("Untitled segment")) { |
| 43 | 503 |
$(this).val(""); |
504 |
} |
|
505 |
}); |
|
| 25 | 506 |
$("#segment-description").on("keyup change input paste", function() { |
| 27 | 507 |
if (currentMedia && currentSegment) { |
508 |
currentSegment.description = $(this).val(); |
|
| 64 | 509 |
updateSegmentUI(); |
|
41
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
510 |
mashup.trigger("change"); |
| 25 | 511 |
} |
512 |
}); |
|
513 |
$("#segment-form").submit(function() { |
|
| 64 | 514 |
currentSegment.title = $("#segment-title").val(); |
515 |
currentSegment.description = $("#segment-description").val(); |
|
516 |
currentSegment.keywords = $("#segment-tags").tagit("assignedTags"); |
|
517 |
updateSegmentUI(); |
|
| 27 | 518 |
if (addMode) { |
519 |
mashup.addAnnotation(currentSegment); |
|
| 45 | 520 |
currentSegment = undefined; |
521 |
setMedia(currentMedia); |
|
| 27 | 522 |
} else { |
|
41
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
523 |
mashup.trigger("change"); |
| 49 | 524 |
var segment = mashup.getAnnotation(currentSegment); |
| 45 | 525 |
currentSegment = undefined; |
| 97 | 526 |
if (mashupModeAfterSave) { |
527 |
setMedia(mashup); |
|
528 |
if (segment) { |
|
529 |
mashup.setCurrentTime(segment.begin); |
|
530 |
mashup.trigger("enter-annotation",segment); |
|
531 |
} |
|
532 |
} else { |
|
533 |
|
|
| 45 | 534 |
} |
| 27 | 535 |
} |
| 29 | 536 |
return false; |
|
41
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
537 |
}); |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
538 |
|
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
539 |
$("#segment-tags").tagit(); |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
540 |
|
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
541 |
|
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
542 |
/* We have to defer this function because the tagit events |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
543 |
* are triggered before the data are updated */ |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
544 |
function updateSegmentTags() { |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
545 |
window.setTimeout(function() { |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
546 |
if (currentMedia && currentSegment) { |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
547 |
currentSegment.keywords = $("#segment-tags").tagit("assignedTags"); |
| 64 | 548 |
updateSegmentUI(); |
549 |
mashup.trigger("change"); |
|
|
41
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
550 |
} |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
551 |
}, 0); |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
552 |
} |
| 25 | 553 |
|
| 22 | 554 |
/* Click on media items */ |
555 |
|
|
556 |
$(".col-left").on("click", ".item-video", function() { |
|
| 27 | 557 |
currentSegment = undefined; |
558 |
setMedia(project.getElement($(this).attr("data-media-id"))); |
|
| 22 | 559 |
}); |
| 12 | 560 |
|
| 22 | 561 |
/* Click on Tabs */ |
562 |
|
|
563 |
function showSegmentation() { |
|
564 |
$(".col-middle").removeClass("empty-mode pvw-mode").addClass("segment-mode"); |
|
565 |
return false; |
|
566 |
} |
|
567 |
function showPreview() { |
|
568 |
$(".col-middle").removeClass("empty-mode segment-mode").addClass("pvw-mode"); |
|
569 |
return false; |
|
570 |
} |
|
| 32 | 571 |
function showEmpty() { |
572 |
$("video").hide(); |
|
573 |
$(".col-middle").removeClass("pvw-mode segment-mode").addClass("empty-mode"); |
|
574 |
return false; |
|
575 |
} |
|
| 22 | 576 |
|
| 27 | 577 |
$(".tab-pvw").click(function() { |
578 |
if (mashup.segments.length) { |
|
579 |
setMedia(mashup); |
|
| 22 | 580 |
} |
581 |
}); |
|
582 |
|
|
| 27 | 583 |
/* Click on segments */ |
584 |
|
|
585 |
function reorganizeMashup() { |
|
586 |
var ids = $(".organize-segments .item-video").map(function(){return $(this).attr("data-segment-id")}); |
|
587 |
mashup.setAnnotationsById(ids); |
|
588 |
} |
|
589 |
|
|
|
41
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
590 |
project.on("mouseover-annotation", function(annotation) { |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
591 |
var mediaid = annotation.getMedia().id; |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
592 |
$(".media").removeClass("active"); |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
593 |
$(".media[data-media-id='" + mediaid + "']").addClass("active"); |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
594 |
}); |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
595 |
|
| 43 | 596 |
project.on("mouseout-annotation", function() { |
|
41
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
597 |
$(".media").removeClass("active"); |
| 32 | 598 |
var mediaid = undefined; |
|
41
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
599 |
if (currentMedia && currentMedia.elementType === "media") { |
| 32 | 600 |
mediaid = currentMedia.id; |
|
41
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
601 |
if (currentSegment) { |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
602 |
$(".annotation").removeClass("active"); |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
603 |
$(".annotation[data-segment-id='" + currentSegment.id + "']").addClass("active"); |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
604 |
} |
| 32 | 605 |
} |
|
41
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
606 |
if (currentMedia === mashup && mashup.currentMedia) { |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
607 |
mediaid = mashup.currentMedia.id |
| 32 | 608 |
} |
|
41
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
609 |
$(".media[data-media-id='" + mediaid + "']").addClass("active"); |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
610 |
}); |
| 32 | 611 |
|
612 |
$(".organize-segments") |
|
613 |
.sortable({ |
|
| 27 | 614 |
stop : reorganizeMashup |
| 32 | 615 |
}) |
|
41
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
616 |
.on("mouseover", ".item-video", function() { |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
617 |
project.trigger("mouseover-annotation", project.getElement($(this).attr("data-segment-id"))); |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
618 |
}) |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
619 |
.on("mouseout", ".item-video", function() { |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
620 |
project.trigger("mouseout-annotation"); |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
621 |
}) |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
622 |
.on("click", ".item-video", function() { |
| 69 | 623 |
var segment = project.getElement($(this).attr("data-segment-id")); |
624 |
if (currentMedia === mashup) { |
|
625 |
project.trigger("click-annotation", segment); |
|
626 |
} else { |
|
627 |
currentSegment = segment; |
|
628 |
setMedia(segment.getMedia()); |
|
629 |
} |
|
| 32 | 630 |
}) |
631 |
.on("click", ".edit", function(e) { |
|
| 27 | 632 |
var currentItem = $(this).parents(".item-video"), |
633 |
media = project.getElement(currentItem.attr("data-media-id")), |
|
634 |
segment = project.getElement(currentItem.attr("data-segment-id")); |
|
| 97 | 635 |
mashupModeAfterSave = !!(currentMedia === mashup); |
| 27 | 636 |
currentSegment = segment; |
637 |
setMedia(media); |
|
638 |
return false; |
|
| 32 | 639 |
}) |
640 |
.on("click", ".top", function(e){ |
|
| 22 | 641 |
var currentItem = $(this).parents(".item-video"); |
642 |
currentItem.insertBefore(currentItem.prev()); |
|
| 27 | 643 |
reorganizeMashup(); |
644 |
return false; |
|
| 32 | 645 |
}) |
646 |
.on("click", ".bottom", function(e){ |
|
| 22 | 647 |
var currentItem = $(this).parents(".item-video"); |
648 |
currentItem.insertAfter(currentItem.next()); |
|
| 27 | 649 |
reorganizeMashup(); |
650 |
return false; |
|
| 32 | 651 |
}) |
652 |
.on("click", ".delete", function(e){ |
|
| 27 | 653 |
var id = $(this).parents(".item-video").attr("data-segment-id"); |
654 |
mashup.removeAnnotationById(id); |
|
| 32 | 655 |
if (!mashup.segments.length) { |
656 |
showEmpty(); |
|
657 |
} |
|
| 27 | 658 |
return false; |
| 22 | 659 |
}); |
660 |
|
|
| 73 | 661 |
$(".mashup-frise").click(function(evt) { |
662 |
if (!mashup.duration.milliseconds) { |
|
663 |
return; |
|
664 |
} |
|
665 |
var el = $(this), t = ( evt.pageX - el.offset().left ) * mashup.duration / el.width(), segment = mashup.getAnnotationAtTime(t); |
|
666 |
if (segment) { |
|
667 |
if (currentMedia === mashup) { |
|
668 |
project.trigger("click-annotation", segment.annotation); |
|
669 |
} else { |
|
670 |
currentSegment = segment.annotation; |
|
671 |
setMedia(currentSegment.getMedia()); |
|
672 |
} |
|
673 |
} |
|
674 |
}); |
|
675 |
|
|
| 25 | 676 |
/* Tangles */ |
677 |
var tangleMsPerPixel = 100, |
|
678 |
activeTangle, |
|
| 23 | 679 |
tangleStartX, |
| 25 | 680 |
tangleStartVal, |
681 |
tangleHasMoved; |
|
682 |
|
|
| 23 | 683 |
$(".time-tangle").mousedown(function(evt) { |
684 |
activeTangle = $(this); |
|
685 |
activeTangle.addClass("active"); |
|
686 |
tangleStartVal = +activeTangle.attr("data-milliseconds"); |
|
687 |
tangleStartX = evt.pageX; |
|
| 25 | 688 |
tangleHasMoved = false; |
689 |
$(this).siblings(".time-tangle").addClass("deactivate"); |
|
| 23 | 690 |
return false; |
691 |
}); |
|
692 |
$(document) |
|
693 |
.mousemove(function(evt) { |
|
694 |
if (activeTangle) { |
|
| 25 | 695 |
tangleHasMoved = true; |
696 |
var newval = new IriSP.Model.Time(tangleMsPerPixel * (evt.pageX - tangleStartX) + tangleStartVal); |
|
| 23 | 697 |
activeTangle.trigger("valuechange", newval); |
698 |
return false; |
|
699 |
} |
|
700 |
}) |
|
701 |
.mouseup(function() { |
|
702 |
if (activeTangle) { |
|
| 27 | 703 |
activeTangle.text(activeTangle.text().replace(/\.\d+$/,'')); |
| 25 | 704 |
$(".time-tangle").removeClass("active deactivate"); |
| 23 | 705 |
activeTangle = undefined; |
706 |
} |
|
| 25 | 707 |
}); |
708 |
|
|
709 |
$(".tangle-start") |
|
710 |
.mouseup(function(evt) { |
|
| 27 | 711 |
if (!tangleHasMoved && currentMedia && currentSegment) { |
712 |
currentMedia.setCurrentTime(currentSegment.begin); |
|
| 25 | 713 |
} |
| 23 | 714 |
}) |
| 25 | 715 |
.on("valuechange", function(evt, val) { |
| 27 | 716 |
if (currentMedia && currentSegment) { |
717 |
currentSegment.setBegin(val); |
|
| 25 | 718 |
} |
719 |
}); |
|
720 |
$(".tangle-end") |
|
721 |
.mouseup(function(evt) { |
|
| 27 | 722 |
if (!tangleHasMoved && currentMedia && currentSegment) { |
723 |
currentMedia.setCurrentTime(currentSegment.end); |
|
| 25 | 724 |
} |
725 |
}) |
|
726 |
.on("valuechange", function(evt, val) { |
|
| 27 | 727 |
if (currentMedia && currentSegment) { |
728 |
currentSegment.setEnd(val); |
|
| 25 | 729 |
} |
730 |
}); |
|
731 |
$(".tangle-duration").on("valuechange", function(evt, val) { |
|
| 27 | 732 |
if (currentMedia && currentSegment) { |
733 |
currentSegment.setDuration(val); |
|
| 25 | 734 |
} |
735 |
}); |
|
| 27 | 736 |
|
| 29 | 737 |
/* Click on current segment in Preview */ |
738 |
|
|
| 27 | 739 |
$(".mashup-description .edit").click(function() { |
| 43 | 740 |
if (mashup.currentAnnotation) { |
| 97 | 741 |
mashupModeAfterSave = !!(currentMedia === mashup); |
| 43 | 742 |
currentSegment = mashup.currentAnnotation.annotation; |
743 |
setMedia(mashup.currentAnnotation.getMedia()); |
|
| 27 | 744 |
} |
| 43 | 745 |
return false; |
| 29 | 746 |
}); |
747 |
|
|
748 |
/* Handling related segments */ |
|
749 |
|
|
| 45 | 750 |
function cloneSegment(sid) { |
751 |
var s = directory.getElement(sid) || apidirectory.getElement(sid), |
|
752 |
media = directory.getElement(s.getMedia().id); |
|
753 |
|
|
754 |
currentSegment = new IriSP.Model.Annotation(false, project); |
|
755 |
currentSegment.setMedia(media.id); |
|
756 |
currentSegment.setBegin(s.begin); |
|
757 |
currentSegment.setEnd(s.end); |
|
| 104 | 758 |
currentSegment.title = gettext("Copy of ") + s.title; |
| 45 | 759 |
currentSegment.description = s.description; |
760 |
currentSegment.keywords = s.keywords; |
|
761 |
currentSegment.color = media.color; |
|
762 |
currentSegment.thumbnail = media.thumbnail; |
|
763 |
currentSegment.created = new Date(); |
|
764 |
currentSegment.on("change-begin", function() { |
|
765 |
if (currentMedia && currentSegment === this) { |
|
766 |
currentMedia.setCurrentTime(this.begin); |
|
767 |
updateSegmentUI(); |
|
768 |
} |
|
769 |
}); |
|
770 |
currentSegment.on("change-end", function() { |
|
771 |
if (currentMedia && currentSegment === this) { |
|
772 |
currentMedia.setCurrentTime(this.end); |
|
773 |
updateSegmentUI(); |
|
774 |
} |
|
775 |
}); |
|
776 |
setMedia(media); |
|
777 |
} |
|
778 |
|
|
| 29 | 779 |
$(".media-segments-list").on("mouseover", ".media-segment", function() { |
780 |
$(this).find(".media-segment-popin").show(); |
|
781 |
}).on("mouseout", ".media-segment", function() { |
|
782 |
$(this).find(".media-segment-popin").hide(); |
|
783 |
}).on("click", ".reprendre-segment", function() { |
|
| 45 | 784 |
cloneSegment($(this).attr("data-segment-id")); |
| 29 | 785 |
return false; |
| 49 | 786 |
}).on("click", ".media-segment-section", function() { |
787 |
var sid = $(this).attr("data-segment-id"), |
|
788 |
s = directory.getElement(sid) || apidirectory.getElement(sid); |
|
789 |
if (s.media.id === currentMedia.id) { |
|
790 |
currentMedia.setCurrentTime(s.begin); |
|
791 |
} |
|
| 29 | 792 |
}); |
793 |
|
|
| 45 | 794 |
$(".col-left").on("mouseover", ".media-segment", function() { |
795 |
$(this).find(".media-found-popin").show(); |
|
796 |
}).on("mouseout", ".media-segment", function() { |
|
797 |
$(this).find(".media-found-popin").hide(); |
|
798 |
}).on("click", ".clone-segment", function() { |
|
799 |
cloneSegment($(this).attr("data-segment-id")); |
|
800 |
return false; |
|
801 |
}); |
|
| 32 | 802 |
/* Changing Hashcut Title and description */ |
| 39 | 803 |
|
| 104 | 804 |
mashup.title = gettext("Untitled Hashcut"); |
| 39 | 805 |
$(".title-video-wrap a").text(mashup.title); |
806 |
$("#hashcut-title").val(mashup.title); |
|
807 |
|
|
| 32 | 808 |
$("#hashcut-title").on("keyup change input paste", function() { |
809 |
mashup.title = $(this).val(); |
|
810 |
$(".title-video-wrap a").text(mashup.title); |
|
|
41
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
811 |
mashup.trigger("change"); |
| 32 | 812 |
}); |
| 43 | 813 |
$("#hashcut-title").on("focus click", function() { |
| 104 | 814 |
if ($(this).val() === gettext("Untitled Hashcut")) { |
| 43 | 815 |
$(this).val(""); |
816 |
} |
|
817 |
}); |
|
| 32 | 818 |
|
| 39 | 819 |
$("#hashcut-description").on("keyup change input paste", function() { |
820 |
mashup.description = $(this).val(); |
|
|
41
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
821 |
mashup.trigger("change"); |
| 39 | 822 |
}); |
823 |
|
|
| 43 | 824 |
$("#hashcut-form").submit(function() { |
825 |
$(".update-title").hide(); |
|
826 |
return false; |
|
827 |
}) |
|
|
41
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
828 |
|
| 42 | 829 |
/* Publication */ |
830 |
|
|
| 49 | 831 |
function onLeave() { |
| 104 | 832 |
return gettext("You haven't published your hashcut yet.\nIf you leave this page, it will be lost."); |
| 49 | 833 |
} |
834 |
|
|
835 |
$(window).on("beforeunload", onLeave); |
|
836 |
|
|
| 42 | 837 |
$(".publier-button").click(function() { |
| 43 | 838 |
if ($(this).hasClass("disable")) { |
| 104 | 839 |
alert(gettext("The hashcut can't be published because:")+"\n\n"+mashupstatus); |
| 43 | 840 |
return false; |
841 |
} |
|
| 42 | 842 |
var postproject = directory.newLocalSource(), |
| 43 | 843 |
medias = mashup.getMedias() |
| 42 | 844 |
annotations = mashup.getOriginalAnnotations(); |
| 43 | 845 |
postproject.addList("annotationType"); |
846 |
postproject.addList("tag"); |
|
847 |
medias.forEach(function(_m) { |
|
848 |
var anntype = new IriSP.Model.AnnotationType(false, postproject); |
|
849 |
anntype.title = "Segments from " + _m.title; |
|
850 |
anntype.media = _m; |
|
851 |
postproject.getAnnotationTypes().push(anntype); |
|
| 42 | 852 |
}); |
| 43 | 853 |
annotations.forEach(function(_a) { |
854 |
_a.setAnnotationType( |
|
855 |
postproject.getAnnotationTypes().filter( |
|
856 |
function(_at) { return _at.media === _a.getMedia() } |
|
857 |
)[0].id); |
|
858 |
var tagids = []; |
|
859 |
_(_a.keywords).each(function(keyword) { |
|
860 |
var tags = postproject.getTags().searchByTitle(keyword); |
|
861 |
if (tags.length) { |
|
862 |
tagids.push(tags[0].id); |
|
863 |
} else { |
|
864 |
var tag = new IriSP.Model.Tag(false, postproject); |
|
865 |
tag.title = tag.description = keyword; |
|
866 |
postproject.getTags().push(tag); |
|
867 |
tagids.push(tag.id); |
|
868 |
} |
|
869 |
}); |
|
870 |
_a.setTags(tagids); |
|
871 |
}); |
|
| 42 | 872 |
postproject.addList("annotation",annotations); |
| 43 | 873 |
postproject.addList("media",medias); |
| 42 | 874 |
postproject.addList("mashup",[mashup]); |
| 69 | 875 |
postproject.creator = options.creator; |
| 43 | 876 |
postproject.created = new Date(); |
877 |
postproject.modified = new Date(); |
|
| 42 | 878 |
postproject.title = mashup.title; |
879 |
postproject.description = mashup.description; |
|
| 73 | 880 |
var waitscreen = $('<div class="full-wait">'); |
881 |
waitscreen.appendTo('body'); |
|
| 42 | 882 |
$.ajax({ |
883 |
type: "POST", |
|
| 49 | 884 |
url: IriSP.endpoints.project, |
| 42 | 885 |
data: IriSP.serializers.ldt.serialize(postproject), |
886 |
contentType: "application/cinelab", |
|
| 69 | 887 |
headers: { |
888 |
"X-CSRFToken": options.csrf_token |
|
889 |
}, |
|
| 42 | 890 |
success: function(data, status, request){ |
| 49 | 891 |
var location = request.getResponseHeader("Location"), |
892 |
projid = location.match(/([^/]+)\/?$/)[1], |
|
893 |
destination = IriSP.endpoints.hashcut_page + projid; |
|
894 |
$(window).off("beforeunload", onLeave); |
|
895 |
document.location.href = destination; |
|
| 42 | 896 |
}, |
897 |
error: function(jqXHR, textStatus, errorThrown){ |
|
| 104 | 898 |
alert(gettext("Server error\nYour hashcut couldn't be published")); |
| 73 | 899 |
waitscreen.remove(); |
| 42 | 900 |
} |
901 |
}); |
|
| 49 | 902 |
|
| 43 | 903 |
return false; |
| 42 | 904 |
}); |
905 |
|
|
|
41
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
906 |
mashup.trigger("change"); |
| 13 | 907 |
} |
| 50 | 908 |
|
909 |
/* END editor.js */ |