X-Git-Url: http://sru.miketaylor.org.uk/?a=blobdiff_plain;f=tools%2Fhtdocs%2Fmkws.js;h=b5dc51d1b35efc3befb7da2ea8759630f0cbb414;hb=e1910c1453642bea8ffad32e3e1a4e52f1ecf8eb;hp=1bf213776ffb1ea51bbb9e082978699c76d7401c;hpb=2ebf0662a51ed32e0c274740ea0d59545c6dded1;p=mkws-moved-to-github.git diff --git a/tools/htdocs/mkws.js b/tools/htdocs/mkws.js index 1bf2137..b5dc51d 100644 --- a/tools/htdocs/mkws.js +++ b/tools/htdocs/mkws.js @@ -10,7 +10,6 @@ Handlebars.registerHelper('json', function(obj) { Handlebars.registerHelper('translate', function(s) { - debug("translating '" + s + "'"); return mkws.M(s); }); @@ -144,7 +143,7 @@ if (mkws_config == null || typeof mkws_config != 'object') { // wrapper for jQuery lib function _make_mkws_team($, teamName) { var that = {}; - var m_termName = teamName; + var m_teamName = teamName; var m_submitted = false; var m_query; // initially undefined var m_sort = 'relevance'; @@ -159,6 +158,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 @@ -189,53 +189,6 @@ function _make_mkws_team($, teamName) { var debug = mkws.debug_function; // local alias debug("start running MKWS"); - - { - - /* default mkws config */ - var config_default = { - use_service_proxy: true, - pazpar2_url: "http://mkws.indexdata.com/service-proxy/", - service_proxy_auth: "http://mkws.indexdata.com/service-proxy-auth", - lang: "", - sort_options: [["relevance"], ["title:1", "title"], ["date:0", "newest"], ["date:1", "oldest"]], - perpage_options: [10, 20, 30, 50], - sort_default: "relevance", - perpage_default: 20, - query_width: 50, - show_lang: true, /* show/hide language menu */ - show_sort: true, /* show/hide sort menu */ - show_perpage: true, /* show/hide perpage menu */ - lang_options: [], /* display languages links for given languages, [] for all */ - facets: ["sources", "subjects", "authors"], /* display facets, in this order, [] for none */ - responsive_design_width: undefined, /* a page with less pixel width considered as narrow */ - debug_level: 1, /* debug level for development: 0..2 */ - - dummy: "dummy" - }; - - /* Set global debug_level flag early so that debug() works */ - if (typeof mkws_config.debug_level !== 'undefined') { - mkws.debug_level = mkws_config.debug_level; - } else if (typeof config_default.debug_level !== 'undefined') { - mkws.debug_level = config_default.debug_level; - } - - // make sure the mkws_config is a valid hash - if (!$.isPlainObject(mkws_config)) { - debug("ERROR: mkws_config is not an JS object, ignore it...."); - mkws_config = {}; - } - - /* override standard config values by function parameters */ - for (var k in config_default) { - if (typeof mkws_config[k] === 'undefined') - mkws_config[k] = config_default[k]; - //debug("Set config: " + k + ' => ' + mkws_config[k]); - } - } - - m_sort = mkws_config.sort_default; debug("copied mkws_config.sort_default '" + mkws_config.sort_default + "' to m_sort"); @@ -255,27 +208,28 @@ function _make_mkws_team($, teamName) { } } - // protocol independend link for pazpar2: "//mkws/sp" -> "https://mkws/sp" + // protocol independent link for pazpar2: "//mkws/sp" -> "https://mkws/sp" if (mkws_config.pazpar2_url.match(/^\/\//)) { mkws_config.pazpar2_url = document.location.protocol + mkws_config.pazpar2_url; - debug("adjust protocol independend links: " + mkws_config.pazpar2_url); + debug("adjust protocol independent links: " + mkws_config.pazpar2_url); } debug("Create main pz2 object"); // 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 - mkws.paz = new pz2({ "onshow": my_onshow, - "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); @@ -285,13 +239,15 @@ function _make_mkws_team($, teamName) { // // pz2.js event handlers: // - function my_oninit() { - mkws.paz.stat(); - mkws.paz.bytarget(); + function my_oninit(teamName) { + debug("init for " + teamName); + m_paz.stat(); + m_paz.bytarget(); } - function my_onshow(data) { + function my_onshow(data, teamName) { + debug("show for " + teamName); m_totalRec = data.merged; // move it out var pager = document.getElementById("mkwsPager"); @@ -305,7 +261,7 @@ function _make_mkws_team($, teamName) { } // navi - var results = document.getElementById("mkwsRecords"); + var results = $(".mkwsRecords.mkwsTeam_" + m_teamName); var html = []; for (var i = 0; i < data.hits.length; i++) { @@ -317,7 +273,7 @@ function _make_mkws_team($, teamName) { html.push(renderDetails(m_curDetRecData)); } } - replaceHtml(results, html.join('')); + results.html(html.join('')); } @@ -330,7 +286,8 @@ function _make_mkws_team($, teamName) { } - function my_onstat(data) { + function my_onstat(data, teamName) { + debug("stat for " + teamName); var stat = document.getElementById("mkwsStat"); if (stat == null) return; @@ -343,7 +300,8 @@ function _make_mkws_team($, teamName) { } - function my_onterm(data) { + function my_onterm(data, teamName) { + debug("term for " + teamName); // no facets if (!mkws_config.facets || mkws_config.facets.length == 0) { $("#mkwsTermlists").hide(); @@ -369,9 +327,9 @@ function _make_mkws_team($, teamName) { } } - var termlist = document.getElementById("mkwsTermlists"); + var termlist = $("#mkwsTermlists"); if (termlist) - replaceHtml(termlist, acc.join('')); + termlist.html(acc.join('')); } @@ -397,9 +355,10 @@ function _make_mkws_team($, teamName) { } - function my_onrecord(data) { + 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; @@ -410,7 +369,8 @@ function _make_mkws_team($, teamName) { } - function my_onbytarget(data) { + function my_onbytarget(data, teamName) { + debug("target for " + teamName); var targetDiv = document.getElementById("mkwsBytarget"); if (!targetDiv) { // No mkwsTargets div. @@ -444,7 +404,14 @@ function _make_mkws_team($, teamName) { // wait until the DOM is ready function domReady () { - document.mkwsSearchForm.onsubmit = onFormSubmitEventHandler; + $('.mkwsSearchForm').each(function (i, obj) { + var node = this; + debug("adding class 'foo' to node " + node); + mkws.handle_node_with_team(node, function(tname) { + $(node).submit(onFormSubmitEventHandler); + }); + }); + document.mkwsSearchForm.mkwsQuery.value = ''; if (document.mkwsSelect) { if (document.mkwsSelect.mkwsSort) @@ -458,12 +425,12 @@ function _make_mkws_team($, teamName) { // when search button pressed function onFormSubmitEventHandler() { - newSearch(document.mkwsSearchForm.mkwsQuery.value); + that.newSearch(document.mkwsSearchForm.mkwsQuery.value); return false; } - function newSearch(query, sort, targets, windowid) + that.newSearch = function(query, sort, targets, windowid) { debug("newSearch: " + query); @@ -487,7 +454,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; } @@ -543,7 +510,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); } @@ -707,21 +674,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--; } @@ -780,25 +747,10 @@ function _make_mkws_team($, teamName) { return; } // request the record - mkws.paz.record(recId); + m_paz.record(recId); } - function replaceHtml(el, html) { - var oldEl = typeof el === "string" ? document.getElementById(el) : el; - /*@cc_on // Pure innerHTML is slightly faster in IE - oldEl.innerHTML = html; - return oldEl; - @*/ - var newEl = oldEl.cloneNode(false); - newEl.innerHTML = html; - oldEl.parentNode.replaceChild(newEl, oldEl); - /* Since we just removed the old element from the DOM, return a reference - to the new element, which can be used to restore variable references. */ - return newEl; - }; - - function renderDetails(data, marker) { var template = loadTemplate("Record"); @@ -918,11 +870,16 @@ 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('\ -
'); + }); + }); debug("HTML records"); // If the application has an #mkwsResults, populate it in the @@ -937,19 +894,19 @@ function _make_mkws_team($, teamName) { $("#mkwsResults").html('\\ - \ + | \ + \ | \\ - \ - \ - \ - \ + \ + \ + \ + \ | \
\ - \ + \ | \