2013-06-12 18:31:16 +03:00
|
|
|
/**
|
2013-07-03 20:27:00 +03:00
|
|
|
* Main javascript code for the backend of Easy!Appointments.
|
2013-06-12 18:31:16 +03:00
|
|
|
*/
|
|
|
|
$(document).ready(function() {
|
|
|
|
$(window).resize(function() {
|
2013-06-13 19:25:34 +03:00
|
|
|
Backend.placeFooterToBottom();
|
2013-06-12 18:31:16 +03:00
|
|
|
}).trigger('resize');
|
2013-06-28 17:23:17 +03:00
|
|
|
|
|
|
|
$(document).ajaxStart(function() {
|
|
|
|
$('#loading').show();
|
|
|
|
});
|
|
|
|
|
|
|
|
$(document).ajaxStop(function() {
|
|
|
|
$('#loading').hide();
|
|
|
|
});
|
2013-06-12 18:31:16 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
2013-06-13 19:25:34 +03:00
|
|
|
* This namespace contains functions that are used in the backend section of
|
|
|
|
* the applications.
|
|
|
|
*
|
|
|
|
* @namespace Backend
|
2013-06-12 18:31:16 +03:00
|
|
|
*/
|
2013-06-13 19:25:34 +03:00
|
|
|
var Backend = {
|
2013-07-09 17:46:48 +03:00
|
|
|
/**
|
|
|
|
* Backend Constants
|
|
|
|
*/
|
|
|
|
EXCEPTIONS_TITLE: 'Unexpected Issues',
|
|
|
|
EXCEPTIONS_MESSAGE: 'The operation could not complete due to unexpected issues. ',
|
|
|
|
WARNINGS_TITLE: 'Unexpected Warnings',
|
|
|
|
WARNINGS_MESSAGE: 'The operation completed but some warnings appeared. ',
|
2013-09-14 19:10:59 +03:00
|
|
|
DB_SLUG_ADMIN: 'admin',
|
|
|
|
DB_SLUG_PROVIDER: 'provider',
|
|
|
|
DB_SLUG_SECRETARY: 'secretary',
|
|
|
|
DB_SLUG_CUSTOMER: 'customer',
|
2013-07-09 17:46:48 +03:00
|
|
|
|
2013-06-13 19:25:34 +03:00
|
|
|
/**
|
|
|
|
* Place the backend footer always on the bottom of the page.
|
2013-09-18 19:36:29 +03:00
|
|
|
*
|
|
|
|
* @task Re-enable this method.
|
2013-06-13 19:25:34 +03:00
|
|
|
*/
|
|
|
|
placeFooterToBottom: function() {
|
2013-09-18 19:36:29 +03:00
|
|
|
// var $footer = $('#footer');
|
|
|
|
//
|
|
|
|
// if (window.innerHeight > $('body').height()) {
|
|
|
|
// $footer.css({
|
|
|
|
// 'position': 'absolute',
|
|
|
|
// 'width': '100%',
|
|
|
|
// 'bottom': '0px'
|
|
|
|
// });
|
|
|
|
// } else {
|
|
|
|
// $footer.css({
|
|
|
|
// 'position': 'static'
|
|
|
|
// });
|
|
|
|
// }
|
2013-06-18 19:06:34 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display backend notifications to user.
|
|
|
|
*
|
|
|
|
* Using this method you can display notifications to the use with custom
|
|
|
|
* messages. If the 'actions' array is provided then an action link will
|
|
|
|
* be displayed too.
|
|
|
|
*
|
|
|
|
* @param {string} message Notification message
|
|
|
|
* @param {array} actions An array with custom actions that will be available
|
|
|
|
* to the user. Every array item is an object that contains the 'label' and
|
|
|
|
* 'function' key values.
|
|
|
|
*/
|
|
|
|
displayNotification: function(message, actions) {
|
|
|
|
if (message === undefined) {
|
|
|
|
message = 'NO MESSAGE PROVIDED FOR THIS NOTIFICATION';
|
|
|
|
}
|
|
|
|
|
2013-07-15 10:32:19 +03:00
|
|
|
if (actions === undefined) {
|
|
|
|
actions = [];
|
|
|
|
}
|
|
|
|
|
2013-06-18 19:06:34 +03:00
|
|
|
var notificationHtml =
|
|
|
|
'<div class="notification alert">' +
|
|
|
|
'<strong>' + message + '</strong>';
|
|
|
|
|
|
|
|
$.each(actions, function(index, action) {
|
|
|
|
var actionId = action['label'].toLowerCase().replace(' ', '-');
|
|
|
|
notificationHtml += '<button id="' + actionId + '" class="btn">'
|
|
|
|
+ action['label'] + '</button>';
|
|
|
|
|
|
|
|
$(document).off('click', '#' + actionId);
|
|
|
|
$(document).on('click', '#' + actionId, action['function']);
|
|
|
|
});
|
|
|
|
|
2013-09-13 16:21:03 +03:00
|
|
|
notificationHtml += '<a class="close" data-dismiss="alert" href="#">×</a></div>';
|
2013-06-18 19:06:34 +03:00
|
|
|
|
|
|
|
$('#notification').html(notificationHtml);
|
|
|
|
$('#notification').show('blind');
|
2013-07-17 19:29:51 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* All backend js code has the same way of dislaying exceptions that are raised on the
|
|
|
|
* server during an ajax call.
|
|
|
|
*
|
|
|
|
* @param {object} response Contains the server response. If exceptions or warnings are
|
|
|
|
* found, user friendly messages are going to be displayed to the user.
|
|
|
|
* @returns {bool} Returns whether the the ajax callback should continue the execution or
|
|
|
|
* stop, due to critical server exceptions.
|
|
|
|
*/
|
|
|
|
handleAjaxExceptions: function(response) {
|
|
|
|
if (response.exceptions) {
|
|
|
|
response.exceptions = GeneralFunctions.parseExceptions(response.exceptions);
|
|
|
|
GeneralFunctions.displayMessageBox(Backend.EXCEPTIONS_TITLE, Backend.EXCEPTIONS_MESSAGE);
|
|
|
|
$('#message_box').append(GeneralFunctions.exceptionsToHtml(response.exceptions));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (response.warnings) {
|
|
|
|
response.warnings = GeneralFunctions.parseExceptions(response.warnings);
|
|
|
|
GeneralFunctions.displayMessageBox(Backend.WARNINGS_TITLE, Backend.WARNINGS_MESSAGE);
|
|
|
|
$('#message_box').append(GeneralFunctions.exceptionsToHtml(response.warnings));
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2013-06-12 18:31:16 +03:00
|
|
|
}
|
2013-06-18 19:06:34 +03:00
|
|
|
};
|