var App_SiteChange = { sendChangeRequest: function(form) { $.blockUI({message: '

Redirect to site...

'}); this._isAuthorized(form); }, _isAuthorized: function(form) { var data = { action: 'isAuthorized' }; var obj = this; $.getJSON($(form).find('#' + $(form).attr('id') + '-site').val() + '/admin/__changeSite?jsoncallback=?', data, function(data) { if (data.success) { window.location = $(form).find('#' + $(form).attr('id') + '-site').val() + '/admin'; } else { obj._ajaxRequest($(form).attr('action'), $(form).serialize(), function(data) { if (data.success) { obj._loginRequest($(form).find('#' + $(form).attr('id') + '-site').val(), data.success); } else { $('.blockMsg').children('h1').html('Error authorization in site'); setTimeout(function() { $.unblockUI(); }, 2000); } }, true); } }); }, _loginRequest: function(url, code) { var data = { action: 'siteChangeLogin', code: code }; $.getJSON(url + '/admin/__changeSite?jsoncallback=?', data, function(data) { if (data.success) { window.location = url + '/admin'; } }); }, _ajaxRequest: function(url, data, successCallback) { var options = { url: url, data: data, dataType: 'json', type: 'POST', success: function(data) { successCallback(data); } }; $.ajax(options); } };