Merge remote-tracking branch 'origin/master' into wosch
[mkws-moved-to-github.git] / tools / htdocs / mkws.js
index 4eb2f20..484773e 100644 (file)
@@ -201,9 +201,10 @@ function my_onterm(data) {
 }
 
 function add_single_facet(acc, caption, data, max, cclIndex) {
-    acc.push('<div class="facet">');
+    acc.push('<div class="facet" id="mkwsFacet' + caption + '">');
     acc.push('<div class="termtitle">' + M(caption) + '</div>');
     for (var i = 0; i < data.length && i < max; i++ ) {
+       acc.push('<div class="term">');
         acc.push('<a href="#" ');
        var action;
        if (!cclIndex) {
@@ -214,7 +215,8 @@ function add_single_facet(acc, caption, data, max, cclIndex) {
            action = 'limitQuery(\'' + cclIndex + '\', this.firstChild.nodeValue)';
        }
        acc.push('onclick="' + action + ';return false;">' + data[i].name + '</a>'
-                + '<span> (' + data[i].freq + ')</span><br/>');
+                + ' <span>' + data[i].freq + '</span>');
+       acc.push('</div>');
     }
     acc.push('</div>');
 }
@@ -308,7 +310,7 @@ function loadSelect ()
 // limit the query after clicking the facet
 function limitQuery (field, value)
 {
-    document.mkwsSearchForm.query.value += ' and ' + field + '="' + value + '"';
+    document.mkwsSearchForm.mkwsQuery.value += ' and ' + field + '="' + value + '"';
     onFormSubmitEventHandler();
 }
 
@@ -522,7 +524,6 @@ function mkws_html_all(config) {
        sort_default: "relevance",
        perpage_default: 20,
        query_width: 50,
-       switch_menu: false,     /* show/hide Records|Targets menu */
        lang_menu: true,        /* show/hide language menu */
        sort_menu: true,        /* show/hide sort menu */
        perpage_menu: true,     /* show/hide perpage menu */
@@ -638,7 +639,7 @@ function mkws_html_all(config) {
 }
 
 function mkws_set_lang(mkws_config)  {
-    var lang = jQuery.parseQuerystring().lang || mkws_config.lang || "";
+    var lang = $.parseQuerystring().lang || mkws_config.lang || "";
     if (!lang || !mkws_locale_lang[lang]) {
        mkws_config.lang = ""
     } else {
@@ -670,11 +671,6 @@ function mkws_html_switch(config) {
        No information available yet.\
       </div>');
     $("#mkwsTargets").css("display", "none");
-
-    if (!config.switch_menu) {
-       debug("disable switch menu");
-        $("#mkwsSwitch").css("display", "none");
-    }
 }
 
 function mkws_html_sort(config) {
@@ -725,9 +721,12 @@ function mkws_service_proxy_auth(auth_url) {
 
     debug("Run service proxy auth URL: " + auth_url);
 
-    var request = new pzHttpRequest(auth_url);
+    var request = new pzHttpRequest(auth_url, function(err) {
+       alert("HTTP call for authentication failed: " + err)
+       return;
+    });
     request.get(null, function(data) {
-       if (!jQuery.isXMLDoc(data)) {
+       if (!$.isXMLDoc(data)) {
            alert("service proxy auth response document is not valid XML document, give up!");
            return;
        }
@@ -821,8 +820,8 @@ function M(word) {
 /*
  * implement jQuery plugins
  */
-jQuery.extend({
-    // implement jQuery.parseQuerystring() for parsing URL parameters
+$.extend({
+    // implement $.parseQuerystring() for parsing URL parameters
     parseQuerystring: function() {
        var nvpair = {};
        var qs = window.location.search.replace('?', '');
@@ -840,6 +839,9 @@ jQuery.extend({
 
     // service-proxy or pazpar2
     pazpar2: function(config) {
+       var id_popup = config.id_popup || "#mkwsPopup";
+       id_popup = id_popup.replace(/^#/, "");
+
        // simple layout
        var div = '<div id="mkwsSwitch"></div>\
        <div id="mkwsLang"></div>\
@@ -896,21 +898,21 @@ jQuery.extend({
 
        var popup = '\
          <div id="mkwsSearch"></div>\
-         <div id="mkwsPopup">\
+         <div id="' + id_popup + '">\
            <div id="mkwsSwitch"></div>\
            <div id="mkwsLang"></div>\
            <div id="mkwsResults"></div>\
            <div id="mkwsTargets"></div>\
            <div id="mkwsStat"></div>\
-         </div>\
-         <script> $(document).ready(function() { init_popup();});  </script>';
+         </div>'
 
        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");
+           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);
@@ -918,12 +920,28 @@ jQuery.extend({
     }
 });
 
-function init_popup(config) {
-    $("#mkwsPopup").dialog({
+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);
+
+    // make sure that jquery-ui was loaded afte jQuery core lib, e.g.:
+    // <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.min.js"></script>
+    if (!$.ui) {
+       debug("Error: jquery-ui.js is missing, did you included it after jquery core in the HTML file?");
+       return;
+    }
+
+    $(id_popup).dialog({
       closeOnEscape: true,
       autoOpen: false,
-      height: 760,
-      width: 880,
+      height: height,
+      width: width,
       modal: true,
       resizable: true,
       buttons: {
@@ -931,15 +949,13 @@ function init_popup(config) {
                      $(this).dialog("close");
              }
       },
-      close: function() {
-             // allFields.val( "" ).removeClass( "ui-state-error" );
-      }
+      close: function() { }
     });
 
-    $("input#mkwsButton")
+    $(id_button)
       .button()
       .click(function() {
-             $("#mkwsPopup").dialog("open");
+             $(id_popup).dialog("open");
       });
 };
 
@@ -962,4 +978,13 @@ function debug(string) {
 
 
 /* magic */
-$(document).ready(function() { mkws_html_all(mkws_config) });
+$(document).ready(function() {
+    try {
+       mkws_html_all(mkws_config)
+    }
+
+    catch (e) {
+       mkws_config.error = e.message;
+       // alert(e.message);
+    }
+});