From: Mike Taylor Date: Fri, 24 Jan 2014 12:47:11 +0000 (+0000) Subject: Merge branch 'master' of ssh://git.indexdata.com/home/git/private/mkws X-Git-Tag: 1.0.0~1614 X-Git-Url: http://sru.miketaylor.org.uk/?a=commitdiff_plain;h=b54e55b511561023764d5c6fc49a87804651334c;hp=f3e7a9a3d78643e8b856caedf0a705212a3e4f50;p=mkws-moved-to-github.git Merge branch 'master' of ssh://git.indexdata.com/home/git/private/mkws --- diff --git a/tools/htdocs/mkws.js b/tools/htdocs/mkws.js index 2a6d7ba..b332500 100644 --- a/tools/htdocs/mkws.js +++ b/tools/htdocs/mkws.js @@ -159,6 +159,7 @@ function _make_mkws_team($, teamName) { "start": $.now(), "last": $.now() }; + var m_paz; // will be initialised below // if (console && console.log) // disabled, will fail in IE8 @@ -265,20 +266,18 @@ function _make_mkws_team($, teamName) { // create a parameters array and pass it to the pz2's constructor // then register the form submit event with the pz2.search function // autoInit is set to true on default - if (!mkws.paz) { - mkws.paz = new pz2({ "onshow": my_onshow, - "windowid": teamName, - "showtime": 500, //each timer (show, stat, term, bytarget) can be specified this way - "pazpar2path": mkws_config.pazpar2_url, - "oninit": my_oninit, - "onstat": my_onstat, - "onterm": my_onterm, - "termlist": "xtargets,subject,author", - "onbytarget": my_onbytarget, - "usesessions" : mkws_config.use_service_proxy ? false : true, - "showResponseType": '', // or "json" (for debugging?) - "onrecord": my_onrecord }); - } + m_paz = new pz2({ "onshow": my_onshow, + "windowid": teamName, + "showtime": 500, //each timer (show, stat, term, bytarget) can be specified this way + "pazpar2path": mkws_config.pazpar2_url, + "oninit": my_oninit, + "onstat": my_onstat, + "onterm": my_onterm, + "termlist": "xtargets,subject,author", + "onbytarget": my_onbytarget, + "usesessions" : mkws_config.use_service_proxy ? false : true, + "showResponseType": '', // or "json" (for debugging?) + "onrecord": my_onrecord }); if (!isNaN(parseInt(mkws_config.perpage_default))) { m_recPerPage = parseInt(mkws_config.perpage_default); @@ -290,8 +289,8 @@ function _make_mkws_team($, teamName) { // function my_oninit(teamName) { debug("init for " + teamName); - mkws.paz.stat(); - mkws.paz.bytarget(); + m_paz.stat(); + m_paz.bytarget(); } @@ -407,7 +406,7 @@ function _make_mkws_team($, teamName) { function my_onrecord(data, teamName) { debug("record for " + teamName); // FIXME: record is async!! - clearTimeout(mkws.paz.recordTimer); + clearTimeout(m_paz.recordTimer); // in case on_show was faster to redraw element var detRecordDiv = document.getElementById('mkwsDet_'+data.recid); if (detRecordDiv) return; @@ -496,7 +495,7 @@ function _make_mkws_team($, teamName) { if (!m_submitted) return false; resetPage(); loadSelect(); - mkws.paz.show(0, m_recPerPage, m_sort); + m_paz.show(0, m_recPerPage, m_sort); return false; } @@ -552,7 +551,7 @@ function _make_mkws_team($, teamName) { } debug("triggerSearch(" + m_query + "): filters = " + $.toJSON(m_filters) + ", pp2filter = " + pp2filter + ", params = " + $.toJSON(params)); - mkws.paz.search(m_query, m_recPerPage, m_sort, pp2filter, undefined, params); + m_paz.search(m_query, m_recPerPage, m_sort, pp2filter, undefined, params); } @@ -716,21 +715,21 @@ function _make_mkws_team($, teamName) { mkws.showPage = function (pageNum) { m_curPage = pageNum; - mkws.paz.showPage(m_curPage - 1); + m_paz.showPage(m_curPage - 1); } // simple paging functions mkws.pagerNext = function () { if (m_totalRec - m_recPerPage*m_curPage > 0) { - mkws.paz.showNext(); + m_paz.showNext(); m_curPage++; } } mkws.pagerPrev = function () { - if (mkws.paz.showPrev() != false) + if (m_paz.showPrev() != false) m_curPage--; } @@ -789,7 +788,7 @@ function _make_mkws_team($, teamName) { return; } // request the record - mkws.paz.record(recId); + m_paz.record(recId); } @@ -1002,33 +1001,6 @@ function _make_mkws_team($, teamName) { } - function run_auto_searches() { - debug("running auto searches"); - - $('[id^="mkwsRecords"]').each(function () { - var node = $(this); - var query = node.attr('autosearch'); - - if (query) { - var windowid = undefined; - var id = node.attr('id'); - if (id.match(/^mkwsRecords_/, '')) { - windowid = id.replace(/^mkwsRecords_/, ''); - } - - var sort = node.attr('sort'); - var targets = node.attr('targets'); - var s = "running auto search: '" + query + "'"; - if (windowid) s += " [windowid '" + windowid + "']"; - if (sort) s += " sorted by '" + sort + "'"; - if (targets) s += " in targets '" + targets + "'"; - debug(s); - newSearch(query, sort, targets, windowid); - } - }); - } - - // implement $.parseQuerystring() for parsing URL parameters function parseQuerystring() { var nvpair = {}; @@ -1111,42 +1083,6 @@ function _make_mkws_team($, teamName) { } - /* - * Run service-proxy authentication in background (after page load). - * The username/password is configured in the apache config file - * for the site. - */ - mkws.service_proxy_auth = function(auth_url, auth_domain, pp2_url) { - debug("Run service proxy auth URL: " + auth_url); - - if (!auth_domain) { - auth_domain = pp2_url.replace(/^(https?:)?\/\/(.*?)\/.*/, '$2'); - debug("guessed auth_domain '" + auth_domain + "' from pp2_url '" + pp2_url + "'"); - } - - var request = new pzHttpRequest(auth_url, function(err) { - alert("HTTP call for authentication failed: " + err) - return; - }, auth_domain); - - request.get(null, function(data) { - if (!$.isXMLDoc(data)) { - alert("service proxy auth response document is not valid XML document, give up!"); - return; - } - var status = $(data).find("status"); - if (status.text() != "OK") { - alert("service proxy auth repsonse status: " + status.text() + ", give up!"); - return; - } - - debug("Service proxy auth successfully done"); - mkws.authenticated = true; - run_auto_searches(); - }); - } - - /* create locale language menu */ function mkws_html_lang() { var lang_default = "en"; @@ -1454,7 +1390,70 @@ function _mkws_jquery_plugin ($) { mkws_config.pazpar2_url); } else { // raw pp2 - run_auto_searches(); + mkws.run_auto_searches(); } }); + + + /* + * Run service-proxy authentication in background (after page load). + * The username/password is configured in the apache config file + * for the site. + */ + mkws.service_proxy_auth = function(auth_url, auth_domain, pp2_url) { + debug("Run service proxy auth URL: " + auth_url); + + if (!auth_domain) { + auth_domain = pp2_url.replace(/^(https?:)?\/\/(.*?)\/.*/, '$2'); + debug("guessed auth_domain '" + auth_domain + "' from pp2_url '" + pp2_url + "'"); + } + + var request = new pzHttpRequest(auth_url, function(err) { + alert("HTTP call for authentication failed: " + err) + return; + }, auth_domain); + + request.get(null, function(data) { + if (!$.isXMLDoc(data)) { + alert("service proxy auth response document is not valid XML document, give up!"); + return; + } + var status = $(data).find("status"); + if (status.text() != "OK") { + alert("service proxy auth repsonse status: " + status.text() + ", give up!"); + return; + } + + debug("Service proxy auth successfully done"); + mkws.authenticated = true; + mkws.run_auto_searches(); + }); + } + + + mkws.run_auto_searches = function() { + debug("running auto searches"); + + $('[id^="mkwsRecords"]').each(function () { + var node = $(this); + var query = node.attr('autosearch'); + + if (query) { + var windowid = undefined; + var id = node.attr('id'); + if (id.match(/^mkwsRecords_/, '')) { + windowid = id.replace(/^mkwsRecords_/, ''); + } + + var sort = node.attr('sort'); + var targets = node.attr('targets'); + var s = "running auto search: '" + query + "'"; + if (windowid) s += " [windowid '" + windowid + "']"; + if (sort) s += " sorted by '" + sort + "'"; + if (targets) s += " in targets '" + targets + "'"; + debug(s); + newSearch(query, sort, targets, windowid); + } + }); + } })(jQuery);