diff -r a21b851538b2 -r 89e152523cb6 integration/js/mediaplayer.js --- a/integration/js/mediaplayer.js Fri Nov 23 19:13:50 2012 +0100 +++ b/integration/js/mediaplayer.js Mon Nov 26 18:42:56 2012 +0100 @@ -5,14 +5,124 @@ url: IriSP.endpoints.content + options.id, serializer: IriSP.serializers.content }), - apidirectory = new IriSP.Model.Directory(); + apidirectory = new IriSP.Model.Directory(), + segmenttemplate = _.template( + '
' + + '
' + + '
' + + '

<%= annotation.title %>

' + + '

<%= IriSP.translate("From:") %> <%= annotation.begin.toString() %> <%= IriSP.translate("to:") %> <%= annotation.end.toString() %> (<%= IriSP.translate("duration:") %> <%= annotation.getDuration().toString() %>)

' + + '' + + '
' + ), + segmentlisttemplate = _.template( + '
<%= segments %>
' + ), + projtemplate = _.template( + '
  • ' + + '<%= title %>
    ' + + '

    <%= title %>

    <%= description %>

    ' + + '

  • ' + ), + media; + + function mediaSegmentList(_annotations) { + var html = '', + k = $(".Ldt-Slider").width() / media.duration, + lines = []; + _(_annotations).each(function(_a, i) { + var pos = k * (_a.begin + _a.end) / 2, + corrpos = Math.max(106, Math.min(516, 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: IriSP.vizcolors[i % IriSP.vizcolors.length] + } + html += segmenttemplate(vizdata); + }); + return segmentlisttemplate({ + height: 8 * lines.length, + segments: html + }); + } content.onLoad(function() { IriSP.mashupcore(content, new IriSP.Model.Mashup(false, content)); - var media = content.getMedias()[0]; + media = content.getMedias()[0]; + apidirectory.remoteSource({ + url: IriSP.endpoints.segment, + url_params: { + iri_id: options.id, + limit: 0 + }, + serializer: IriSP.serializers.segmentapi + }).onLoad(function() { + var medias = this.getMedias(), + annotations = this.getAnnotations(), + projlist = {}; + $(".media-segments").html(mediaSegmentList(annotations)); + annotations.forEach(function(a) { + projlist[a.project_id] = 1 + (projlist[a.project_id] || 0); + }); + var projkeys = _(projlist) + .chain() + .keys() + .sortBy(function(v) { + return - projlist[v]; + }) + .first(8) + .value(); + $.ajax({ + url: IriSP.endpoints.project, + dataType: "json", + data: { + format: "json", + ldt_id__in: projkeys + }, + traditional: true, + success: function(data) { + var proj = _(data.objects) + .filter(function(p) { + return /