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