-
-
+
+
Categories
@@ -122,6 +122,8 @@
Details
+
+
diff --git a/src/assets/css/backend.css b/src/assets/css/backend.css
index 9495fe63..139fe332 100644
--- a/src/assets/css/backend.css
+++ b/src/assets/css/backend.css
@@ -92,6 +92,11 @@ root {
#services-page .details select,
#services-page .details textarea { background-color: white; cursor: pointer; }
+#services-page #categories .category-row { padding: 10px 7px; border-radius: 3px; }
+#services-page #categories .category-row:hover { background-color: #C6E7D5; cursor: pointer; }
+
+
+
/* BACKEND PROVIDERS PAGE
-------------------------------------------------------------------- */
diff --git a/src/assets/js/backend_services.js b/src/assets/js/backend_services.js
index 6bb1ae0a..faa55e54 100644
--- a/src/assets/js/backend_services.js
+++ b/src/assets/js/backend_services.js
@@ -65,6 +65,10 @@ var BackendServices = {
$('#categories').show();
BackendServices.helper = new CategoriesHelper();
}
+
+ BackendServices.helper.resetForm();
+ BackendServices.helper.filter('');
+ $('.filter-key').val('');
});
/**
@@ -77,28 +81,63 @@ var BackendServices = {
BackendServices.helper.filter(key);
});
+ /**
+ * Event: Filter Categories Button "Click"
+ */
+ $('.filter-categories').click(function() {
+ var key = $('#categories .filter-key').val();
+ $('.selected-row').removeClass('selected-row');
+ BackendServices.helper.resetForm();
+ BackendServices.helper.filter(key);
+ });
+
/**
* Event: Filter Service Row "Click"
*
* Display the selected service data to the user.
*/
$(document).on('click', '.service-row', function() {
- var service = { 'id': $(this).attr('data-id') };
+ if ($('#services .filter-services').prop('disabled')) {
+ $('#services .filter-results').css('color', '#AAA');
+ return; // exit because we are on edit mode
+ }
+ var service = { 'id': $(this).attr('data-id') };
$.each(BackendServices.helper.filterResults, function(index, item) {
if (item.id === service.id) {
service = item;
return;
}
});
-
BackendServices.helper.display(service);
-
$('.selected-row').removeClass('selected-row');
$(this).addClass('selected-row');
$('#edit-service, #delete-service').prop('disabled', false);
});
+ /**
+ * Event: Filter Categories Row "Click"
+ *
+ * Displays the selected row data on the right side of the page.
+ */
+ $(document).on('click', '.category-row', function() {
+ if ($('#categories .filter-categories').prop('disabled')) {
+ $('#categories .filter-results').css('color', '#AAA');
+ return; // exit because we are on edit mode
+ }
+ var category = { 'id': $(this).attr('data-id') };
+ $.each(BackendServices.helper.filterResults, function(index, item) {
+ if (item.id === category.id) {
+ category = item;
+ return;
+ }
+ });
+ BackendServices.helper.display(category);
+ $('.selected-row').removeClass('selected-row');
+ $(this).addClass('selected-row');
+ $('#edit-category, #delete-category').prop('disabled', false);
+ });
+
/**
* Event: Add New Service Button "Click"
*/
@@ -109,6 +148,20 @@ var BackendServices = {
$('#services .details').find('input, textarea').prop('readonly', false);
$('#services .details').find('select').prop('disabled', false);
$('#service-duration').spinner('enable');
+ $('#services .filter-services').prop('disabled', true);
+ $('#services .filter-results').css('color', '#AAA');
+ });
+
+ /**
+ * Event: Add Category Button "Click"
+ */
+ $('#add-category').click(function() {
+ BackendServices.helper.resetForm();
+ $('#categories .add-edit-delete-group').hide();
+ $('#categories .save-cancel-group').show();
+ $('#categories .details').find('input, textarea').prop('readonly', false);
+ $('#categories .filter-categories').prop('disabled', true);
+ $('#categories .filter-results').css('color', '#AAA');
});
/**
@@ -120,6 +173,13 @@ var BackendServices = {
BackendServices.helper.resetForm();
});
+ /**
+ * Event: Cancel Category Button "Click"
+ */
+ $('#cancel-category').click(function() {
+ BackendServices.helper.resetForm();
+ });
+
/**
* Event: Save Service Button "Click"
*/
@@ -147,6 +207,24 @@ var BackendServices = {
BackendServices.helper.save(service);
});
+ /**
+ * Event: Categories Save Button "Click"
+ */
+ $('#save-category').click(function() {
+ var category = {
+ 'name': $('#category-name').val(),
+ 'description': $('#category-description').val()
+ };
+
+ if ($('#category-id').val() !== '') {
+ category.id = $('#category-id').val();
+ }
+
+ if (!BackendServices.helper.validate(category)) return;
+
+ BackendServices.helper.save(category);
+ });
+
/**
* Event: Edit Service Button "Click"
*/
@@ -154,12 +232,23 @@ var BackendServices = {
$('#services .add-edit-delete-group').hide();
$('#services .save-cancel-group').show();
$('.filter-services').prop('disabled', true);
-
+ $('#services .filter-results').css('color', '#AAA');
$('#services .details').find('input, textarea').prop('readonly', false);
$('#services .details select').prop('disabled', false);
$('#service-duration').spinner('enable');
});
+ /**
+ * Event: Edit Category Button "Click"
+ */
+ $('#edit-category').click(function() {
+ $('#categories .add-edit-delete-group').hide();
+ $('#categories .save-cancel-group').show();
+ $('.filter-categories').prop('disabled', true);
+ $('#categories .filter-results').css('color', '#AAA');
+ $('#categories .details').find('input, textarea').prop('readonly', false);
+ });
+
/**
* Event: Delete Service Button "Click"
*/
@@ -179,6 +268,23 @@ var BackendServices = {
GeneralFunctions.displayMessageBox('Delete Service', 'Are you sure that you want '
+ 'to delete this record? This action cannot be undone.', messageBtns);
});
+
+ $('#delete-category').click(function() {
+ var categoryId = $('#category-id').val();
+
+ var messageBtns = {
+ 'Delete': function() {
+ BackendServices.helper.delete(categoryId);
+ $('#message_box').dialog('close');
+ },
+ 'Cancel': function() {
+ $('#message_box').dialog('close');
+ }
+ };
+
+ GeneralFunctions.displayMessageBox('Delete Category', 'Are you sure that you want '
+ + 'to delete this record? This action cannot be undone.', messageBtns);
+ });
}
};
@@ -226,10 +332,10 @@ ServicesHelper.prototype.delete = function(id) {
if (!Backend.handleAjaxExceptions(response)) return;
- Backend.displayNotification('Services deleted successfully!');
+ Backend.displayNotification('Service deleted successfully!');
BackendServices.helper.resetForm();
- BackendServices.helper.filter($('.filter-services').val());
+ BackendServices.helper.filter($('#services .filter-key').val());
});
};
@@ -273,6 +379,7 @@ ServicesHelper.prototype.resetForm = function() {
$('#services .details').find('input, textarea').prop('readonly', true);
$('#service-category').prop('disabled', true);
$('.filter-services').prop('disabled', false);
+ $('#services .filter-results').css('color', '');
};
/**
@@ -351,7 +458,7 @@ var CategoriesHelper = function() {
* @param {string} key This key string is used to filter the category records.
*/
CategoriesHelper.prototype.filter = function(key) {
- var postUrl = GlobalVariables.baseUrl + 'backend_api/ajax_filter_categories';
+ var postUrl = GlobalVariables.baseUrl + 'backend_api/ajax_filter_service_categories';
var postData = { 'key': key };
$.post(postUrl, postData, function(response) {
@@ -361,6 +468,7 @@ CategoriesHelper.prototype.filter = function(key) {
if (!Backend.handleAjaxExceptions(response)) return;
+ BackendServices.helper.filterResults = response;
$('#categories .filter-results').html('');
$.each(response, function(index, category) {
var html = BackendServices.helper.getFilterHtml(category);
@@ -376,7 +484,20 @@ CategoriesHelper.prototype.filter = function(key) {
* @param {object} category Contains the category data.
*/
CategoriesHelper.prototype.save = function(category) {
+ var postUrl = GlobalVariables.baseUrl + 'backend_api/ajax_save_service_category';
+ var postData = { 'category': JSON.stringify(category) };
+ $.post(postUrl, postData, function(response) {
+ ///////////////////////////////////////////////////////////
+ console.log('Save Service Category Response:', response);
+ ///////////////////////////////////////////////////////////
+
+ if (!Backend.handleAjaxExceptions(response)) return;
+
+ Backend.displayNotification('Service saved successfully!');
+ BackendServices.helper.resetForm();
+ BackendServices.helper.filter($('#categories .filter-key').val());
+ });
};
/**
@@ -385,7 +506,21 @@ CategoriesHelper.prototype.save = function(category) {
* @param {int} id Record id to be deleted.
*/
CategoriesHelper.prototype.delete = function(id) {
+ var postUrl = GlobalVariables.baseUrl + 'backend_api/ajax_delete_service_category';
+ var postData = { 'category_id': id };
+ $.post(postUrl, postData, function(response) {
+ ////////////////////////////////////////////////////
+ console.log('Delete category response:', response);
+ ////////////////////////////////////////////////////
+
+ if (!Backend.handleAjaxExceptions(response)) return;
+
+ Backend.displayNotification('Category deleted successfully!');
+
+ BackendServices.helper.resetForm();
+ BackendServices.helper.filter($('#categories .filter-key').val());
+ });
};
/**
@@ -394,7 +529,9 @@ CategoriesHelper.prototype.delete = function(id) {
* @param {object} category Contains the category data.
*/
CategoriesHelper.prototype.display = function(category) {
-
+ $('#category-id').val(category.id);
+ $('#category-name').val(category.name);
+ $('#category-description').val(category.description);
};
/**
@@ -403,14 +540,37 @@ CategoriesHelper.prototype.display = function(category) {
* @param {object} category Contains the category data.
*/
CategoriesHelper.prototype.validate = function(category) {
+ $('#categories .details').find('input, textarea').css('border', '');
+ try {
+ var missingRequired = false;
+ $('#categories .required').each(function() {
+ if ($(this).val() == '' || $(this).val() == undefined) {
+ $(this).css('border', '2px solid red');
+ missingRequired = true;
+ }
+ });
+ if (missingRequired) throw 'Required field is missing.';
+
+ return true;
+
+ } catch(exc) {
+ console.log('Category Record Validation Exc:', exc);
+ return false;
+ }
};
/**
* Bring the category form back to its initial state.
*/
CategoriesHelper.prototype.resetForm = function() {
-
+ $('#categories .add-edit-delete-group').show();
+ $('#categories .save-cancel-group').hide();
+ $('#categories .details').find('input, textarea').val('');
+ $('#categories .details').find('input, textarea').prop('readonly', true);
+ $('#edit-category, #delete-category').prop('disabled', true);
+ $('#categories .filter-results').css('color', '');
+ $('#categories .filter-categories').prop('disabled', false);
};
/**
@@ -419,10 +579,10 @@ CategoriesHelper.prototype.resetForm = function() {
* @param {object} category Contains the category data.
* @return {string} Returns the record html code.
*/
-CategoriesHelper.prototype.getFilterHtml = function(category) {
+CategoriesHelper.prototype.getFilterHtml = function(category) {
var html =
'
' +
- '' + category.name + '' +
+ '' + category.name + '' +
'
';
return html;