X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=src%2Fmkws-team.js;h=2b962a2ff5a8b05ca4f1d6545fa4f4a4f2057173;hb=fccf768cf4e1a2a4c8747cb4c7c807315f226304;hp=d99370d6ac5d1d0aa3627f7e17aa7a68eaa1aa05;hpb=0e5fc9c87c4a2c8d3cecaa0e389bd2f4d8ccea28;p=mkws-moved-to-github.git
diff --git a/src/mkws-team.js b/src/mkws-team.js
index d99370d..2b962a2 100644
--- a/src/mkws-team.js
+++ b/src/mkws-team.js
@@ -26,7 +26,8 @@ function team($, teamName) {
"last": $.now()
};
var m_paz; // will be initialised below
- var m_template = {};
+ var m_tempateText = {}; // widgets can register tempates to be compiled
+ var m_template = {}; // compiled templates, from any source
var m_config = mkws.objectInheritingFrom(mkws.config);
var m_widgets = {}; // Maps widget-type to object
@@ -35,6 +36,7 @@ function team($, teamName) {
// Accessor methods for individual widgets: readers
that.name = function() { return m_teamName; };
that.submitted = function() { return m_submitted; };
+ that.sortOrder = function() { return m_sortOrder; };
that.perpage = function() { return m_perpage; };
that.totalRecordCount = function() { return m_totalRecordCount; };
that.currentPage = function() { return m_currentPage; };
@@ -170,7 +172,7 @@ function team($, teamName) {
that.limitTarget = function(id, name) {
log("limitTarget(id=" + id + ", name=" + name + ")");
m_filterSet.add(targetFilter(id, name));
- triggerSearch();
+ if (m_query) triggerSearch();
return false;
};
@@ -178,15 +180,17 @@ function team($, teamName) {
that.limitQuery = function(field, value) {
log("limitQuery(field=" + field + ", value=" + value + ")");
m_filterSet.add(fieldFilter(field, value));
- triggerSearch();
+ if (m_query) triggerSearch();
return false;
};
that.limitCategory = function(id) {
log("limitCategory(id=" + id + ")");
- // ### Add a filter
- // ### triggerSearch() if there's a query
+ // Only one category filter at a time
+ m_filterSet.removeMatching(function(f) { return f.type === 'category' });
+ if (id !== '') m_filterSet.add(categoryFilter(id));
+ if (m_query) triggerSearch();
return false;
};
@@ -194,7 +198,7 @@ function team($, teamName) {
that.delimitTarget = function(id) {
log("delimitTarget(id=" + id + ")");
m_filterSet.removeMatching(function(f) { return f.type === 'target' });
- triggerSearch();
+ if (m_query) triggerSearch();
return false;
};
@@ -203,7 +207,7 @@ function team($, teamName) {
log("delimitQuery(field=" + field + ", value=" + value + ")");
m_filterSet.removeMatching(function(f) { return f.type == 'field' &&
field == f.field && value == f.value });
- triggerSearch();
+ if (m_query) triggerSearch();
return false;
};
@@ -249,7 +253,7 @@ function team($, teamName) {
return;
}
- m_filterSet = filterSet(that);
+ m_filterSet.removeMatching(function(f) { return f.type !== 'category' });
triggerSearch(query, sortOrder, maxrecs, perpage, limit, targets, torusquery);
switchView('records'); // In case it's configured to start off as hidden
m_submitted = true;
@@ -261,15 +265,18 @@ function team($, teamName) {
resetPage();
queue("navi").publish();
-
// Continue to use previous query/sort-order unless new ones are specified
if (query) m_query = query;
if (sortOrder) m_sortOrder = sortOrder;
if (perpage) m_perpage = perpage;
- if (targets) m_filterSet.add(targetFilter(id, id));
+ if (targets) m_filterSet.add(targetFilter(targets, targets));
var pp2filter = m_filterSet.pp2filter();
var pp2limit = m_filterSet.pp2limit(limit);
+ var pp2catLimit = m_filterSet.pp2catLimit();
+ if (pp2catLimit) {
+ pp2filter = pp2filter ? pp2filter + "," + pp2catLimit : pp2catLimit;
+ }
var params = {};
if (pp2limit) params.limit = pp2limit;
@@ -307,13 +314,6 @@ function team($, teamName) {
if (blanket) blanket.css('display', 'block');
if (motd) motd.css('display', 'none');
break;
- case 'none':
- alert("mkws.switchView(" + m_teamName + ", 'none') shouldn't happen");
- if (targets) targets.css('display', 'none');
- if (results) results.css('display', 'none');
- if (blanket) blanket.css('display', 'none');
- if (motd) motd.css('display', 'none');
- break;
default:
alert("Unknown view '" + view + "'");
}
@@ -346,76 +346,6 @@ function team($, teamName) {
* result pages.
*/
function mkwsHtmlAll() {
- mkwsSetLang();
- if (m_config.show_lang)
- mkwsHtmlLang();
-
- log("HTML search form");
- findnode('.mkwsSearch').html('\
-
');
-
- log("HTML records");
- // If the team has a .mkwsResults, populate it in the usual
- // way. If not, assume that it's a smarter application that
- // defines its own subcomponents, some or all of the
- // following:
- // .mkwsTermlists
- // .mkwsRanking
- // .mkwsPager
- // .mkwsNavi
- // .mkwsRecords
- findnode(".mkwsResults").html('\
-
\
-
\
-
\
- \
-
\
-
\
- \
- \
- \
- \
-
\
-
\
-
\
-
\
- \
-
\
-
\
-
');
-
- var acc = [];
- var facets = m_config.facets;
- acc.push('
' + M('Termlists') + '
');
- for (var i = 0; i < facets.length; i++) {
- acc.push('
');
- acc.push('
');
- }
- findnode(".mkwsTermlists").html(acc.join(''));
-
- var ranking_data = '';
- findnode(".mkwsRanking").html(ranking_data);
-
- mkwsHtmlSwitch();
-
- findnode('.mkwsSearchForm').submit(function() {
- var val = widgetNode('Query').val();
- newSearch(val);
- return false;
- });
-
- // on first page, hide the termlist
- $(document).ready(function() { widgetNode("Termlists").hide(); });
var container = findnode(".mkwsMOTDContainer");
if (container.length) {
// Move the MOTD from the provided element down into the container
@@ -437,107 +367,6 @@ function team($, teamName) {
}
- /* create locale language menu */
- function mkwsHtmlLang() {
- var lang_default = "en";
- var lang = m_config.lang || lang_default;
- var list = [];
-
- /* display a list of configured languages, or all */
- var lang_options = m_config.lang_options || [];
- var toBeIncluded = {};
- for (var i = 0; i < lang_options.length; i++) {
- toBeIncluded[lang_options[i]] = true;
- }
-
- for (var k in mkws.locale_lang) {
- if (toBeIncluded[k] || lang_options.length == 0)
- list.push(k);
- }
-
- // add english link
- if (lang_options.length == 0 || toBeIncluded[lang_default])
- list.push(lang_default);
-
- 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 + ' '
- }
- }
-
- findnode(".mkwsLang").html(data);
- }
-
-
- function mkwsHtmlSort() {
- log("HTML sort, m_sortOrder = '" + m_sortOrder + "'");
- var sort_html = '';
-
- return sort_html;
- }
-
-
- function mkwsHtmlPerpage() {
- log("HTML perpage, m_perpage = " + m_perpage);
- var perpage_html = '';
-
- return perpage_html;
- }
-
-
- function mkwsHtmlSwitch() {
- log("HTML switch for team " + m_teamName);
-
- var node = findnode(".mkwsSwitch");
- node.append($('' + M('Records') + ''));
- node.append($("", { text: " | " }));
- node.append($('' + M('Targets') + ''));
-
- log("HTML targets");
- var node = findnode(".mkwsTargets");
- node.html('\
-
\
- No information available yet.\
-
');
- node.css("display", "none");
- }
-
-
// Translation function. At present, this is properly a
// global-level function (hence the assignment to mkws.M) but we
// want to make it per-team so different teams can operate in
@@ -588,6 +417,11 @@ function team($, teamName) {
that.renderDetails = renderDetails;
+ that.registerTemplate = function(name, text) {
+ m_tempateText[name] = text;
+ };
+
+
function loadTemplate(name) {
var template = m_template[name];
@@ -603,7 +437,10 @@ function team($, teamName) {
}
if (!source) {
- source = defaultTemplate(name);
+ source = m_tempateText[name];
+ }
+ if (!source) {
+ source = mkws.defaultTemplate(name);
}
template = Handlebars.compile(source);
@@ -616,94 +453,6 @@ function team($, teamName) {
that.loadTemplate = loadTemplate;
- function defaultTemplate(name) {
- if (name === 'Record') {
- return '\
-