X-Git-Url: http://sru.miketaylor.org.uk/?a=blobdiff_plain;f=src%2Fmkws-team.js;h=4e91fce55e69641c813970d1a3e29b1ada3b6254;hb=ca8a466132753c8239f41680cb21edee8c7f4262;hp=8d33d9e87cb9a1fb661f169e6902aeea0f28429d;hpb=6a8b6776618229ff0cae8b19288124daf9239463;p=mkws-moved-to-github.git
diff --git a/src/mkws-team.js b/src/mkws-team.js
index 8d33d9e..4e91fce 100644
--- a/src/mkws-team.js
+++ b/src/mkws-team.js
@@ -26,15 +26,17 @@ 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
+ var m_widgets = {}; // Maps widget-type to array of widget objects
that.toString = function() { return '[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; };
@@ -185,7 +187,9 @@ function team($, teamName) {
that.limitCategory = function(id) {
log("limitCategory(id=" + id + ")");
- m_filterSet.add(categoryFilter(id));
+ // 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;
};
@@ -265,15 +269,17 @@ function team($, teamName) {
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;
- if (pp2catLimit) params.categoryfilter = pp2catLimit;
if (maxrecs) params.maxrecs = maxrecs;
if (torusquery) {
if (!mkws.config.use_service_proxy)
@@ -297,23 +303,16 @@ function team($, teamName) {
switch(view) {
case 'targets':
- if (targets) targets.css('display', 'block');
- if (results) results.css('display', 'none');
- if (blanket) blanket.css('display', 'none');
- if (motd) motd.css('display', 'none');
+ if (targets) $(targets).show();
+ if (results) $(results).hide();
+ if (blanket) $(blanket).hide();
+ if (motd) $(motd).hide();
break;
case 'records':
- if (targets) targets.css('display', 'none');
- if (results) results.css('display', 'block');
- 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');
+ if (targets) $(targets).hide();
+ if (results) $(results).show();
+ if (blanket) $(blanket).show();
+ if (motd) $(motd).hide();
break;
default:
alert("Unknown view '" + view + "'");
@@ -342,219 +341,6 @@ function team($, teamName) {
};
- /*
- * All the HTML stuff to render the search forms and
- * 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
- findnode(".mkwsMOTD").appendTo(container);
- }
- }
-
-
- function mkwsSetLang() {
- var lang = mkws.getParameterByName("lang") || m_config.lang;
- if (!lang || !mkws.locale_lang[lang]) {
- m_config.lang = ""
- } else {
- m_config.lang = lang;
- }
-
- log("Locale language: " + (m_config.lang ? m_config.lang : "none"));
- return m_config.lang;
- }
-
-
- /* 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
- // different languages.
- //
- function M(word) {
- var lang = m_config.lang;
-
- if (!lang || !mkws.locale_lang[lang])
- return word;
-
- return mkws.locale_lang[lang][word] || word;
- }
- mkws.M = M; // so the Handlebars helper can use it
-
-
// Finds the node of the specified class within the current team
function findnode(selector, teamName) {
teamName = teamName || m_teamName;
@@ -570,11 +356,8 @@ function team($, teamName) {
//log('findnode(' + selector + ') found ' + node.length + ' nodes');
return node;
}
- that.findnode = findnode;
- // This much simpler and more efficient function should be usable
- // in place of most uses of findnode.
function widgetNode(type) {
var w = that.widget(type);
return w ? $(w.node) : undefined;
@@ -589,6 +372,11 @@ function team($, teamName) {
that.renderDetails = renderDetails;
+ that.registerTemplate = function(name, text) {
+ m_tempateText[name] = text;
+ };
+
+
function loadTemplate(name) {
var template = m_template[name];
@@ -604,7 +392,10 @@ function team($, teamName) {
}
if (!source) {
- source = defaultTemplate(name);
+ source = m_tempateText[name];
+ }
+ if (!source) {
+ source = mkws.defaultTemplate(name);
}
template = Handlebars.compile(source);
@@ -617,118 +408,49 @@ function team($, teamName) {
that.loadTemplate = loadTemplate;
- function defaultTemplate(name) {
- if (name === 'Record') {
- return '\
-