client/js/ldtjson-bin.js
changeset 170 603ffa4c6fa5
parent 160 408da84d4dc0
child 195 15e048e00002
equal deleted inserted replaced
169:a60a450b8f3b 170:603ffa4c6fa5
     1 Rkns.Ldt = {}
     1 Rkns.Ldt = {};
     2 
     2 
     3 Rkns.Ldt.Bin = function(_renkan, _opts) {
     3 Rkns.Ldt.Bin = function(_renkan, _opts) {
     4     if (_opts.ldt_type) {
     4     if (_opts.ldt_type) {
     5         var resclass = Rkns.Ldt[_opts.ldt_type+"Bin"];
     5         var resclass = Rkns.Ldt[_opts.ldt_type+"Bin"];
     6         if (resclass) {
     6         if (resclass) {
     7             return new resclass(_renkan, _opts);
     7             return new resclass(_renkan, _opts);
     8         }
     8         }
     9     }
     9     }
    10     console.error("No such LDT Bin Type");
    10     console.error("No such LDT Bin Type");
    11 }
    11 };
    12 
    12 
    13 Rkns.Ldt.ProjectBin = Rkns.Utils.inherit(Rkns._BaseBin);
    13 Rkns.Ldt.ProjectBin = Rkns.Utils.inherit(Rkns._BaseBin);
    14 
    14 
    15 Rkns.Ldt.ProjectBin.prototype.tagTemplate = Rkns._.template(
    15 Rkns.Ldt.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%>\'">'
    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%>\'">'
    27     this.proj_id = _opts.project_id;
    27     this.proj_id = _opts.project_id;
    28     this.ldt_platform = _opts.ldt_platform || "http://ldt.iri.centrepompidou.fr/";
    28     this.ldt_platform = _opts.ldt_platform || "http://ldt.iri.centrepompidou.fr/";
    29     this.title_$.html(_opts.title);
    29     this.title_$.html(_opts.title);
    30     this.title_icon_$.addClass('Rk-Ldt-Title-Icon');
    30     this.title_icon_$.addClass('Rk-Ldt-Title-Icon');
    31     this.refresh();
    31     this.refresh();
    32 }
    32 };
    33 
    33 
    34 Rkns.Ldt.ProjectBin.prototype.render = function(searchstr) {
    34 Rkns.Ldt.ProjectBin.prototype.render = function(searchstr) {
    35     if (searchstr) {
    35     if (searchstr) {
    36         var rxbase = searchstr.replace(/(\W)/g,'\\$1'),
    36         var rxbase = searchstr.replace(/(\W)/g,'\\$1'),
    37             _rgxp = new RegExp('('+rxbase+')','gi'),
    37             _rgxp = new RegExp('('+rxbase+')','gi'),
    38             rxtest = new RegExp(rxbase,'i')
    38             rxtest = new RegExp(rxbase,'i');
    39     }
    39     }
    40     function highlight(_text) {
    40     function highlight(_text) {
    41         return searchstr ? _text.replace(_rgxp, "<span class='searchmatch'>$1</span>") : _text;
    41         return searchstr ? _text.replace(_rgxp, "<span class='searchmatch'>$1</span>") : _text;
    42     }
    42     }
    43     function convertTC(_ms) {
    43     function convertTC(_ms) {
    52             _hours = Math.floor(_totalSeconds / 3600),
    52             _hours = Math.floor(_totalSeconds / 3600),
    53             _minutes = (Math.floor(_totalSeconds / 60) % 60),
    53             _minutes = (Math.floor(_totalSeconds / 60) % 60),
    54             _seconds = _totalSeconds % 60,
    54             _seconds = _totalSeconds % 60,
    55             _res = '';
    55             _res = '';
    56         if (_hours) {
    56         if (_hours) {
    57             _res += pad(_hours) + ':'
    57             _res += pad(_hours) + ':';
    58         }
    58         }
    59         _res += pad(_minutes) + ':' + pad(_seconds);
    59         _res += pad(_minutes) + ':' + pad(_seconds);
    60         return _res;
    60         return _res;
    61     }
    61     }
    62     
    62     
    75             ldt_platform: _this.ldt_platform,
    75             ldt_platform: _this.ldt_platform,
    76             title: _title,
    76             title: _title,
    77             htitle: highlight(_title),
    77             htitle: highlight(_title),
    78             encodedtitle : encodeURIComponent(_title),
    78             encodedtitle : encodeURIComponent(_title),
    79             static_url: _this.renkan.options.static_url
    79             static_url: _this.renkan.options.static_url
    80         })
    80         });
    81     });
    81     });
    82     _html += '<li><h3>Annotations</h3></li>';
    82     _html += '<li><h3>Annotations</h3></li>';
    83     Rkns._(_this.data.annotations).map(function(_annotation) {
    83     Rkns._(_this.data.annotations).map(function(_annotation) {
    84         var _description = _annotation.content.description,
    84         var _description = _annotation.content.description,
    85             _title = _annotation.content.title.replace(_description,"");
    85             _title = _annotation.content.title.replace(_description,"");
   119         this.$.hide();
   119         this.$.hide();
   120     } else {
   120     } else {
   121         this.$.show();
   121         this.$.show();
   122     }
   122     }
   123     this.renkan.resizeBins();
   123     this.renkan.resizeBins();
   124 }
   124 };
   125 
   125 
   126 Rkns.Ldt.ProjectBin.prototype.refresh = function() {
   126 Rkns.Ldt.ProjectBin.prototype.refresh = function() {
   127     var _this = this;
   127     var _this = this;
   128     Rkns.$.ajax({
   128     Rkns.$.ajax({
   129         url: this.ldt_platform + 'ldtplatform/ldt/cljson/id/' + this.proj_id,
   129         url: this.ldt_platform + 'ldtplatform/ldt/cljson/id/' + this.proj_id,
   131         success: function(_data) {
   131         success: function(_data) {
   132             _this.data = _data;
   132             _this.data = _data;
   133             _this.render();
   133             _this.render();
   134         }
   134         }
   135     });
   135     });
   136 }
   136 };
   137 
   137 
   138 Rkns.Ldt.Search = function(_renkan, _opts) {
   138 Rkns.Ldt.Search = function(_renkan, _opts) {
   139     this.renkan = _renkan;
   139     this.renkan = _renkan;
   140     this.lang = _opts.lang || "en";
   140     this.lang = _opts.lang || "en";
   141 }
   141 };
   142 
   142 
   143 Rkns.Ldt.Search.prototype.getBgClass = function() {
   143 Rkns.Ldt.Search.prototype.getBgClass = function() {
   144     return "Rk-Ldt-Icon";
   144     return "Rk-Ldt-Icon";
   145 }
   145 };
   146 
   146 
   147 Rkns.Ldt.Search.prototype.getSearchTitle = function() {
   147 Rkns.Ldt.Search.prototype.getSearchTitle = function() {
   148     return this.renkan.translate("Lignes de Temps");
   148     return this.renkan.translate("Lignes de Temps");
   149 }
   149 };
   150 
   150 
   151 Rkns.Ldt.Search.prototype.search = function(_q) {
   151 Rkns.Ldt.Search.prototype.search = function(_q) {
   152     this.renkan.tabs.push(
   152     this.renkan.tabs.push(
   153         new Rkns.Ldt.ResultsBin(this.renkan, {
   153         new Rkns.Ldt.ResultsBin(this.renkan, {
   154             search: _q
   154             search: _q
   155         })
   155         })
   156     );
   156     );
   157 }
   157 };
   158 
   158 
   159 Rkns.Ldt.ResultsBin = Rkns.Utils.inherit(Rkns._BaseBin);
   159 Rkns.Ldt.ResultsBin = Rkns.Utils.inherit(Rkns._BaseBin);
   160 
   160 
   161 Rkns.Ldt.ResultsBin.prototype.segmentTemplate = Rkns._.template(
   161 Rkns.Ldt.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%>">'
   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%>">'
   169     this.max_results = _opts.max_results || 50;
   169     this.max_results = _opts.max_results || 50;
   170     this.search = _opts.search;
   170     this.search = _opts.search;
   171     this.title_$.html('Lignes de Temps: "' + _opts.search + '"');
   171     this.title_$.html('Lignes de Temps: "' + _opts.search + '"');
   172     this.title_icon_$.addClass('Rk-Ldt-Title-Icon');
   172     this.title_icon_$.addClass('Rk-Ldt-Title-Icon');
   173     this.refresh();
   173     this.refresh();
   174 }
   174 };
   175 
   175 
   176 Rkns.Ldt.ResultsBin.prototype.render = function(searchstr) {
   176 Rkns.Ldt.ResultsBin.prototype.render = function(searchstr) {
   177     if (searchstr) {
   177     if (searchstr) {
   178         var rxbase = searchstr.replace(/(\W)/g,'\\$1'),
   178         var rxbase = searchstr.replace(/(\W)/g,'\\$1'),
   179             _rgxp = new RegExp('('+rxbase+')','gi'),
   179             _rgxp = new RegExp('('+rxbase+')','gi'),
   180             rxtest = new RegExp(rxbase,'i')
   180             rxtest = new RegExp(rxbase,'i');
   181     } else {
   181     } else {
   182         var rxbase = this.search.replace(/(\W)/g,'\\$1'),
   182         var rxbase = this.search.replace(/(\W)/g,'\\$1'),
   183             _rgxp = new RegExp('('+rxbase+')','gi');
   183             _rgxp = new RegExp('('+rxbase+')','gi');
   184     }
   184     }
   185     function highlight(_text) {
   185     function highlight(_text) {
   197             _hours = Math.floor(_totalSeconds / 3600),
   197             _hours = Math.floor(_totalSeconds / 3600),
   198             _minutes = (Math.floor(_totalSeconds / 60) % 60),
   198             _minutes = (Math.floor(_totalSeconds / 60) % 60),
   199             _seconds = _totalSeconds % 60,
   199             _seconds = _totalSeconds % 60,
   200             _res = '';
   200             _res = '';
   201         if (_hours) {
   201         if (_hours) {
   202             _res += pad(_hours) + ':'
   202             _res += pad(_hours) + ':';
   203         }
   203         }
   204         _res += pad(_minutes) + ':' + pad(_seconds);
   204         _res += pad(_minutes) + ':' + pad(_seconds);
   205         return _res;
   205         return _res;
   206     }
   206     }
   207     
   207     
   215             return;
   215             return;
   216         }
   216         }
   217         count++;
   217         count++;
   218         var _duration = _segment.duration,
   218         var _duration = _segment.duration,
   219             _begin = _segment.start_ts,
   219             _begin = _segment.start_ts,
   220             _end = + _segment.duration + _begin
   220             _end = + _segment.duration + _begin,
   221             _img = (
   221             _img = (
   222                 _duration
   222                 _duration
   223                 ? _this.renkan.options.static_url + "img/ldt-segment.png"
   223                 ? _this.renkan.options.static_url + "img/ldt-segment.png"
   224                 : _this.renkan.options.static_url + "img/ldt-point.png"
   224                 : _this.renkan.options.static_url + "img/ldt-point.png"
   225             );
   225             );
   250         this.$.hide();
   250         this.$.hide();
   251     } else {
   251     } else {
   252         this.$.show();
   252         this.$.show();
   253     }
   253     }
   254     this.renkan.resizeBins();
   254     this.renkan.resizeBins();
   255 }
   255 };
   256 
   256 
   257 Rkns.Ldt.ResultsBin.prototype.refresh = function() {
   257 Rkns.Ldt.ResultsBin.prototype.refresh = function() {
   258     var _this = this;
   258     var _this = this;
   259     Rkns.$.ajax({
   259     Rkns.$.ajax({
   260         url: this.ldt_platform + 'ldtplatform/api/ldt/1.0/segments/search/',
   260         url: this.ldt_platform + 'ldtplatform/api/ldt/1.0/segments/search/',
   267         success: function(_data) {
   267         success: function(_data) {
   268             _this.data = _data;
   268             _this.data = _data;
   269             _this.render();
   269             _this.render();
   270         }
   270         }
   271     });
   271     });
   272 }
   272 };