Single global mkws.paz changed to per-team m_paz.
[mkws-moved-to-github.git] / tools / htdocs / mkws.js
index 2a6d7ba..1a0782d 100644 (file)
@@ -159,6 +159,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
@@ -265,20 +266,18 @@ function _make_mkws_team($, teamName) {
     // 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
-    if (!mkws.paz) {
-       mkws.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 });
-    }
+    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);
@@ -290,8 +289,8 @@ function _make_mkws_team($, teamName) {
     //
     function my_oninit(teamName) {
        debug("init for " + teamName);
-       mkws.paz.stat();
-       mkws.paz.bytarget();
+       m_paz.stat();
+       m_paz.bytarget();
     }
 
 
@@ -407,7 +406,7 @@ function _make_mkws_team($, teamName) {
     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;
@@ -496,7 +495,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;
     }
 
@@ -552,7 +551,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);
     }
 
 
@@ -716,21 +715,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--;
     }
 
@@ -789,7 +788,7 @@ function _make_mkws_team($, teamName) {
             return;
        }
        // request the record
-       mkws.paz.record(recId);
+       m_paz.record(recId);
     }
 
 
@@ -1002,7 +1001,7 @@ function _make_mkws_team($, teamName) {
     }
 
 
-    function run_auto_searches() {
+    mkws.run_auto_searches = function() {
        debug("running auto searches");
 
        $('[id^="mkwsRecords"]').each(function () {
@@ -1111,42 +1110,6 @@ function _make_mkws_team($, teamName) {
     }
 
 
-    /*
-     * Run service-proxy authentication in background (after page load).
-     * The username/password is configured in the apache config file
-     * for the site.
-     */
-    mkws.service_proxy_auth = function(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 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";
@@ -1454,7 +1417,43 @@ function _mkws_jquery_plugin ($) {
                                    mkws_config.pazpar2_url);
        } else {
            // raw pp2
-           run_auto_searches();
+           mkws.run_auto_searches();
        }
     });
+
+
+    /*
+     * Run service-proxy authentication in background (after page load).
+     * The username/password is configured in the apache config file
+     * for the site.
+     */
+    mkws.service_proxy_auth = function(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 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;
+           mkws.run_auto_searches();
+       });
+    }
 })(jQuery);