X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmkws-widget-main.js;h=1ea183522d9084df1216cbf0a252209b96c02f55;hb=6fca436aa42f947b752e583ecf1fe201769782a2;hp=c3eac87ffa036716c512a5dc1c05dc70f94b44da;hpb=e215340ab13b641a83b5f6aa1a027b81b6566670;p=mkws-moved-to-github.git
diff --git a/src/mkws-widget-main.js b/src/mkws-widget-main.js
index c3eac87..1ea1835 100644
--- a/src/mkws-widget-main.js
+++ b/src/mkws-widget-main.js
@@ -4,46 +4,38 @@
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 ='
' +
- '
' + M('Target ID') + '
' +
- '
' + M('Hits') + '
' +
- '
' + M('Diags') + '
' +
- '
' + M('Records') + '
' +
- '
' + M('State') + '
' +
- '
';
-
+ // 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 += "
';
+ 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));
});
});
@@ -117,57 +92,58 @@ 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.node).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();
});
mkws.registerWidgetType('Navi', function() {
var that = this;
var teamName = this.team.name();
- var M = mkws.M;
this.team.queue("navi").subscribe(function() {
var filters = that.team.filters();
- var text = "";
+ var output = {filters:[]};
filters.visitTargets(function(id, name) {
- if (text) text += " | ";
- text += M('source') + ': ' + name + '';
+ var cur = {};
+ cur.facet = 'source';
+ cur.value = name;
+ cur.click = "mkws.delimitTarget('" + teamName + "', '" + id + "'); return false;";
+ output.filters.push(cur);
});
filters.visitFields(function(field, value) {
- if (text) text += " | ";
- text += M(field) + ': ' + value + '';
+ var cur = {};
+ cur.facet = field;
+ cur.value = value;
+ cur.click = "mkws.delimitQuery('" + teamName + "', '" + field + "', '" + value + "'" + ");return false;";
+ output.filters.push(cur);
});
- $(that.node).html(text);
+ var template = that.team.loadTemplate(that.config.template || "Navi");
+ that.node.html(template(output));
});
});
@@ -178,8 +154,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();
}
@@ -191,8 +167,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();
}
@@ -203,38 +179,37 @@ mkws.registerWidgetType('Perpage', function() {
mkws.registerWidgetType('Done', function() {
var that = this;
-
this.team.queue("complete").subscribe(function(n) {
- $(that.node).html("Search complete: found " + n + " records");
+ var template = that.team.loadTemplate(that.config.template || "Done");
+ that.node.html(template({count: n}));
});
});
mkws.registerWidgetType('Switch', function() {
+ if (!this.config.show_switch) return;
var tname = this.team.name();
- $(this.node).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.node).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.node).submit(function() {
+ this.node.submit(function() {
var val = team.widget('Query').value();
team.newSearch(val);
return false;
@@ -243,90 +218,42 @@ mkws.registerWidgetType('SearchForm', function() {
mkws.registerWidgetType('Results', function() {
- var tname = this.team.name();
-
- $(this.node).html('\
-
\
-
\
-
\
- \
-
\
-
\
- \
- \
- \
- \
-
\
-
\
-
\
-
\
- \
-
\
-
\
-
');
-
- widget.autosearch(this);
+ var template = this.team.loadTemplate(this.config.template || "Results");
+ this.node.html(template({team: this.team.name()}));
+ this.autosearch();
});
mkws.registerWidgetType('Ranking', function() {
- var tname = this.team.name();
- var that = this;
- var M = mkws.M;
-
- var s = '';
-
- $(this.node).html(s);
-
-
- function mkwsHtmlSort() {
- var order = that.team.sortOrder();
- that.log("HTML sort, sortOrder = '" + order + "'");
- var sort_html = '';
-
- return sort_html;
+ var perpage = this.team.perpage();
+ this.log("making perpage, perpage = " + perpage);
+ for(var i = 0; i < this.config.perpage_options.length; i++) {
+ var cur = {};
+ cur.perPage = this.config.perpage_options[i];
+ if (cur.perPage == perpage) cur.selected = true;
+ output.perPage.push(cur);
}
- function mkwsHtmlPerpage() {
- var perpage = that.team.perpage();
-
- that.log("HTML perpage, perpage = " + perpage);
- var perpage_html = '';
-
- return perpage_html;
- }
+ var template = this.team.loadTemplate(this.config.template || "Ranking");
+ this.node.html(template(output));
});
@@ -347,33 +274,29 @@ mkws.registerWidgetType('Lang', function() {
}
for (var k in mkws.locale_lang) {
- if (toBeIncluded[k] || lang_options.length == 0)
- list.push(k);
+ if (toBeIncluded[k] || lang_options.length == 0) {
+ cur = {};
+ if (lang === k) cur.selected = true;
+ cur.code = k;
+ cur.url = lang_url(k);
+ list.push(cur);
+ }
}
// add english link
- if (lang_options.length == 0 || toBeIncluded[lang_default])
- list.push(lang_default);
-
- this.log("Language menu for: " + list.join(", "));
-
- /* the HTML part */
- var data = "";
- for (var i = 0; i < list.length; i++) {
- var l = list[i];
- if (data)
- data += ' | ';
-
- if (lang == l) {
- data += ' ' + l + ' ';
- } else {
- data += ' ' + l + ' '
- }
+ if (lang_options.length == 0 || toBeIncluded[lang_default]) {
+ cur = {};
+ if (lang === lang_default) cur.selected = true;
+ cur.code = lang_default;
+ cur.url = lang_url(lang_default);
+ list.push(cur);
}
- $(this.node).html(data);
- widget.hideWhenNarrow(this);
+ this.log("language menu: " + list.join(", "));
+ var template = this.team.loadTemplate(this.config.template || "Lang");
+ this.node.html(template({languages: list}));
+ this.hideWhenNarrow();
// set or re-set "lang" URL parameter
function lang_url(lang) {
@@ -400,11 +323,40 @@ 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 template = that.team.loadTemplate(that.config.template || "Progress");
+ that.node.html(template({
+ done: data.clients - data.activeclients,
+ waiting: data.activeclients
+ }));
+ 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 +365,5 @@ mkws.registerWidgetType('MOTD', function() {
mkws.registerWidgetType('Query', function() {});
mkws.registerWidgetType('MOTDContainer', function() {});
mkws.registerWidgetType('Button', function() {});
-mkws.registerWidgetType('Popup', function() {});