From 2dd4a48631ecb284f5318e17314d34f24f364f6f Mon Sep 17 00:00:00 2001 From: "alextselegidis@gmail.com" Date: Fri, 19 Jul 2013 15:29:59 +0000 Subject: [PATCH] * Finished with managing service categories (backend services page) --- src/application/controllers/backend_api.php | 43 ++++- src/application/views/backend/services.php | 10 +- src/assets/css/backend.css | 5 + src/assets/js/backend_services.js | 182 ++++++++++++++++++-- 4 files changed, 220 insertions(+), 20 deletions(-) diff --git a/src/application/controllers/backend_api.php b/src/application/controllers/backend_api.php index 0b1f95d1..9c52cd5c 100644 --- a/src/application/controllers/backend_api.php +++ b/src/application/controllers/backend_api.php @@ -1,7 +1,7 @@ load->model('services_model'); @@ -499,6 +504,11 @@ class Backend_api extends CI_Controller { } } + /** + * [AJAX] Delete service record from database. + * + * @param numeric $_POST['service_id'] Record id to be deleted. + */ public function ajax_delete_service() { try { $this->load->model('services_model'); @@ -511,6 +521,12 @@ class Backend_api extends CI_Controller { } } + /** + * [AJAX] Filter service records by given key string. + * + * @param string $_POST['key'] Key string used to filter the records. + * @return array Returns a json encoded array back to client. + */ public function ajax_filter_services() { try { $this->load->model('services_model'); @@ -528,6 +544,12 @@ class Backend_api extends CI_Controller { } } + /** + * [AJAX] Save (insert or update) category record. + * + * @param array $_POST['category'] Json encoded array with the category data. If an id + * value is provided then the category is going to be udpated instead of inserted. + */ public function ajax_save_service_category() { try { $this->load->model('services_model'); @@ -541,10 +563,15 @@ class Backend_api extends CI_Controller { } } + /** + * [AJAX] Delete category record from database. + * + * @param numeric $_POST['category_id'] Record id to be deleted. + */ public function ajax_delete_service_category() { try { $this->load->model('services_model'); - $result = $this->services_model->delete($_POST['category_id']); + $result = $this->services_model->delete_category($_POST['category_id']); echo ($result) ? json_encode(AJAX_SUCCESS) : json_encode(AJAX_FAILURE); } catch(Exception $exc) { echo json_encode(array( @@ -553,12 +580,18 @@ class Backend_api extends CI_Controller { } } + /** + * [AJAX] Filter services categories with key string. + * + * @param string $_POST['key'] The key string used to filter the records. + * @return array Returns a json encoded array back to client with the category records. + */ public function ajax_filter_service_categories() { try { $this->load->model('services_model'); $key = $_POST['key']; // @task sql injection $where = '(name LIKE "%' . $key . '%" OR description LIKE "%' . $key . '%")'; - $categories = $this->services_model->get_categories($where); + $categories = $this->services_model->get_all_categories($where); echo json_encode($categories); } catch(Exception $exc) { echo json_encode(array( diff --git a/src/application/views/backend/services.php b/src/application/views/backend/services.php index 64c83e1d..cdd364ba 100644 --- a/src/application/views/backend/services.php +++ b/src/application/views/backend/services.php @@ -64,10 +64,10 @@ - + - + @@ -87,8 +87,8 @@