X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fmkws-widget-main.js;h=85c2ba41748ab903412408758cddfe9d1924faa2;hb=9414c1ffb05c80a52d0ab39ee13889276c5a5a04;hp=96937df162060f3ffd233bfcce9cd0b676157c20;hpb=0d9aa1a4cc69782eb4037cf11fe9012c6a362b6c;p=mkws-moved-to-github.git diff --git a/src/mkws-widget-main.js b/src/mkws-widget-main.js index 96937df..85c2ba4 100644 --- a/src/mkws-widget-main.js +++ b/src/mkws-widget-main.js @@ -4,14 +4,12 @@ mkws.registerWidgetType('Targets', function() { + if (!this.config.show_switch) return; var that = this; var M = mkws.M; - $(this.node).html('\ -
\ -No information available yet.\ -
'); - $(this.node).css("display", "none"); + this.node.html('No information available yet.'); + this.node.css("display", "none"); this.team.queue("targets").subscribe(function(data) { var table ='' + @@ -31,8 +29,7 @@ No information available yet.\ } table += '
'; - var subnode = $(that.node).children('.mkwsBytarget'); - subnode.html(table); + that.node.html(table); }); }); @@ -42,13 +39,10 @@ mkws.registerWidgetType('Stat', function() { var M = mkws.M; this.team.queue("stat").subscribe(function(data) { - if (that.node.length === 0) alert("huh?!"); - - $(that.node).html('' + M('Status info') + '' + - ' -- ' + - '' + M('Active clients') + ': ' + data.activeclients + '/' + data.clients + '' + + that.node.html(' -- ' + + '' + M('Active clients') + ': ' + data.activeclients + '/' + data.clients + '' + ' -- ' + - '' + M('Retrieved records') + ': ' + data.records + '/' + data.hits + ''); + M('Retrieved records') + ': ' + data.records + '/' + data.hits); }); }); @@ -58,7 +52,7 @@ mkws.registerWidgetType('Pager', function() { var M = mkws.M; this.team.queue("pager").subscribe(function(data) { - $(that.node).html(drawPager(data)) + that.node.html(drawPager(data)) function drawPager(data) { var teamName = that.team.name(); @@ -89,7 +83,7 @@ mkws.registerWidgetType('Pager', function() { for(var i = firstClkbl; i <= lastClkbl; i++) { var numLabel = i; if(i == currentPage) - numLabel = '' + i + ''; + numLabel = '' + i + ''; middle += ' ' + numLabel + ' '; @@ -127,7 +121,7 @@ mkws.registerWidgetType('Records', function() { var hit = data.hits[i]; that.team.queue("record").publish(hit); var divId = team.recordElementId(hit.recid[0]); - html.push('
', renderSummary(hit), '
'); + html.push('
', renderSummary(hit), '
'); // ### At some point, we may be able to move the // m_currentRecordId and m_currentRecordData members // from the team object into this widget. @@ -136,7 +130,7 @@ mkws.registerWidgetType('Records', function() { html.push(team.renderDetails(team.currentRecordData())); } } - $(that.node).html(html.join('')); + that.node.html(html.join('')); function renderSummary(hit) { var template = team.loadTemplate(that.config.template || "Summary"); @@ -146,7 +140,7 @@ mkws.registerWidgetType('Records', function() { } }); - widget.autosearch(that); + that.autosearch(); }); @@ -161,18 +155,18 @@ mkws.registerWidgetType('Navi', function() { filters.visitTargets(function(id, name) { if (text) text += " | "; - text += M('source') + ': ' + name + ''; }); filters.visitFields(function(field, value) { if (text) text += " | "; - text += M(field) + ': ' + value + ''; }); - $(that.node).html(text); + that.node.html(text); }); }); @@ -183,8 +177,8 @@ mkws.registerWidgetType('Navi', function() { mkws.registerWidgetType('Sort', function() { var that = this; - $(this.node).change(function() { - that.team.set_sortOrder($(that.node).val()); + this.node.change(function() { + that.team.set_sortOrder(that.node.val()); if (that.team.submitted()) { that.team.reShow(); } @@ -196,8 +190,8 @@ mkws.registerWidgetType('Sort', function() { mkws.registerWidgetType('Perpage', function() { var that = this; - $(this.node).change(function() { - that.team.set_perpage($(that.node).val()); + this.node.change(function() { + that.team.set_perpage(that.node.val()); if (that.team.submitted()) { that.team.reShow(); } @@ -210,18 +204,19 @@ mkws.registerWidgetType('Done', function() { var that = this; this.team.queue("complete").subscribe(function(n) { - $(that.node).html("Search complete: found " + n + " records"); + that.node.html("Search complete: found " + n + " records"); }); }); mkws.registerWidgetType('Switch', function() { + if (!this.config.show_switch) return; var tname = this.team.name(); - $(this.node).html('\ + this.node.html('\ Records \ | \ Targets'); - widget.hideWhenNarrow(this); + this.hideWhenNarrow(); }); @@ -229,7 +224,7 @@ mkws.registerWidgetType('Search', function() { var tname = this.team.name(); var M = mkws.M; - $(this.node).html('\ + this.node.html('\
\ \ \ @@ -238,8 +233,8 @@ mkws.registerWidgetType('Search', function() { mkws.registerWidgetType('SearchForm', function() { - var team = this.team; - $(this.node).submit(function() { + var team = this.team; + this.node.submit(function() { var val = team.widget('Query').value(); team.newSearch(val); return false; @@ -250,7 +245,7 @@ mkws.registerWidgetType('SearchForm', function() { mkws.registerWidgetType('Results', function() { var tname = this.team.name(); - $(this.node).html('\ + this.node.html('\ \ \ \
\ @@ -270,7 +265,7 @@ mkws.registerWidgetType('Results', function() {
'); - widget.autosearch(this); + this.autosearch(); }); @@ -279,7 +274,7 @@ mkws.registerWidgetType('Ranking', function() { var that = this; var M = mkws.M; - var s = ''; + var s = ''; if (this.config.show_sort) { s += M('Sort by') + ' ' + mkwsHtmlSort() + ' '; } @@ -288,13 +283,13 @@ mkws.registerWidgetType('Ranking', function() { } s += '
'; - $(this.node).html(s); + this.node.html(s); function mkwsHtmlSort() { var order = that.team.sortOrder(); - that.log("HTML sort, sortOrder = '" + order + "'"); + that.log("making sort HTML, sortOrder = '" + order + "'"); var sort_html = ''; for(var i = 0; i < that.config.perpage_options.length; i++) { @@ -360,7 +355,7 @@ mkws.registerWidgetType('Lang', function() { if (lang_options.length == 0 || toBeIncluded[lang_default]) list.push(lang_default); - this.log("Language menu for: " + list.join(", ")); + this.log("language menu: " + list.join(", ")); /* the HTML part */ var data = ""; @@ -376,8 +371,8 @@ mkws.registerWidgetType('Lang', function() { } } - $(this.node).html(data); - widget.hideWhenNarrow(this); + this.node.html(data); + this.hideWhenNarrow(); // set or re-set "lang" URL parameter @@ -405,11 +400,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.node).appendTo(container.node); + 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