mirror of
https://github.com/alextselegidis/easyappointments.git
synced 2024-12-22 22:52:35 +03:00
Added ajax failure handler to jquery post requests.
This commit is contained in:
parent
daa4d28a6e
commit
a24597ba4d
10 changed files with 743 additions and 722 deletions
|
@ -444,7 +444,7 @@ var BackendCalendar = {
|
|||
|
||||
// Refresh calendar event items.
|
||||
$('#select-filter-item').trigger('change');
|
||||
}, 'json');
|
||||
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
};
|
||||
|
||||
messageButtons[EALang['cancel']] = function() {
|
||||
|
@ -486,7 +486,7 @@ var BackendCalendar = {
|
|||
|
||||
// Refresh calendar event items.
|
||||
$('#select-filter-item').trigger('change');
|
||||
}, 'json');
|
||||
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -740,7 +740,7 @@ var BackendCalendar = {
|
|||
|
||||
$('#select-google-calendar').modal('show');
|
||||
|
||||
}, 'json');
|
||||
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
}
|
||||
}
|
||||
}, 100);
|
||||
|
@ -970,7 +970,7 @@ var BackendCalendar = {
|
|||
if (!GeneralFunctions.handleAjaxExceptions(response)) return;
|
||||
Backend.displayNotification(EALang['google_calendar_selected']);
|
||||
$('#select-google-calendar').modal('hide');
|
||||
});
|
||||
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
});
|
||||
|
||||
/**
|
||||
|
@ -1038,7 +1038,7 @@ var BackendCalendar = {
|
|||
};
|
||||
|
||||
calendarEvents.push(event);
|
||||
});
|
||||
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
|
||||
$calendar.fullCalendar('removeEvents');
|
||||
$calendar.fullCalendar('addEventSource', calendarEvents);
|
||||
|
@ -1403,7 +1403,7 @@ var BackendCalendar = {
|
|||
$.post(postUrl, postData, function(response) {
|
||||
$('#notification').hide('blind');
|
||||
revertFunc();
|
||||
});
|
||||
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
};
|
||||
|
||||
Backend.displayNotification(EALang['appointment_updated'], [
|
||||
|
@ -1459,7 +1459,7 @@ var BackendCalendar = {
|
|||
$.post(postUrl, postData, function(response) {
|
||||
$('#notification').hide('blind');
|
||||
revertFunc();
|
||||
});
|
||||
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
};
|
||||
|
||||
Backend.displayNotification(EALang['unavailable_updated'], [
|
||||
|
@ -1686,7 +1686,7 @@ var BackendCalendar = {
|
|||
$.post(postUrl, postData, function(response) {
|
||||
$('#notification').hide('blind');
|
||||
revertFunc();
|
||||
});
|
||||
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
};
|
||||
|
||||
Backend.displayNotification(EALang['appointment_updated'], [
|
||||
|
@ -1751,7 +1751,7 @@ var BackendCalendar = {
|
|||
$.post(postUrl, postData, function(response) {
|
||||
$('#notification').hide('blind');
|
||||
revertFunc();
|
||||
});
|
||||
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
};
|
||||
|
||||
Backend.displayNotification(EALang['unavailable_updated'], [
|
||||
|
@ -1823,7 +1823,7 @@ var BackendCalendar = {
|
|||
$('#message_box').append(GeneralFunctions.exceptionsToHtml(response.exceptions));
|
||||
return;
|
||||
}
|
||||
}, 'json');
|
||||
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -243,7 +243,7 @@ CustomersHelper.prototype.save = function(customer) {
|
|||
BackendCustomers.helper.resetForm();
|
||||
$('#filter-customers .key').val('');
|
||||
BackendCustomers.helper.filter('', response.id, true);
|
||||
}, 'json');
|
||||
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -268,7 +268,7 @@ CustomersHelper.prototype.delete = function(id) {
|
|||
Backend.displayNotification(EALang['customer_deleted']);
|
||||
BackendCustomers.helper.resetForm();
|
||||
BackendCustomers.helper.filter($('#filter-customers .key').val());
|
||||
}, 'json');
|
||||
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -405,7 +405,7 @@ CustomersHelper.prototype.filter = function(key, selectId, display) {
|
|||
BackendCustomers.helper.select(selectId, display);
|
||||
}
|
||||
|
||||
}, 'json');
|
||||
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -114,7 +114,7 @@ var BackendServices = {
|
|||
$select.append(option);
|
||||
});
|
||||
$select.append(new Option('- ' + EALang['no_category'] + ' -', null)).val('null');
|
||||
}, 'json');
|
||||
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -289,7 +289,7 @@ ServicesHelper.prototype.save = function(service) {
|
|||
BackendServices.helper.resetForm();
|
||||
$('#filter-services .key').val('');
|
||||
BackendServices.helper.filter('', response.id, true);
|
||||
}, 'json');
|
||||
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -315,7 +315,7 @@ ServicesHelper.prototype.delete = function(id) {
|
|||
|
||||
BackendServices.helper.resetForm();
|
||||
BackendServices.helper.filter($('#filter-services .key').val());
|
||||
}, 'json');
|
||||
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -424,7 +424,7 @@ ServicesHelper.prototype.filter = function(key, selectId, display) {
|
|||
if (selectId != undefined) {
|
||||
BackendServices.helper.select(selectId, display);
|
||||
}
|
||||
}, 'json');
|
||||
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -648,7 +648,7 @@ CategoriesHelper.prototype.filter = function(key, selectId, display) {
|
|||
BackendServices.helper.select(selectId, display);
|
||||
}
|
||||
|
||||
}, 'json');
|
||||
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -675,7 +675,7 @@ CategoriesHelper.prototype.save = function(category) {
|
|||
$('#filter-categories .key').val('');
|
||||
BackendServices.helper.filter('', response.id, true);
|
||||
BackendServices.updateAvailableCategories();
|
||||
}, 'json');
|
||||
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -702,7 +702,7 @@ CategoriesHelper.prototype.delete = function(id) {
|
|||
BackendServices.helper.resetForm();
|
||||
BackendServices.helper.filter($('#filter-categories .key').val());
|
||||
BackendServices.updateAvailableCategories();
|
||||
}, 'json');
|
||||
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -199,7 +199,7 @@ var BackendSettings = {
|
|||
$input.css('border', '');
|
||||
$input.attr('already-exists', 'false');
|
||||
}
|
||||
}, 'json');
|
||||
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
@ -242,7 +242,7 @@ SystemSettings.prototype.save = function(settings) {
|
|||
BackendSettings.wp.setup(workingPlan);
|
||||
BackendSettings.wp.timepickers(false);
|
||||
|
||||
}, 'json');
|
||||
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -377,7 +377,7 @@ UserSettings.prototype.save = function(settings) {
|
|||
// Update footer greetings.
|
||||
$('#footer-user-display-name').text('Hello, ' + $('#first-name').val() + ' ' + $('#last-name').val() + '!');
|
||||
|
||||
}, 'json');
|
||||
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -159,7 +159,7 @@ var BackendUsers = {
|
|||
|
||||
$('#secretary-providers input[type="checkbox"]').prop('disabled', true);
|
||||
$('#secretary-providers').jScrollPane({ mouseWheelSpeed: 70 });
|
||||
}, 'json');
|
||||
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
}
|
||||
|
||||
BackendUsers.helper.resetForm();
|
||||
|
@ -204,7 +204,7 @@ var BackendUsers = {
|
|||
$input.parents().eq(3).find('.form-message').hide();
|
||||
}
|
||||
}
|
||||
}, 'json');
|
||||
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
});
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
|
|
@ -194,7 +194,7 @@ AdminsHelper.prototype.save = function(admin) {
|
|||
BackendUsers.helper.resetForm();
|
||||
$('#filter-admins .key').val('');
|
||||
BackendUsers.helper.filter('', response.id, true);
|
||||
}, 'json');
|
||||
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -217,7 +217,7 @@ AdminsHelper.prototype.delete = function(id) {
|
|||
Backend.displayNotification(EALang['admin_deleted']);
|
||||
BackendUsers.helper.resetForm();
|
||||
BackendUsers.helper.filter($('#filter-admins .key').val());
|
||||
}, 'json');
|
||||
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -364,7 +364,7 @@ AdminsHelper.prototype.filter = function(key, selectId, display) {
|
|||
if (selectId != undefined) {
|
||||
BackendUsers.helper.select(selectId, display);
|
||||
}
|
||||
}, 'json');
|
||||
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -245,7 +245,7 @@ ProvidersHelper.prototype.save = function(provider) {
|
|||
BackendUsers.helper.resetForm();
|
||||
$('#filter-providers .key').val('');
|
||||
BackendUsers.helper.filter('', response.id, true);
|
||||
}, 'json');
|
||||
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -268,7 +268,7 @@ ProvidersHelper.prototype.delete = function(id) {
|
|||
Backend.displayNotification(EALang['provider_deleted']);
|
||||
BackendUsers.helper.resetForm();
|
||||
BackendUsers.helper.filter($('#filter-providers .key').val());
|
||||
}, 'json');
|
||||
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -441,7 +441,7 @@ ProvidersHelper.prototype.filter = function(key, selectId, display) {
|
|||
if (selectId != undefined) {
|
||||
BackendUsers.helper.select(selectId, display);
|
||||
}
|
||||
}, 'json');
|
||||
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -205,7 +205,7 @@ SecretariesHelper.prototype.save = function(secretary) {
|
|||
BackendUsers.helper.resetForm();
|
||||
$('#filter-secretaries .key').val('');
|
||||
BackendUsers.helper.filter('', response.id, true);
|
||||
}, 'json');
|
||||
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -228,7 +228,7 @@ SecretariesHelper.prototype.delete = function(id) {
|
|||
Backend.displayNotification(EALang['secretary_deleted']);
|
||||
BackendUsers.helper.resetForm();
|
||||
BackendUsers.helper.filter($('#filter-secretaries .key').val());
|
||||
}, 'json');
|
||||
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -385,7 +385,7 @@ SecretariesHelper.prototype.filter = function(key, selectId, display) {
|
|||
if (selectId != undefined) {
|
||||
BackendUsers.helper.select(selectId, display);
|
||||
}
|
||||
}, 'json');
|
||||
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -292,7 +292,7 @@ var FrontendBook = {
|
|||
+ 'another hour.');
|
||||
FrontendBook.getAvailableHours($('#select-date').val());
|
||||
}
|
||||
}, 'json');
|
||||
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
});
|
||||
},
|
||||
|
||||
|
@ -320,6 +320,9 @@ var FrontendBook = {
|
|||
var appointmentId = (FrontendBook.manageMode)
|
||||
? GlobalVariables.appointmentData['id'] : undefined;
|
||||
|
||||
// Make ajax post request and get the available hours.
|
||||
var postUrl = GlobalVariables.baseUrl + '/index.php/appointments/ajax_get_available_hours';
|
||||
|
||||
var postData = {
|
||||
'csrfToken': GlobalVariables.csrfToken,
|
||||
'service_id': $('#select-service').val(),
|
||||
|
@ -330,9 +333,7 @@ var FrontendBook = {
|
|||
'appointment_id': appointmentId
|
||||
};
|
||||
|
||||
// Make ajax post request and get the available hours.
|
||||
var ajaxurl = GlobalVariables.baseUrl + '/index.php/appointments/ajax_get_available_hours';
|
||||
$.post(ajaxurl, postData, function(response) {
|
||||
$.post(postUrl, postData, function(response) {
|
||||
///////////////////////////////////////////////////////////////
|
||||
console.log('Get Available Hours JSON Response:', response);
|
||||
///////////////////////////////////////////////////////////////
|
||||
|
@ -373,7 +374,7 @@ var FrontendBook = {
|
|||
} else {
|
||||
$('#available-hours').text(EALang['no_available_hours']);
|
||||
}
|
||||
}, 'json');
|
||||
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -331,7 +331,27 @@ var GeneralFunctions = {
|
|||
if (!GeneralFunctions.handleAjaxExceptions(response)) return;
|
||||
document.location.reload(true);
|
||||
|
||||
}, 'json');
|
||||
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Use this method for common error handling between
|
||||
*
|
||||
* @param {object} jqxhr
|
||||
* @param {string} textStatus
|
||||
* @param {object} errorThrown
|
||||
*/
|
||||
ajaxFailureHandler: function(jqxhr, textStatus, errorThrown) {
|
||||
var exceptions = [
|
||||
{
|
||||
message: 'AJAX Error: ' + textStatus
|
||||
}
|
||||
];
|
||||
|
||||
console.log('AJAX Failure Handler:', jqxhr, textStatus, errorThrown);
|
||||
GeneralFunctions.displayMessageBox(GeneralFunctions.EXCEPTIONS_TITLE,
|
||||
GeneralFunctions.EXCEPTIONS_MESSAGE);
|
||||
$('#message_box').append(GeneralFunctions.exceptionsToHtml(exceptions));
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue