X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=experiments%2Fspclient%2Fmkws.js;h=6bc3a30790c8cb148932221fa555eaec69f8c942;hb=3c47d3fe9fecf21d12f38f6dda73c1b7e5ff2c49;hp=4a6eb6dadaad3db3e64746b755f7fc1eeddf916f;hpb=71aa8121e550f16068eddc1365881e2ab652f8ee;p=mkws-moved-to-github.git diff --git a/experiments/spclient/mkws.js b/experiments/spclient/mkws.js index 4a6eb6d..6bc3a30 100644 --- a/experiments/spclient/mkws.js +++ b/experiments/spclient/mkws.js @@ -13,10 +13,13 @@ if (!mkws_config) var mkws_config = {}; // for the guys who forgot to define mkws_config... +if (typeof mkws_config.use_service_proxy === 'undefined') + mkws_config.use_service_proxy = true; + var mkws_debug = 1; var pazpar2_url = mkws_config.pazpar2_url ? mkws_config.pazpar2_url : "/pazpar2/search.pz2"; -var service_proxy_url = mkws_config.service_proxy_url ? mkws_config.service_proxy_url : "/service-proxy/"; +var service_proxy_url = mkws_config.service_proxy_url ? mkws_config.service_proxy_url : "http://mkws.indexdata.com/service-proxy/"; var pazpar2path = mkws_config.use_service_proxy ? service_proxy_url : pazpar2_url; var usesessions = mkws_config.use_service_proxy ? false : true; @@ -27,7 +30,7 @@ var mkws_locale_lang = { "Authors": "Autoren", "Subjects": "Schlagwörter", "Sources": "Daten und Quellen", - "TERMLISTS": "Termlisten", + "Termlists": "Termlisten", "Next": "Weiter", "Prev": "Zurück", "Search": "Suche", @@ -51,7 +54,7 @@ var mkws_locale_lang = { "Authors": "Forfattere", "Subjects": "Emner", "Sources": "Kilder", - "TERMLISTS": "TERMLISTS", + "Termlists": "Termlists", "Next": "Næste", "Prev": "Forrige", "Search": "Søg", @@ -147,11 +150,11 @@ function my_onstat(data) { if (stat == null) return; - stat.innerHTML = 'STATUS INFO -- Active clients: ' - + data.activeclients - + '/' + data.clients + ' -- ' - + 'Retrieved records: ' + data.records - + '/' + data.hits + ' :.'; + stat.innerHTML = 'Status info' + + ' -- ' + + '' + data.activeclients + '/' + data.clients + '' + + ' -- ' + + '' + data.records + '/' + data.hits + ''; } function my_onterm(data) { @@ -159,20 +162,27 @@ function my_onterm(data) { return; var termlists = []; - termlists.push('
' + M('TERMLISTS') + ':
' + M('Sources') + '
'); + termlists.push('
' + M('Termlists') + '
'); + + termlists.push('
'); + termlists.push('
' + M('Sources') + '
'); for (var i = 0; i < data.xtargets.length && i < SourceMax; i++ ) { termlists.push('' + data.xtargets[i].name + ' (' + data.xtargets[i].freq + ')
'); } + termlists.push('
'); - termlists.push('
' + M('Subjects') + '
'); + termlists.push('
'); + termlists.push('
' + M('Subjects') + '
'); for (var i = 0; i < data.subject.length && i < SubjectMax; i++ ) { termlists.push('' + data.subject[i].name + ' (' + data.subject[i].freq + ')
'); } + termlists.push('
'); - termlists.push('
' + M('Authors') + '
'); + termlists.push('
'); + termlists.push('
' + M('Authors') + '
'); for (var i = 0; i < data.author.length && i < AuthorMax; i++ ) { termlists.push('' + data.author[i].name @@ -180,6 +190,8 @@ function my_onterm(data) { + data.author[i].freq + ')
'); } + termlists.push('
'); + var termlist = document.getElementById("termlist"); replaceHtml(termlist, termlists.join('')); } @@ -231,6 +243,7 @@ function onFormSubmitEventHandler() resetPage(); loadSelect(); triggerSearch(); + switchView('records'); // In case it's configured to start off as hidden submitted = true; return false; } @@ -366,15 +379,23 @@ function switchView(view) { var targets = document.getElementById('mkwsTargets'); var records = document.getElementById('mkwsRecords'); + var blanket = document.getElementById('mkwsBlanket'); switch(view) { case 'targets': targets.style.display = "block"; records.style.display = "none"; + if (blanket) { blanket.style.display = "none"; } break; case 'records': targets.style.display = "none"; records.style.display = "block"; + if (blanket) { blanket.style.display = "block"; } + break; + case 'none': + targets.style.display = "none"; + records.style.display = "none"; + if (blanket) { blanket.style.display = "none"; } break; default: alert('Unknown view.'); @@ -449,10 +470,10 @@ function renderDetails(data, marker) * All the HTML stuff to render the search forms and * result pages. */ -function mkws_html_all(data) { +function mkws_html_all(config) { - /* default config */ - var config = { + /* default mkws config */ + var mkws_config_default = { sort: [["relevance"], ["title:1", "title"], ["date:0", "newest"], ["date:1", "oldest"]], perpage: [10, 20, 30, 50], sort_default: "relevance", @@ -468,17 +489,19 @@ function mkws_html_all(data) { }; /* set global debug flag early */ - if (data.debug !== 'undefined') { - mkws_debug = data.debug; - } else if (config.debug !== 'undefined') { + if (config.debug !== 'undefined') { mkws_debug = config.debug; + } else if (mkws_config_default.debug !== 'undefined') { + mkws_debug = mkws_config_default.debug; } /* override standard config values by function parameters */ - for (var k in config) { - mkws_config[k] = config[k]; - debug("Set config: " + k + ' => ' + config[k]); + for (var k in mkws_config_default) { + if (typeof config[k] === 'undefined') + mkws_config[k] = mkws_config_default[k]; + debug("Set config: " + k + ' => ' + mkws_config[k]); } + if (mkws_config.query_width < 5 || mkws_config.query_width > 150) { debug("Reset query width: " + mkws_config.query_width); mkws_config.query_width = 50; @@ -507,7 +530,7 @@ function mkws_html_all(data) { \
\
\ - ' + M('Sort by') + mkws_html_sort(config) + '\ + ' + M('Sort by') + ' ' + mkws_html_sort(config) + '\ ' + M('and show') + ' ' + mkws_html_perpage(config) + '\ ' + M('per page') + '.\
\ @@ -610,25 +633,22 @@ function mkws_html_perpage(config) { */ function mkws_service_proxy_auth(auth_url) { if (!auth_url) - auth_url = "/service-proxy-auth"; + auth_url = "http://mkws.indexdata.com/service-proxy-auth"; debug("Run service proxy auth URL: " + auth_url); - var jqxhr = jQuery.get(auth_url) - .fail(function() { - alert("service proxy authentication failed, give up!"); - }) - .success(function(data) { - if (!jQuery.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; - } - }); + var request = new pzHttpRequest(auth_url); + request.get(null, function(data) { + if (!jQuery.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; + } + }); } /* create locale language menu */ @@ -644,13 +664,15 @@ function mkws_html_lang(mkws_config) { hash[lang_display[i]] = 1; } - if (hash[lang_default] == 1) - list.push(lang_default); - for (var k in mkws_locale_lang) { if (hash[k] == 1 || lang_display.length == 0) list.push(k); } + + // add english link + if (lang_display.length == 0 || hash[lang_default] == 1) + list.push(lang_default); + debug("Language menu for: " + list.join(", ")); /* the HTML part */ @@ -683,7 +705,7 @@ function M(word) { /* implement jQuery.parseQuerystring() for parsing URL parameters */ jQuery.extend({ - parseQuerystring: function() { + parseQuerystring: function() { var nvpair = {}; var qs = window.location.search.replace('?', ''); var pairs = qs.split('&'); @@ -692,13 +714,27 @@ jQuery.extend({ nvpair[pair[0]] = pair[1]; }); return nvpair; -} }); + }, + pazpar2: function(data) { + document.write('
\ +
\ +
\ +
\ +
\ +
'); + + mkws_html_all(mkws_config); + } +}); function debug(string) { if (!mkws_debug) return; - if (typeof console === "undefined" || typeof console.log === "undefined") { /* ARGH!!! */ + if (typeof console === "undefined" || typeof console.log === "undefined") { /* ARGH!!! old IE */ return; }