check mkws.authenticated only for SP config, MKWS-82
[mkws-moved-to-github.git] / tools / htdocs / mkws.js
index 6c07d2d..10a3915 100644 (file)
@@ -7,7 +7,7 @@
 var mkws = {
     sort: 'relevance',
     authenticated: false,
-    filters: [],
+    filters: []
 };
 
 /*
@@ -104,7 +104,7 @@ var debug = mkws.debug_function; // local alias
 
 
 Handlebars.registerHelper('json', function(obj) {
-    return JSON.stringify(obj);
+    return $.toJSON(obj);
 });
 
 
@@ -422,7 +422,7 @@ function onFormSubmitEventHandler()
 
 function newSearch(query, sort, targets)
 {
-    if (!mkws.authenticated) {
+    if (mkws_config.use_service_proxy && !mkws.authenticated) {
        alert("searching before authentication");
        return;
     }
@@ -486,7 +486,7 @@ function triggerSearch (query, sort, targets)
        }
     }
 
-    debug("triggerSearch(" + mkws.query + "): filters = " + JSON.stringify(mkws.filters) + ", pp2filter = " + pp2filter + ", pp2limit = " + pp2limit);
+    debug("triggerSearch(" + mkws.query + "): filters = " + $.toJSON(mkws.filters) + ", pp2filter = " + pp2filter + ", pp2limit = " + pp2limit);
     my_paz.search(mkws.query, recPerPage, mkws.sort, pp2filter, undefined, { limit: pp2limit });
 }
 
@@ -533,9 +533,9 @@ mkws.delimitQuery = function (field, value)
        if (filter.field &&
            field == filter.field &&
            value == filter.value) {
-           debug("delimitTarget() removing filter " + JSON.stringify(filter));
+           debug("delimitTarget() removing filter " + $.toJSON(filter));
        } else {
-           debug("delimitTarget() keeping filter " + JSON.stringify(filter));
+           debug("delimitTarget() keeping filter " + $.toJSON(filter));
            newFilters.push(filter);
        }
     }
@@ -556,9 +556,9 @@ mkws.delimitTarget = function (id)
     for (var i in mkws.filters) {
        var filter = mkws.filters[i];
        if (filter.id) {
-           debug("delimitTarget() removing filter " + JSON.stringify(filter));
+           debug("delimitTarget() removing filter " + $.toJSON(filter));
        } else {
-           debug("delimitTarget() keeping filter " + JSON.stringify(filter));
+           debug("delimitTarget() keeping filter " + $.toJSON(filter));
            newFilters.push(filter);
        }
     }
@@ -906,7 +906,8 @@ function mkws_html_all() {
 
     if (mkws_config.use_service_proxy)
          mkws_service_proxy_auth(mkws_config.service_proxy_auth,
-          mkws_config.service_proxy_auth_domain);
+                                 mkws_config.service_proxy_auth_domain,
+                                 mkws_config.pazpar2_url);
 
     if (mkws_config.responsive_design_width) {
        // Responsive web design - change layout on the fly based on
@@ -1015,9 +1016,14 @@ function mkws_html_perpage() {
  * The username/password is configured in the apache config file
  * for the site.
  */
-function mkws_service_proxy_auth(auth_url, auth_domain) {
+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(/^http:\/\/(.*?)\/.*/, '$1');
+       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;