diff -r 5a5024bc74e6 -r f39df810caab integration/js/editor.js --- a/integration/js/editor.js Fri Nov 16 19:23:20 2012 +0100 +++ b/integration/js/editor.js Thu Nov 22 10:52:28 2012 +0100 @@ -25,25 +25,44 @@ serializer: IriSP.serializers.medialist }), mashup = new IriSP.Model.Mashup(false, project), - mediatemplate = _.template('
  • ' - + '<%= title %>' + mediatemplate = _.template( + '
  • ' + + '<%= title %>' + '

    <%= title %>

    <%= description %>

    ' - + '

    <%= IriSP.hc_messages.Duration_ %> <%= duration.toString() %>

  • '), - segmenttemplate = _.template('
  • ' - + '<%= annotation.getMedia().title %>' + + '

    <%= IriSP.hc_messages.Duration_ %> <%= duration.toString() %>

  • ' + ), + segmenttemplate = _.template( + '
  • ' + + '<%= annotation.getMedia().title %>' + '
    • <%= annotation.status_messages.join("
    • ") %>

    <%= annotation.getMedia().title %>

    ' + '

    <%= annotation.title %>

    <%= annotation.begin.toString() %> - <%= annotation.end.toString() %> (<%= annotation.getDuration().toString() %>)

    ' + '
  • '), - mediasegmenttemplate = _.template('
    ' - + '
    ' - + '
    ' - + '
    ' + + '
  • ' + ), + mediasegmenttemplate = _.template( + '
    ' + + '
    ' + + '
    ' + '

    <%= annotation.title %>

    <%= IriSP.hc_messages.clone_segment %>' + '

    <%= IriSP.hc_messages.From_ %> <%= annotation.begin.toString() %> <%= IriSP.hc_messages.to_ %> <%= annotation.end.toString() %> (<%= IriSP.hc_messages.duration_ %> <%= annotation.getDuration().toString() %>)

    ' - + '
    '), + + '
    ' + ), + mediasegmentlisttemplate = _.template( + '
    <%= segments %>
    ' + ), + mediafoundtemplate = _.template( + '
    ' + + '
    ' + + '

    <%= title %>

    <%= IriSP.hc_messages.clone_segment %>' + + '
    ' + ), + mediafoundlisttemplate = _.template( + '
    <%= segments %>
    ' + ), mashupstatus = '', addMode, currentMedia, currentSegment; + + var colors = ["#1f77b4","#ff7f0e","#2ca02c","#d62728","#9467bd","#8c564b","#e377c2","#7f7f7f","#bcbd22","#17becf"]; IriSP.mashupcore(project, mashup); @@ -116,25 +135,6 @@ }); $(".col-left .list-video").html(html); project.getMedias().forEach(function(_m) { -/* var dataType = (IriSP.Model.isLocalURL(options.segment_api_endpoint) ? "json" : "jsonp"); - $.ajax({ - url: , - dataType: dataType, - data: { - format: dataType, - iri_id: _m.id - }, - success: function(data) { - console.log(data); - if (data.objects && data.objects.length) { - var mediaid = data.objects[0].iri_id; - mediasegmentscache[mediaid] = data.objects; - if (currentMedia && mediaid === currentMedia.id && currentSegment) { - showOtherSegments(); - } - } - } - }); */ apidirectory.remoteSource({ url: options.segment_api_endpoint, url_params: { @@ -168,17 +168,60 @@ } $(".col-left .item-video").each(function() { var li = $(this), - title = $(this).find(".title-video"), - titletext = title.text(); - if (val && find.test(titletext)) { - title.html(titletext.replace(replace, '$1')); + mediaid = li.attr("data-media-id"), + media = directory.getElement(mediaid); + if (!val) { + li.find(".title-video").text(media.title); + li.find(".description").text(media.description); + li.find(".media-found-segments").html(""); li.show(); } else { - title.text(titletext); - if (val) { + var apimedia = apidirectory.getElement(mediaid); + if (apimedia) { + var annotations = apimedia.getAnnotations().searchByTextFields(val); + } else { + var annotations = []; + } + var found = find.test(media.title) || find.test(media.description) || annotations.length; + if (found) { + li.find(".title-video").html(media.title.replace(replace, '$1')); + li.find(".description").html(media.description.replace(replace, '$1')); + var html = '', + k = 230 / media.duration, + lines = []; + _(annotations).each(function(_a, i) { + var pos = k * (_a.begin + _a.end) / 2, + corrpos = Math.max(76, Math.min(156, pos)), + line = IriSP._(lines).find(function(line) { + return !IriSP._(line.annotations).find(function(ann) { + return ann.begin < _a.end && ann.end > _a.begin + }); + }); + if (!line) { + line = { index: lines.length, annotations: []}; + lines.push(line); + } + line.annotations.push(_a); + vizdata = { + annotation : _a, + left : k * _a.begin, + width : k * _a.getDuration(), + top: 8 * line.index, + color: colors[i % colors.length], + title: _a.title.replace(replace, '$1'), + popleft : corrpos, + pointerpos : (pos - corrpos), + } + html += mediafoundtemplate(vizdata); + }); + html = mediafoundlisttemplate({ + height: 8 * lines.length, + segments: html + }); + li.find(".media-found-segments").html(html); + li.show(); + } else { li.hide(); - } else { - li.show(); } } }) @@ -343,8 +386,8 @@ if (!currentSegment) { currentSegment = new IriSP.Model.Annotation(false, project); currentSegment.setMedia(currentMedia.id); - currentSegment.setBegin(0); - currentSegment.setEnd(currentMedia.duration); + currentSegment.setBegin(currentMedia.getCurrentTime()); + currentSegment.setEnd(Math.min(currentMedia.getCurrentTime() + 180000, currentMedia.duration)); currentSegment.title = IriSP.hc_messages.segment_title_placeholder; currentSegment.color = currentMedia.color; currentSegment.thumbnail = currentMedia.thumbnail; @@ -385,30 +428,12 @@ var relatedSegments = mashup.segments.filter(function(_s) { return _s.getMedia() === currentMedia && _s.annotation !== currentSegment; }); - var html = "", - k = $(".Ldt-Slider").width() / currentMedia.duration, - currentleft = k * currentSegment.begin, - currentwidth = k * currentSegment.getDuration(); if (relatedSegments.length) { - relatedSegments.forEach(function(_s) { - var pos = k * (_s.annotation.begin + _s.annotation.end) / 2, - corrpos = Math.max(145, Math.min(305, pos)); - vizdata = { - annotation : _s.annotation, - currentleft : currentleft, - currentwidth : currentwidth, - popleft : corrpos, - left : k * _s.annotation.begin, - width : k * _s.annotation.getDuration(), - pointerpos : (pos - corrpos) - } - html += mediasegmenttemplate(vizdata); - }); $(".self-media-segments").show(); } else { $(".self-media-segments").hide(); } - $(".self-media-segments .media-segments-list").html(html); + $(".self-media-segments .media-segments-list").html(mediaSegmentList(_(relatedSegments).pluck("annotation"))); showOtherSegments(); project.trigger("mouseout-annotation"); } @@ -417,36 +442,53 @@ } } + function mediaSegmentList(_annotations) { + var html = '', + k = $(".Ldt-Slider").width() / currentMedia.duration, + lines = []; + _(_annotations).each(function(_a, i) { + var pos = k * (_a.begin + _a.end) / 2, + corrpos = Math.max(145, Math.min(305, pos)), + line = IriSP._(lines).find(function(line) { + return !IriSP._(line.annotations).find(function(ann) { + return ann.begin < _a.end && ann.end > _a.begin + }); + }); + if (!line) { + line = { index: lines.length, annotations: []}; + lines.push(line); + } + line.annotations.push(_a); + vizdata = { + annotation : _a, + popleft : corrpos, + left : k * _a.begin, + width : k * _a.getDuration(), + height: 8, + top: 8 * line.index, + pointerpos : (pos - corrpos), + color: colors[i % colors.length] + } + html += mediasegmenttemplate(vizdata); + }); + return mediasegmentlisttemplate({ + height: 8 * lines.length, + left: k * currentSegment.begin, + width: k * currentSegment.getDuration(), + segments: html + }); + } + /* Show Related Segments */ function showOtherSegments() { - var annotations = mediasegmentscache[currentMedia.id] + var annotations = mediasegmentscache[currentMedia.id]; + $(".other-media-segments .media-segments-list").html(mediaSegmentList(annotations)); if (annotations && annotations.length) { - var html = "", - k = $(".Ldt-Slider").width() / currentMedia.duration, - currentleft = k * currentSegment.begin, - currentwidth = k * currentSegment.getDuration(); - annotations.forEach(function(_a) { - var pos = k * (_a.begin + _a.end) / 2, - corrpos = Math.max(145, Math.min(305, pos)); - vizdata = { - annotation : _a, - currentleft : currentleft, - currentwidth : currentwidth, - popleft : corrpos, - left : k * _a.begin, - width : k * _a.getDuration(), - pointerpos : (pos - corrpos), - color: currentMedia.color - } - html += mediasegmenttemplate(vizdata); - }); $(".other-media-segments").show(); - $(".other-media-segments .media-segments-list").html(html); } else { $(".other-media-segments").hide(); - $(".other-media-segments .media-segments-list").html(""); } } /* Set In, Out */ @@ -485,15 +527,16 @@ $("#segment-form").submit(function() { if (addMode) { mashup.addAnnotation(currentSegment); + currentSegment = undefined; + setMedia(currentMedia); } else { mashup.trigger("change"); - } - var segment = mashup.getAnnotation(currentSegment); - currentSegment = undefined; - setMedia(mashup); - if (segment) { - mashup.setCurrentTime(segment.begin); - mashup.trigger("enter-annotation",segment); + currentSegment = undefined; + setMedia(mashup); + if (segment) { + mashup.setCurrentTime(segment.begin); + mashup.trigger("enter-annotation",segment); + } } return false; }); @@ -684,23 +727,52 @@ /* Handling related segments */ + function cloneSegment(sid) { + var s = directory.getElement(sid) || apidirectory.getElement(sid), + media = directory.getElement(s.getMedia().id); + + currentSegment = new IriSP.Model.Annotation(false, project); + currentSegment.setMedia(media.id); + currentSegment.setBegin(s.begin); + currentSegment.setEnd(s.end); + currentSegment.title = IriSP.hc_messages.copy_of_ + s.title; + currentSegment.description = s.description; + currentSegment.keywords = s.keywords; + currentSegment.color = media.color; + currentSegment.thumbnail = media.thumbnail; + currentSegment.created = new Date(); + currentSegment.on("change-begin", function() { + if (currentMedia && currentSegment === this) { + currentMedia.setCurrentTime(this.begin); + updateSegmentUI(); + } + }); + currentSegment.on("change-end", function() { + if (currentMedia && currentSegment === this) { + currentMedia.setCurrentTime(this.end); + updateSegmentUI(); + } + }); + setMedia(media); + } + $(".media-segments-list").on("mouseover", ".media-segment", function() { $(this).find(".media-segment-popin").show(); }).on("mouseout", ".media-segment", function() { $(this).find(".media-segment-popin").hide(); }).on("click", ".reprendre-segment", function() { - var sid = $(this).attr("data-segment-id"), - s = directory.getElement(sid) || apidirectory.getElement(sid); - currentSegment.title = IriSP.hc_messages.copy_of_ + s.title; - currentSegment.description = s.description; - $("#segment-title").val(IriSP.hc_messages.copy_of_ + s.title); - $("#segment-description").val(s.description); - currentSegment.setBegin(s.begin); - currentSegment.setEnd(s.end); - //TODO: ET LES TAGS ! + cloneSegment($(this).attr("data-segment-id")); return false; }); + $(".col-left").on("mouseover", ".media-segment", function() { + $(this).find(".media-found-popin").show(); + }).on("mouseout", ".media-segment", function() { + $(this).find(".media-found-popin").hide(); + }).on("click", ".clone-segment", function() { + cloneSegment($(this).attr("data-segment-id")); + return false; + }); /* Changing Hashcut Title and description */ mashup.title = IriSP.hc_messages.mashup_title_placeholder;