X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=tools%2Fhtdocs%2Fmkws.js;h=d325f71ced218913b3eb233a2082ec2795f36977;hb=b9f4617ba1b2ab18cb2ddc920bf15658c0504e15;hp=ecba8dabf5efea4895b3655e624e59819165e8c5;hpb=6c2be612315d7afb929dbd1d38df7fd6de625600;p=mkws-moved-to-github.git diff --git a/tools/htdocs/mkws.js b/tools/htdocs/mkws.js index ecba8da..d325f71 100644 --- a/tools/htdocs/mkws.js +++ b/tools/htdocs/mkws.js @@ -141,7 +141,7 @@ if (mkws_config == null || typeof mkws_config != 'object') { // wrapper for jQuery lib -function _make_mkws_team($, teamName) { +function team($, teamName) { var that = {}; var m_teamName = teamName; var m_submitted = false; @@ -162,10 +162,11 @@ function _make_mkws_team($, teamName) { // if (console && console.log) // disabled, will fail in IE8 - // console.log("run _make_mkws_team(" + (teamName ? teamName : "") + ")"); + // console.log("run team(" + (teamName ? teamName : "") + ")"); - // Needs to be defined inside _make_mkws_team() so it can see m_debug_time + // Needs to be defined inside team() so it can see m_debug_time + // ### member access won't work: there is only one instance of this function mkws.debug_function = function (string) { if (!mkws.debug_level) return; @@ -270,7 +271,8 @@ function _make_mkws_team($, teamName) { renderSummary(hit), ''); if (hit.recid == m_curDetRecId) { - html.push(renderDetails(m_curDetRecData)); + if (m_curDetRecData) + html.push(renderDetails(m_curDetRecData)); } } results.html(html.join('')); @@ -281,22 +283,22 @@ function _make_mkws_team($, teamName) { { var template = loadTemplate("Summary"); hit._id = "mkwsRec_" + hit.recid; - hit._onclick = "mkws.showDetails(this.id);return false;" + hit._onclick = "mkws.showDetails(this.id, '" + m_teamName + "');return false;" return template(hit); } function my_onstat(data, teamName) { debug("stat for " + teamName); - var stat = document.getElementById("mkwsStat"); - if (stat == null) + var stat = $('.mkwsStat.mkwsTeam_' + teamName); + if (stat.length === 0) return; - stat.innerHTML = '' + M('Status info') + '' + + stat.html('' + M('Status info') + '' + ' -- ' + '' + M('Active clients') + ': ' + data.activeclients + '/' + data.clients + '' + ' -- ' + - '' + M('Retrieved records') + ': ' + data.records + '/' + data.hits + ''; + '' + M('Retrieved records') + ': ' + data.records + '/' + data.hits + ''); } @@ -355,7 +357,7 @@ function _make_mkws_team($, teamName) { } - function my_onrecord(data, teamName) { + function my_onrecord(data, args, teamName) { debug("record for " + teamName); // FIXME: record is async!! clearTimeout(m_paz.recordTimer); @@ -371,9 +373,8 @@ function _make_mkws_team($, teamName) { function my_onbytarget(data, teamName) { debug("target for " + teamName); - var targetDiv = document.getElementById("mkwsBytarget"); + var targetDiv = $('.mkwsBytarget.mkwsTeam_' + teamName); if (!targetDiv) { - // No mkwsTargets div. return; } @@ -394,7 +395,7 @@ function _make_mkws_team($, teamName) { } table += ''; - targetDiv.innerHTML = table; + targetDiv.html(table); } //////////////////////////////////////////////////////////////////////////////// @@ -404,7 +405,15 @@ function _make_mkws_team($, teamName) { // wait until the DOM is ready function domReady () { - document.mkwsSearchForm.onsubmit = onFormSubmitEventHandler; + $('.mkwsSearchForm.mkwsTeam_' + m_teamName).each(function (i, obj) { + debug("adding search-forms for team '" + m_teamName + "'"); + var node = this; + mkws.handle_node_with_team(node, function(tname) { + debug("adding search-form '" + tname + "' for team '" + m_teamName + "'"); + $(node).submit(onFormSubmitEventHandler); + }); + }); + document.mkwsSearchForm.mkwsQuery.value = ''; if (document.mkwsSelect) { if (document.mkwsSelect.mkwsSort) @@ -418,7 +427,11 @@ function _make_mkws_team($, teamName) { // when search button pressed function onFormSubmitEventHandler() { - that.newSearch(document.mkwsSearchForm.mkwsQuery.value); + mkws.handle_node_with_team(this, function (tname) { + var val = $('.mkwsQuery.mkwsTeam_' + tname).val(); + mkws.teams[tname].newSearch(val); + }); + return false; } @@ -437,7 +450,7 @@ function _make_mkws_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; } @@ -687,33 +700,33 @@ function _make_mkws_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 results = document.getElementById('mkwsResults') || - document.getElementById('mkwsRecords'); - var blanket = document.getElementById('mkwsBlanket'); - var motd = document.getElementById('mkwsMOTD'); + var targets = $('.mkwsTargets.mkwsTeam_' + tname); + var results = $('.mkwsResults.mkwsTeam_' + tname + ',.mkwsRecords.mkwsTeam_' + tname); + var blanket = $('#mkwsBlanket'); + var motd = $('#mkwsMOTD'); switch(view) { case 'targets': - if (targets) targets.style.display = "block"; - if (results) results.style.display = "none"; - if (blanket) blanket.style.display = "none"; - if (motd) motd.style.display = "none"; + if (targets) targets.css('display', 'block'); + if (results) results.css('display', 'none'); + if (blanket) blanket.css('display', 'none'); + if (motd) motd.css('display', 'none'); break; case 'records': - if (targets) targets.style.display = "none"; - if (results) results.style.display = "block"; - if (blanket) blanket.style.display = "block"; - if (motd) motd.style.display = "none"; + 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': - if (targets) targets.style.display = "none"; - if (results) results.style.display = "none"; - if (blanket) blanket.style.display = "none"; - if (motd) motd.style.display = "none"; + 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'); + if (motd) motd.css('display', 'none'); break; default: alert("Unknown view '" + view + "'"); @@ -722,7 +735,7 @@ function _make_mkws_team($, teamName) { // detailed record drawing - mkws.showDetails = function (prefixRecId) { + that.showDetails = function (prefixRecId) { var recId = prefixRecId.replace('mkwsRec_', ''); var oldRecId = m_curDetRecId; m_curDetRecId = recId; @@ -863,38 +876,45 @@ function _make_mkws_team($, teamName) { // For some reason, doing this programmatically results in // document.mkwsSearchForm.mkwsQuery being undefined, hence the raw HTML. debug("HTML search form"); - $("#mkwsSearch").html('\ -
\ - \ - \ + // ### 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('\ +\ + \ + \
'); + }); + }); 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('\ \ \ - \ \ \ \ \ \
\ -
\ +
\ +
\
\ -
\ -
\ -
\ -
\ +
\ +
\ +
\ +
\
\ -
\ +
\
'); @@ -919,9 +939,9 @@ function _make_mkws_team($, teamName) { if (mkws_config.responsive_design_width) { // Responsive web design - change layout on the fly based on // current screen width. Required for mobile devices. - $(window).resize(function(e) { mkws_resize_page() }); + $(window).resize(function(e) { mkws.resize_page() }); // initial check after page load - $(document).ready(function() { mkws_resize_page() }); + $(document).ready(function() { mkws.resize_page() }); } domReady(); @@ -965,18 +985,20 @@ function _make_mkws_team($, teamName) { function mkws_html_switch() { - debug("HTML switch"); + debug("HTML switch for team " + m_teamName); - $("#mkwsSwitch").append($('' + M('Records') + '')); - $("#mkwsSwitch").append($("", { text: " | " })); - $("#mkwsSwitch").append($('' + M('Targets') + '')); + var node = $(".mkwsSwitch.mkwsTeam_" + m_teamName); + node.append($('' + M('Records') + '')); + node.append($("", { text: " | " })); + node.append($('' + M('Targets') + '')); debug("HTML targets"); - $("#mkwsTargets").html('\ -
\ + var node = $(".mkwsTargets.mkwsTeam_" + m_teamName); + node.html('\ +
\ No information available yet.\
'); - $("#mkwsTargets").css("display", "none"); + node.css("display", "none"); } @@ -1028,18 +1050,18 @@ function _make_mkws_team($, teamName) { /* display a list of configured languages, or all */ var lang_options = mkws_config.lang_options || []; - var hash = {}; + var toBeIncluded = {}; for (var i = 0; i < lang_options.length; i++) { - hash[lang_options[i]] = 1; + toBeIncluded[lang_options[i]] = true; } for (var k in mkws.locale_lang) { - if (hash[k] == 1 || lang_options.length == 0) + if (toBeIncluded[k] || lang_options.length == 0) list.push(k); } // add english link - if (lang_options.length == 0 || hash[lang_default] == 1) + if (lang_options.length == 0 || toBeIncluded[lang_default]) list.push(lang_default); debug("Language menu for: " + list.join(", ")); @@ -1059,38 +1081,10 @@ function _make_mkws_team($, teamName) { } } - $("#mkwsLang").html(data); + $(".mkwsLang.mkwsTeam_" + m_teamName).html(data); } - function mkws_resize_page () { - var list = ["mkwsSwitch"]; - - var width = mkws_config.responsive_design_width; - var parentId = $("#mkwsTermlists").parent().attr('id'); - - if ($(window).width() <= width && - parentId === "mkwsTermlistContainer1") { - debug("changing from wide to narrow: " + $(window).width()); - $("#mkwsTermlists").appendTo($("#mkwsTermlistContainer2")); - $("#mkwsTermlistContainer1").hide(); - $("#mkwsTermlistContainer2").show(); - for(var i = 0; i < list.length; i++) { - $("#" + list[i]).hide(); - } - } else if ($(window).width() > width && - parentId === "mkwsTermlistContainer2") { - debug("changing from narrow to wide: " + $(window).width()); - $("#mkwsTermlists").appendTo($("#mkwsTermlistContainer1")); - $("#mkwsTermlistContainer1").show(); - $("#mkwsTermlistContainer2").hide(); - for(var i = 0; i < list.length; i++) { - $("#" + list[i]).show(); - } - } - }; - - /* locale */ function M(word) { var lang = mkws_config.lang; @@ -1264,7 +1258,7 @@ function _mkws_jquery_plugin ($) { }; -// wrapper to call _make_mkws_team() after page load +// wrapper to call team() after page load (function (j) { function log(s) { if (typeof console === "undefined" || typeof console.log === "undefined") { /* ARGH!!! old IE */ @@ -1289,21 +1283,30 @@ function _mkws_jquery_plugin ($) { var id = 'mkws' + ids[i]; var node = $('#' + id); if (node.attr('id')) { - node.addClass(id + " mkwsTeam_AUTO"); - log("added magic classes to '" + node.attr('id') + "'"); + node.addClass(id); + log("added magic class to '" + node.attr('id') + "'"); } } + // For all MKWS-classed nodes that don't have a team + // specified, set the team to AUTO. + $('div[class^="mkws"],div[class*=" mkws"]').each(function () { + if (!this.className.match(/mkwsTeam_/)) { + log("adding AUTO team to node with class '" + this.className + "'"); + $(this).addClass('mkwsTeam_AUTO'); + } + }); + // Find all nodes with class (NOT id) mkwsRecords, and // determine their team from the mkwsTeam_* class. So: //
- $('.mkwsResults, .mkwsRecords, .mkwsTermlists').each(function () { + $('.mkwsSearch, .mkwsResults, .mkwsRecords, .mkwsTermlists').each(function () { var node = this; mkws.handle_node_with_team(node, function(tname) { if (mkws.teams[tname]) { log("MKWS team '" + tname + "' already exists, skipping"); } else { - mkws.teams[tname] = _make_mkws_team(j, tname); + mkws.teams[tname] = team(j, tname); log("Made MKWS team '" + tname + "'"); } }); @@ -1330,12 +1333,43 @@ function _mkws_jquery_plugin ($) { tname = cname.replace(/^mkwsTeam_/, ''); } } - if (!tname) - tname = "AUTO"; callback(tname); } + mkws.resize_page = function () { + var list = ["mkwsSwitch"]; + + var width = mkws_config.responsive_design_width; + var parentId = $("#mkwsTermlists").parent().attr('id'); + + if ($(window).width() <= width && + parentId === "mkwsTermlistContainer1") { + log("changing from wide to narrow: " + $(window).width()); + $("#mkwsTermlists").appendTo($("#mkwsTermlistContainer2")); + $("#mkwsTermlistContainer1").hide(); + $("#mkwsTermlistContainer2").show(); + for(var i = 0; i < list.length; i++) { + $("#" + list[i]).hide(); // ### make team-aware + } + } else if ($(window).width() > width && + parentId === "mkwsTermlistContainer2") { + log("changing from narrow to wide: " + $(window).width()); + $("#mkwsTermlists").appendTo($("#mkwsTermlistContainer1")); + $("#mkwsTermlistContainer1").show(); + $("#mkwsTermlistContainer2").hide(); + for(var i = 0; i < list.length; i++) { + $("#" + list[i]).show(); // ### make team-aware + } + } + }; + + + mkws.showDetails = function (prefixRecId, tname) { + mkws.teams[tname].showDetails(prefixRecId); + } + + function default_mkws_config() { /* default mkws config */ var config_default = { @@ -1387,11 +1421,11 @@ function _mkws_jquery_plugin ($) { * for the site. */ function authenticate_session(auth_url, auth_domain, pp2_url) { - console.log("Run service proxy auth URL: " + auth_url); + log("Run service proxy auth URL: " + auth_url); if (!auth_domain) { auth_domain = pp2_url.replace(/^(https?:)?\/\/(.*?)\/.*/, '$2'); - console.log("guessed auth_domain '" + auth_domain + "' from pp2_url '" + pp2_url + "'"); + log("guessed auth_domain '" + auth_domain + "' from pp2_url '" + pp2_url + "'"); } var request = new pzHttpRequest(auth_url, function(err) { @@ -1410,7 +1444,7 @@ function _mkws_jquery_plugin ($) { return; } - console.log("Service proxy auth successfully done"); + log("Service proxy auth successfully done"); mkws.authenticated = true; run_auto_searches(); }); @@ -1418,13 +1452,13 @@ function _mkws_jquery_plugin ($) { function run_auto_searches() { - console.log("running auto searches"); + log("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'); - console.log("teamName '" + teamName + "', node=" + node + ", class='" + node.className + "', query=" + query); + log("teamName '" + teamName + "', node=" + node + ", class='" + node.className + "', query=" + query); if (query) { var sort = node.attr('sort'); @@ -1433,9 +1467,9 @@ function _mkws_jquery_plugin ($) { if (teamName) s += " [teamName '" + teamName + "']"; if (sort) s += " sorted by '" + sort + "'"; if (targets) s += " in targets '" + targets + "'"; - console.log(s); + log(s); var team = mkws.teams[teamName]; - console.log($.toJSON(team)); + log($.toJSON(team)); team.newSearch(query, sort, targets, teamName); } }