| author | veltr |
| Wed, 28 Nov 2012 12:19:21 +0100 | |
| changeset 65 | 60a1e58b0a08 |
| parent 64 | 2de3ca9542ed |
| child 69 | e56b4456668f |
| 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>' |
| 65 | 35 |
+ '<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">' |
| 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>' |
|
| 65 | 45 |
+ '<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">' |
| 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 |
|
|
41
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
55 |
IriSP.mashupcore(project, mashup); |
| 39 | 56 |
|
57 |
/* Validation of segments and mashup */ |
|
58 |
|
|
59 |
var segmentcritical = [ |
|
60 |
{ |
|
61 |
validate: function(_s) { |
|
|
41
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
62 |
return (_s.getDuration() >= 1000); |
| 39 | 63 |
}, |
| 49 | 64 |
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
|
65 |
}, |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
66 |
{ |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
67 |
validate: function(_s) { |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
68 |
return (_s.getDuration() < 180000); |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
69 |
}, |
| 49 | 70 |
message: "A segment must be at most three minutes long" |
| 39 | 71 |
}, |
72 |
{ |
|
73 |
validate: function(_s) { |
|
| 49 | 74 |
return (!!_s.title && _s.title !== IriSP.translate("Untitled segment")); |
| 39 | 75 |
}, |
| 49 | 76 |
message: "A segment must have a title" |
| 39 | 77 |
} |
78 |
]; |
|
79 |
var segmentwarning = [ |
|
80 |
{ |
|
81 |
validate: function(_s) { |
|
|
41
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
82 |
return (!!_s.description); |
| 39 | 83 |
}, |
| 49 | 84 |
message: "A segment should have a description" |
|
41
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
85 |
}, |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
86 |
{ |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
87 |
validate: function(_s) { |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
88 |
return (!!_s.keywords.length); |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
89 |
}, |
| 49 | 90 |
message: "A segment should have tags" |
| 39 | 91 |
} |
92 |
]; |
|
93 |
|
|
94 |
var mashupcritical = [ |
|
95 |
{ |
|
96 |
validate: function(_m) { |
|
97 |
return _m.segments.length > 2; |
|
98 |
}, |
|
| 49 | 99 |
message: "A hashcut must be made from at least three segments" |
| 39 | 100 |
}, |
101 |
{ |
|
102 |
validate: function(_m) { |
|
| 49 | 103 |
return (!!_m.title && _m.title !== IriSP.translate("Untitled Hashcut")); |
| 39 | 104 |
}, |
| 49 | 105 |
message: "A hashcut must have a title" |
| 39 | 106 |
} |
107 |
]; |
|
108 |
var mashupwarning = [ |
|
109 |
{ |
|
110 |
validate: function(_m) { |
|
111 |
return !!_m.description |
|
112 |
}, |
|
| 49 | 113 |
message: "A hashcut should have a description" |
| 39 | 114 |
} |
115 |
]; |
|
| 22 | 116 |
|
117 |
/* Fill left column with Media List */ |
|
| 25 | 118 |
|
| 22 | 119 |
project.onLoad(function() { |
120 |
var html = ''; |
|
121 |
project.getMedias().forEach(function(_m) { |
|
| 27 | 122 |
html += mediatemplate(_m); |
| 13 | 123 |
}); |
| 22 | 124 |
$(".col-left .list-video").html(html); |
| 43 | 125 |
project.getMedias().forEach(function(_m) { |
126 |
apidirectory.remoteSource({ |
|
| 49 | 127 |
url: IriSP.endpoints.segment, |
| 43 | 128 |
url_params: { |
129 |
iri_id: _m.id, |
|
130 |
limit: 0 |
|
131 |
}, |
|
132 |
serializer: IriSP.serializers.segmentapi |
|
133 |
}).onLoad(function() { |
|
134 |
var medias = this.getMedias(), |
|
135 |
annotations = this.getAnnotations(); |
|
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 |
} |
| 49 | 248 |
mashupstatus = ' - ' + _(messages).map(IriSP.translate).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 |
} |
| 49 | 353 |
currentSegment.status_messages = _(messages).map(IriSP.translate); |
| 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 |
|
|
| 42 | 360 |
var mediasegmentscache = {}; |
361 |
|
|
| 27 | 362 |
function setMedia(media) { |
| 23 | 363 |
if (currentMedia) { |
364 |
currentMedia.pause(); |
|
365 |
} |
|
| 27 | 366 |
currentMedia = media; |
|
41
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
367 |
project.trigger("set-current", media); |
| 22 | 368 |
if (currentMedia.elementType == "media") { |
| 23 | 369 |
showSegmentation(); |
370 |
$(".tab-media-title").text(currentMedia.title); |
|
| 27 | 371 |
|
372 |
addMode = !(currentSegment && mashup.hasAnnotation(currentSegment)); |
|
373 |
|
|
374 |
if (!currentSegment) { |
|
375 |
currentSegment = new IriSP.Model.Annotation(false, project); |
|
376 |
currentSegment.setMedia(currentMedia.id); |
|
| 45 | 377 |
currentSegment.setBegin(currentMedia.getCurrentTime()); |
378 |
currentSegment.setEnd(Math.min(currentMedia.getCurrentTime() + 180000, currentMedia.duration)); |
|
| 49 | 379 |
currentSegment.title = IriSP.translate("Untitled segment"); |
|
41
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
380 |
currentSegment.color = currentMedia.color; |
| 43 | 381 |
currentSegment.thumbnail = currentMedia.thumbnail; |
| 42 | 382 |
currentSegment.created = new Date(); |
|
41
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
383 |
currentSegment.keywords = []; |
| 39 | 384 |
currentSegment.description = ""; |
| 27 | 385 |
currentSegment.on("change-begin", function() { |
386 |
if (currentMedia && currentSegment === this) { |
|
| 25 | 387 |
currentMedia.setCurrentTime(this.begin); |
| 39 | 388 |
updateSegmentUI(); |
| 25 | 389 |
} |
390 |
}); |
|
| 27 | 391 |
currentSegment.on("change-end", function() { |
392 |
if (currentMedia && currentSegment === this) { |
|
| 25 | 393 |
currentMedia.setCurrentTime(this.end); |
| 39 | 394 |
updateSegmentUI(); |
| 25 | 395 |
} |
396 |
}); |
|
397 |
} |
|
| 27 | 398 |
if (currentMedia.loaded) { |
399 |
currentMedia.setCurrentTime(currentSegment.begin); |
|
400 |
} |
|
| 49 | 401 |
$(".add-segment").val(IriSP.translate(addMode ? "Add segment to hashcut" : "Save segment")); |
402 |
$(".create-or-edit").text(IriSP.translate(addMode ? "Create new segment" : "Edit existing segment")); |
|
| 27 | 403 |
media.show(); |
404 |
$("#segment-title").val(currentSegment.title); |
|
405 |
$("#segment-description").val(currentSegment.description); |
|
|
41
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
406 |
var segment_tags = $("#segment-tags"); |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
407 |
segment_tags.tagit("option","onTagRemoved",function(){}); |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
408 |
segment_tags.tagit("option","onTagAdded",function(){}); |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
409 |
segment_tags.tagit("removeAll"); |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
410 |
_(currentSegment.keywords).each(function(tag) { |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
411 |
segment_tags.tagit("createTag",tag); |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
412 |
}); |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
413 |
segment_tags.tagit("option","onTagRemoved",updateSegmentTags); |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
414 |
segment_tags.tagit("option","onTagAdded",updateSegmentTags); |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
415 |
updateSegmentUI(); |
| 29 | 416 |
var relatedSegments = mashup.segments.filter(function(_s) { |
417 |
return _s.getMedia() === currentMedia && _s.annotation !== currentSegment; |
|
418 |
}); |
|
419 |
if (relatedSegments.length) { |
|
420 |
$(".self-media-segments").show(); |
|
421 |
} else { |
|
422 |
$(".self-media-segments").hide(); |
|
423 |
} |
|
| 45 | 424 |
$(".self-media-segments .media-segments-list").html(mediaSegmentList(_(relatedSegments).pluck("annotation"))); |
| 43 | 425 |
showOtherSegments(); |
426 |
project.trigger("mouseout-annotation"); |
|
| 22 | 427 |
} |
| 27 | 428 |
if (currentMedia.elementType === "mashup") { |
429 |
showPreview(); |
|
430 |
} |
|
| 22 | 431 |
} |
| 43 | 432 |
|
| 45 | 433 |
function mediaSegmentList(_annotations) { |
434 |
var html = '', |
|
435 |
k = $(".Ldt-Slider").width() / currentMedia.duration, |
|
436 |
lines = []; |
|
437 |
_(_annotations).each(function(_a, i) { |
|
438 |
var pos = k * (_a.begin + _a.end) / 2, |
|
439 |
corrpos = Math.max(145, Math.min(305, pos)), |
|
440 |
line = IriSP._(lines).find(function(line) { |
|
441 |
return !IriSP._(line.annotations).find(function(ann) { |
|
442 |
return ann.begin < _a.end && ann.end > _a.begin |
|
443 |
}); |
|
444 |
}); |
|
445 |
if (!line) { |
|
446 |
line = { index: lines.length, annotations: []}; |
|
447 |
lines.push(line); |
|
448 |
} |
|
449 |
line.annotations.push(_a); |
|
450 |
vizdata = { |
|
451 |
annotation : _a, |
|
452 |
popleft : corrpos, |
|
453 |
left : k * _a.begin, |
|
454 |
width : k * _a.getDuration(), |
|
455 |
height: 8, |
|
456 |
top: 8 * line.index, |
|
457 |
pointerpos : (pos - corrpos), |
|
| 50 | 458 |
color: IriSP.vizcolors[i % IriSP.vizcolors.length] |
| 45 | 459 |
} |
460 |
html += mediasegmenttemplate(vizdata); |
|
461 |
}); |
|
462 |
return mediasegmentlisttemplate({ |
|
463 |
height: 8 * lines.length, |
|
464 |
left: k * currentSegment.begin, |
|
465 |
width: k * currentSegment.getDuration(), |
|
466 |
segments: html |
|
467 |
}); |
|
468 |
} |
|
469 |
|
|
| 43 | 470 |
/* Show Related Segments */ |
471 |
|
|
472 |
function showOtherSegments() { |
|
| 45 | 473 |
var annotations = mediasegmentscache[currentMedia.id]; |
474 |
$(".other-media-segments .media-segments-list").html(mediaSegmentList(annotations)); |
|
| 43 | 475 |
if (annotations && annotations.length) { |
476 |
$(".other-media-segments").show(); |
|
477 |
} |
|
478 |
else { |
|
479 |
$(".other-media-segments").hide(); |
|
480 |
} |
|
481 |
} |
|
482 |
/* Set In, Out */ |
|
483 |
|
|
484 |
$(".Ldt-Ctrl-SetIn").click(function() { |
|
485 |
if (currentMedia && currentSegment) { |
|
486 |
currentSegment.setBegin(currentMedia.getCurrentTime()); |
|
487 |
} |
|
488 |
}); |
|
489 |
$(".Ldt-Ctrl-SetOut").click(function() { |
|
490 |
if (currentMedia && currentSegment) { |
|
491 |
currentSegment.setEnd(currentMedia.getCurrentTime()); |
|
492 |
} |
|
493 |
}); |
|
494 |
|
|
| 25 | 495 |
/* Segment Form interaction */ |
496 |
|
|
497 |
$("#segment-title").on("keyup change input paste", function() { |
|
| 27 | 498 |
if (currentMedia && currentSegment) { |
499 |
currentSegment.title = $(this).val(); |
|
| 39 | 500 |
updateSegmentUI(); |
|
41
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
501 |
mashup.trigger("change"); |
| 25 | 502 |
} |
503 |
}); |
|
| 43 | 504 |
$("#segment-title").on("focus click", function() { |
| 49 | 505 |
if ($(this).val() === IriSP.translate("Untitled segment")) { |
| 43 | 506 |
$(this).val(""); |
507 |
} |
|
508 |
}); |
|
| 25 | 509 |
$("#segment-description").on("keyup change input paste", function() { |
| 27 | 510 |
if (currentMedia && currentSegment) { |
511 |
currentSegment.description = $(this).val(); |
|
| 64 | 512 |
updateSegmentUI(); |
|
41
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
513 |
mashup.trigger("change"); |
| 25 | 514 |
} |
515 |
}); |
|
516 |
$("#segment-form").submit(function() { |
|
| 64 | 517 |
currentSegment.title = $("#segment-title").val(); |
518 |
currentSegment.description = $("#segment-description").val(); |
|
519 |
currentSegment.keywords = $("#segment-tags").tagit("assignedTags"); |
|
520 |
updateSegmentUI(); |
|
| 27 | 521 |
if (addMode) { |
522 |
mashup.addAnnotation(currentSegment); |
|
| 45 | 523 |
currentSegment = undefined; |
524 |
setMedia(currentMedia); |
|
| 27 | 525 |
} else { |
|
41
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
526 |
mashup.trigger("change"); |
| 49 | 527 |
var segment = mashup.getAnnotation(currentSegment); |
| 45 | 528 |
currentSegment = undefined; |
529 |
setMedia(mashup); |
|
530 |
if (segment) { |
|
531 |
mashup.setCurrentTime(segment.begin); |
|
532 |
mashup.trigger("enter-annotation",segment); |
|
533 |
} |
|
| 27 | 534 |
} |
| 29 | 535 |
return false; |
|
41
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 |
$("#segment-tags").tagit(); |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
539 |
|
|
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 |
/* 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
|
542 |
* are triggered before the data are updated */ |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
543 |
function updateSegmentTags() { |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
544 |
window.setTimeout(function() { |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
545 |
if (currentMedia && currentSegment) { |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
546 |
currentSegment.keywords = $("#segment-tags").tagit("assignedTags"); |
| 64 | 547 |
updateSegmentUI(); |
548 |
mashup.trigger("change"); |
|
|
41
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
549 |
} |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
550 |
}, 0); |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
551 |
} |
| 25 | 552 |
|
| 22 | 553 |
/* Click on media items */ |
554 |
|
|
555 |
$(".col-left").on("click", ".item-video", function() { |
|
| 27 | 556 |
currentSegment = undefined; |
557 |
setMedia(project.getElement($(this).attr("data-media-id"))); |
|
| 22 | 558 |
}); |
| 12 | 559 |
|
| 22 | 560 |
/* Click on Tabs */ |
561 |
|
|
562 |
function showSegmentation() { |
|
563 |
$(".col-middle").removeClass("empty-mode pvw-mode").addClass("segment-mode"); |
|
564 |
return false; |
|
565 |
} |
|
566 |
function showPreview() { |
|
567 |
$(".col-middle").removeClass("empty-mode segment-mode").addClass("pvw-mode"); |
|
568 |
return false; |
|
569 |
} |
|
| 32 | 570 |
function showEmpty() { |
571 |
$("video").hide(); |
|
572 |
$(".col-middle").removeClass("pvw-mode segment-mode").addClass("empty-mode"); |
|
573 |
return false; |
|
574 |
} |
|
| 22 | 575 |
|
| 27 | 576 |
$(".tab-pvw").click(function() { |
577 |
if (mashup.segments.length) { |
|
578 |
setMedia(mashup); |
|
| 22 | 579 |
} |
580 |
}); |
|
581 |
|
|
| 27 | 582 |
/* Click on segments */ |
583 |
|
|
584 |
function reorganizeMashup() { |
|
585 |
var ids = $(".organize-segments .item-video").map(function(){return $(this).attr("data-segment-id")}); |
|
586 |
mashup.setAnnotationsById(ids); |
|
587 |
} |
|
588 |
|
|
|
41
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
589 |
project.on("mouseover-annotation", function(annotation) { |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
590 |
var mediaid = annotation.getMedia().id; |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
591 |
$(".media").removeClass("active"); |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
592 |
$(".media[data-media-id='" + mediaid + "']").addClass("active"); |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
593 |
}); |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
594 |
|
| 43 | 595 |
project.on("mouseout-annotation", function() { |
|
41
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
596 |
$(".media").removeClass("active"); |
| 32 | 597 |
var mediaid = undefined; |
|
41
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
598 |
if (currentMedia && currentMedia.elementType === "media") { |
| 32 | 599 |
mediaid = currentMedia.id; |
|
41
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
600 |
if (currentSegment) { |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
601 |
$(".annotation").removeClass("active"); |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
602 |
$(".annotation[data-segment-id='" + currentSegment.id + "']").addClass("active"); |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
603 |
} |
| 32 | 604 |
} |
|
41
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
605 |
if (currentMedia === mashup && mashup.currentMedia) { |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
606 |
mediaid = mashup.currentMedia.id |
| 32 | 607 |
} |
|
41
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
608 |
$(".media[data-media-id='" + mediaid + "']").addClass("active"); |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
609 |
}); |
| 32 | 610 |
|
611 |
$(".organize-segments") |
|
612 |
.sortable({ |
|
| 27 | 613 |
stop : reorganizeMashup |
| 32 | 614 |
}) |
|
41
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
615 |
.on("mouseover", ".item-video", function() { |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
616 |
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
|
617 |
}) |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
618 |
.on("mouseout", ".item-video", function() { |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
619 |
project.trigger("mouseout-annotation"); |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
620 |
}) |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
621 |
.on("click", ".item-video", function() { |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
622 |
project.trigger("click-annotation", project.getElement($(this).attr("data-segment-id"))); |
| 32 | 623 |
}) |
624 |
.on("click", ".edit", function(e) { |
|
| 27 | 625 |
var currentItem = $(this).parents(".item-video"), |
626 |
media = project.getElement(currentItem.attr("data-media-id")), |
|
627 |
segment = project.getElement(currentItem.attr("data-segment-id")); |
|
628 |
currentSegment = segment; |
|
629 |
setMedia(media); |
|
630 |
return false; |
|
| 32 | 631 |
}) |
632 |
.on("click", ".top", function(e){ |
|
| 22 | 633 |
var currentItem = $(this).parents(".item-video"); |
634 |
currentItem.insertBefore(currentItem.prev()); |
|
| 27 | 635 |
reorganizeMashup(); |
636 |
return false; |
|
| 32 | 637 |
}) |
638 |
.on("click", ".bottom", function(e){ |
|
| 22 | 639 |
var currentItem = $(this).parents(".item-video"); |
640 |
currentItem.insertAfter(currentItem.next()); |
|
| 27 | 641 |
reorganizeMashup(); |
642 |
return false; |
|
| 32 | 643 |
}) |
644 |
.on("click", ".delete", function(e){ |
|
| 27 | 645 |
var id = $(this).parents(".item-video").attr("data-segment-id"); |
646 |
mashup.removeAnnotationById(id); |
|
| 32 | 647 |
if (!mashup.segments.length) { |
648 |
showEmpty(); |
|
649 |
} |
|
| 27 | 650 |
return false; |
| 22 | 651 |
}); |
652 |
|
|
| 25 | 653 |
/* Tangles */ |
654 |
var tangleMsPerPixel = 100, |
|
655 |
activeTangle, |
|
| 23 | 656 |
tangleStartX, |
| 25 | 657 |
tangleStartVal, |
658 |
tangleHasMoved; |
|
659 |
|
|
| 23 | 660 |
$(".time-tangle").mousedown(function(evt) { |
661 |
activeTangle = $(this); |
|
662 |
activeTangle.addClass("active"); |
|
663 |
tangleStartVal = +activeTangle.attr("data-milliseconds"); |
|
664 |
tangleStartX = evt.pageX; |
|
| 25 | 665 |
tangleHasMoved = false; |
666 |
$(this).siblings(".time-tangle").addClass("deactivate"); |
|
| 23 | 667 |
return false; |
668 |
}); |
|
669 |
$(document) |
|
670 |
.mousemove(function(evt) { |
|
671 |
if (activeTangle) { |
|
| 25 | 672 |
tangleHasMoved = true; |
673 |
var newval = new IriSP.Model.Time(tangleMsPerPixel * (evt.pageX - tangleStartX) + tangleStartVal); |
|
| 23 | 674 |
activeTangle.trigger("valuechange", newval); |
675 |
return false; |
|
676 |
} |
|
677 |
}) |
|
678 |
.mouseup(function() { |
|
679 |
if (activeTangle) { |
|
| 27 | 680 |
activeTangle.text(activeTangle.text().replace(/\.\d+$/,'')); |
| 25 | 681 |
$(".time-tangle").removeClass("active deactivate"); |
| 23 | 682 |
activeTangle = undefined; |
683 |
} |
|
| 25 | 684 |
}); |
685 |
|
|
686 |
$(".tangle-start") |
|
687 |
.mouseup(function(evt) { |
|
| 27 | 688 |
if (!tangleHasMoved && currentMedia && currentSegment) { |
689 |
currentMedia.setCurrentTime(currentSegment.begin); |
|
| 25 | 690 |
} |
| 23 | 691 |
}) |
| 25 | 692 |
.on("valuechange", function(evt, val) { |
| 27 | 693 |
if (currentMedia && currentSegment) { |
694 |
currentSegment.setBegin(val); |
|
| 25 | 695 |
} |
696 |
}); |
|
697 |
$(".tangle-end") |
|
698 |
.mouseup(function(evt) { |
|
| 27 | 699 |
if (!tangleHasMoved && currentMedia && currentSegment) { |
700 |
currentMedia.setCurrentTime(currentSegment.end); |
|
| 25 | 701 |
} |
702 |
}) |
|
703 |
.on("valuechange", function(evt, val) { |
|
| 27 | 704 |
if (currentMedia && currentSegment) { |
705 |
currentSegment.setEnd(val); |
|
| 25 | 706 |
} |
707 |
}); |
|
708 |
$(".tangle-duration").on("valuechange", function(evt, val) { |
|
| 27 | 709 |
if (currentMedia && currentSegment) { |
710 |
currentSegment.setDuration(val); |
|
| 25 | 711 |
} |
712 |
}); |
|
| 27 | 713 |
|
| 29 | 714 |
/* Click on current segment in Preview */ |
715 |
|
|
| 27 | 716 |
$(".mashup-description .edit").click(function() { |
| 43 | 717 |
if (mashup.currentAnnotation) { |
718 |
currentSegment = mashup.currentAnnotation.annotation; |
|
719 |
setMedia(mashup.currentAnnotation.getMedia()); |
|
| 27 | 720 |
} |
| 43 | 721 |
return false; |
| 29 | 722 |
}); |
723 |
|
|
724 |
/* Handling related segments */ |
|
725 |
|
|
| 45 | 726 |
function cloneSegment(sid) { |
727 |
var s = directory.getElement(sid) || apidirectory.getElement(sid), |
|
728 |
media = directory.getElement(s.getMedia().id); |
|
729 |
|
|
730 |
currentSegment = new IriSP.Model.Annotation(false, project); |
|
731 |
currentSegment.setMedia(media.id); |
|
732 |
currentSegment.setBegin(s.begin); |
|
733 |
currentSegment.setEnd(s.end); |
|
| 49 | 734 |
currentSegment.title = IriSP.translate("Copy of ") + s.title; |
| 45 | 735 |
currentSegment.description = s.description; |
736 |
currentSegment.keywords = s.keywords; |
|
737 |
currentSegment.color = media.color; |
|
738 |
currentSegment.thumbnail = media.thumbnail; |
|
739 |
currentSegment.created = new Date(); |
|
740 |
currentSegment.on("change-begin", function() { |
|
741 |
if (currentMedia && currentSegment === this) { |
|
742 |
currentMedia.setCurrentTime(this.begin); |
|
743 |
updateSegmentUI(); |
|
744 |
} |
|
745 |
}); |
|
746 |
currentSegment.on("change-end", function() { |
|
747 |
if (currentMedia && currentSegment === this) { |
|
748 |
currentMedia.setCurrentTime(this.end); |
|
749 |
updateSegmentUI(); |
|
750 |
} |
|
751 |
}); |
|
752 |
setMedia(media); |
|
753 |
} |
|
754 |
|
|
| 29 | 755 |
$(".media-segments-list").on("mouseover", ".media-segment", function() { |
756 |
$(this).find(".media-segment-popin").show(); |
|
757 |
}).on("mouseout", ".media-segment", function() { |
|
758 |
$(this).find(".media-segment-popin").hide(); |
|
759 |
}).on("click", ".reprendre-segment", function() { |
|
| 45 | 760 |
cloneSegment($(this).attr("data-segment-id")); |
| 29 | 761 |
return false; |
| 49 | 762 |
}).on("click", ".media-segment-section", function() { |
763 |
var sid = $(this).attr("data-segment-id"), |
|
764 |
s = directory.getElement(sid) || apidirectory.getElement(sid); |
|
765 |
if (s.media.id === currentMedia.id) { |
|
766 |
currentMedia.setCurrentTime(s.begin); |
|
767 |
} |
|
| 29 | 768 |
}); |
769 |
|
|
| 45 | 770 |
$(".col-left").on("mouseover", ".media-segment", function() { |
771 |
$(this).find(".media-found-popin").show(); |
|
772 |
}).on("mouseout", ".media-segment", function() { |
|
773 |
$(this).find(".media-found-popin").hide(); |
|
774 |
}).on("click", ".clone-segment", function() { |
|
775 |
cloneSegment($(this).attr("data-segment-id")); |
|
776 |
return false; |
|
777 |
}); |
|
| 32 | 778 |
/* Changing Hashcut Title and description */ |
| 39 | 779 |
|
| 49 | 780 |
mashup.title = IriSP.translate("Untitled Hashcut"); |
| 39 | 781 |
$(".title-video-wrap a").text(mashup.title); |
782 |
$("#hashcut-title").val(mashup.title); |
|
783 |
|
|
| 32 | 784 |
$("#hashcut-title").on("keyup change input paste", function() { |
785 |
mashup.title = $(this).val(); |
|
786 |
$(".title-video-wrap a").text(mashup.title); |
|
|
41
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
787 |
mashup.trigger("change"); |
| 32 | 788 |
}); |
| 43 | 789 |
$("#hashcut-title").on("focus click", function() { |
| 49 | 790 |
if ($(this).val() === IriSP.translate("Untitled Hashcut")) { |
| 43 | 791 |
$(this).val(""); |
792 |
} |
|
793 |
}); |
|
| 32 | 794 |
|
| 39 | 795 |
$("#hashcut-description").on("keyup change input paste", function() { |
796 |
mashup.description = $(this).val(); |
|
|
41
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
797 |
mashup.trigger("change"); |
| 39 | 798 |
}); |
799 |
|
|
| 43 | 800 |
$("#hashcut-form").submit(function() { |
801 |
$(".update-title").hide(); |
|
802 |
return false; |
|
803 |
}) |
|
|
41
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
804 |
|
| 42 | 805 |
/* Publication */ |
806 |
|
|
| 49 | 807 |
function onLeave() { |
808 |
return IriSP.translate("You haven't published your hashcut yet.\nIf you leave this page, it will be lost"); |
|
809 |
} |
|
810 |
|
|
811 |
$(window).on("beforeunload", onLeave); |
|
812 |
|
|
| 42 | 813 |
$(".publier-button").click(function() { |
| 43 | 814 |
if ($(this).hasClass("disable")) { |
| 49 | 815 |
alert(IriSP.translate("The mashup can't be published because:")+"\n\n"+mashupstatus); |
| 43 | 816 |
return false; |
817 |
} |
|
| 42 | 818 |
var postproject = directory.newLocalSource(), |
| 43 | 819 |
medias = mashup.getMedias() |
| 42 | 820 |
annotations = mashup.getOriginalAnnotations(); |
| 43 | 821 |
postproject.addList("annotationType"); |
822 |
postproject.addList("tag"); |
|
823 |
medias.forEach(function(_m) { |
|
824 |
var anntype = new IriSP.Model.AnnotationType(false, postproject); |
|
825 |
anntype.title = "Segments from " + _m.title; |
|
826 |
anntype.media = _m; |
|
827 |
postproject.getAnnotationTypes().push(anntype); |
|
| 42 | 828 |
}); |
| 43 | 829 |
annotations.forEach(function(_a) { |
830 |
_a.setAnnotationType( |
|
831 |
postproject.getAnnotationTypes().filter( |
|
832 |
function(_at) { return _at.media === _a.getMedia() } |
|
833 |
)[0].id); |
|
834 |
var tagids = []; |
|
835 |
_(_a.keywords).each(function(keyword) { |
|
836 |
var tags = postproject.getTags().searchByTitle(keyword); |
|
837 |
if (tags.length) { |
|
838 |
tagids.push(tags[0].id); |
|
839 |
} else { |
|
840 |
var tag = new IriSP.Model.Tag(false, postproject); |
|
841 |
tag.title = tag.description = keyword; |
|
842 |
postproject.getTags().push(tag); |
|
843 |
tagids.push(tag.id); |
|
844 |
} |
|
845 |
}); |
|
846 |
_a.setTags(tagids); |
|
847 |
}); |
|
| 42 | 848 |
postproject.addList("annotation",annotations); |
| 43 | 849 |
postproject.addList("media",medias); |
| 42 | 850 |
postproject.addList("mashup",[mashup]); |
| 43 | 851 |
postproject.creator = "admin"; |
852 |
postproject.created = new Date(); |
|
853 |
postproject.modified = new Date(); |
|
| 42 | 854 |
postproject.title = mashup.title; |
855 |
postproject.description = mashup.description; |
|
856 |
$.ajax({ |
|
857 |
type: "POST", |
|
| 49 | 858 |
url: IriSP.endpoints.project, |
| 42 | 859 |
data: IriSP.serializers.ldt.serialize(postproject), |
860 |
contentType: "application/cinelab", |
|
861 |
// headers: {"X-CSRFToken": "{{csrf_token}}"}, |
|
862 |
success: function(data, status, request){ |
|
| 49 | 863 |
var location = request.getResponseHeader("Location"), |
864 |
projid = location.match(/([^/]+)\/?$/)[1], |
|
865 |
destination = IriSP.endpoints.hashcut_page + projid; |
|
866 |
$(window).off("beforeunload", onLeave); |
|
867 |
document.location.href = destination; |
|
| 42 | 868 |
}, |
869 |
error: function(jqXHR, textStatus, errorThrown){ |
|
| 49 | 870 |
console.log(arguments); |
871 |
alert(IriSP.translate("Server error\nYour hashcut couldn't be published")); |
|
| 42 | 872 |
} |
873 |
}); |
|
| 49 | 874 |
//TODO: ADD WAITING SCREEN |
875 |
|
|
| 43 | 876 |
return false; |
| 42 | 877 |
}); |
878 |
|
|
|
41
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
39
diff
changeset
|
879 |
mashup.trigger("change"); |
| 13 | 880 |
} |
| 50 | 881 |
|
882 |
/* END editor.js */ |