22 project = directory.remoteSource({ |
23 project = directory.remoteSource({ |
23 url: options.url, |
24 url: options.url, |
24 serializer: IriSP.serializers.medialist |
25 serializer: IriSP.serializers.medialist |
25 }), |
26 }), |
26 mashup = new IriSP.Model.Mashup(false, project), |
27 mashup = new IriSP.Model.Mashup(false, project), |
27 mediatemplate = _.template('<li class="item-video media" data-media-id="<%= id %>"><img src="<%= thumbnail %>" alt="<%= title %>" />' |
28 mediatemplate = _.template('<li class="item-video media" data-media-id="<%= id %>"><div class="media-count-wrap"><span class="media-count"></span></div>' |
28 + '<span class="video-info"><span class="title-video"><%= title %></span><span class="author"><%= description %></span>' |
29 + '<img src="<%= thumbnail %>" alt="<%= title %>" />' |
29 + '<span class="time-length"><%= IriSP.hc_messages.Duration_ %> <span><%= duration.toString() %></span></span></span></li>'), |
30 + '<div class="video-info"><h3 class="title-video"><%= title %></h3><p class="description"><%= description %></p>' |
|
31 + '<p class="time-length"><%= IriSP.hc_messages.Duration_ %> <span><%= duration.toString() %></span></p></div></li>'), |
30 segmenttemplate = _.template('<li class="item-video annotation" data-segment-id="<%= annotation.id %>" data-media-id="<%= annotation.getMedia().id %>">' |
32 segmenttemplate = _.template('<li class="item-video annotation" data-segment-id="<%= annotation.id %>" data-media-id="<%= annotation.getMedia().id %>">' |
31 + '<img src="<%= annotation.getMedia().thumbnail %>" alt="<%= annotation.getMedia().title %>" />' |
33 + '<img src="<%= annotation.thumbnail %>" alt="<%= annotation.getMedia().title %>" />' |
32 + '<div class="validate <%= annotation.status %>"><div class="validate-tooltip"><ul><li><%= annotation.status_messages.join("</li><li>") %></li></ul></div></div><span class="video-info"><span class="title-video"><%= annotation.getMedia().title %></span>' |
34 + '<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>' |
33 + '<span class="subtitle"><%= annotation.title %></span><span class="duration"><%= annotation.begin.toString() %> - <%= annotation.end.toString() %> (<%= annotation.getDuration().toString() %>)</span>' |
35 + '<p class="subtitle"><%= annotation.title %></p><p class="duration"><%= annotation.begin.toString() %> - <%= annotation.end.toString() %> (<%= annotation.getDuration().toString() %>)</p>' |
34 + '<ul class="tools"><li><a class="edit" href="#" title="<%= IriSP.hc_messages.edit_segment %>"></a></li><li><a class="bottom" href="#" title="<%= IriSP.hc_messages.segment_down %>"></a></li>' |
36 + '<ul class="tools"><li><a class="edit" href="#" title="<%= IriSP.hc_messages.edit_segment %>"></a></li><li><a class="bottom" href="#" title="<%= IriSP.hc_messages.segment_down %>"></a></li>' |
35 + '<li><a class="top" href="#" title="<%= IriSP.hc_messages.segment_up %>"></a></li><li><a class="delete" href="#" title="<%= IriSP.hc_messages.delete_segment %>"></a></li></ul></span></li>'), |
37 + '<li><a class="top" href="#" title="<%= IriSP.hc_messages.segment_up %>"></a></li><li><a class="delete" href="#" title="<%= IriSP.hc_messages.delete_segment %>"></a></li></ul></div></li>'), |
36 mediasegmenttemplate = _.template('<div class="media-segments-list"><div class="media-segment">' |
38 mediasegmenttemplate = _.template('<div class="media-segments-list"><div class="media-segment">' |
37 + '<div class="media-section media-segment-section" style="left:<%= left %>px; width:<%= width %>px; background:<%= annotation.color %>"></div>' |
39 + '<div class="media-section media-segment-section" style="left:<%= left %>px; width:<%= width %>px; background:<%= color %>"></div>' |
38 + '<div class="media-section media-current-section" style="left:<%= currentleft %>px; width:<%= currentwidth %>px;"><div class="media-current-section-inner"></div></div>' |
40 + '<div class="media-section media-current-section" style="left:<%= currentleft %>px; width:<%= currentwidth %>px;"><div class="media-current-section-inner"></div></div>' |
39 + '<div class="popin media-segment-popin" style="left:<%= popleft %>px"><img style="left:<%= pointerpos %>px;" class="pointer" src="img/popin-triangle.png" alt="" /><div class="popin-content">' |
41 + '<div class="popin media-segment-popin" style="left:<%= popleft %>px"><img style="left:<%= pointerpos %>px;" class="pointer" src="img/popin-triangle.png" alt="" /><div class="popin-content">' |
40 + '<h3><%= annotation.title %></h3><a href="#" class="button reprendre-segment" data-segment-id="<%= annotation.id %>"><%= IriSP.hc_messages.clone_segment %></a>' |
42 + '<h3><%= annotation.title %></h3><a href="#" class="button reprendre-segment" data-segment-id="<%= annotation.id %>"><%= IriSP.hc_messages.clone_segment %></a>' |
41 + '<p><%= IriSP.hc_messages.From_ %> <span><%= annotation.begin.toString() %></span> <%= IriSP.hc_messages.to_ %> <span><%= annotation.end.toString() %></span> (<%= IriSP.hc_messages.duration_ %> <span><%= annotation.getDuration().toString() %></span>)</p>' |
43 + '<p><%= IriSP.hc_messages.From_ %> <span><%= annotation.begin.toString() %></span> <%= IriSP.hc_messages.to_ %> <span><%= annotation.end.toString() %></span> (<%= IriSP.hc_messages.duration_ %> <span><%= annotation.getDuration().toString() %></span>)</p>' |
42 + '</div></div></div></div>'), |
44 + '</div></div></div></div>'), |
|
45 mashupstatus = '', |
43 addMode, currentMedia, currentSegment; |
46 addMode, currentMedia, currentSegment; |
44 |
47 |
45 IriSP.mashupcore(project, mashup); |
48 IriSP.mashupcore(project, mashup); |
46 |
49 |
47 /* Validation of segments and mashup */ |
50 /* Validation of segments and mashup */ |
110 var html = ''; |
113 var html = ''; |
111 project.getMedias().forEach(function(_m) { |
114 project.getMedias().forEach(function(_m) { |
112 html += mediatemplate(_m); |
115 html += mediatemplate(_m); |
113 }); |
116 }); |
114 $(".col-left .list-video").html(html); |
117 $(".col-left .list-video").html(html); |
|
118 project.getMedias().forEach(function(_m) { |
|
119 /* var dataType = (IriSP.Model.isLocalURL(options.segment_api_endpoint) ? "json" : "jsonp"); |
|
120 $.ajax({ |
|
121 url: , |
|
122 dataType: dataType, |
|
123 data: { |
|
124 format: dataType, |
|
125 iri_id: _m.id |
|
126 }, |
|
127 success: function(data) { |
|
128 console.log(data); |
|
129 if (data.objects && data.objects.length) { |
|
130 var mediaid = data.objects[0].iri_id; |
|
131 mediasegmentscache[mediaid] = data.objects; |
|
132 if (currentMedia && mediaid === currentMedia.id && currentSegment) { |
|
133 showOtherSegments(); |
|
134 } |
|
135 } |
|
136 } |
|
137 }); */ |
|
138 apidirectory.remoteSource({ |
|
139 url: options.segment_api_endpoint, |
|
140 url_params: { |
|
141 iri_id: _m.id, |
|
142 limit: 0 |
|
143 }, |
|
144 serializer: IriSP.serializers.segmentapi |
|
145 }).onLoad(function() { |
|
146 var medias = this.getMedias(), |
|
147 annotations = this.getAnnotations(); |
|
148 if (medias && medias.length) { |
|
149 var mediaid = medias[0].id; |
|
150 el = $(".item-video[data-media-id='" + mediaid + "'] .media-count"); |
|
151 el.text(annotations.length).parent().show(); |
|
152 mediasegmentscache[mediaid] = annotations; |
|
153 if (currentMedia && mediaid === currentMedia.id && currentSegment) { |
|
154 showOtherSegments(); |
|
155 } |
|
156 } |
|
157 }); |
|
158 }); |
115 }); |
159 }); |
116 |
160 |
117 /* Search Media with left column form */ |
161 /* Search Media with left column form */ |
118 |
162 |
119 $(".col-left input").on("keyup change input paste", function() { |
163 $(".col-left input").on("keyup change input paste", function() { |
360 $(".self-media-segments").show(); |
407 $(".self-media-segments").show(); |
361 } else { |
408 } else { |
362 $(".self-media-segments").hide(); |
409 $(".self-media-segments").hide(); |
363 } |
410 } |
364 $(".self-media-segments .media-segments-list").html(html); |
411 $(".self-media-segments .media-segments-list").html(html); |
365 |
412 showOtherSegments(); |
366 $(".other-media-segments").hide(); |
413 project.trigger("mouseout-annotation"); |
367 apidirectory.remoteSource({ |
|
368 url: options.segment_api_endpoint + currentMedia.id + "/0/" + currentMedia.duration.milliseconds + "?format=json", |
|
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 } |
414 } |
394 if (currentMedia.elementType === "mashup") { |
415 if (currentMedia.elementType === "mashup") { |
395 showPreview(); |
416 showPreview(); |
396 } |
417 } |
397 } |
418 } |
398 |
419 |
|
420 /* Show Related Segments */ |
|
421 |
|
422 function showOtherSegments() { |
|
423 var annotations = mediasegmentscache[currentMedia.id] |
|
424 if (annotations && annotations.length) { |
|
425 var html = "", |
|
426 k = $(".Ldt-Slider").width() / currentMedia.duration, |
|
427 currentleft = k * currentSegment.begin, |
|
428 currentwidth = k * currentSegment.getDuration(); |
|
429 annotations.forEach(function(_a) { |
|
430 var pos = k * (_a.begin + _a.end) / 2, |
|
431 corrpos = Math.max(145, Math.min(305, pos)); |
|
432 vizdata = { |
|
433 annotation : _a, |
|
434 currentleft : currentleft, |
|
435 currentwidth : currentwidth, |
|
436 popleft : corrpos, |
|
437 left : k * _a.begin, |
|
438 width : k * _a.getDuration(), |
|
439 pointerpos : (pos - corrpos), |
|
440 color: currentMedia.color |
|
441 } |
|
442 html += mediasegmenttemplate(vizdata); |
|
443 }); |
|
444 $(".other-media-segments").show(); |
|
445 $(".other-media-segments .media-segments-list").html(html); |
|
446 } |
|
447 else { |
|
448 $(".other-media-segments").hide(); |
|
449 $(".other-media-segments .media-segments-list").html(""); |
|
450 } |
|
451 } |
|
452 /* Set In, Out */ |
|
453 |
|
454 $(".Ldt-Ctrl-SetIn").click(function() { |
|
455 if (currentMedia && currentSegment) { |
|
456 currentSegment.setBegin(currentMedia.getCurrentTime()); |
|
457 } |
|
458 }); |
|
459 $(".Ldt-Ctrl-SetOut").click(function() { |
|
460 if (currentMedia && currentSegment) { |
|
461 currentSegment.setEnd(currentMedia.getCurrentTime()); |
|
462 } |
|
463 }); |
|
464 |
399 /* Segment Form interaction */ |
465 /* Segment Form interaction */ |
400 |
466 |
401 $("#segment-title").on("keyup change input paste", function() { |
467 $("#segment-title").on("keyup change input paste", function() { |
402 if (currentMedia && currentSegment) { |
468 if (currentMedia && currentSegment) { |
403 currentSegment.title = $(this).val(); |
469 currentSegment.title = $(this).val(); |
404 updateSegmentUI(); |
470 updateSegmentUI(); |
405 mashup.trigger("change"); |
471 mashup.trigger("change"); |
406 } |
472 } |
407 }); |
473 }); |
|
474 $("#segment-title").on("focus click", function() { |
|
475 if ($(this).val() === IriSP.hc_messages.segment_title_placeholder) { |
|
476 $(this).val(""); |
|
477 } |
|
478 }); |
408 $("#segment-description").on("keyup change input paste", function() { |
479 $("#segment-description").on("keyup change input paste", function() { |
409 if (currentMedia && currentSegment) { |
480 if (currentMedia && currentSegment) { |
410 currentSegment.description = $(this).val(); |
481 currentSegment.description = $(this).val(); |
411 mashup.trigger("change"); |
482 mashup.trigger("change"); |
412 } |
483 } |
617 }).on("mouseout", ".media-segment", function() { |
689 }).on("mouseout", ".media-segment", function() { |
618 $(this).find(".media-segment-popin").hide(); |
690 $(this).find(".media-segment-popin").hide(); |
619 }).on("click", ".reprendre-segment", function() { |
691 }).on("click", ".reprendre-segment", function() { |
620 var sid = $(this).attr("data-segment-id"), |
692 var sid = $(this).attr("data-segment-id"), |
621 s = directory.getElement(sid) || apidirectory.getElement(sid); |
693 s = directory.getElement(sid) || apidirectory.getElement(sid); |
622 currentSegment.title = s.title; |
694 currentSegment.title = IriSP.hc_messages.copy_of_ + s.title; |
623 currentSegment.description = s.description; |
695 currentSegment.description = s.description; |
624 $("#segment-title").val(s.title); |
696 $("#segment-title").val(IriSP.hc_messages.copy_of_ + s.title); |
625 $("#segment-description").val(s.description); |
697 $("#segment-description").val(s.description); |
626 currentSegment.setBegin(s.begin); |
698 currentSegment.setBegin(s.begin); |
627 currentSegment.setEnd(s.end); |
699 currentSegment.setEnd(s.end); |
|
700 //TODO: ET LES TAGS ! |
628 return false; |
701 return false; |
629 }); |
702 }); |
630 |
703 |
631 /* Changing Hashcut Title and description */ |
704 /* Changing Hashcut Title and description */ |
632 |
|
633 $("#hashcut-tags").tagit({ |
|
634 onTagRemoved: updateSegmentTags, |
|
635 onTagAdded: updateSegmentTags |
|
636 }); |
|
637 |
705 |
638 mashup.title = IriSP.hc_messages.mashup_title_placeholder; |
706 mashup.title = IriSP.hc_messages.mashup_title_placeholder; |
639 $(".title-video-wrap a").text(mashup.title); |
707 $(".title-video-wrap a").text(mashup.title); |
640 $("#hashcut-title").val(mashup.title); |
708 $("#hashcut-title").val(mashup.title); |
641 |
709 |
642 $("#hashcut-title").on("keyup change input paste", function() { |
710 $("#hashcut-title").on("keyup change input paste", function() { |
643 mashup.title = $(this).val(); |
711 mashup.title = $(this).val(); |
644 $(".title-video-wrap a").text(mashup.title); |
712 $(".title-video-wrap a").text(mashup.title); |
645 mashup.trigger("change"); |
713 mashup.trigger("change"); |
646 }); |
714 }); |
|
715 $("#hashcut-title").on("focus click", function() { |
|
716 if ($(this).val() === IriSP.hc_messages.mashup_title_placeholder) { |
|
717 $(this).val(""); |
|
718 } |
|
719 }); |
647 |
720 |
648 $("#hashcut-description").on("keyup change input paste", function() { |
721 $("#hashcut-description").on("keyup change input paste", function() { |
649 mashup.description = $(this).val(); |
722 mashup.description = $(this).val(); |
650 mashup.trigger("change"); |
723 mashup.trigger("change"); |
651 }); |
724 }); |
652 |
725 |
653 function updateMashupTags() { |
726 $("#hashcut-form").submit(function() { |
654 window.setTimeout(function() { |
727 $(".update-title").hide(); |
655 mashup.keywords = $("#segment-tags").tagit("assignedTags"); |
728 return false; |
656 }, 0); |
729 }) |
657 } |
|
658 |
730 |
659 /* Publication */ |
731 /* Publication */ |
660 |
732 |
661 $(".publier-button").click(function() { |
733 $(".publier-button").click(function() { |
|
734 if ($(this).hasClass("disable")) { |
|
735 alert("Le Mashup ne peut pas être publié pour les raisons suivantes :\n\n"+mashupstatus); |
|
736 return false; |
|
737 } |
662 var postproject = directory.newLocalSource(), |
738 var postproject = directory.newLocalSource(), |
663 anntype = new IriSP.Model.AnnotationType(false, postproject), |
739 medias = mashup.getMedias() |
664 annotations = mashup.getOriginalAnnotations(); |
740 annotations = mashup.getOriginalAnnotations(); |
665 anntype.title = "hashcut-segments"; |
741 postproject.addList("annotationType"); |
|
742 postproject.addList("tag"); |
|
743 medias.forEach(function(_m) { |
|
744 var anntype = new IriSP.Model.AnnotationType(false, postproject); |
|
745 anntype.title = "Segments from " + _m.title; |
|
746 anntype.media = _m; |
|
747 postproject.getAnnotationTypes().push(anntype); |
|
748 }); |
666 annotations.forEach(function(_a) { |
749 annotations.forEach(function(_a) { |
667 _a.setAnnotationType(anntype.id); |
750 _a.setAnnotationType( |
668 }); |
751 postproject.getAnnotationTypes().filter( |
669 postproject.addList("media",mashup.getMedias()); |
752 function(_at) { return _at.media === _a.getMedia() } |
670 postproject.addList("annotationType",[anntype]); |
753 )[0].id); |
|
754 var tagids = []; |
|
755 _(_a.keywords).each(function(keyword) { |
|
756 var tags = postproject.getTags().searchByTitle(keyword); |
|
757 if (tags.length) { |
|
758 tagids.push(tags[0].id); |
|
759 } else { |
|
760 var tag = new IriSP.Model.Tag(false, postproject); |
|
761 tag.title = tag.description = keyword; |
|
762 postproject.getTags().push(tag); |
|
763 tagids.push(tag.id); |
|
764 } |
|
765 }); |
|
766 _a.setTags(tagids); |
|
767 }); |
671 postproject.addList("annotation",annotations); |
768 postproject.addList("annotation",annotations); |
|
769 postproject.addList("media",medias); |
672 postproject.addList("mashup",[mashup]); |
770 postproject.addList("mashup",[mashup]); |
673 postproject.addList("tag"); |
771 postproject.creator = "admin"; |
674 postproject.creator = "IRI"; |
772 postproject.created = new Date(); |
|
773 postproject.modified = new Date(); |
675 postproject.title = mashup.title; |
774 postproject.title = mashup.title; |
676 postproject.description = mashup.description; |
775 postproject.description = mashup.description; |
677 console.log(IriSP.serializers.ldt.serialize(postproject)); |
|
678 $.ajax({ |
776 $.ajax({ |
679 type: "POST", |
777 type: "POST", |
680 url: options.project_api_endpoint, |
778 url: options.project_api_endpoint, |
681 data: IriSP.serializers.ldt.serialize(postproject), |
779 data: IriSP.serializers.ldt.serialize(postproject), |
682 contentType: "application/cinelab", |
780 contentType: "application/cinelab", |
683 // headers: {"X-CSRFToken": "{{csrf_token}}"}, |
781 // headers: {"X-CSRFToken": "{{csrf_token}}"}, |
684 success: function(data, status, request){ |
782 success: function(data, status, request){ |
685 alert("api post success"); |
783 console.log(request.getResponseHeader("Location")); |
686 }, |
784 }, |
687 error: function(jqXHR, textStatus, errorThrown){ |
785 error: function(jqXHR, textStatus, errorThrown){ |
688 alert(errorThrown); |
786 alert(errorThrown); |
689 } |
787 } |
690 }); |
788 }); |
|
789 return false; |
691 }); |
790 }); |
692 |
791 |
693 mashup.trigger("change"); |
792 mashup.trigger("change"); |
694 } |
793 } |