messing around with the ajax stuff to make autocomplete work better

This commit is contained in:
Andy Janata 2012-01-12 17:05:09 -08:00
parent 9e8c46ec2f
commit a7cc7c8d36
2 changed files with 12 additions and 10 deletions

View File

@ -55,7 +55,7 @@ cah.ajax.Builder.prototype.withErrback = function(errback) {
*/ */
cah.ajax.Builder.prototype.run = function() { cah.ajax.Builder.prototype.run = function() {
this.data.serial = cah.ajax.Builder.serial++; this.data.serial = cah.ajax.Builder.serial++;
cah.Ajax.requestWithBuilder(this); cah.Ajax.instance.requestWithBuilder(this);
}; };
/** /**

View File

@ -4,6 +4,8 @@
* @author ajanata * @author ajanata
*/ */
cah.Ajax = {};
cah.Ajax.instance = {};
cah.ajax = {}; cah.ajax = {};
cah.ajax.ErrorHandlers = {}; cah.ajax.ErrorHandlers = {};
cah.ajax.SuccessHandlers = {}; cah.ajax.SuccessHandlers = {};
@ -14,7 +16,7 @@ cah.ajax.SuccessHandlers = {};
* @returns {cah.ajax.lib} * @returns {cah.ajax.lib}
* @constructor * @constructor
*/ */
cah.ajax.lib = function() { cah.Ajax = function() {
// TODO run a timer to see if we have more than X pending requests and delay further ones until // TODO run a timer to see if we have more than X pending requests and delay further ones until
// we get results // we get results
this.pendingRequests = {}; this.pendingRequests = {};
@ -26,12 +28,12 @@ $(document).ready(function() {
* *
* @type {cah.ajax.lib} * @type {cah.ajax.lib}
*/ */
cah.Ajax = new cah.ajax.lib(); cah.Ajax.instance = new cah.Ajax();
$.ajaxSetup({ $.ajaxSetup({
cache : false, cache : false,
context : cah.Ajax, context : cah.Ajax.instance,
error : cah.Ajax.error, error : cah.Ajax.instance.error,
success : cah.Ajax.done, success : cah.Ajax.instance.done,
timeout : cah.DEBUG ? undefined : 10 * 1000, // 10 second timeout for normal requests timeout : cah.DEBUG ? undefined : 10 * 1000, // 10 second timeout for normal requests
type : 'POST', type : 'POST',
url : '/cah/AjaxServlet' url : '/cah/AjaxServlet'
@ -47,7 +49,7 @@ $(document).ready(function() {
* @param {cah.ajax.Builder} * @param {cah.ajax.Builder}
* builder Request builder containing data to use. * builder Request builder containing data to use.
*/ */
cah.ajax.lib.prototype.requestWithBuilder = function(builder) { cah.Ajax.prototype.requestWithBuilder = function(builder) {
var jqXHR = $.ajax({ var jqXHR = $.ajax({
data : builder.data data : builder.data
}); });
@ -58,14 +60,14 @@ cah.ajax.lib.prototype.requestWithBuilder = function(builder) {
} }
}; };
cah.ajax.lib.prototype.error = function(jqXHR, textStatus, errorThrown) { cah.Ajax.prototype.error = function(jqXHR, textStatus, errorThrown) {
// TODO deal with this somehow // TODO deal with this somehow
// and figure out which request it was so we can remove it from pending // and figure out which request it was so we can remove it from pending
debugger; debugger;
cah.log.error(textStatus); cah.log.error(textStatus);
}; };
cah.ajax.lib.prototype.done = function(data) { cah.Ajax.prototype.done = function(data) {
cah.log.debug("ajax done", data); cah.log.debug("ajax done", data);
if (data['error']) { if (data['error']) {
// TODO cancel any timers or whatever we may have, and disable interface // TODO cancel any timers or whatever we may have, and disable interface
@ -98,6 +100,6 @@ cah.ajax.lib.prototype.done = function(data) {
* op Operation code for the request. * op Operation code for the request.
* @returns {cah.ajax.Builder} Builder to create the request. * @returns {cah.ajax.Builder} Builder to create the request.
*/ */
cah.ajax.lib.prototype.build = function(op) { cah.Ajax.build = function(op) {
return new cah.ajax.Builder(op); return new cah.ajax.Builder(op);
}; };