client/js/ldtjson-bin.js
changeset 195 15e048e00002
parent 170 603ffa4c6fa5
child 196 2a2fcec209d0
equal deleted inserted replaced
194:f53a7999ae7b 195:15e048e00002
     1 Rkns.Ldt = {};
     1 (function(Rkns) {
     2 
     2 "use strict"
     3 Rkns.Ldt.Bin = function(_renkan, _opts) {
     3 
       
     4 var Ldt = Rkns.Ldt = {};
       
     5 
       
     6 var Bin = Ldt.Bin = function(_renkan, _opts) {
     4     if (_opts.ldt_type) {
     7     if (_opts.ldt_type) {
     5         var resclass = Rkns.Ldt[_opts.ldt_type+"Bin"];
     8         var resclass = Ldt[_opts.ldt_type+"Bin"];
     6         if (resclass) {
     9         if (resclass) {
     7             return new resclass(_renkan, _opts);
    10             return new resclass(_renkan, _opts);
     8         }
    11         }
     9     }
    12     }
    10     console.error("No such LDT Bin Type");
    13     console.error("No such LDT Bin Type");
    11 };
    14 };
    12 
    15 
    13 Rkns.Ldt.ProjectBin = Rkns.Utils.inherit(Rkns._BaseBin);
    16 var ProjectBin = Ldt.ProjectBin = Rkns.Utils.inherit(Rkns._BaseBin);
    14 
    17 
    15 Rkns.Ldt.ProjectBin.prototype.tagTemplate = Rkns._.template(
    18 ProjectBin.prototype.tagTemplate = Rkns._.template(
    16     '<li class="Rk-Bin-Item" draggable="true" data-image="<%- Rkns.Utils.getFullURL(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%>\'">'
    19     '<li class="Rk-Bin-Item" draggable="true" data-image="<%- Rkns.Utils.getFullURL(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%>\'">'
    17     + '<img class="Rk-Ldt-Tag-Icon" src="<%-static_url%>img/ldt-tag.png" /><h4><%=htitle%></h4><div class="Rk-Clear"></div></li>'
    20     + '<img class="Rk-Ldt-Tag-Icon" src="<%-static_url%>img/ldt-tag.png" /><h4><%=htitle%></h4><div class="Rk-Clear"></div></li>'
    18 );
    21 );
    19 
    22 
    20 Rkns.Ldt.ProjectBin.prototype.annotationTemplate = Rkns._.template(
    23 ProjectBin.prototype.annotationTemplate = Rkns._.template(
    21     '<li class="Rk-Bin-Item" draggable="true" data-image="<%- Rkns.Utils.getFullURL(image) %>" data-uri="<%=ldt_platform%>ldtplatform/ldt/front/player/<%=mediaid%>/#id=<%=annotationid%>" data-title="<%-title%>" data-description="<%-description%>">'
    24     '<li class="Rk-Bin-Item" draggable="true" data-image="<%- Rkns.Utils.getFullURL(image) %>" data-uri="<%=ldt_platform%>ldtplatform/ldt/front/player/<%=mediaid%>/#id=<%=annotationid%>" data-title="<%-title%>" data-description="<%-description%>">'
    22     + '<img class="Rk-Ldt-Annotation-Icon" src="<%=image%>"/><h4><%=htitle%></h4><p><%=hdescription%></p><p>Start: <%=start%>, End: <%=end%>, Duration: <%=duration%></p><div class="Rk-Clear"></div></li>'
    25     + '<img class="Rk-Ldt-Annotation-Icon" src="<%=image%>"/><h4><%=htitle%></h4><p><%=hdescription%></p><p>Start: <%=start%>, End: <%=end%>, Duration: <%=duration%></p><div class="Rk-Clear"></div></li>'
    23 );
    26 );
    24 
    27 
    25 Rkns.Ldt.ProjectBin.prototype._init = function(_renkan, _opts) {
    28 ProjectBin.prototype._init = function(_renkan, _opts) {
    26     this.renkan = _renkan;
    29     this.renkan = _renkan;
    27     this.proj_id = _opts.project_id;
    30     this.proj_id = _opts.project_id;
    28     this.ldt_platform = _opts.ldt_platform || "http://ldt.iri.centrepompidou.fr/";
    31     this.ldt_platform = _opts.ldt_platform || "http://ldt.iri.centrepompidou.fr/";
    29     this.title_$.html(_opts.title);
    32     this.title_$.html(_opts.title);
    30     this.title_icon_$.addClass('Rk-Ldt-Title-Icon');
    33     this.title_icon_$.addClass('Rk-Ldt-Title-Icon');
    31     this.refresh();
    34     this.refresh();
    32 };
    35 };
    33 
    36 
    34 Rkns.Ldt.ProjectBin.prototype.render = function(searchstr) {
    37 ProjectBin.prototype.render = function(searchstr) {
    35     if (searchstr) {
    38     if (searchstr) {
    36         var rxbase = searchstr.replace(/(\W)/g,'\\$1'),
    39         var rxbase = searchstr.replace(/(\W)/g,'\\$1'),
    37             _rgxp = new RegExp('('+rxbase+')','gi'),
    40             _rgxp = new RegExp('('+rxbase+')','gi'),
    38             rxtest = new RegExp(rxbase,'i');
    41             rxtest = new RegExp(rxbase,'i');
    39     }
    42     }
   121         this.$.show();
   124         this.$.show();
   122     }
   125     }
   123     this.renkan.resizeBins();
   126     this.renkan.resizeBins();
   124 };
   127 };
   125 
   128 
   126 Rkns.Ldt.ProjectBin.prototype.refresh = function() {
   129 ProjectBin.prototype.refresh = function() {
   127     var _this = this;
   130     var _this = this;
   128     Rkns.$.ajax({
   131     Rkns.$.ajax({
   129         url: this.ldt_platform + 'ldtplatform/ldt/cljson/id/' + this.proj_id,
   132         url: this.ldt_platform + 'ldtplatform/ldt/cljson/id/' + this.proj_id,
   130         dataType: "jsonp",
   133         dataType: "jsonp",
   131         success: function(_data) {
   134         success: function(_data) {
   133             _this.render();
   136             _this.render();
   134         }
   137         }
   135     });
   138     });
   136 };
   139 };
   137 
   140 
   138 Rkns.Ldt.Search = function(_renkan, _opts) {
   141 var Search = Ldt.Search = function(_renkan, _opts) {
   139     this.renkan = _renkan;
   142     this.renkan = _renkan;
   140     this.lang = _opts.lang || "en";
   143     this.lang = _opts.lang || "en";
   141 };
   144 };
   142 
   145 
   143 Rkns.Ldt.Search.prototype.getBgClass = function() {
   146 Search.prototype.getBgClass = function() {
   144     return "Rk-Ldt-Icon";
   147     return "Rk-Ldt-Icon";
   145 };
   148 };
   146 
   149 
   147 Rkns.Ldt.Search.prototype.getSearchTitle = function() {
   150 Search.prototype.getSearchTitle = function() {
   148     return this.renkan.translate("Lignes de Temps");
   151     return this.renkan.translate("Lignes de Temps");
   149 };
   152 };
   150 
   153 
   151 Rkns.Ldt.Search.prototype.search = function(_q) {
   154 Search.prototype.search = function(_q) {
   152     this.renkan.tabs.push(
   155     this.renkan.tabs.push(
   153         new Rkns.Ldt.ResultsBin(this.renkan, {
   156         new ResultsBin(this.renkan, {
   154             search: _q
   157             search: _q
   155         })
   158         })
   156     );
   159     );
   157 };
   160 };
   158 
   161 
   159 Rkns.Ldt.ResultsBin = Rkns.Utils.inherit(Rkns._BaseBin);
   162 var ResultsBin = Ldt.ResultsBin = Rkns.Utils.inherit(Rkns._BaseBin);
   160 
   163 
   161 Rkns.Ldt.ResultsBin.prototype.segmentTemplate = Rkns._.template(
   164 ResultsBin.prototype.segmentTemplate = Rkns._.template(
   162     '<li class="Rk-Bin-Item" draggable="true" data-image="<%- Rkns.Utils.getFullURL(image) %>" data-uri="<%=ldt_platform%>ldtplatform/ldt/front/player/<%=mediaid%>/#id=<%=annotationid%>" data-title="<%-title%>" data-description="<%-description%>">'
   165     '<li class="Rk-Bin-Item" draggable="true" data-image="<%- Rkns.Utils.getFullURL(image) %>" data-uri="<%=ldt_platform%>ldtplatform/ldt/front/player/<%=mediaid%>/#id=<%=annotationid%>" data-title="<%-title%>" data-description="<%-description%>">'
   163     + '<img class="Rk-Ldt-Annotation-Icon" src="<%=image%>"/><h4><%=htitle%></h4><p><%=hdescription%></p><p>Start: <%=start%>, End: <%=end%>, Duration: <%=duration%></p><div class="Rk-Clear"></div></li>'
   166     + '<img class="Rk-Ldt-Annotation-Icon" src="<%=image%>"/><h4><%=htitle%></h4><p><%=hdescription%></p><p>Start: <%=start%>, End: <%=end%>, Duration: <%=duration%></p><div class="Rk-Clear"></div></li>'
   164 );
   167 );
   165 
   168 
   166 Rkns.Ldt.ResultsBin.prototype._init = function(_renkan, _opts) {
   169 ResultsBin.prototype._init = function(_renkan, _opts) {
   167     this.renkan = _renkan;
   170     this.renkan = _renkan;
   168     this.ldt_platform = _opts.ldt_platform || "http://ldt.iri.centrepompidou.fr/";
   171     this.ldt_platform = _opts.ldt_platform || "http://ldt.iri.centrepompidou.fr/";
   169     this.max_results = _opts.max_results || 50;
   172     this.max_results = _opts.max_results || 50;
   170     this.search = _opts.search;
   173     this.search = _opts.search;
   171     this.title_$.html('Lignes de Temps: "' + _opts.search + '"');
   174     this.title_$.html('Lignes de Temps: "' + _opts.search + '"');
   172     this.title_icon_$.addClass('Rk-Ldt-Title-Icon');
   175     this.title_icon_$.addClass('Rk-Ldt-Title-Icon');
   173     this.refresh();
   176     this.refresh();
   174 };
   177 };
   175 
   178 
   176 Rkns.Ldt.ResultsBin.prototype.render = function(searchstr) {
   179 ResultsBin.prototype.render = function(searchstr) {
   177     if (searchstr) {
   180     if (searchstr) {
   178         var rxbase = searchstr.replace(/(\W)/g,'\\$1'),
   181         var rxbase = searchstr.replace(/(\W)/g,'\\$1'),
   179             _rgxp = new RegExp('('+rxbase+')','gi'),
   182             _rgxp = new RegExp('('+rxbase+')','gi'),
   180             rxtest = new RegExp(rxbase,'i');
   183             rxtest = new RegExp(rxbase,'i');
   181     } else {
   184     } else {
   252         this.$.show();
   255         this.$.show();
   253     }
   256     }
   254     this.renkan.resizeBins();
   257     this.renkan.resizeBins();
   255 };
   258 };
   256 
   259 
   257 Rkns.Ldt.ResultsBin.prototype.refresh = function() {
   260 ResultsBin.prototype.refresh = function() {
   258     var _this = this;
   261     var _this = this;
   259     Rkns.$.ajax({
   262     Rkns.$.ajax({
   260         url: this.ldt_platform + 'ldtplatform/api/ldt/1.0/segments/search/',
   263         url: this.ldt_platform + 'ldtplatform/api/ldt/1.0/segments/search/',
   261         data: {
   264         data: {
   262             format: "jsonp",
   265             format: "jsonp",
   268             _this.data = _data;
   271             _this.data = _data;
   269             _this.render();
   272             _this.render();
   270         }
   273         }
   271     });
   274     });
   272 };
   275 };
       
   276 
       
   277 })(window.Rkns);