X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=js%2Fpz2.js;h=a9259948d16cf63891686c8b3bec7aa1976b02ed;hb=3a4c4cf2b436623060e1fb033b8f7cbf6b7c4d19;hp=0dc578db934a35c0ce5e586e44f1836cce35c19f;hpb=8c17e0ef3df38d2f7af3b6ac0afe18baa6c95774;p=pazpar2-moved-to-github.git diff --git a/js/pz2.js b/js/pz2.js index 0dc578d..a925994 100644 --- a/js/pz2.js +++ b/js/pz2.js @@ -1,5 +1,5 @@ /* -** $Id: pz2.js,v 1.19 2007-05-21 09:07:43 jakub Exp $ +** $Id: pz2.js,v 1.36 2007-06-13 17:25:02 jakub Exp $ ** pz2.js - pazpar2's javascript client library. */ @@ -109,7 +109,16 @@ var pz2 = function(paramArray) { if (paramArray.autoInit !== false) __myself.init(); }; -pz2.prototype = { +pz2.prototype = +{ + stop: function () + { + clearTimeout(__myself.statTimer); + clearTimeout(__myself.showTimer); + clearTimeout(__myself.termTimer); + clearTimeout(__myself.bytargetTimer); + }, + reset: function () { __myself.sessionID = null; @@ -117,10 +126,7 @@ pz2.prototype = { __myself.pingStatusOK = false; __myself.searchStatusOK = false; - clearTimeout(__myself.statTimer); - clearTimeout(__myself.showTimer); - clearTimeout(__myself.termTimer); - clearTimeout(__myself.bytargetTimer); + __myself.stop(); if ( __myself.resetCallback ) __myself.resetCallback(); @@ -314,7 +320,9 @@ pz2.prototype = { } else { var nodeName = hits[i].childNodes[j].nodeName; - var nodeText = hits[i].childNodes[j].firstChild.nodeValue; + var nodeText = 'ERROR' + if ( hits[i].childNodes[j].firstChild ) + nodeText = hits[i].childNodes[j].firstChild.nodeValue; show.hits[i][nodeName] = nodeText; } } @@ -352,6 +360,7 @@ pz2.prototype = { if ( recordNode = data.getElementsByTagName("record")[0] ) { // if stylesheet was fetched do not parse the response if ( __myself.xslDoc ) { + record['recid'] = recordNode.getElementsByTagName("recid")[0].firstChild.nodeValue; record['xmlDoc'] = data; record['xslDoc'] = __myself.xslDoc; } else { @@ -383,12 +392,13 @@ pz2.prototype = { } } } + __myself.recordCallback(record); } else // if it gets here the http return code was 200 (pz2 errors are 417) // but the response was invalid, it should never occur - setTimeout("__myself.record(__myself.currRecID)", 1000); + setTimeout("__myself.record(__myself.currRecID)", 500); } ); }, @@ -415,8 +425,10 @@ pz2.prototype = { //for each term in the list for (j = 0; j < terms.length; j++) { var term = { - "name": terms[j].getElementsByTagName("name")[0].childNodes[0].nodeValue, - "freq": terms[j].getElementsByTagName("frequency")[0].childNodes[0].nodeValue + "name": (terms[j].getElementsByTagName("name")[0].childNodes.length + ? terms[j].getElementsByTagName("name")[0].childNodes[0].nodeValue + : 'ERROR'), + "freq": terms[j].getElementsByTagName("frequency")[0].childNodes[0].nodeValue || 'ERROR' }; var termIdNode = terms[j].getElementsByTagName("id"); @@ -510,6 +522,7 @@ var pzHttpRequest = function ( url, errorHandler ) { this.request = null; this.url = url; this.errorHandler = errorHandler || null; + this.async = true; if ( window.XMLHttpRequest ) { this.request = new XMLHttpRequest(); @@ -526,24 +539,39 @@ pzHttpRequest.prototype = { get: function ( params, callback ) { + this._send( 'GET', params, null, callback ); + }, + + post: function ( params, data, callback ) + { + this._send( 'POST', params, data, callback ); + }, + + _send: function ( type, params, data, callback ) + { this.callback = callback; - + var context = this; + this.request.open( type, this._urlAppendParams(params), this.async ); + //this.request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); + this.request.onreadystatechange = function () { + context._handleResponse(); + } + this.request.send(data); + }, + + _urlAppendParams: function (params) + { var getUrl = this.url; var paramArr = new Array(); for ( var key in params ) { - paramArr.push(key + '=' + escape(params[key])); + paramArr.push(key + '=' + encodeURI(params[key]) ); } if ( paramArr.length ) getUrl += '?' + paramArr.join('&'); - var context = this; - this.request.open( 'GET', getUrl, true ); - this.request.onreadystatechange = function () { - context._handleResponse(); - } - this.request.send(null); + return getUrl; }, _handleResponse: function () @@ -606,6 +634,10 @@ pzQuery.prototype = { this.simpleFilter = null; this.numTerms = 0; }, + clearSimpleQuery: function() + { + this.simpleQuery = ''; + }, addTerm: function(field, value) { var term = {"field": field, "value": value}; @@ -650,7 +682,7 @@ pzQuery.prototype = { { var ccl = ''; if( this.simpleQuery != '') - ccl = '"'+this.simpleQuery+'"'; + ccl = this.simpleQuery; for(var i = 0; i < this.advTerms.length; i++) { if (ccl != '') ccl = ccl + ' and ';