X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fmkws-team.js;h=38b850765fb9eb04327f1f3395cb44c8b70c3b16;hb=a3e4a88ed0be613c6e9e06f50d24058f460bfe76;hp=d6fc49f45cccfacc45411fa69daf7ca29685a58e;hpb=ca8479c3a7bda382d3fcac21b936091dd82f03cb;p=mkws-moved-to-github.git diff --git a/src/mkws-team.js b/src/mkws-team.js index d6fc49f..38b8507 100644 --- a/src/mkws-team.js +++ b/src/mkws-team.js @@ -28,6 +28,7 @@ function team($, teamName) { var m_paz; // will be initialised below var m_template = {}; var m_config = mkws.objectInheritingFrom(mkws.config); + var m_widgets = {}; // Maps widget-type to object that.toString = function() { return '[Team ' + teamName + ']'; }; @@ -331,10 +332,10 @@ function team($, teamName) { // switching view between targets and records function switchView(view) { - var targets = findnode('.mkwsTargets'); - var results = findnode('.mkwsResults,.mkwsRecords'); - var blanket = findnode('.mkwsBlanket'); - var motd = findnode('.mkwsMOTD'); + var targets = widgetNode('Targets'); + var results = widgetNode('Results') || widgetNode('Records'); + var blanket = widgetNode('Blanket'); + var motd = widgetNode('MOTD'); switch(view) { case 'targets': @@ -451,13 +452,13 @@ function team($, teamName) { mkwsHtmlSwitch(); findnode('.mkwsSearchForm').submit(function() { - var val = findnode('.mkwsQuery').val(); + var val = widgetNode('Query').val(); newSearch(val); return false; }); // on first page, hide the termlist - $(document).ready(function() { findnode(".mkwsTermlists").hide(); }); + $(document).ready(function() { widgetNode("Termlists").hide(); }); var container = findnode(".mkwsMOTDContainer"); if (container.length) { // Move the MOTD from the provided element down into the container @@ -619,6 +620,13 @@ function team($, teamName) { 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; + } + function renderDetails(data, marker) { var template = loadTemplate("Record"); var details = template(data); @@ -741,6 +749,28 @@ function team($, teamName) { return s; } + that.addWidget = function(w) { + if (!m_widgets[w.type]) { + m_widgets[w.type] = w; + log("Registered '" + w.type + "' widget in team '" + m_teamName + "'"); + } else if (typeof(m_widgets[w.type]) !== 'number') { + m_widgets[w.type] = 2; + log("Registered duplicate '" + w.type + "' widget in team '" + m_teamName + "'"); + } else { + m_widgets[w.type] += 1; + log("Registered '" + w.type + "' widget #" + m_widgets[w.type] + "' in team '" + m_teamName + "'"); + } + } + + that.widgetTypes = function() { + var keys = []; + for (var k in m_widgets) keys.push(k); + return keys.sort(); + } + + that.widget = function(type) { + return m_widgets[type]; + } mkwsHtmlAll()