X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;ds=inline;f=src%2Fmkws-widget-main.js;h=e01675ff9159fa4f7b1252d0dad510ac40c5f756;hb=d7f7e11af10210fd9872cedc1489fe0b692ca589;hp=be2f588853c5686ccced5497910447246ea95e14;hpb=462ef80604c5f016f8a70e3a87ecbc90f33cc5d9;p=mkws-moved-to-github.git
diff --git a/src/mkws-widget-main.js b/src/mkws-widget-main.js
index be2f588..e01675f 100644
--- a/src/mkws-widget-main.js
+++ b/src/mkws-widget-main.js
@@ -1,3 +1,5 @@
+(function($) { // jQuery wrapper
+
// Functions follow for promoting the regular widget object into
// widgets of specific types. These could be moved into their own
// source files.
@@ -86,6 +88,25 @@ mkws.registerWidgetType('Pager', function() {
});
});
+mkws.registerWidgetType('Details', function() {
+ var that = this;
+ var recid = that.node.attr("data-mkws-recid");
+ if (this.team.gotRecords()) {
+ that.team.fetchDetails(recid);
+ } else {
+ this.team.queue("firstrecords").subscribe(function() {
+ that.team.fetchDetails(recid);
+ });
+ }
+ this.team.queue("record").subscribe(function(data) {
+ console.log(data);
+ if ($.inArray(recid, data.recid) > -1) {
+ var template = that.team.loadTemplate(that.config.template || "Record");
+ that.node.html(template(data));
+ }
+ });
+ that.autosearch();
+});
mkws.registerWidgetType('Records', function() {
var that = this;
@@ -96,7 +117,7 @@ mkws.registerWidgetType('Records', function() {
var hit = data.hits[i];
that.team.queue("record").publish(hit);
hit.detailLinkId = team.recordElementId(hit.recid[0]);
- hit.detailClick = "mkws.showDetails('" + team.name() + "', '" + hit.recid[0] + "');return false;"
+ 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
@@ -105,7 +126,6 @@ mkws.registerWidgetType('Records', function() {
if (hit.recid == team.currentRecordId()) {
if (team.currentRecordData()) {
hit.renderedDetails = team.renderDetails(team.currentRecordData());
- console.log(hit.renderedDetails);
}
}
}
@@ -121,26 +141,29 @@ mkws.registerWidgetType('Records', function() {
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));
});
});
@@ -215,90 +238,42 @@ mkws.registerWidgetType('SearchForm', function() {
mkws.registerWidgetType('Results', function() {
- var tname = this.team.name();
-
- this.node.html('\
-
\
- \
- \
- \
- | \
- \
- \
- \
- \
- \
- | \
-
\
- \
- \
- \
- | \
-
\
-
');
-
+ 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("making sort HTML, 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("making perpage HTML, perpage = " + perpage);
- var perpage_html = '';
-
- return perpage_html;
- }
+ var template = this.team.loadTemplate(this.config.template || "Ranking");
+ this.node.html(template(output));
});
@@ -319,34 +294,30 @@ 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);
+ 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.log("language menu: " + 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 + ' '
- }
- }
-
- this.node.html(data);
+ 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) {
var query = location.search;
@@ -394,19 +365,13 @@ mkws.registerWidgetType('Config', function() {
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);
+ var template = that.team.loadTemplate(that.config.template || "Progress");
+ that.node.html(template({
+ done: data.clients - data.activeclients,
+ waiting: data.activeclients
+ }));
that.node.show();
});
});
@@ -422,3 +387,4 @@ mkws.registerWidgetType('MOTDContainer', function() {});
mkws.registerWidgetType('Button', function() {});
+})(mkws.$); // jQuery wrapper