X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=js%2Fpz2.js;h=55a92c7e27f0f8f9f392b8348bd3145ef35ea71d;hb=3677728f894c7296cbad739187c2991d00874479;hp=bfec8426096f5657ec2ed9148eb08dd2d7d6a699;hpb=2aceb532a6d1d78c662c309eb371f644111d0cb5;p=pazpar2-moved-to-github.git diff --git a/js/pz2.js b/js/pz2.js index bfec842..55a92c7 100644 --- a/js/pz2.js +++ b/js/pz2.js @@ -1,5 +1,5 @@ /* -** $Id: pz2.js,v 1.43 2007-07-02 20:55:07 adam Exp $ +** $Id: pz2.js,v 1.48 2007-07-18 13:40:56 adam Exp $ ** pz2.js - pazpar2's javascript client library. */ @@ -30,7 +30,7 @@ var pz2 = function(paramArray) { //supported pazpar2's protocol version __myself.suppProtoVer = '1'; - __myself.pz2String = paramArray.pazpar2path || "search.pz2"; + __myself.pz2String = paramArray.pazpar2path || "/pazpar2/search.pz2"; __myself.stylesheet = paramArray.detailstylesheet || null; __myself.useSessions = true; if (paramArray.usesessions != undefined) { @@ -40,13 +40,7 @@ var pz2 = function(paramArray) { //load stylesheet if required in async mode if( __myself.stylesheet ) { var request = new pzHttpRequest( __myself.stylesheet ); - request.async = false; - request.get( - [], - function ( doc ) { - __myself.xslDoc = doc; - } - ); + request.get( {}, function ( doc ) { __myself.xslDoc = doc; } ); } // at least one callback required @@ -352,8 +346,22 @@ pz2.prototype = } ); }, - record: function(id,offset) + record: function(id,offset, params) { + if ( params == undefined ) + params = {}; + + if ( params.callback != undefined ) { + callback = params.callback; + } else { + callback = __myself.recordCallback; + } + + if ( params['handle'] == undefined ) + handle = {}; + else + handle = params['handle']; + if( !__myself.searchStatusOK && __myself.useSessions) return; @@ -364,9 +372,12 @@ pz2.prototype = var recordParams = { "command": "record", "session": __myself.sessionID, "id": __myself.currRecID }; if (offset !== undefined) { recordParams["offset"] = offset; - recordParams["syntax"] = "usmarc"; - recordParams["esn"] = "F"; } + + if (params.syntax != undefined) { + recordParams['syntax'] = params.syntax; + } + __myself.currRecOffset = offset; request.get( recordParams, @@ -376,7 +387,7 @@ pz2.prototype = record['xmlDoc'] = data; if (__myself.currRecOffset !== undefined) { record['offset'] = __myself.currRecOffset; - __myself.recordCallback(record); + callback(record, handle); } else if ( recordNode = data.getElementsByTagName("record")[0] ) { // if stylesheet was fetched do not parse the response if ( __myself.xslDoc ) { @@ -412,7 +423,7 @@ pz2.prototype = } } - __myself.recordCallback(record); + callback(record, handle); } else // if it gets here the http return code was 200 (pz2 errors are 417) @@ -558,7 +569,7 @@ pzHttpRequest.prototype = { get: function ( params, callback ) { - this._send( 'GET', params, null, callback ); + this._send( 'GET', params, '', callback ); }, post: function ( params, data, callback ) @@ -566,12 +577,21 @@ pzHttpRequest.prototype = this._send( 'POST', params, data, callback ); }, + load: function () + { + this.async = false; + this.request.open( 'GET', this.url, this.async ); + this.request.send(''); + if ( this.request.status == 200 ) + return this.request.responseXML; + }, + _send: function ( type, params, data, callback ) { this.callback = callback; var context = this; + this.async = true; 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(); }