';
- drawPager(pager);
- // navi
- var results = document.getElementById("mkwsRecords");
-
- var html = [];
- for (var i = 0; i < data.hits.length; i++) {
- var hit = data.hits[i];
- html.push('
');
-}
-function my_onrecord(data) {
- // FIXME: record is async!!
- clearTimeout(my_paz.recordTimer);
- // in case on_show was faster to redraw element
- var detRecordDiv = document.getElementById('mkwsDet_'+data.recid);
- if (detRecordDiv) return;
- curDetRecData = data;
- var recordDiv = document.getElementById('mkwsRecdiv_'+curDetRecData.recid);
- var html = renderDetails(curDetRecData);
- recordDiv.innerHTML += html;
-}
+ function my_onrecord(data) {
+ // FIXME: record is async!!
+ clearTimeout(m_paz.recordTimer);
+ // in case on_show was faster to redraw element
+ var detRecordDiv = document.getElementById('mkwsDet_'+data.recid);
+ if (detRecordDiv) return;
+ curDetRecData = data;
+ var recordDiv = document.getElementById('mkwsRecdiv_'+curDetRecData.recid);
+ var html = renderDetails(curDetRecData);
+ recordDiv.innerHTML += html;
+ }
-function my_onbytarget(data) {
- var targetDiv = document.getElementById("mkwsBytarget");
- if (!targetDiv) {
- // No mkwsTargets div.
- return;
+ function my_onbytarget(data) {
+ var targetDiv = document.getElementById("mkwsBytarget");
+ if (!targetDiv) {
+ // No mkwsTargets div.
+ return;
+ }
+
+ var table ='
' +
+ '
' + M('Target ID') + '
' +
+ '
' + M('Hits') + '
' +
+ '
' + M('Diags') + '
' +
+ '
' + M('Records') + '
' +
+ '
' + M('State') + '
' +
+ '
';
+
+ for (var i = 0; i < data.length; i++ ) {
+ table += "
" + data[i].id +
+ "
" + data[i].hits +
+ "
" + data[i].diagnostic +
+ "
" + data[i].records +
+ "
" + data[i].state + "
";
+ }
+
+ table += '
';
+ targetDiv.innerHTML = table;
}
- var table ='
Target ID
Hits
Diags
'
- +'
Records
State
';
+ ////////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////////
+
+ // wait until the DOM is ready
+ function domReady ()
+ {
+ document.mkwsSearchForm.onsubmit = onFormSubmitEventHandler;
+ document.mkwsSearchForm.mkwsQuery.value = '';
+ if (document.mkwsSelect) {
+ if (document.mkwsSelect.mkwsSort)
+ document.mkwsSelect.mkwsSort.onchange = onSelectDdChange;
+ if (document.mkwsSelect.mkwsPerpage)
+ document.mkwsSelect.mkwsPerpage.onchange = onSelectDdChange;
+ }
+ }
- for (var i = 0; i < data.length; i++ ) {
- table += "
\
+';
+ } else if (name === "Summary") {
+ return '\
+\
+ {{md-title}}\
+\
+{{#if md-title-remainder}}\
+ {{md-title-remainder}}\
+{{/if}}\
+{{#if md-title-responsibility}}\
+ {{md-title-responsibility}}\
+{{/if}}\
+';
+ }
+
+ var s = "There is no default '" + name +"' template!";
+ alert(s);
+ return s;
}
- return '
' + M(caption) + '
' + data + '
';
-}
+ /*
+ * All the HTML stuff to render the search forms and
+ * result pages.
+ */
+ function mkws_html_all() {
+ mkws_set_lang();
+ if (mkws_config.show_lang)
+ mkws_html_lang();
+
+ // 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
+ // 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('\
+
\
+
\
+
\
+ \
+
\
+
\
+ \
+ \
+ \
+ \
+
\
+
\
+
\
+
\
+ \
+
\
+
\
+
');
+ }
-/*
- * All the HTML stuff to render the search forms and
- * result pages.
- */
-function mkws_html_all(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",
- perpage_default: 20,
- query_width: 50,
- lang_menu: true, /* show/hide language menu */
- sort_menu: true, /* show/hide sort menu */
- perpage_menu: true, /* show/hide perpage menu */
- lang_display: [], /* display languages links for given languages, [] for all */
- facets: ["sources", "subjects", "authors"], /* display facets, in this order, [] for none */
- responsive_design_width: 980, /* a page with less pixel width considered as narrow */
- debug: 1, /* debug level for development: 0..2 */
-
- dummy: "dummy"
- };
+ if ($("#mkwsRanking").length) {
+ var ranking_data = '';
+ ranking_data += '';
+
+ $("#mkwsRanking").html(ranking_data);
+ }
- /* set global debug flag early */
- if (typeof config.debug !== 'undefined') {
- mkws.debug = config.debug;
- } else if (typeof mkws_config_default.debug !== 'undefined') {
- mkws.debug = mkws_config_default.debug;
- }
+ mkws_html_switch();
- /* override standard config values by function parameters */
- 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.use_service_proxy) {
+ mkws_service_proxy_auth(mkws_config.service_proxy_auth,
+ mkws_config.service_proxy_auth_domain,
+ mkws_config.pazpar2_url);
+ } else {
+ // raw pp2
+ run_auto_searches();
+ }
- if (mkws_config.query_width < 5 || mkws_config.query_width > 150) {
- debug("Reset query width: " + mkws_config.query_width);
- mkws_config.query_width = 50;
- }
+ 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() });
+ // initial check after page load
+ $(document).ready(function() { mkws_resize_page() });
+ }
- mkws_set_lang(mkws_config);
- if (mkws_config.lang_menu)
- mkws_html_lang(mkws_config);
-
- // 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
- // 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 ($("#mkwsRanking").length) {
- var ranking_data = '';
- ranking_data += '';
-
- $("#mkwsRanking").html(ranking_data);
- }
-
- mkws_html_switch(config);
-
- if (mkws_config.use_service_proxy)
- mkws_service_proxy_auth(config.service_proxy_auth);
-
- if (mkws_config.responsive_design) {
- // Responsive web design - change layout on the fly based on
- // current screen width. Required for mobile devices.
- $(window).resize( function(e) { mkws_resize_page() });
- // initial check after page load
- $(document).ready(function() { mkws_resize_page() });
- }
-
- domReady();
-
- // on first page, hide the termlist
- $(document).ready(function() { $("#mkwsTermlists").hide(); } );
- var motd = document.getElementById("mkwsMOTD");
- var container = document.getElementById("mkwsMOTDContainer");
- if (motd && container) {
- // Move the MOTD from the provided element down into the container
- motd.parentNode.removeChild(motd);
- container.appendChild(motd);
- }
-}
+ domReady();
-function mkws_set_lang(mkws_config) {
- var lang = $.parseQuerystring().lang || mkws_config.lang || "";
- if (!lang || !mkws.locale_lang[lang]) {
- mkws_config.lang = ""
- } else {
- mkws_config.lang = lang;
+ // on first page, hide the termlist
+ $(document).ready(function() { $("#mkwsTermlists").hide(); } );
+ var motd = document.getElementById("mkwsMOTD");
+ var container = document.getElementById("mkwsMOTDContainer");
+ if (motd && container) {
+ // Move the MOTD from the provided element down into the container
+ motd.parentNode.removeChild(motd);
+ container.appendChild(motd);
+ }
}
- debug("Locale language: " + (mkws_config.lang ? mkws_config.lang : "none"));
- return mkws_config.lang;
-}
-function mkws_html_switch(config) {
- debug("HTML switch");
-
- $("#mkwsSwitch").html($("", {
- href: '#',
- onclick: "mkws.switchView(\'records\')",
- text: M("Records")
- }));
- $("#mkwsSwitch").append($("", { text: " | " }));
- $("#mkwsSwitch").append($("", {
- href: '#',
- onclick: "mkws.switchView(\'targets\')",
- text: M("Targets")
- }));
-
- debug("HTML targets");
- $("#mkwsTargets").html('\
-
\
- No information available yet.\
-
');
- $("#mkwsTargets").css("display", "none");
-}
+ 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);
+ }
+ });
+ }
-function mkws_html_sort(config) {
- debug("HTML sort");
- var sort_html = '';
- return sort_html;
-}
+ function mkws_html_switch() {
+ debug("HTML switch");
+
+ $("#mkwsSwitch").append($('' + M('Records') + ''));
+ $("#mkwsSwitch").append($("", { text: " | " }));
+ $("#mkwsSwitch").append($('' + M('Targets') + ''));
-function mkws_html_perpage(config) {
- debug("HTML perpage");
- var perpage_html = '';
- return perpage_html;
-}
+ function mkws_html_perpage() {
+ debug("HTML perpage");
+ var perpage_html = '';
-/*
- * Run service-proxy authentication in background (after page load).
- * The username/password is configured in the apache config file
- * for the site.
- */
-function mkws_service_proxy_auth(auth_url) {
- if (!auth_url)
- auth_url = "http://mkws.indexdata.com/service-proxy-auth";
+ for(var i = 0; i < mkws_config.perpage_options.length; i++) {
+ var key = mkws_config.perpage_options[i];
- debug("Run service proxy auth URL: " + auth_url);
+ perpage_html += '';
+ }
+ perpage_html += '';
- var request = new pzHttpRequest(auth_url, function(err) {
- alert("HTTP call for authentication failed: " + err)
- return;
- });
- request.get(null, function(data) {
- if (!$.isXMLDoc(data)) {
- alert("service proxy auth response document is not valid XML document, give up!");
- return;
+ return perpage_html;
+ }
+
+ /*
+ * Run service-proxy authentication in background (after page load).
+ * The username/password is configured in the apache config file
+ * for the site.
+ */
+ function mkws_service_proxy_auth(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 status = $(data).find("status");
- if (status.text() != "OK") {
- alert("service proxy auth repsonse status: " + status.text() + ", give up!");
+
+ 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";
+ var lang = mkws_config.lang || lang_default;
+ var list = [];
+
+ /* display a list of configured languages, or all */
+ var lang_options = mkws_config.lang_options || [];
+ var hash = {};
+ for (var i = 0; i < lang_options.length; i++) {
+ hash[lang_options[i]] = 1;
}
- });
-}
-/* create locale language menu */
-function mkws_html_lang(mkws_config) {
- var lang_default = "en";
- var lang = mkws_config.lang || lang_default;
- var list = [];
+ for (var k in mkws.locale_lang) {
+ if (hash[k] == 1 || lang_options.length == 0)
+ list.push(k);
+ }
- /* display a list of configured languages, or all */
- var lang_display = mkws_config.lang_display || [];
- var hash = {};
- for (var i = 0; i < lang_display.length; i++) {
- hash[lang_display[i]] = 1;
- }
+ // add english link
+ if (lang_options.length == 0 || 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);
- }
+ debug("Language menu for: " + list.join(", "));
- // add english link
- if (lang_display.length == 0 || hash[lang_default] == 1)
- list.push(lang_default);
+ /* the HTML part */
+ var data = "";
+ for(var i = 0; i < list.length; i++) {
+ var l = list[i];
- debug("Language menu for: " + list.join(", "));
+ if (data)
+ data += ' | ';
- /* the HTML part */
- var data = "";
- for(var i = 0; i < list.length; i++) {
- var l = list[i];
+ if (lang == l) {
+ data += ' ' + l + ' ';
+ } else {
+ data += ' ' + l + ' '
+ }
+ }
- if (data)
- data += ' | ';
+ $("#mkwsLang").html(data);
+ }
- if (lang == l) {
- data += ' ' + l + ' ';
- } else {
- data += ' ' + l + ' '
+ 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();
+ }
}
- }
+ };
- $("#mkwsLang").html(data);
-}
+ /* locale */
+ function M(word) {
+ var lang = mkws_config.lang;
-function mkws_resize_page () {
- var list = ["mkwsSwitch"];
+ if (!lang || !mkws.locale_lang[lang])
+ return word;
- var width = mkws_config.responsive_design_width || 980;
- var parentId = $("#mkwsTermlists").parent().attr('id');
+ return mkws.locale_lang[lang][word] || word;
+ }
- 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();
+ // main
+ (function() {
+ try {
+ mkws_html_all()
}
- }
-};
-/* locale */
-function M(word) {
- var lang = mkws_config.lang;
+ catch (e) {
+ mkws_config.error = e.message;
+ // alert(e.message);
+ }
+ })();
- if (!lang || !mkws.locale_lang[lang])
- return word;
+ // done
+ mkws.init = true;
+};
- return mkws.locale_lang[lang][word] ? mkws.locale_lang[lang][word] : word;
-}
/*
- * implement jQuery plugins
+ * implement jQuery plugin $.pazpar2({})
*/
-$.extend({
- // implement $.parseQuerystring() for parsing URL parameters
- parseQuerystring: function() {
- var nvpair = {};
- var qs = window.location.search.replace('?', '');
- var pairs = qs.split('&');
- $.each(pairs, function(i, v){
- var pair = v.split('=');
- nvpair[pair[0]] = pair[1];
- });
- return nvpair;
- },
+function _mkws_jquery_plugin ($) {
+ var debug_level = 1;
- debug2: function(string) { // delayed debug, internal variables are set after dom ready
- setTimeout(function() { debug(string); }, 500);
- },
+ function debug (string) {
+ if (!debug_level)
+ return;
- // service-proxy or pazpar2
- pazpar2: function(config) {
- var id_popup = config.id_popup || "#mkwsPopup";
- id_popup = id_popup.replace(/^#/, "");
+ if (typeof console === "undefined" || typeof console.log === "undefined")
+ return;
- // simple layout
- var div = '\
- \
- \
- \
- \
- ';
-
- // new table layout
- var table = '\
- \
- \
-
\
-
\
-
\
- \
- \
- \
-
\
-
\
-
\
-
\
-
\
- \
- \
- \
- \
- \
-
\
-
\
-
\
-
\
-
\
-
\
- \
-
\
-
\
-
\
-
\
-
\
- \
-
\
-
\
-
';
-
- var popup = '\
- \
-
\
- \
- \
- \
- \
- \
-
'
-
- if (config && config.layout == 'div') {
- this.debug2("jquery plugin layout: div");
- document.write(div);
- } else if (config && config.layout == 'popup') {
- this.debug2("jquery plugin layout: popup with id: " + id_popup);
- document.write(popup);
- $(document).ready( function() { init_popup(config); } );
- } else {
- this.debug2("jquery plugin layout: table");
- document.write(table);
- }
+ console.log("jquery.pazpar2: " + string);
}
-});
-
-function init_popup(obj) {
- var config = obj ? obj : {};
-
- var height = config.height || 760;
- var width = config.width || 880;
- var id_button = config.id_button || "input#mkwsButton";
- var id_popup = config.id_popup || "#mkwsPopup";
- debug("popup height: " + height + ", width: " + width);
+ function init_popup(obj) {
+ var config = obj ? obj : {};
- // make sure that jquery-ui was loaded afte jQuery core lib, e.g.:
- //
- if (!$.ui) {
- debug("Error: jquery-ui.js is missing, did you included it after jquery core in the HTML file?");
- return;
- }
+ var height = config.height || 760;
+ var width = config.width || 880;
+ var id_button = config.id_button || "input#mkwsButton";
+ var id_popup = config.id_popup || "#mkwsPopup";
- $(id_popup).dialog({
- closeOnEscape: true,
- autoOpen: false,
- height: height,
- width: width,
- modal: true,
- resizable: true,
- buttons: {
- Cancel: function() {
- $(this).dialog("close");
- }
- },
- close: function() { }
- });
+ debug("popup height: " + height + ", width: " + width);
- $(id_button)
- .button()
- .click(function() {
- $(id_popup).dialog("open");
- });
-};
+ // make sure that jquery-ui was loaded afte jQuery core lib, e.g.:
+ //
+ if (!$.ui) {
+ debug("Error: jquery-ui.js is missing, did you include it after jQuery core in the HTML file?");
+ return;
+ }
+ $(id_popup).dialog({
+ closeOnEscape: true,
+ autoOpen: false,
+ height: height,
+ width: width,
+ modal: true,
+ resizable: true,
+ buttons: {
+ Cancel: function() {
+ $(this).dialog("close");
+ }
+ },
+ close: function() { }
+ });
+ $(id_button)
+ .button()
+ .click(function() {
+ $(id_popup).dialog("open");
+ });
+ };
+ $.extend({
+
+ // service-proxy or pazpar2
+ pazpar2: function(config) {
+ var id_popup = config.id_popup || "#mkwsPopup";
+ id_popup = id_popup.replace(/^#/, "");
+
+ // simple layout
+ var div = '\
+\
+\
+\
+\
+\
+';
+
+ // new table layout
+ var table = '\
+\
+ \
+