Created
July 24, 2015 13:17
-
-
Save acmisiti/4621d01b14d448690e85 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TCB.EmployiiMainRouter = Backbone.Router.extend({ | |
/* This is the main router in which everything will eventually go through */ | |
routes : { | |
}, | |
init: function(options) { | |
this.ajax = {}; | |
this.ajax['rapid'] = $.manageAjax.create('rapid', {queue: false}); | |
this.ajax['queue'] = $.manageAjax.create('queue', {queue: true}); | |
this.ajax['queue_clear'] = $.manageAjax.create('queue_clear', {queue: 'clear'}); | |
$.ajaxSettings.traditional = true; | |
}, | |
validate_form : function( formID ) { | |
var valid = $(formID).validate().form(); | |
if(!valid){ | |
$('.modal').modal('hide'); | |
} | |
return function() { return $(formID).validate().form(); } | |
}, | |
make_request: function(url, data, callback, error_callback, options) { | |
var self = this; | |
var options = $.extend({ | |
'ajax_group': 'rapid', | |
'traditional': true, | |
'domSuccessTrigger': true, | |
'preventDoubleRequests': false | |
}, options); | |
var request_type = options.request_type || 'POST'; | |
var clear_queue = false; | |
this.ajax[options['ajax_group']].add(_.extend({ | |
url: url, | |
data: data, | |
type: request_type, | |
cache: false, | |
cacheResponse: false, | |
beforeSend: function() { | |
$.isFunction(options['beforeSend']) && options['beforeSend'](); | |
return true; | |
}, | |
success: function(o) { | |
if (o && o.code < 0 && error_callback) { | |
error_callback(o); | |
} else if ($.isFunction(callback)) { | |
callback(o); | |
} | |
}, | |
error: function(e, textStatus, errorThrown) { | |
if (errorThrown == 'abort') { | |
return; | |
} | |
TCB.log(['AJAX Uploader Error', e, e.status, textStatus, errorThrown, | |
!!error_callback, error_callback, $.isFunction(callback)]); | |
if (error_callback) { | |
error_callback(e, textStatus, errorThrown); | |
} else if ($.isFunction(callback)) { | |
var message = "Please create an account. Not much to do without an account."; | |
if (TCB.Globals.is_authenticated) { | |
message = "Sorry, there was an unhandled error."; | |
} | |
callback({'message': message, status_code: e.status}); | |
} | |
} | |
}, options)); | |
}, | |
}); | |
$(document).ready(function() { | |
// intialize router globally | |
TCB.router = new TCB.EmployiiMainRouter() | |
TCB.router.init(); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment