server/src/main/webapp/static/js/ldtjson-bin.js
changeset 47 267d67791e05
child 50 7b517a54b708
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/server/src/main/webapp/static/js/ldtjson-bin.js	Tue Dec 25 21:29:11 2012 +0100
@@ -0,0 +1,87 @@
+Rkns.Ldt = {}
+
+Rkns.Ldt.ProjectBin = Rkns.Utils.inherit(Rkns._BaseBin);
+
+Rkns.Ldt.ProjectBin.prototype.tagTemplate = Rkns._.template(
+    '<li class="Rk-Bin-Item" data-image="<%=static_url%>img/ldt-tag.png" data-uri="<%=ldt_platform%>ldtplatform/ldt/front/search/?search=<%=encodedtitle%>&field=all" data-title="<%-title%>" data-description="Tag \'<%-title%>\'">'
+    + '<img class="Rk-Ldt-Tag-Icon" src="<%=static_url%>img/ldt-tag.png" /><h4><%-title%></h4><div class="Rk-Clear"></div></li>'
+);
+
+Rkns.Ldt.ProjectBin.prototype.annotationTemplate = Rkns._.template(
+    '<li class="Rk-Bin-Item" data-image="<%=image%>" data-uri="<%=ldt_platform%>ldtplatform/ldt/front/player/<%=mediaid%>/#id=<%=annotationid%>" data-title="<%-title%>" data-description="<%-description%>">'
+    + '<img class="Rk-Ldt-Annotation-Icon" src="<%=image%>"/><h4><%-title%></h4><p><%-description%></p><p>Start: <%=start%>, End: <%=end%>, Duration: <%=duration%></p><div class="Rk-Clear"></div></li>'
+);
+
+Rkns.Ldt.ProjectBin.prototype._init = function(_renkan, _opts) {
+    this.proj_id = _opts.project_id;
+    this.ldt_platform = _opts.ldt_platform || "http://ldt.iri.centrepompidou.fr/";
+    this.title_$.html(_opts.title);
+    this.refresh();
+}
+
+Rkns.Ldt.ProjectBin.prototype.refresh = function() {
+    var _this = this;
+    function convertTC(_ms) {
+        function pad(_n) {
+            var _res = _n.toString();
+            while (_res.length < 2) {
+                _res = '0' + _res;
+            }
+            return _res;
+        }
+        var _totalSeconds = Math.abs(Math.floor(_ms/1000)),
+            _hours = Math.floor(_totalSeconds / 3600),
+            _minutes = (Math.floor(_totalSeconds / 60) % 60),
+            _seconds = _totalSeconds % 60,
+            _res = '';
+        if (_hours) {
+            _res += pad(_hours) + ':'
+        }
+        _res += pad(_minutes) + ':' + pad(_seconds);
+        return _res;
+    }
+    Rkns.$.ajax({
+        url: this.ldt_platform + 'ldtplatform/ldt/cljson/id/' + this.proj_id,
+        dataType: "jsonp",
+        success: function(_data) {
+            var _html = '<li><h3>Tags</h3></li>',
+                _projtitle = _data.meta["dc:title"];
+            _this.title_$.html('LDT Project: "' + _projtitle + '"');
+            _html += Rkns._(_data.tags).map(function(_tag) {
+                var _title = _tag.meta["dc:title"]
+                return _this.tagTemplate({
+                    ldt_platform: _this.ldt_platform,
+                    title: _title,
+                    encodedtitle : encodeURIComponent(_title),
+                    static_url: _this.renkan.static_url
+                })
+            }).join("");
+            _html += '<li><h3>Annotations</h3></li>';
+            _html += Rkns._(_data.annotations).map(function(_annotation) {
+                var _description = _annotation.content.description,
+                    _title = _annotation.content.title.replace(_description,""),
+                    _duration = _annotation.end - _annotation.begin,
+                    _img = (
+                        (_annotation.content && _annotation.content.img && _annotation.content.img.src)
+                        ? _annotation.content.img.src
+                        : _this.renkan.static_url + ( _duration ? "img/ldt-segment.png" : "img/ldt-point.png" )
+                    );
+                return _this.annotationTemplate({
+                    ldt_platform: _this.ldt_platform,
+                    title: _title,
+                    description: _description,
+                    start: convertTC(_annotation.begin),
+                    end: convertTC(_annotation.end),
+                    duration: convertTC(_duration),
+                    mediaid: _annotation.media,
+                    annotationid: _annotation.id,
+                    image: _img,
+                    static_url: _this.renkan.static_url
+                });
+            }).join("");
+            
+            _this.main_$.html(_html);
+            _renkan.resizeBins();
+        }
+    });
+}
\ No newline at end of file