X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=mkdru.client.js;h=03f950715247c326c3adba90f5581486f718a14b;hb=56667175166fd1553aa05e4e2d08e1d77ea3e5ec;hp=add8bd1cfd3a4736d72be53dda4f42bade6cf68e;hpb=2b5e7db83479b99d46023a9e832d374f66fad453;p=mkdru-moved-to-drupal.org.git diff --git a/mkdru.client.js b/mkdru.client.js index add8bd1..03f9507 100644 --- a/mkdru.client.js +++ b/mkdru.client.js @@ -30,14 +30,18 @@ var mkdru = { perpage: 20, sort: 'relevance', filter: null, - query:null, + query:'', recid:null }, - state: {} + state: {}, + realm: '' }; +// Wrapper for jQuery +(function ($) { + // So we can use jQuery BBQ with Drupal 6 and its 1.2.6 jQuery if (!$.isArray) $.isArray = function(obj) { return Object.prototype.toString.call(obj) === "[object Array]"; @@ -78,18 +82,15 @@ mkdru.pz2Init = function () { if (mkdru.state.query) { mkdru.search(); } - //mkdru.pz2.stat(); + mkdru.pz2.stat(); //mkdru.pz2.bytarget(); }; mkdru.pz2Show = function (data) { mkdru.totalRec = data.merged; $('.mkdru-pager').html(mkdru.generatePager()); - var countsHtml = Drupal.t('Displaying: ') + (data.start + 1) + - Drupal.t(' to ') + (data.start + data.num) + Drupal.t(' of ') - + data.merged + Drupal.t(' (found: ') + data.total + ')'; - $('.mkdru-counts').html(countsHtml); - + $('.mkdru-counts').html(Drupal.theme('mkdruCounts', data.start + 1, + data.num, data.merged, data.total)); var html = ""; for (var i = 0; i < data.hits.length; i++) { html += Drupal.theme('mkdruResult', data.hits[i], @@ -108,6 +109,7 @@ mkdru.pz2Show = function (data) { }; mkdru.pz2Status = function (data) { + $('.mkdru-status').html(Drupal.theme('mkdruStatus', data.activeclients, data.clients)); }; mkdru.pz2Term = function (data) { @@ -132,8 +134,8 @@ mkdru.pz2ByTarget = function (data) { mkdru.pz2Record = function (data) { clearTimeout(mkdru.pz2.showTimer); $('.mkdru-results').hide(); - $('.mkdru-detail').html(Drupal.theme('mkdruDetail', data)); - $('.mkdru-detail-back').bind('click', function () {$.bbq.removeState('recid');}); + $('.mkdru-detail').html(Drupal.theme('mkdruDetail', data, + mkdru.hashAddDelOne(null, null, 'recid'))); $('.mkdru-detail').show(); clearTimeout(mkdru.pz2.recordTimer); }; @@ -192,9 +194,9 @@ mkdru.hashChange = function () { } // Other internal link else { - // need to run search again to limit targets + // may need to run search again to limit targets for (key in mkdru.state) { - if (key.substring(0,5) === 'limit') { + if (key.substring(0,5) === 'limit' && mkdru.state[key]) { mkdru.search(); break; } @@ -307,7 +309,7 @@ $(document).ready(function () { mkdru.pz2 = new pz2( { "onshow": mkdru.pz2Show, "showtime": 500, //each timer (show, stat, term, bytarget) can be specified this way - "pazpar2path": mkdru.pazpar2path, + "pazpar2path": mkdru.pazpar2Path, "oninit": mkdru.pz2Init, "onstat": mkdru.pz2Status, "onterm": mkdru.pz2Term, @@ -327,14 +329,40 @@ $(document).ready(function () { if (typeof(Drupal.settings.mkdru.query) !== "undefined") { mkdru.state.query = Drupal.settings.mkdru.query } - + + //not running against SP? init, otherwise authenticate if (mkdru.useSessions) { mkdru.pz2.init(); - } - else if (mkdru.state.recid) { - mkdru.pz2.record(mkdru.state.recid); - } - else if (mkdru.state.query) { - mkdru.search(); + } else { + //runnin against SP + var user = Drupal.settings.mkdru.sp_user; + var pass = Drupal.settings.mkdru.sp_pass; + var params = {}; + params['command'] = 'auth'; + if (user && pass) { + params['action'] = 'login'; + params['username'] = user; + params['password'] = pass; + } else { + params['action'] = 'ipauth'; + } + var authReq = new pzHttpRequest(mkdru.pazpar2Path, + function (err) { + alert("Authentication against metasearch gateway failed: " +err); + } + ); + authReq.get(params, + function (data) { + var s = data.getElementsByTagName('status'); + if (s.length && Element_getTextContent(s[0]) == "OK") { + mkdru.realm = data.getElementsByTagName('realm'); + mkdru.pz2Init(); + } else { + alert("Malformed response when authenticating against the metasearch" + + " gateway"); + } + } + ); } }); +})(jQuery); \ No newline at end of file