Skip to content

Commit

Permalink
messing around with the ajax stuff to make autocomplete work better
Browse files Browse the repository at this point in the history
  • Loading branch information
ajanata committed Jan 13, 2012
1 parent 9e8c46e commit a7cc7c8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion WebContent/js/cah.ajax.builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ cah.ajax.Builder.prototype.withErrback = function(errback) {
*/
cah.ajax.Builder.prototype.run = function() {
this.data.serial = cah.ajax.Builder.serial++;
cah.Ajax.requestWithBuilder(this);
cah.Ajax.instance.requestWithBuilder(this);
};

/**
Expand Down
20 changes: 11 additions & 9 deletions WebContent/js/cah.ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* @author ajanata
*/

cah.Ajax = {};
cah.Ajax.instance = {};
cah.ajax = {};
cah.ajax.ErrorHandlers = {};
cah.ajax.SuccessHandlers = {};
Expand All @@ -14,7 +16,7 @@ cah.ajax.SuccessHandlers = {};
* @returns {cah.ajax.lib}
* @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
// we get results
this.pendingRequests = {};
Expand All @@ -26,12 +28,12 @@ $(document).ready(function() {
*
* @type {cah.ajax.lib}
*/
cah.Ajax = new cah.ajax.lib();
cah.Ajax.instance = new cah.Ajax();
$.ajaxSetup({
cache : false,
context : cah.Ajax,
error : cah.Ajax.error,
success : cah.Ajax.done,
context : cah.Ajax.instance,
error : cah.Ajax.instance.error,
success : cah.Ajax.instance.done,
timeout : cah.DEBUG ? undefined : 10 * 1000, // 10 second timeout for normal requests
type : 'POST',
url : '/cah/AjaxServlet'
Expand All @@ -47,7 +49,7 @@ $(document).ready(function() {
* @param {cah.ajax.Builder}
* builder Request builder containing data to use.
*/
cah.ajax.lib.prototype.requestWithBuilder = function(builder) {
cah.Ajax.prototype.requestWithBuilder = function(builder) {
var jqXHR = $.ajax({
data : builder.data
});
Expand All @@ -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
// and figure out which request it was so we can remove it from pending
debugger;
cah.log.error(textStatus);
};

cah.ajax.lib.prototype.done = function(data) {
cah.Ajax.prototype.done = function(data) {
cah.log.debug("ajax done", data);
if (data['error']) {
// TODO cancel any timers or whatever we may have, and disable interface
Expand Down Expand Up @@ -98,6 +100,6 @@ cah.ajax.lib.prototype.done = function(data) {
* op Operation code for 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);
};

0 comments on commit a7cc7c8

Please sign in to comment.