X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=mkdru.client.js;h=5c2d0d029e610af495a298f2a1d9c0f84ab2cd23;hb=db5b797778922d50919364399c90411dfdfb712a;hp=290192898a00f226b00d7067233a166b7196774d;hpb=6ec37cea58b7c25cd7992401ad523359217add53;p=mkdru-moved-to-drupal.org.git diff --git a/mkdru.client.js b/mkdru.client.js index 2901928..5c2d0d0 100644 --- a/mkdru.client.js +++ b/mkdru.client.js @@ -2,42 +2,55 @@ var mkdru = { // Settings to pass to pz2.js useSessions: Drupal.settings.mkdru.use_sessions === '1', - // showResponseType: 'json', // Variables active: false, pz2: null, totalRec: 0, pagerRange: 6, pazpar2Path: Drupal.settings.mkdru.pz2_path, + facetContainerSelector: Drupal.settings.mkdru.facetContainerSelector, // Facets facets: { source: { + displayName: Drupal.settings.mkdru.source_dname || "Source", + orderWeight: Drupal.settings.mkdru.source_weight || 1, pz2Name: 'xtargets', - max: Drupal.settings.mkdru.source_max + max: Drupal.settings.mkdru.source_max || 10 }, subject: { + displayName: Drupal.settings.mkdru.subject_dname || "Subject", + orderWeight: Drupal.settings.mkdru.source_weight || 2, pz2Name: 'subject', - max: Drupal.settings.mkdru.subject_max + max: Drupal.settings.mkdru.subject_max || 10, + multiLimit: true, + limiter: 'su' }, author: { + displayName: Drupal.settings.mkdru.author_dname || "Author", + orderWeight: Drupal.settings.mkdru.source_weight || 3, pz2Name: 'author', - max: Drupal.settings.mkdru.author_max + max: Drupal.settings.mkdru.author_max || 10, + multiLimit: false, + limiter: 'au' } }, - // State + // State; Keys limit_{facet key} will also be initialised defaultState: { page: 1, perpage: 20, sort: 'relevance', - filter: 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]"; @@ -108,18 +121,49 @@ mkdru.pz2Status = function (data) { $('.mkdru-status').html(Drupal.theme('mkdruStatus', data.activeclients, data.clients)); }; +mkdru.contains = function (hash, key, value) { + if (hash[key]) { + if (hash[key].length) { + for (var i=0; i 0) ? mkdru.state.page - mkdru.pagerRange : 1; var last = first + 2 * mkdru.pagerRange < total - ? first + 2 * mkdru.pagerRange : total; + ? first + 2 * mkdru.pagerRange : total; var prev = null; var next = null; var pages = []; @@ -305,7 +401,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, @@ -324,15 +420,43 @@ $(document).ready(function () { // ting thing if (typeof(Drupal.settings.mkdru.query) !== "undefined") { mkdru.state.query = Drupal.settings.mkdru.query + //force the hash to contain query + mkdru.hashFromState(); } + //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);