diff -r d0da34fda4b4 -r 7b517a54b708 server/src/main/webapp/static/js/ldtjson-bin.js --- a/server/src/main/webapp/static/js/ldtjson-bin.js Mon Dec 31 13:37:31 2012 +0100 +++ b/server/src/main/webapp/static/js/ldtjson-bin.js Tue Jan 01 09:28:03 2013 +0100 @@ -4,12 +4,12 @@ Rkns.Ldt.ProjectBin.prototype.tagTemplate = Rkns._.template( '
  • ' - + '

    <%-title%>

  • ' + + '

    <%=htitle%>

    ' ); Rkns.Ldt.ProjectBin.prototype.annotationTemplate = Rkns._.template( '
  • ' - + '

    <%-title%>

    <%-description%>

    Start: <%=start%>, End: <%=end%>, Duration: <%=duration%>

  • ' + + '

    <%=htitle%>

    <%=hdescription%>

    Start: <%=start%>, End: <%=end%>, Duration: <%=duration%>

    ' ); Rkns.Ldt.ProjectBin.prototype._init = function(_renkan, _opts) { @@ -19,8 +19,15 @@ this.refresh(); } -Rkns.Ldt.ProjectBin.prototype.refresh = function() { - var _this = this; +Rkns.Ldt.ProjectBin.prototype.render = function(searchstr) { + if (searchstr) { + var rxbase = searchstr.replace(/(\W)/g,'\\$1'), + _rgxp = new RegExp('('+rxbase+')','gi'), + rxtest = new RegExp(rxbase,'i') + } + function highlight(_text) { + return searchstr ? _text.replace(_rgxp, "$1") : _text; + } function convertTC(_ms) { function pad(_n) { var _res = _n.toString(); @@ -40,48 +47,78 @@ _res += pad(_minutes) + ':' + pad(_seconds); return _res; } + + var _html = '
  • Tags

  • ', + _projtitle = this.data.meta["dc:title"], + _this = this, + count = 0; + _this.title_$.text('LDT Project: "' + _projtitle + '"'); + Rkns._(_this.data.tags).map(function(_tag) { + var _title = _tag.meta["dc:title"]; + if (searchstr && !rxtest.test(_title)) { + return; + } + count++; + _html += _this.tagTemplate({ + ldt_platform: _this.ldt_platform, + title: _title, + htitle: highlight(_title), + encodedtitle : encodeURIComponent(_title), + static_url : _this.renkan.static_url + }) + }); + _html += '
  • Annotations

  • '; + Rkns._(_this.data.annotations).map(function(_annotation) { + var _description = _annotation.content.description, + _title = _annotation.content.title.replace(_description,""); + if (searchstr && !rxtest.test(_title) && !rxtest.test(_description)) { + return; + } + count++; + var _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" ) + ); + _html += _this.annotationTemplate({ + ldt_platform: _this.ldt_platform, + static_url: _this.renkan.static_url, + title: _title, + htitle: highlight(_title), + description: _description, + hdescription: highlight(_description), + start: convertTC(_annotation.begin), + end: convertTC(_annotation.end), + duration: convertTC(_duration), + mediaid: _annotation.media, + annotationid: _annotation.id, + image: _img + }); + }); + + this.main_$.html(_html); + if (searchstr && count) { + this.count_$.text(count).show(); + } else { + this.count_$.hide(); + } + if (searchstr && !count) { + this.$.hide(); + } else { + this.$.show(); + } + _renkan.resizeBins(); +} + +Rkns.Ldt.ProjectBin.prototype.refresh = function() { + var _this = this; Rkns.$.ajax({ url: this.ldt_platform + 'ldtplatform/ldt/cljson/id/' + this.proj_id, dataType: "jsonp", success: function(_data) { - var _html = '
  • Tags

  • ', - _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 += '
  • Annotations

  • '; - _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(); + _this.data = _data; + _this.render(); } }); } \ No newline at end of file