/*
-** $Id: pz2.js,v 1.58 2007-09-27 09:15:48 sondberg Exp $
+** $Id: pz2.js,v 1.60 2007-10-02 10:33:18 jakub Exp $
** pz2.js - pazpar2's javascript client library.
*/
pz2.prototype =
{
+ //error handler for async error throws
+ throwError: function (errMsg, errCode)
+ {
+ var err = new Error(errMsg);
+ if (errCode) err.code = errCode;
+
+ if (__myself.errorHandler) {
+ __myself.errorHandler(err);
+ }
+ else {
+ throw err;
+ }
+ },
+
// stop activity by clearing tiemouts
stop: function ()
{
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.init()", 1000);
+ // setTimeout("__myself.init()", 1000);
+ __myself.throwError('Init failed. Malformed WS resonse.', 110);
}
);
// when through proxy no need to init
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.ping()", 1000);
+ // setTimeout("__myself.ping()", 1000);
+ __myself.throwError('Ping failed. Malformed WS resonse.', 111);
}
);
},
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.search(__myself.currQuery)", 500);
+ // setTimeout("__myself.search(__myself.currQuery)", 500);
+ __myself.throwError('Search failed. Malformed WS resonse.', 112);
}
);
},
else
// if it gets here the http return code was 200 (pz2 errors are 417)
// but the response was invalid, it should never occur
- __myself.statTimer = setTimeout("__myself.stat()", __myself.statTime / 4);
+ //__myself.statTimer = setTimeout("__myself.stat()", __myself.statTime / 4);
+ __myself.throwError('Stat failed. Malformed WS resonse.', 113);
}
);
},
else
// if it gets here the http return code was 200 (pz2 errors are 417)
// but the response was invalid, it should never occur
- __myself.showTimer = setTimeout("__myself.show()", __myself.showTime / 4);
+ // __myself.showTimer = setTimeout("__myself.show()", __myself.showTime / 4);
+ __myself.throwError('Show failed. Malformed WS resonse.', 114);
}
);
},
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)", 500);
+ // setTimeout("__myself.record(__myself.currRecID)", 500);
+ __myself.throwError('Record failed. Malformed WS resonse.', 115);
}
);
},
else
// if it gets here the http return code was 200 (pz2 errors are 417)
// but the response was invalid, it should never occur
- __myself.termTimer = setTimeout("__myself.termlist()", __myself.termTime / 4);
+ // __myself.termTimer = setTimeout("__myself.termlist()", __myself.termTime / 4);
+ __myself.throwError('Termlist failed. Malformed WS resonse.', 116);
}
);
else
// if it gets here the http return code was 200 (pz2 errors are 417)
// but the response was invalid, it should never occur
- __myself.bytargetTimer = setTimeout("__myself.bytarget()", __myself.bytargetTime / 4);
+ // __myself.bytargetTimer = setTimeout("__myself.bytarget()", __myself.bytargetTime / 4);
+ __myself.throwError('Bytarget failed. Malformed WS resonse.', 117);
}
);
},
}
}
-/*
-*********************************************************************************
-** QUERY CLASS ******************************************************************
-*********************************************************************************
-*/
-
-var pzFilter = function()
-{
- this.filterHash = new Array();
- this.filterNums = 0;
-};
-
-pzFilter.prototype =
-{
- addFilter: function(name, value)
- {
- var filter = {"name": name, "id": value };
- this.filterHash[this.filterHash.length] = filter;
- this.filterNums++
- return this.filterHash.length - 1;
- },
-
- setFilter: function(name, value)
- {
- this.filterHash = new Array();
- this.filterNums = 0;
- this.addFilter(name, value);
- },
-
- getFilter: function(index)
- {
- return this.filterHash[index].id;
- },
-
- getFilterName: function(index)
- {
- return this.filterHash[index].name;
- },
-
- removeFilter: function(index)
- {
- delete this.filterHash[index];
- this.filterNums--;
- },
-
- clearFilter: function()
- {
- this.filterHash = new Array();
- this.filterNums = 0;
- },
-
- getFilterString: function()
- {
- if( this.filterNums <= 0 ) {
- return undefined;
- }
-
- var filter = 'pz:id=';
- for(var i = 0; i < this.filterHash.length; i++)
- {
- if (this.filterHash[i] == undefined) continue;
- if (filter > 'pz:id=') filter = filter + '|';
- filter += this.filterHash[i].id;
- }
- return filter;
- }
-};
-
-var mkState = function()
-{
- this.sort = 'relevance';
- this.perPage = 20;
- this.page = 0;
- this.simpleQuery = '';
- this.singleFilter = null;
- this.advTerms = new Array();
- this.numTerms = 0;
- this.action = '';
-};
-
-mkState.prototype =
-{
- reset: function()
- {
- this.simpleQuery = '';
- this.advTerms = new Array();
- this.simpleFilter = null;
- this.numTerms = 0;
- },
-
- clearSimpleQuery: function()
- {
- this.simpleQuery = '';
- },
-
- addTerm: function(field, value)
- {
- var term = {"field": field, "value": value};
- this.advTerms[this.numTerms] = term;
- this.numTerms++;
- },
-
- getTermValueByIdx: function(index)
- {
- return this.advTerms[index].value;
- },
-
- getTermFieldByIdx: function(index)
- {
- return this.advTerms[index].field;
- },
-
- /* semicolon separated list of terms for given field*/
- getTermsByField: function(field)
- {
- var terms = '';
- for(var i = 0; i < this.advTerms.length; i++)
- {
- if( this.advTerms[i].field == field )
- terms = terms + this.queryHas[i].value + ';';
- }
- return terms;
- },
-
- addTermsFromList: function(inputString, field)
- {
- var inputArr = inputString.split(';');
- for(var i=0; i < inputArr.length; i++)
- {
- if(inputArr[i].length < 3) continue;
- this.advTerms[this.numTerms]
- = {"field": field, "value": inputArr[i] };
- this.numTerms++;
- }
- },
-
- removeTermByIdx: function(index)
- {
- this.advTerms.splice(index, 1);
- this.numTerms--;
- },
-
- toCCL: function()
- {
- var ccl = '';
- if( this.simpleQuery != '')
- ccl = this.simpleQuery;
- for(var i = 0; i < this.advTerms.length; i++)
- {
- if (ccl != '') ccl = ccl + ' and ';
- ccl = ccl + this.advTerms[i].field
- +'="'+this.advTerms[i].value+'"';
- }
- return ccl;
- },
-
- totalLength: function()
- {
- var simpleLength = this.simpleQuery != '' ? 1 : 0;
- return this.advTerms.length + simpleLength;
- },
-
- clearSingleFilter: function()
- {
- this.singleFilter = null;
- },
-
- setSingleFilter: function(name, value)
- {
- this.singleFilter = {"name": name, "id": value };
- },
-
- getSingleFilterName: function()
- {
- return this.singleFilter.name;
- },
-
- getSingleFilterString: function()
- {
- if( this.singleFilter != null ) {
- return 'pz:id='+this.singleFilter.id;
- } else {
- return undefined;
- }
- }
-};
}