mkws.switchView() now operates on a named team.
authorMike Taylor <mike@indexdata.com>
Tue, 4 Feb 2014 17:09:32 +0000 (17:09 +0000)
committerMike Taylor <mike@indexdata.com>
Tue, 4 Feb 2014 17:09:32 +0000 (17:09 +0000)
(Although #mkwsBlanket and #mkwsMOTD are still used at the moment.)
The search-form is only made once per team!
Fill in .mkwsResults for each team rather than #mkwsResults

tools/htdocs/mkws.js

index 1de5514..45564dd 100644 (file)
@@ -451,7 +451,7 @@ function team($, teamName) {
        resetPage(); // ### the globals it resents should be indexed by windowid
        loadSelect(); // ### should use windowid
        triggerSearch(query, sort, targets, windowid);
-       mkws.switchView('records'); // In case it's configured to start off as hidden
+       mkws.switchView(m_teamName, 'records'); // In case it's configured to start off as hidden
        m_submitted = true;
     }
 
@@ -701,12 +701,12 @@ function team($, teamName) {
 
 
     // switching view between targets and records
-    mkws.switchView = function(view) {
-       debug("switchView: " + view);
+    mkws.switchView = function(tname, view) {
+       debug("switchView(" + tname + ", " + view + ")");
 
        //var targets = document.getElementById('mkwsTargets');
-       var targets = $('#mkwsTargets');
-       var results = $('#mkwsResults,#mkwsRecords');
+       var targets = $('.mkwsTargets.mkwsTeam_' + tname);
+       var results = $('.mkwsResults.mkwsTeam_' + tname + ',.mkwsRecords.mkwsTeam_' + tname);
        var blanket = $('#mkwsBlanket');
        var motd    = $('#mkwsMOTD');
 
@@ -724,7 +724,7 @@ function team($, teamName) {
             if (motd) motd.css('display', 'none');
             break;
        case 'none':
-           alert("mkws.switchView('none') shouldn't happen");
+           alert("mkws.switchView(" + tname + ", 'none') shouldn't happen");
             if (targets) targets.css('display', 'none');
             if (results) results.css('display', 'none');
             if (blanket) blanket.css('display', 'none');
@@ -878,7 +878,8 @@ function team($, teamName) {
        // For some reason, doing this programmatically results in
        // document.mkwsSearchForm.mkwsQuery being undefined, hence the raw HTML.
        debug("HTML search form");
-       $('.mkwsSearch').each(function (i, obj) {
+       // ### There is only one match here by design: fix not to bother looping
+       $('.mkwsSearch.mkwsTeam_' + m_teamName).each(function (i, obj) {
            var node = this;
            mkws.handle_node_with_team(node, function(tname) {
                $(node).html('\
@@ -890,16 +891,17 @@ function team($, teamName) {
        });
 
        debug("HTML records");
-       // If the application has an #mkwsResults, populate it in the
-       // usual way. If not, assume that it's a smarter application that
-       // defines its own subcomponents:
-       //      #mkwsTermlists
-       //      #mkwsRanking
-       //      #mkwsPager
-       //      #mkwsNavi
-       //      #mkwsRecords
-       if ($("#mkwsResults").length) {
-           $("#mkwsResults").html('\
+       // 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
+       if ($(".mkwsResults.mkwsTeam_" + m_teamName).length) {
+           $(".mkwsResults.mkwsTeam_" + m_teamName).html('\
 <table width="100%" border="0" cellpadding="6" cellspacing="0">\
   <tr>\
     <td id="mkwsTermlistContainer1" class="mkwsTermlistContainer1 mkwsTeam_AUTO" width="250" valign="top">\
@@ -988,9 +990,9 @@ function team($, teamName) {
        debug("HTML switch for team " + m_teamName);
 
        var node = $(".mkwsSwitch.mkwsTeam_" + m_teamName);
-       node.append($('<a href="#" onclick="mkws.switchView(\'records\')">' + M('Records') + '</a>'));
+       node.append($('<a href="#" onclick="mkws.switchView(\'' + m_teamName + '\', \'records\')">' + M('Records') + '</a>'));
        node.append($("<span/>", { text: " | " }));
-       node.append($('<a href="#" onclick="mkws.switchView(\'targets\')">' + M('Targets') + '</a>'));
+       node.append($('<a href="#" onclick="mkws.switchView(\'' + m_teamName + '\', \'targets\')">' + M('Targets') + '</a>'));
 
        debug("HTML targets");
        var node = $(".mkwsTargets.mkwsTeam_" + m_teamName);