16 IriSP.editor = function(options) { |
16 IriSP.editor = function(options) { |
17 |
17 |
18 /* Load Media List */ |
18 /* Load Media List */ |
19 |
19 |
20 var directory = new IriSP.Model.Directory(), |
20 var directory = new IriSP.Model.Directory(), |
|
21 apidirectory = new IriSP.Model.Directory(), |
21 project = directory.remoteSource({ |
22 project = directory.remoteSource({ |
22 url: options.url, |
23 url: options.url, |
23 serializer: IriSP.serializers.medialist |
24 serializer: IriSP.serializers.medialist |
24 }), |
25 }), |
25 mashup = new IriSP.Model.Mashup(false, project), |
26 mashup = new IriSP.Model.Mashup(false, project), |
277 $(".segmentation .validate").removeClass("critical warning valid").addClass(currentSegment.status); |
278 $(".segmentation .validate").removeClass("critical warning valid").addClass(currentSegment.status); |
278 $(".segmentation .validate-tooltip").html("<ul><li>" + currentSegment.status_messages.join("</li><li>")+"</li></ul>"); |
279 $(".segmentation .validate-tooltip").html("<ul><li>" + currentSegment.status_messages.join("</li><li>")+"</li></ul>"); |
279 } |
280 } |
280 } |
281 } |
281 |
282 |
|
283 var mediasegmentscache = {}; |
|
284 |
282 function setMedia(media) { |
285 function setMedia(media) { |
283 if (currentMedia) { |
286 if (currentMedia) { |
284 currentMedia.pause(); |
287 currentMedia.pause(); |
285 } |
288 } |
286 currentMedia = media; |
289 currentMedia = media; |
296 currentSegment.setMedia(currentMedia.id); |
299 currentSegment.setMedia(currentMedia.id); |
297 currentSegment.setBegin(0); |
300 currentSegment.setBegin(0); |
298 currentSegment.setEnd(currentMedia.duration); |
301 currentSegment.setEnd(currentMedia.duration); |
299 currentSegment.title = IriSP.hc_messages.segment_title_placeholder; |
302 currentSegment.title = IriSP.hc_messages.segment_title_placeholder; |
300 currentSegment.color = currentMedia.color; |
303 currentSegment.color = currentMedia.color; |
|
304 currentSegment.created = new Date(); |
301 currentSegment.keywords = []; |
305 currentSegment.keywords = []; |
302 currentSegment.description = ""; |
306 currentSegment.description = ""; |
303 currentSegment.on("change-begin", function() { |
307 currentSegment.on("change-begin", function() { |
304 if (currentMedia && currentSegment === this) { |
308 if (currentMedia && currentSegment === this) { |
305 currentMedia.setCurrentTime(this.begin); |
309 currentMedia.setCurrentTime(this.begin); |
332 segment_tags.tagit("option","onTagAdded",updateSegmentTags); |
336 segment_tags.tagit("option","onTagAdded",updateSegmentTags); |
333 updateSegmentUI(); |
337 updateSegmentUI(); |
334 var relatedSegments = mashup.segments.filter(function(_s) { |
338 var relatedSegments = mashup.segments.filter(function(_s) { |
335 return _s.getMedia() === currentMedia && _s.annotation !== currentSegment; |
339 return _s.getMedia() === currentMedia && _s.annotation !== currentSegment; |
336 }); |
340 }); |
337 var html = ""; |
341 var html = "", |
|
342 k = $(".Ldt-Slider").width() / currentSegment.getMedia().duration, |
|
343 currentleft = k * currentSegment.begin, |
|
344 currentwidth = k * currentSegment.getDuration(); |
338 if (relatedSegments.length) { |
345 if (relatedSegments.length) { |
339 var k = $(".Ldt-Slider").width() / currentSegment.getMedia().duration, |
|
340 currentleft = k * currentSegment.begin, |
|
341 currentwidth = k * currentSegment.getDuration(); |
|
342 relatedSegments.forEach(function(_s) { |
346 relatedSegments.forEach(function(_s) { |
343 var pos = k * (_s.annotation.begin + _s.annotation.end) / 2, |
347 var pos = k * (_s.annotation.begin + _s.annotation.end) / 2, |
344 corrpos = Math.max(145, Math.min(305, pos)); |
348 corrpos = Math.max(145, Math.min(305, pos)); |
345 vizdata = { |
349 vizdata = { |
346 annotation : _s.annotation, |
350 annotation : _s.annotation, |
355 }); |
359 }); |
356 $(".self-media-segments").show(); |
360 $(".self-media-segments").show(); |
357 } else { |
361 } else { |
358 $(".self-media-segments").hide(); |
362 $(".self-media-segments").hide(); |
359 } |
363 } |
|
364 $(".self-media-segments .media-segments-list").html(html); |
360 |
365 |
361 //TODO: Show Related Segments from http://capsicum/pf/ldtplatform/api/ldt/1.0/segments/bytimecode/f72aa2f4-29bb-11e2-a193-08002791f1b7/0/674000?format=json |
366 $(".other-media-segments").hide(); |
362 |
367 apidirectory.remoteSource({ |
363 } |
368 url: options.segment_api_endpoint + currentMedia.id + "/0/" + currentMedia.duration.milliseconds + "?format=json", |
364 $(".self-media-segments .media-segments-list").html(html); |
369 serializer: IriSP.serializers.ldt |
|
370 }).onLoad(function() { |
|
371 var medias = this.getMedias(), |
|
372 annotations = this.getAnnotations(); |
|
373 if (medias && medias.length && medias[0].id === currentMedia.id && annotations && annotations.length ) { |
|
374 var html = ""; |
|
375 annotations.forEach(function(_a) { |
|
376 var pos = k * (_a.begin + _a.end) / 2, |
|
377 corrpos = Math.max(145, Math.min(305, pos)); |
|
378 vizdata = { |
|
379 annotation : _a, |
|
380 currentleft : currentleft, |
|
381 currentwidth : currentwidth, |
|
382 popleft : corrpos, |
|
383 left : k * _a.begin, |
|
384 width : k * _a.getDuration(), |
|
385 pointerpos : (pos - corrpos) |
|
386 } |
|
387 html += mediasegmenttemplate(vizdata); |
|
388 }); |
|
389 $(".other-media-segments").show(); |
|
390 $(".other-media-segments .media-segments-list").html(html); |
|
391 } |
|
392 }); |
|
393 } |
365 if (currentMedia.elementType === "mashup") { |
394 if (currentMedia.elementType === "mashup") { |
366 showPreview(); |
395 showPreview(); |
367 } |
396 } |
368 } |
397 } |
369 |
398 |
586 $(".media-segments-list").on("mouseover", ".media-segment", function() { |
615 $(".media-segments-list").on("mouseover", ".media-segment", function() { |
587 $(this).find(".media-segment-popin").show(); |
616 $(this).find(".media-segment-popin").show(); |
588 }).on("mouseout", ".media-segment", function() { |
617 }).on("mouseout", ".media-segment", function() { |
589 $(this).find(".media-segment-popin").hide(); |
618 $(this).find(".media-segment-popin").hide(); |
590 }).on("click", ".reprendre-segment", function() { |
619 }).on("click", ".reprendre-segment", function() { |
591 var s = project.getElement($(this).attr("data-segment-id")); |
620 var sid = $(this).attr("data-segment-id"), |
|
621 s = directory.getElement(sid) || apidirectory.getElement(sid); |
592 currentSegment.title = s.title; |
622 currentSegment.title = s.title; |
593 currentSegment.description = s.description; |
623 currentSegment.description = s.description; |
594 $("#segment-title").val(s.title); |
624 $("#segment-title").val(s.title); |
595 $("#segment-description").val(s.description); |
625 $("#segment-description").val(s.description); |
596 currentSegment.setBegin(s.begin); |
626 currentSegment.setBegin(s.begin); |
624 window.setTimeout(function() { |
654 window.setTimeout(function() { |
625 mashup.keywords = $("#segment-tags").tagit("assignedTags"); |
655 mashup.keywords = $("#segment-tags").tagit("assignedTags"); |
626 }, 0); |
656 }, 0); |
627 } |
657 } |
628 |
658 |
|
659 /* Publication */ |
|
660 |
|
661 $(".publier-button").click(function() { |
|
662 var postproject = directory.newLocalSource(), |
|
663 anntype = new IriSP.Model.AnnotationType(false, postproject), |
|
664 annotations = mashup.getOriginalAnnotations(); |
|
665 anntype.title = "hashcut-segments"; |
|
666 annotations.forEach(function(_a) { |
|
667 _a.setAnnotationType(anntype.id); |
|
668 }); |
|
669 postproject.addList("media",mashup.getMedias()); |
|
670 postproject.addList("annotationType",[anntype]); |
|
671 postproject.addList("annotation",annotations); |
|
672 postproject.addList("mashup",[mashup]); |
|
673 postproject.addList("tag"); |
|
674 postproject.creator = "IRI"; |
|
675 postproject.title = mashup.title; |
|
676 postproject.description = mashup.description; |
|
677 console.log(IriSP.serializers.ldt.serialize(postproject)); |
|
678 $.ajax({ |
|
679 type: "POST", |
|
680 url: options.project_api_endpoint, |
|
681 data: IriSP.serializers.ldt.serialize(postproject), |
|
682 contentType: "application/cinelab", |
|
683 // headers: {"X-CSRFToken": "{{csrf_token}}"}, |
|
684 success: function(data, status, request){ |
|
685 alert("api post success"); |
|
686 }, |
|
687 error: function(jqXHR, textStatus, errorThrown){ |
|
688 alert(errorThrown); |
|
689 } |
|
690 }); |
|
691 }); |
|
692 |
629 mashup.trigger("change"); |
693 mashup.trigger("change"); |
630 } |
694 } |