From c79a20e709ad2dace476db0a54351002b644d223 Mon Sep 17 00:00:00 2001 From: Mike Taylor Date: Fri, 14 Feb 2014 17:29:59 +0000 Subject: [PATCH] run_auto_searches() is now a tiny function that just dispatches run_auto_search() on each team. The work is done by individual teams. --- tools/htdocs/mkws.js | 73 ++++++++++++++++++++++++++------------------------ 1 file changed, 38 insertions(+), 35 deletions(-) diff --git a/tools/htdocs/mkws.js b/tools/htdocs/mkws.js index 58fa52e..539f2bf 100644 --- a/tools/htdocs/mkws.js +++ b/tools/htdocs/mkws.js @@ -1094,6 +1094,43 @@ function team($, teamName) { } + that.run_auto_search = function() { + // ### should check mkwsTermlist as well, for facet-only teams + var node = $('.mkwsRecords.mkwsTeam_' + m_teamName); + var query = node.attr('autosearch'); + if (!query) + return; + + if (query.match(/^!param!/)) { + var param = query.replace(/^!param!/, ''); + query = getParameterByName(param); + debug("obtained query '" + query + "' from param '" + param + "'"); + if (!query) { + alert("This page has a MasterKey widget that needs a query specified by the '" + param + "' parameter"); + } + } else if (query.match(/^!path!/)) { + var index = query.replace(/^!path!/, ''); + var path = window.location.pathname.split('/'); + query = path[path.length - index]; + debug("obtained query '" + query + "' from path-component '" + index + "'"); + if (!query) { + alert("This page has a MasterKey widget that needs a query specified by the path-component " + index); + } + } + + debug("node=" + node + ", class='" + node.className + "', query=" + query); + + var sort = node.attr('sort'); + var targets = node.attr('targets'); + var s = "running auto search: '" + query + "'"; + if (sort) s += " sorted by '" + sort + "'"; + if (targets) s += " in targets '" + targets + "'"; + debug(s); + + this.newSearch(query, sort, targets, m_teamName); + } + + /* locale */ function M(word) { var lang = mkws_config.lang; @@ -1313,41 +1350,7 @@ function team($, teamName) { debug("running auto searches"); for (var teamName in mkws.teams) { - // ### should check mkwsTermlist as well, for facet-only teams - var node = $('.mkwsRecords.mkwsTeam_' + teamName); - var query = node.attr('autosearch'); - if (!query) - continue; - - if (query.match(/^!param!/)) { - var param = query.replace(/^!param!/, ''); - query = getParameterByName(param); - debug("obtained query '" + query + "' from param '" + param + "'"); - if (!query) { - alert("This page has a MasterKey widget that needs a query specified by the '" + param + "' parameter"); - } - } else if (query.match(/^!path!/)) { - var index = query.replace(/^!path!/, ''); - var path = window.location.pathname.split('/'); - query = path[path.length - index]; - debug("obtained query '" + query + "' from path-component '" + index + "'"); - if (!query) { - alert("This page has a MasterKey widget that needs a query specified by the path-component " + index); - } - } - - debug("teamName '" + teamName + "', node=" + node + ", class='" + node.className + "', query=" + query); - - var sort = node.attr('sort'); - var targets = node.attr('targets'); - var s = "running auto search: '" + query + "'"; - if (teamName) s += " [teamName '" + teamName + "']"; - if (sort) s += " sorted by '" + sort + "'"; - if (targets) s += " in targets '" + targets + "'"; - debug(s); - var team = mkws.teams[teamName]; - debug($.toJSON(team)); - team.newSearch(query, sort, targets, teamName); + mkws.teams[teamName].run_auto_search(); } } -- 1.7.10.4