X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fmkws-widget-main.js;h=be2f588853c5686ccced5497910447246ea95e14;hb=8abd9bb4363234e5134aa629a76042354971c5fd;hp=8cfad61137f08b1413231e8e7c24e29fdeb9f3e1;hpb=efe0a1f905f6ebb38ffcfcb478f1b9b8707b558c;p=mkws-moved-to-github.git diff --git a/src/mkws-widget-main.js b/src/mkws-widget-main.js index 8cfad61..be2f588 100644 --- a/src/mkws-widget-main.js +++ b/src/mkws-widget-main.js @@ -6,43 +6,36 @@ mkws.registerWidgetType('Targets', function() { if (!this.config.show_switch) return; var that = this; - var M = mkws.M; - this.jqnode.html('No information available yet.'); - this.jqnode.css("display", "none"); + this.node.html('No information available yet.'); + this.node.css("display", "none"); this.team.queue("targets").subscribe(function(data) { - var table ='' + - '' + - '' + - '' + - '' + - '' + - ''; - + // There is a bug in pz2.js wherein it makes each data object an array but + // simply assigns properties to it. + // TODO: remove this when PAZ-946 is addressed. + var cleandata = []; for (var i = 0; i < data.length; i++) { - table += ""; + var cur = {}; + cur.id = data[i].id; + cur.hits = data[i].hits; + cur.diagnostic = data[i].diagnostic; + cur.records = data[i].records; + cur.state = data[i].state; + cleandata.push(cur); } - table += '
' + M('Target ID') + '' + M('Hits') + '' + M('Diags') + '' + M('Records') + '' + M('State') + '
" + data[i].id + - "" + data[i].hits + - "" + data[i].diagnostic + - "" + data[i].records + - "" + data[i].state + "
'; - that.jqnode.html(table); + var template = that.team.loadTemplate(that.config.template || "Targets"); + that.node.html(template({data: cleandata})); }); }); mkws.registerWidgetType('Stat', function() { var that = this; - var M = mkws.M; - this.team.queue("stat").subscribe(function(data) { - that.jqnode.html(' -- ' + - '' + M('Active clients') + ': ' + data.activeclients + '/' + data.clients + '' + - ' -- ' + - M('Retrieved records') + ': ' + data.records + '/' + data.hits); + var template = that.team.loadTemplate(that.config.template || "Stat"); + that.node.html(template(data)); }); }); @@ -52,61 +45,44 @@ mkws.registerWidgetType('Pager', function() { var M = mkws.M; this.team.queue("pager").subscribe(function(data) { - that.jqnode.html(drawPager(data)) - - function drawPager(data) { - var teamName = that.team.name(); - var s = '
' + M('Displaying') + ': ' - + (data.start + 1) + ' ' + M('to') + ' ' + (data.start + data.num) + - ' ' + M('of') + ' ' + data.merged + ' (' + M('found') + ': ' - + data.total + ')
'; - - //client indexes pages from 1 but pz2 from 0 - var onsides = 6; - var pages = Math.ceil(that.team.totalRecordCount() / that.team.perpage()); - var currentPage = that.team.currentPage(); - - var firstClkbl = (currentPage - onsides > 0) - ? currentPage - onsides - : 1; - - var lastClkbl = firstClkbl + 2*onsides < pages - ? firstClkbl + 2*onsides - : pages; - - var prev = '<< ' + M('Prev') + ' | '; - if (currentPage > 1) - prev = '' - +'<< ' + M('Prev') + ' | '; - - var middle = ''; - for(var i = firstClkbl; i <= lastClkbl; i++) { - var numLabel = i; - if(i == currentPage) - numLabel = '' + i + ''; - - middle += ' ' - + numLabel + ' '; + var teamName = that.team.name(); + var output = {}; + output.first = data.start + 1; + output.last = data.start + data.num; + output.count = data.merged; + output.found = data.total; + + //client indexes pages from 1 but pz2 from 0 + var onsides = 6; + var pages = Math.ceil(that.team.totalRecordCount() / that.team.perpage()); + var currentPage = that.team.currentPage(); + + var firstClkbl = (currentPage - onsides > 0) + ? currentPage - onsides + : 1; + var lastClkbl = firstClkbl + 2*onsides < pages + ? firstClkbl + 2*onsides + : pages; + + if (firstClkbl > 1) output.morePrev = true; + if (lastClkbl < pages) output.moreNext = true; + + if (currentPage > 1) output.prevClick = "mkws.pagerPrev(\'" + teamName + "\');"; + + output.pages = []; + for(var i = firstClkbl; i <= lastClkbl; i++) { + var o = {}; + o.number = i; + if (i !== currentPage) { + o.click = "mkws.showPage(\'" + teamName + "\', " + i + ");"; } + output.pages.push(o); + } - var next = ' | ' + M('Next') + ' >>'; - if (pages - currentPage > 0) - next = ' | ' - + M('Next') + ' >>'; - - var predots = ''; - if (firstClkbl > 1) - predots = '...'; - - var postdots = ''; - if (lastClkbl < pages) - postdots = '...'; - - s += '
' - + prev + predots + middle + postdots + next + '
'; + if (pages - currentPage > 0) output.nextClick = "mkws.pagerNext(\'" + teamName + "\')"; - return s; - } + var template = that.team.loadTemplate(that.config.template || "Pager"); + that.node.html(template(output)); }); }); @@ -116,31 +92,29 @@ mkws.registerWidgetType('Records', function() { var team = this.team; this.team.queue("records").subscribe(function(data) { - var html = []; for (var i = 0; i < data.hits.length; i++) { var hit = data.hits[i]; that.team.queue("record").publish(hit); - var divId = team.recordElementId(hit.recid[0]); - html.push('
', renderSummary(hit), '
'); + hit.detailLinkId = team.recordElementId(hit.recid[0]); + hit.detailClick = "mkws.showDetails('" + team.name() + "', '" + hit.recid[0] + "');return false;" + hit.containerClass = "mkwsSummary mkwsTeam_" + team.name(); + hit.containerClass += " " + hit.detailLinkId; // ### At some point, we may be able to move the // m_currentRecordId and m_currentRecordData members // from the team object into this widget. if (hit.recid == team.currentRecordId()) { - if (team.currentRecordData()) - html.push(team.renderDetails(team.currentRecordData())); + if (team.currentRecordData()) { + hit.renderedDetails = team.renderDetails(team.currentRecordData()); + console.log(hit.renderedDetails); + } } } - that.jqnode.html(html.join('')); - - function renderSummary(hit) { - var template = team.loadTemplate(that.config.template || "Summary"); - hit._id = team.recordElementId(hit.recid[0]); - hit._onclick = "mkws.showDetails('" + team.name() + "', '" + hit.recid[0] + "');return false;" - return template(hit); - } + var template = team.loadTemplate(that.config.template || "Records"); + var targs = $.extend({}, {"hits": data.hits}, that.config.template_vars); + that.node.html(template(targs)); }); - widget.autosearch(that); + that.autosearch(); }); @@ -166,7 +140,7 @@ mkws.registerWidgetType('Navi', function() { ');return false;">' + value + ''; }); - that.jqnode.html(text); + that.node.html(text); }); }); @@ -177,8 +151,8 @@ mkws.registerWidgetType('Navi', function() { mkws.registerWidgetType('Sort', function() { var that = this; - this.jqnode.change(function() { - that.team.set_sortOrder(that.jqnode.val()); + this.node.change(function() { + that.team.set_sortOrder(that.node.val()); if (that.team.submitted()) { that.team.reShow(); } @@ -190,8 +164,8 @@ mkws.registerWidgetType('Sort', function() { mkws.registerWidgetType('Perpage', function() { var that = this; - this.jqnode.change(function() { - that.team.set_perpage(that.jqnode.val()); + this.node.change(function() { + that.team.set_perpage(that.node.val()); if (that.team.submitted()) { that.team.reShow(); } @@ -202,9 +176,9 @@ mkws.registerWidgetType('Perpage', function() { mkws.registerWidgetType('Done', function() { var that = this; - this.team.queue("complete").subscribe(function(n) { - that.jqnode.html("Search complete: found " + n + " records"); + var template = that.team.loadTemplate(that.config.template || "Done"); + that.node.html(template({count: n})); }); }); @@ -212,29 +186,27 @@ mkws.registerWidgetType('Done', function() { mkws.registerWidgetType('Switch', function() { if (!this.config.show_switch) return; var tname = this.team.name(); - this.jqnode.html('\ -Records \ -| \ -Targets'); - widget.hideWhenNarrow(this); + var output = {}; + output.recordClick = "mkws.switchView(\'" + tname + "\', \'records\')"; + output.targetClick = "mkws.switchView(\'" + tname + "\', \'targets\')"; + var template = this.team.loadTemplate(this.config.template || "Switch"); + this.node.html(template(output)); + this.hideWhenNarrow(); }); mkws.registerWidgetType('Search', function() { - var tname = this.team.name(); - var M = mkws.M; - - this.jqnode.html('\ -
\ - \ - \ -
'); + var output = {}; + output.team = this.team.name(); + output.queryWidth = this.config.query_width; + var template = this.team.loadTemplate(this.config.template || "Search"); + this.node.html(template(output)); }); mkws.registerWidgetType('SearchForm', function() { var team = this.team; - this.jqnode.submit(function() { + this.node.submit(function() { var val = team.widget('Query').value(); team.newSearch(val); return false; @@ -245,7 +217,7 @@ mkws.registerWidgetType('SearchForm', function() { mkws.registerWidgetType('Results', function() { var tname = this.team.name(); - this.jqnode.html('\ + this.node.html('\ \ \ \
\ @@ -265,7 +237,7 @@ mkws.registerWidgetType('Results', function() {
'); - widget.autosearch(this); + this.autosearch(); }); @@ -283,7 +255,7 @@ mkws.registerWidgetType('Ranking', function() { } s += ''; - this.jqnode.html(s); + this.node.html(s); function mkwsHtmlSort() { @@ -371,8 +343,8 @@ mkws.registerWidgetType('Lang', function() { } } - this.jqnode.html(data); - widget.hideWhenNarrow(this); + this.node.html(data); + this.hideWhenNarrow(); // set or re-set "lang" URL parameter @@ -400,11 +372,46 @@ mkws.registerWidgetType('MOTD', function() { var container = this.team.widget('MOTDContainer'); if (container) { // Move the MOTD from the provided element down into the container - this.jqnode.appendTo(container.jqnode); + this.node.appendTo(container.node); } }); +// This widget has no functionality of its own, but its configuration +// is copied up into its team, allowing it to affect other widgets in +// the team. +// +mkws.registerWidgetType('Config', function() { + var c = this.config; + for (var name in c) { + if (c.hasOwnProperty(name)) { + this.team.config[name] = c[name]; + this.log(this + " copied property " + name + "='" + c[name] + "' up to team"); + } + } +}); + + +mkws.registerWidgetType('Progress', function() { + var that = this; + + this.node.hide(); + this.team.queue("stat").subscribe(function(data) { + var s = ''; + for (var i = 0; i < data.clients; i++) { + if (i == data.clients - data.activeclients) { + s += ''; + s += ''; + } + s += '█'; + } + s += ''; + that.node.html(s); + that.node.show(); + }); +}); + + // Some elements have mkws* classes that makes them appear as widgets // -- for example, because we want to style them using CSS -- but have // no actual functionality. We register these to prevent ignorable @@ -413,6 +420,5 @@ mkws.registerWidgetType('MOTD', function() { mkws.registerWidgetType('Query', function() {}); mkws.registerWidgetType('MOTDContainer', function() {}); mkws.registerWidgetType('Button', function() {}); -mkws.registerWidgetType('Popup', function() {});