From 0cd45e275e6b760add6bb891f4d79c320c35fb7f Mon Sep 17 00:00:00 2001 From: jekkos Date: Fri, 15 Apr 2016 08:49:28 +0200 Subject: [PATCH] Enable bootstrap-tables for suppliers module (#293) Reuse generic manage view for suppliers and remove original one --- application/controllers/Suppliers.php | 42 +++++----- application/helpers/table_helper.php | 102 +++++++------------------ application/views/people/manage.php | 19 +---- application/views/suppliers/form.php | 2 +- application/views/suppliers/manage.php | 88 --------------------- 5 files changed, 51 insertions(+), 202 deletions(-) delete mode 100644 application/views/suppliers/manage.php diff --git a/application/controllers/Suppliers.php b/application/controllers/Suppliers.php index 7553a1349..5797e20bd 100644 --- a/application/controllers/Suppliers.php +++ b/application/controllers/Suppliers.php @@ -10,12 +10,9 @@ class Suppliers extends Person_controller function index($limit_from=0) { $data['controller_name'] = $this->get_controller_name(); - $lines_per_page = $this->Appconfig->get('lines_per_page'); - $suppliers = $this->Supplier->get_all($lines_per_page); - - $data['links'] = $this->_initialize_pagination($this->Supplier, $lines_per_page, $limit_from); - $data['manage_table'] = get_supplier_manage_table($suppliers, $this); - $this->load->view('suppliers/manage', $data); + $data['table_headers'] = get_suppliers_manage_table_headers(); + + $this->load->view('people/manage', $data); } /* @@ -23,16 +20,20 @@ class Suppliers extends Person_controller */ function search() { - $search = $this->input->post('search') != '' ? $this->input->post('search') : null; - $limit_from = $this->input->post('limit_from'); + $search = $this->input->get('search'); + $limit = $this->input->get('limit'); + $offset = $this->input->get('offset'); $lines_per_page = $this->Appconfig->get('lines_per_page'); - $suppliers = $this->Supplier->search($search, $lines_per_page, $limit_from); + $suppliers = $this->Supplier->search($search, $offset, $limit); $total_rows = $this->Supplier->get_found_rows($search); - $links = $this->_initialize_pagination($this->Supplier, $lines_per_page, $limit_from, $total_rows); - $data_rows = get_supplier_manage_table_data_rows($suppliers, $this); - - echo json_encode(array('total_rows' => $total_rows, 'rows' => $data_rows, 'pagination' => $links)); + $links = $this->_initialize_pagination($this->Employee, $lines_per_page, $limit, $total_rows); + $data_rows = array(); + foreach($suppliers->result() as $supplier) + { + $data_rows[] = get_supplier_data_row($supplier, $this); + } + echo json_encode(array('total' => $total_rows, 'rows' => $data_rows)); } /* @@ -89,18 +90,18 @@ class Suppliers extends Person_controller if($supplier_id==-1) { echo json_encode(array('success'=>true,'message'=>$this->lang->line('suppliers_successful_adding').' '. - $supplier_data['company_name'],'person_id'=>$supplier_data['person_id'])); + $supplier_data['company_name'],'id'=>$supplier_data['person_id'])); } else //previous supplier { echo json_encode(array('success'=>true,'message'=>$this->lang->line('suppliers_successful_updating').' '. - $supplier_data['company_name'],'person_id'=>$supplier_id)); + $supplier_data['company_name'],'id'=>$supplier_id)); } } else//failure { echo json_encode(array('success'=>false,'message'=>$this->lang->line('suppliers_error_adding_updating').' '. - $supplier_data['company_name'],'person_id'=>-1)); + $supplier_data['company_name'],'id'=>-1)); } } @@ -122,14 +123,5 @@ class Suppliers extends Person_controller } } - /* - Gets one row for a supplier manage table. This is called using AJAX to update one row. - */ - function get_row() - { - $person_id = $this->input->post('row_id'); - $data_row=get_supplier_data_row($this->Supplier->get_info($person_id),$this); - echo $data_row; - } } ?> \ No newline at end of file diff --git a/application/helpers/table_helper.php b/application/helpers/table_helper.php index c0c303d72..c140b84da 100644 --- a/application/helpers/table_helper.php +++ b/application/helpers/table_helper.php @@ -143,9 +143,6 @@ function transform_headers($array) }, $array)); } -/* -Gets the html table to manage people. -*/ function get_people_manage_table_headers() { $CI =& get_instance(); @@ -195,87 +192,46 @@ function get_detailed_data_row($row, $controller) return $table_data_row; } -/* -Gets the html table to manage suppliers. -*/ -function get_supplier_manage_table($suppliers,$controller) -{ - $CI =& get_instance(); - $table=''; - - $headers = array('', - $CI->lang->line('suppliers_company_name'), - $CI->lang->line('suppliers_agency_name'), - $CI->lang->line('common_last_name'), - $CI->lang->line('common_first_name'), - $CI->lang->line('common_email'), - $CI->lang->line('common_phone_number'), - $CI->lang->line('common_id'), - ' '); +function get_suppliers_manage_table_headers() if($CI->Employee->has_grant('messages', $CI->session->userdata('person_id'))) { $headers[] = ' '; } - - $table.=''; - foreach($headers as $header) - { - $table.=""; - } - $table.=''; - $table.=get_supplier_manage_table_data_rows($suppliers,$controller); - $table.='
$header
'; - - return $table; -} - -/* -Gets the html data rows for the supplier. -*/ -function get_supplier_manage_table_data_rows($suppliers,$controller) { $CI =& get_instance(); - $table_data_rows=''; - - foreach($suppliers->result() as $supplier) - { - $table_data_rows.=get_supplier_data_row($supplier,$controller); - } - - if($suppliers->num_rows()==0) - { - $table_data_rows.="
".$CI->lang->line('common_no_persons_to_display')."
"; - } - - return $table_data_rows; + + $headers = array( + array('checkbox' => 'select'), + array('id' => $CI->lang->line('common_id')), + array('company_name' => $CI->lang->line('suppliers_company_name')), + array('agency_name' => $CI->lang->line('suppliers_agency_name')), + array('last_name' => $CI->lang->line('common_last_name')), + array('first_name' => $CI->lang->line('common_first_name')), + array('email' => $CI->lang->line('common_email')), + array('phone_number' => $CI->lang->line('common_phone_number')), + array('edit' => '') + ); + + return transform_headers($headers); } -function get_supplier_data_row($supplier,$controller) -{ +function get_supplier_data_row($supplier, $controller) { $CI =& get_instance(); $controller_name=strtolower(get_class($CI)); - $table_data_row=''; - $table_data_row.=""; - $table_data_row.=''.character_limiter($supplier->company_name,13).''; - $table_data_row.=''.character_limiter($supplier->agency_name,13).''; - $table_data_row.=''.character_limiter($supplier->last_name,13).''; - $table_data_row.=''.character_limiter($supplier->first_name,13).''; - $table_data_row.=''.mailto($supplier->email,character_limiter($supplier->email,22)).''; - $table_data_row.=''.character_limiter($supplier->phone_number,13).''; - $table_data_row.=''.character_limiter($supplier->person_id,5).''; - if($CI->Employee->has_grant('messages', $CI->session->userdata('person_id'))) - { - $table_data_row.=''.anchor("Messages/view/$supplier->person_id", '', array('class'=>"modal-dlg modal-btn-submit", 'title'=>$CI->lang->line('messages_sms_send'))).''; - $table_data_row.=''.anchor($controller_name."/view/$supplier->person_id", '', array('class'=>"modal-dlg modal-btn-submit",'title'=>$CI->lang->line($controller_name.'_update'))).''; - } - else - { - $table_data_row.=''.anchor($controller_name."/view/$supplier->person_id", '', array('class'=>"modal-dlg modal-btn-submit",'title'=>$CI->lang->line($controller_name.'_update'))).''; - } - $table_data_row.=''; - - return $table_data_row; + return array ( + 'id' => $supplier->person_id, + 'company_name' => character_limiter($supplier->company_name,13), + 'agency_name' => character_limiter($supplier->agency_name,13), + 'last_name' => character_limiter($supplier->last_name,13), + 'first_name' => character_limiter($supplier->first_name,13), + 'email' => empty($supplier->email) ? '' : mailto($supplier->email,character_limiter($supplier->email,22)), + 'phone_number' => character_limiter($supplier->phone_number,13), + 'messages' => anchor("Messages/view/$supplier->person_id", '', + array('class'=>"modal-dlg modal-btn-submit", 'title'=>$CI->lang->line('messages_sms_send'))), + 'edit' => anchor($controller_name."/view/$supplier->person_id", '', + array('class'=>"modal-dlg modal-btn-submit", 'title'=>$CI->lang->line($controller_name.'_update')) + )); } /* diff --git a/application/views/people/manage.php b/application/views/people/manage.php index 261872f16..9e10c5fdd 100644 --- a/application/views/people/manage.php +++ b/application/views/people/manage.php @@ -3,10 +3,8 @@ @@ -20,22 +18,13 @@ $(document).ready(function() title='lang->line('customers_import_items_excel'); ?>'> lang->line('common_import_excel'); ?> + - - -
diff --git a/application/views/suppliers/form.php b/application/views/suppliers/form.php index 6e808e1d5..089c53c48 100644 --- a/application/views/suppliers/form.php +++ b/application/views/suppliers/form.php @@ -55,7 +55,7 @@ $(document).ready(function() success:function(response) { dialog_support.hide(); - post_person_form_submit(response); + table_support.handle_submit('', response); }, dataType:'json' }); diff --git a/application/views/suppliers/manage.php b/application/views/suppliers/manage.php deleted file mode 100644 index 1bc7e9145..000000000 --- a/application/views/suppliers/manage.php +++ /dev/null @@ -1,88 +0,0 @@ -load->view("partial/header"); ?> - - - -
- - - " . $this->lang->line($controller_name . '_new') . "
", - array('class'=>'modal-dlg modal-btn-submit none', 'title'=>$this->lang->line($controller_name . '_new'))); ?> -
- -'search_form', 'class'=>'form-horizontal')); ?> -
-
-
    -
  • ' . $this->lang->line("common_delete") . '
', array('id'=>'delete')); ?> -
  • lang->line("common_email");?>
  • - -
  • - 'search', 'class'=>'form-control input-sm', 'id'=>'search')); ?> - 'limit_from', 'type'=>'hidden', 'id'=>'limit_from')); ?> -
  • - - -
    - - -
    - -
    - -load->view("partial/footer"); ?> \ No newline at end of file