client/js/ldtjson-bin.js
changeset 64 3a5a9421687b
parent 61 cf48c6d69717
child 66 9b459e41e2df
equal deleted inserted replaced
62:f9019462465a 64:3a5a9421687b
    15 Rkns.Ldt.ProjectBin.prototype._init = function(_renkan, _opts) {
    15 Rkns.Ldt.ProjectBin.prototype._init = function(_renkan, _opts) {
    16     this.renkan = _renkan;
    16     this.renkan = _renkan;
    17     this.proj_id = _opts.project_id;
    17     this.proj_id = _opts.project_id;
    18     this.ldt_platform = _opts.ldt_platform || "http://ldt.iri.centrepompidou.fr/";
    18     this.ldt_platform = _opts.ldt_platform || "http://ldt.iri.centrepompidou.fr/";
    19     this.title_$.html(_opts.title);
    19     this.title_$.html(_opts.title);
       
    20     this.title_icon_$.addClass('Rk-Ldt-Title-Icon');
    20     this.refresh();
    21     this.refresh();
    21 }
    22 }
    22 
    23 
    23 Rkns.Ldt.ProjectBin.prototype.render = function(searchstr) {
    24 Rkns.Ldt.ProjectBin.prototype.render = function(searchstr) {
    24     if (searchstr) {
    25     if (searchstr) {
   121             _this.data = _data;
   122             _this.data = _data;
   122             _this.render();
   123             _this.render();
   123         }
   124         }
   124     });
   125     });
   125 }
   126 }
       
   127 
       
   128 Rkns.Ldt.Search = function(_renkan, _opts) {
       
   129     this.renkan = _renkan;
       
   130     this.lang = _opts.lang || "en";
       
   131 }
       
   132 
       
   133 Rkns.Ldt.Search.prototype.getBgClass = function() {
       
   134     return "Rk-Ldt-Icon";
       
   135 }
       
   136 
       
   137 Rkns.Ldt.Search.prototype.getSearchTitle = function() {
       
   138     return this.renkan.l10n.search_ldt;
       
   139 }
       
   140 
       
   141 Rkns.Ldt.Search.prototype.search = function(_q) {
       
   142     this.renkan.tabs.push(
       
   143         new Rkns.Ldt.ResultsBin(this.renkan, {
       
   144             search: _q
       
   145         })
       
   146     );
       
   147 }
       
   148 
       
   149 Rkns.Ldt.ResultsBin = Rkns.Utils.inherit(Rkns._BaseBin);
       
   150 
       
   151 Rkns.Ldt.ResultsBin.prototype.segmentTemplate = Rkns._.template(
       
   152     '<li class="Rk-Bin-Item" data-image="<%=image%>" data-uri="<%=ldt_platform%>ldtplatform/ldt/front/player/<%=mediaid%>/<%=projectid%>/<%=cuttingid%>/#id=<%=annotationid%>" data-title="<%-title%>" data-description="<%-description%>">'
       
   153     + '<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>'
       
   154 );
       
   155 
       
   156 Rkns.Ldt.ResultsBin.prototype._init = function(_renkan, _opts) {
       
   157     this.renkan = _renkan;
       
   158     this.ldt_platform = _opts.ldt_platform || "http://ldt.iri.centrepompidou.fr/";
       
   159     this.max_results = _opts.max_results || 50;
       
   160     this.search = _opts.search;
       
   161     this.title_$.html('Lignes de Temps: "' + _opts.search + '"');
       
   162     this.title_icon_$.addClass('Rk-Ldt-Title-Icon');
       
   163     this.refresh();
       
   164 }
       
   165 
       
   166 Rkns.Ldt.ResultsBin.prototype.render = function(searchstr) {
       
   167     if (searchstr) {
       
   168         var rxbase = searchstr.replace(/(\W)/g,'\\$1'),
       
   169             _rgxp = new RegExp('('+rxbase+')','gi'),
       
   170             rxtest = new RegExp(rxbase,'i')
       
   171     }
       
   172     function highlight(_text) {
       
   173         return searchstr ? _text.replace(_rgxp, "<span class='searchmatch'>$1</span>") : _text;
       
   174     }
       
   175     function convertTC(_ms) {
       
   176         function pad(_n) {
       
   177             var _res = _n.toString();
       
   178             while (_res.length < 2) {
       
   179                 _res = '0' + _res;
       
   180             }
       
   181             return _res;
       
   182         }
       
   183         var _totalSeconds = Math.abs(Math.floor(_ms/1000)),
       
   184             _hours = Math.floor(_totalSeconds / 3600),
       
   185             _minutes = (Math.floor(_totalSeconds / 60) % 60),
       
   186             _seconds = _totalSeconds % 60,
       
   187             _res = '';
       
   188         if (_hours) {
       
   189             _res += pad(_hours) + ':'
       
   190         }
       
   191         _res += pad(_minutes) + ':' + pad(_seconds);
       
   192         return _res;
       
   193     }
       
   194     
       
   195     var _html = '',
       
   196         _this = this,
       
   197         count = 0;
       
   198     Rkns._(_this.data.objects).each(function(_segment) {
       
   199         var _description = _segment.abstract,
       
   200             _title = _segment.title;
       
   201         if (searchstr && !rxtest.test(_title) && !rxtest.test(_description)) {
       
   202             return;
       
   203         }
       
   204         count++;
       
   205         var _duration = _segment.duration,
       
   206             _begin = _segment.start_ts,
       
   207             _end = + _segment.duration + _begin
       
   208             _img = (
       
   209                 _duration
       
   210                 ? _this.renkan.static_url + "img/ldt-segment.png"
       
   211                 : _this.renkan.static_url + "img/ldt-point.png"
       
   212             );
       
   213         _html += _this.segmentTemplate({
       
   214             ldt_platform: _this.ldt_platform,
       
   215             title: _title,
       
   216             htitle: highlight(_title),
       
   217             description: _description,
       
   218             hdescription: highlight(_description),
       
   219             start: convertTC(_begin),
       
   220             end: convertTC(_end),
       
   221             duration: convertTC(_duration),
       
   222             mediaid: _segment.iri_id,
       
   223             projectid: _segment.project_id,
       
   224             cuttingid: _segment.cutting_id,
       
   225             annotationid: _segment.element_id,
       
   226             image: _img
       
   227         });
       
   228     });
       
   229     
       
   230     this.main_$.html(_html);
       
   231     if (searchstr && count) {
       
   232         this.count_$.text(count).show();
       
   233     } else {
       
   234         this.count_$.hide();
       
   235     }
       
   236     if (searchstr && !count) {
       
   237         this.$.hide();
       
   238     } else {
       
   239         this.$.show();
       
   240     }
       
   241     this.renkan.resizeBins();
       
   242 }
       
   243 
       
   244 Rkns.Ldt.ResultsBin.prototype.refresh = function() {
       
   245     var _this = this;
       
   246     Rkns.$.ajax({
       
   247         url: this.ldt_platform + 'ldtplatform/api/ldt/1.0/segments/search/',
       
   248         data: {
       
   249             format: "jsonp",
       
   250             q: this.search,
       
   251             limit: this.max_results
       
   252         },
       
   253         dataType: "jsonp",
       
   254         success: function(_data) {
       
   255             _this.data = _data;
       
   256             _this.render();
       
   257         }
       
   258     });
       
   259 }