From 36f825d0feccff56a65c145a625ff3938a00910f Mon Sep 17 00:00:00 2001 From: jekkos Date: Mon, 7 Mar 2016 21:23:29 +0100 Subject: [PATCH] Replace legeacy autocomplete with jquery-ui version (#328) Cleanup PHP search suggestion functionality Add jquery-ui css explicitly (wasn't included in bower main attribute) --- .gitignore | 2 +- Gruntfile.js | 5 +- application/controllers/Customers.php | 2 +- application/controllers/Employees.php | 2 +- application/controllers/Item_kits.php | 3 +- application/controllers/Items.php | 12 +- application/controllers/Receivings.php | 16 +- application/controllers/Sales.php | 12 +- application/controllers/Suppliers.php | 8 +- application/models/Item.php | 89 ++++++----- application/models/Item_kit.php | 28 +++- application/models/Sale.php | 2 +- application/models/Supplier.php | 164 +++++++------------- application/views/item_kits/form.php | 3 +- application/views/item_kits/manage.php | 2 +- application/views/items/manage.php | 2 +- application/views/partial/header.php | 4 +- application/views/people/manage.php | 2 +- application/views/receivings/form.php | 36 ++--- application/views/receivings/receiving.php | 30 ++-- application/views/sales/form.php | 22 +-- application/views/sales/manage.php | 2 +- application/views/sales/register.php | 31 ++-- application/views/suppliers/manage.php | 2 +- bower.json | 9 +- dist/opensourcepos.js | 1 - js/nominatim.autocomplete.js | 1 - templates/spacelab/views/partial/header.php | 2 +- 28 files changed, 229 insertions(+), 265 deletions(-) diff --git a/.gitignore b/.gitignore index 59c3fb532..cfed0a7ea 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ node_modules bower_components -dist/*_bower.* +dist/ application/config/email.php application/config/database.php *.patch diff --git a/Gruntfile.js b/Gruntfile.js index 83d2032c6..849882418 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -29,6 +29,7 @@ module.exports = function(grunt) { destPrefix: 'dist' }, files: { + 'jquery-ui.css': 'jquery-ui/themes/smoothness/jquery-ui.css', 'bootstrap.min.css': 'bootswatch-dist/css/bootstrap.min.css' } } @@ -99,7 +100,7 @@ module.exports = function(grunt) { closeTag: '', absolutePath: true }, - src: [ 'dist/*min.css' ], + src: [ 'dist/*.css' ], dest: 'application/views/partial/header.php' }, css_login: { @@ -109,7 +110,7 @@ module.exports = function(grunt) { closeTag: '', absolutePath: true }, - src: [ 'dist/bootstrap.min.css', 'css/login.css' ], + src: [ 'dist/jquery-ui.min.css', 'dist/bootstrap.min.css', 'css/login.css' ], dest: 'application/views/login.php' }, js: { diff --git a/application/controllers/Customers.php b/application/controllers/Customers.php index 1b3647e32..db409ef38 100644 --- a/application/controllers/Customers.php +++ b/application/controllers/Customers.php @@ -40,7 +40,7 @@ class Customers extends Person_controller */ function suggest() { - $suggestions = $this->Customer->get_search_suggestions($this->input->post('term'), TRUE); + $suggestions = $this->Customer->get_search_suggestions($this->input->get('term'), TRUE); echo json_encode($suggestions); } diff --git a/application/controllers/Employees.php b/application/controllers/Employees.php index 6d6a5a70a..130dc629d 100644 --- a/application/controllers/Employees.php +++ b/application/controllers/Employees.php @@ -38,7 +38,7 @@ class Employees extends Person_controller /* Gives search suggestions based on what is being searched for */ - function suggest() + function suggest_search() { $suggestions = $this->Employee->get_search_suggestions($this->input->post('term')); echo json_encode($suggestions); diff --git a/application/controllers/Item_kits.php b/application/controllers/Item_kits.php index ad652ed41..7645058e1 100644 --- a/application/controllers/Item_kits.php +++ b/application/controllers/Item_kits.php @@ -73,8 +73,7 @@ class Item_kits extends Secure_area implements iData_controller */ function suggest() { - $suggestions = $this->Item_kit->get_search_suggestions($this->input->post('term'), $this->input->post('limit')); - + $suggestions = $this->Item_kit->get_search_suggestions($this->input->post('term'), TRUE); echo json_encode($suggestions); } diff --git a/application/controllers/Items.php b/application/controllers/Items.php index 53abe45d5..cb5351aa6 100644 --- a/application/controllers/Items.php +++ b/application/controllers/Items.php @@ -115,18 +115,20 @@ class Items extends Secure_area implements iData_controller /* Gives search suggestions based on what is being searched for */ - function suggest() + function suggest_search() { - $suggestions = $this->Item->get_search_suggestions($this->input->post('term'), array( + $suggestions = $this->Item->get_search_suggestions($this->input->post_get('term'), array( 'search_custom' => $this->input->post('search_custom'), - 'is_deleted' => $this->input->post('is_deleted') != "0"), + 'is_deleted' => !empty($this->input->post('is_deleted'))), FALSE, $this->input->post('limit')); echo json_encode($suggestions); } - function suggest_search() + function suggest() { - $suggestions = $this->Item->get_search_suggestions($this->input->post('term'), TRUE); + $suggestions = $this->Item->get_search_suggestions($this->input->post_get('term'), array( + 'search_custom' => FALSE, + 'is_deleted' => FALSE), TRUE); echo json_encode($suggestions); } diff --git a/application/controllers/Receivings.php b/application/controllers/Receivings.php index 0e5aca336..5cd66f78c 100644 --- a/application/controllers/Receivings.php +++ b/application/controllers/Receivings.php @@ -16,14 +16,9 @@ class Receivings extends Secure_area function item_search() { - $suggestions = $this->Item->get_search_suggestions($this->input->post('term')); - $suggestions = array_merge($suggestions, $this->Item_kit->get_search_suggestions($this->input->post('term'))); - echo json_encode($suggestions); - } - - function supplier_search() - { - $suggestions = $this->Supplier->get_suppliers_search_suggestions($this->input->post('term'),$this->input->post('limit')); + $suggestions = $this->Item->get_search_suggestions($this->input->get('term'), + array('is_deleted' => FALSE, 'search_custom' => FALSE), FALSE); + $suggestions = array_merge($suggestions, $this->Item_kit->get_search_suggestions($this->input->get('term'))); echo json_encode($suggestions); } @@ -141,7 +136,8 @@ class Receivings extends Secure_area $receiving_info = $this->Receiving->get_info($receiving_id)->row_array(); $person_name = $receiving_info['first_name'] . " " . $receiving_info['last_name']; - $data['selected_supplier'] = !empty($receiving_info['supplier_id']) ? $receiving_info['supplier_id'] . "|" . $person_name : ""; + $data['selected_supplier_name'] = !empty($receiving_info['supplier_id']) ? $person_name : ""; + $data['selected_supplier_id'] = $receiving_info['supplier_id']; $data['receiving_info'] = $receiving_info; $this->load->view('receivings/form', $data); @@ -367,7 +363,7 @@ class Receivings extends Secure_area $receiving_data = array( 'receiving_time' => $date_formatter->format('Y-m-d H:i:s'), - 'supplier_id' => $this->input->post('supplier_id'), + 'supplier_id' => $this->input->post('supplier_id', TRUE) ? $this->input->post('supplier_id') : null, 'employee_id' => $this->input->post('employee_id'), 'comment' => $this->input->post('comment'), 'invoice_number' => $this->input->post('invoice_number') diff --git a/application/controllers/Sales.php b/application/controllers/Sales.php index dcd588582..901ba3483 100644 --- a/application/controllers/Sales.php +++ b/application/controllers/Sales.php @@ -126,19 +126,20 @@ class Sales extends Secure_area function item_search() { $suggestions = array(); - $search = $this->input->post('term'); + $search = $this->input->get('term'); if ($this->sale_lib->get_mode() == 'return' && $this->sale_lib->is_valid_receipt($search) ) { $suggestions[] = $search; } - $suggestions = array_merge($suggestions, $this->Item->get_search_suggestions($search)); - $suggestions = array_merge($suggestions, $this->Item_kit->get_item_kit_search_suggestions($search)); + $suggestions = array_merge($suggestions, $this->Item->get_search_suggestions($search, + array('is_deleted' => FALSE, 'search_custom' => FALSE), FALSE)); + $suggestions = array_merge($suggestions, $this->Item_kit->get_search_suggestions($search)); echo json_encode($suggestions); } - function suggest() + function suggest_search() { $suggestions = $this->Sale->get_search_suggestions($this->input->post('term')); echo json_encode($suggestions); @@ -628,7 +629,8 @@ class Sales extends Secure_area $sale_info = $this->Sale->get_info($sale_id)->row_array(); $person_name = $sale_info['first_name'] . " " . $sale_info['last_name']; - $data['selected_customer'] = !empty($sale_info['customer_id']) ? $sale_info['customer_id'] . "|" . $person_name : ""; + $data['selected_customer_name'] = !empty($sale_info['customer_id']) ? $person_name : ''; + $data['selected_customer_id'] = $sale_info['customer_id']; $data['sale_info'] = $sale_info; $this->load->view('sales/form', $data); diff --git a/application/controllers/Suppliers.php b/application/controllers/Suppliers.php index 5f032ba61..58d3c492d 100644 --- a/application/controllers/Suppliers.php +++ b/application/controllers/Suppliers.php @@ -41,7 +41,13 @@ class Suppliers extends Person_controller */ function suggest() { - $suggestions = $this->Supplier->get_search_suggestions($this->input->post('q'),$this->input->post('limit')); + $suggestions = $this->Supplier->get_search_suggestions($this->input->get('term'), TRUE); + echo json_encode($suggestions); + } + + function suggest_search() + { + $suggestions = $this->Supplier->get_search_suggestions($this->input->post('term'), FALSE); echo json_encode($suggestions); } diff --git a/application/models/Item.php b/application/models/Item.php index 901a76ba0..5e8dd9d03 100644 --- a/application/models/Item.php +++ b/application/models/Item.php @@ -263,7 +263,7 @@ class Item extends CI_Model return $this->db->update('items', array('deleted' => 1)); } - public function get_search_suggestions($search, $filters, $unique = FALSE, $limit=25) + public function get_search_suggestions($search, $filters = array("is_deleted"), $unique = FALSE, $limit=25) { $suggestions = array(); @@ -280,7 +280,7 @@ class Item extends CI_Model $this->db->select('item_id, item_number'); $this->db->from('items'); - $this->db->where('deleted', $filters['is_deleted']); + $this->db->where('deleted', $filters['is_deleted'] != null); $this->db->like('item_number', $search); $this->db->order_by('item_number', 'asc'); $by_item_number = $this->db->get(); @@ -289,55 +289,58 @@ class Item extends CI_Model $suggestions[] = array('value' => $row->item_id, 'label' => $row->item_number); } - $this->db->select('company_name'); - $this->db->from('suppliers'); - $this->db->like('company_name', $search); - // restrict to non deleted companies only if is_deleted if false - $this->db->where('deleted', $filters['is_deleted']); - $this->db->distinct(); - $this->db->order_by('company_name', 'asc'); - $by_company_name = $this->db->get(); - foreach($by_company_name->result() as $row) + if (!$unique) { - $suggestions[] = array('value' => $row->item_id, 'label' => $row->company_name); - } - - //Search by description - $this->db->select('item_id, name, description'); - $this->db->from('items'); - $this->db->where('deleted', $filters['is_deleted']); - $this->db->like('description', $search); - $this->db->order_by('description', 'asc'); - $by_description = $this->db->get(); - foreach($by_description->result() as $row) - { - $entry = array('value' => $row->item_id, 'label' => $row->name); - if (!array_walk($suggestions, function($value, $label) use ($entry) { - return $entry['label'] != $label; - })) { - $suggestions[] = $entry; + $this->db->select('company_name'); + $this->db->from('suppliers'); + $this->db->like('company_name', $search); + // restrict to non deleted companies only if is_deleted if false + $this->db->where('deleted', $filters['is_deleted']); + $this->db->distinct(); + $this->db->order_by('company_name', 'asc'); + $by_company_name = $this->db->get(); + foreach($by_company_name->result() as $row) + { + $suggestions[] = array('value' => $row->item_id, 'label' => $row->company_name); } - } - //Search by custom fields - if ($filters['search_custom'] != 0) - { + //Search by description + $this->db->select('item_id, name, description'); $this->db->from('items'); $this->db->where('deleted', $filters['is_deleted']); - $this->db->like('custom1', $search); - $this->db->or_like('custom2', $search); - $this->db->or_like('custom3', $search); - $this->db->or_like('custom4', $search); - $this->db->or_like('custom5', $search); - $this->db->or_like('custom6', $search); - $this->db->or_like('custom7', $search); - $this->db->or_like('custom8', $search); - $this->db->or_like('custom9', $search); - $this->db->or_like('custom10', $search); + $this->db->like('description', $search); + $this->db->order_by('description', 'asc'); $by_description = $this->db->get(); foreach($by_description->result() as $row) { - $suggestions[] = array('value' => $row->item_id, 'label' => $row->name); + $entry = array('value' => $row->item_id, 'label' => $row->name); + if (!array_walk($suggestions, function($value, $label) use ($entry) { + return $entry['label'] != $label; + })) { + $suggestions[] = $entry; + } + } + + //Search by custom fields + if ($filters['search_custom'] != 0) + { + $this->db->from('items'); + $this->db->where('deleted', $filters['is_deleted']); + $this->db->like('custom1', $search); + $this->db->or_like('custom2', $search); + $this->db->or_like('custom3', $search); + $this->db->or_like('custom4', $search); + $this->db->or_like('custom5', $search); + $this->db->or_like('custom6', $search); + $this->db->or_like('custom7', $search); + $this->db->or_like('custom8', $search); + $this->db->or_like('custom9', $search); + $this->db->or_like('custom10', $search); + $by_description = $this->db->get(); + foreach($by_description->result() as $row) + { + $suggestions[] = array('value' => $row->item_id, 'label' => $row->name); + } } } diff --git a/application/models/Item_kit.php b/application/models/Item_kit.php index 7ab243ec2..bb11ad8af 100644 --- a/application/models/Item_kit.php +++ b/application/models/Item_kit.php @@ -123,13 +123,31 @@ class Item_kit extends CI_Model $suggestions = array(); $this->db->from('item_kits'); - $this->db->like('name', $search); - $this->db->order_by('name', 'asc'); - $by_name = $this->db->get(); - foreach($by_name->result() as $row) + //KIT # + if (stripos($search, 'KIT ') !== false) { - $suggestions[] = array('value' => 'KIT ' . $row->item_kit_id, 'label' => $row->name); + $this->db->like('item_kit_id', str_ireplace('KIT ', '', $search)); + + $this->db->order_by('item_kit_id', 'asc'); + $by_name = $this->db->get(); + + foreach($by_name->result() as $row) + { + $suggestions[] = array('value' => 'KIT '. $row->item_kit_id, 'label' => 'KIT ' . $row->item_kit_id); + } + } + else + { + $this->db->like('name', $search); + + $this->db->order_by('name', 'asc'); + $by_name = $this->db->get(); + + foreach($by_name->result() as $row) + { + $suggestions[] = array('value' => 'KIT ' . $row->item_kit_id, 'label' => $row->name); + } } //only return $limit suggestions diff --git a/application/models/Sale.php b/application/models/Sale.php index 40a2f542c..cb437d55b 100644 --- a/application/models/Sale.php +++ b/application/models/Sale.php @@ -199,7 +199,7 @@ class Sale extends CI_Model } else { - $suggestions[] = $search; + $suggestions[] = array('label' => $search); } return $suggestions; diff --git a/application/models/Supplier.php b/application/models/Supplier.php index 04862c3a4..562d49db1 100644 --- a/application/models/Supplier.php +++ b/application/models/Supplier.php @@ -136,78 +136,79 @@ class Supplier extends Person /* Get search suggestions to find suppliers */ - function get_search_suggestions($search,$limit=25) + function get_search_suggestions($search, $unique = FALSE, $limit = 25) { $suggestions = array(); - + $this->db->from('suppliers'); - $this->db->join('people','suppliers.person_id=people.person_id'); + $this->db->join('people', 'suppliers.person_id=people.person_id'); $this->db->where('deleted', 0); - $this->db->like("company_name",$search); - $this->db->order_by("company_name", "asc"); + $this->db->like("company_name", $search); + $this->db->order_by("company_name", "asc"); $by_company_name = $this->db->get(); - foreach($by_company_name->result() as $row) - { - $suggestions[]=array('label' => $row->company_name); + foreach ($by_company_name->result() as $row) { + $suggestions[] = array('value' => $row->person_id, 'label' => $row->company_name); } $this->db->from('suppliers'); - $this->db->join('people','suppliers.person_id=people.person_id'); + $this->db->join('people', 'suppliers.person_id=people.person_id'); $this->db->where('deleted', 0); $this->db->distinct(); - $this->db->like("agency_name",$search); - $this->db->order_by("agency_name", "asc"); + $this->db->like("agency_name", $search); + $this->db->where("agency_name", "<> null"); + $this->db->order_by("agency_name", "asc"); $by_agency_name = $this->db->get(); - foreach($by_agency_name->result() as $row) - { - $suggestions[]=array('label' => $row->agency_name); - } - - $this->db->from('suppliers'); - $this->db->join('people','suppliers.person_id=people.person_id'); - $this->db->where("(first_name LIKE '%".$this->db->escape_like_str($search)."%' or - last_name LIKE '%".$this->db->escape_like_str($search)."%' or - CONCAT(`first_name`,' ',`last_name`) LIKE '%".$this->db->escape_like_str($search)."%') and deleted=0"); - $this->db->order_by("last_name", "asc"); - $by_name = $this->db->get(); - foreach($by_name->result() as $row) - { - $suggestions[]=array('label' => $row->first_name.' '.$row->last_name); - } - - $this->db->from('suppliers'); - $this->db->join('people','suppliers.person_id=people.person_id'); - $this->db->where('deleted', 0); - $this->db->like("email",$search); - $this->db->order_by("email", "asc"); - $by_email = $this->db->get(); - foreach($by_email->result() as $row) - { - $suggestions[]=array('label' => $row->email); + foreach ($by_agency_name->result() as $row) { + $suggestions[] = array('value' => $row->person_id, 'label' => $row->agency_name); } $this->db->from('suppliers'); - $this->db->join('people','suppliers.person_id=people.person_id'); - $this->db->where('deleted', 0); - $this->db->like("phone_number",$search); - $this->db->order_by("phone_number", "asc"); - $by_phone = $this->db->get(); - foreach($by_phone->result() as $row) - { - $suggestions[]=array('label' => $row->phone_number); + $this->db->join('people', 'suppliers.person_id=people.person_id'); + $this->db->where("(first_name LIKE '%" . $this->db->escape_like_str($search) . "%' or + last_name LIKE '%" . $this->db->escape_like_str($search) . "%' or + CONCAT(`first_name`,' ',`last_name`) LIKE '%" . $this->db->escape_like_str($search) . "%') and deleted=0"); + $this->db->order_by("last_name", "asc"); + $by_name = $this->db->get(); + foreach ($by_name->result() as $row) { + $suggestions[] = array('value' => $row->person_id, 'label' => $row->first_name . ' ' . $row->last_name); } - - $this->db->from('suppliers'); - $this->db->join('people','suppliers.person_id=people.person_id'); - $this->db->where('deleted', 0); - $this->db->like("account_number",$search); - $this->db->order_by("account_number", "asc"); - $by_account_number = $this->db->get(); - foreach($by_account_number->result() as $row) + + if (!$unique) { - $suggestions[]=array('label' => $row->account_number); + $this->db->from('suppliers'); + $this->db->join('people','suppliers.person_id=people.person_id'); + $this->db->where('deleted', 0); + $this->db->like("email",$search); + $this->db->order_by("email", "asc"); + $by_email = $this->db->get(); + foreach($by_email->result() as $row) + { + $suggestions[]=array('value' => $row->person_id, 'label' => $row->email); + } + + $this->db->from('suppliers'); + $this->db->join('people','suppliers.person_id=people.person_id'); + $this->db->where('deleted', 0); + $this->db->like("phone_number",$search); + $this->db->order_by("phone_number", "asc"); + $by_phone = $this->db->get(); + foreach($by_phone->result() as $row) + { + $suggestions[]=array('value' => $row->person_id, 'label' => $row->phone_number); + } + + $this->db->from('suppliers'); + $this->db->join('people','suppliers.person_id=people.person_id'); + $this->db->where('deleted', 0); + $this->db->like("account_number",$search); + $this->db->order_by("account_number", "asc"); + $by_account_number = $this->db->get(); + foreach($by_account_number->result() as $row) + { + $suggestions[]=array('value' => $row->person_id, 'label' => $row->account_number); + } } - + //only return $limit suggestions if(count($suggestions > $limit)) { @@ -216,60 +217,7 @@ class Supplier extends Person return $suggestions; } - - /* - Get search suggestions to find suppliers - */ - function get_suppliers_search_suggestions($search,$limit=25) - { - $suggestions = array(); - - $this->db->from('suppliers'); - $this->db->join('people','suppliers.person_id=people.person_id'); - $this->db->where('deleted', 0); - $this->db->like("company_name",$search); - $this->db->order_by("company_name", "asc"); - $by_company_name = $this->db->get(); - foreach($by_company_name->result() as $row) - { - $suggestions[]=array('value' => $row->person_id, 'label' => $row->company_name); - } - - $this->db->from('suppliers'); - $this->db->join('people','suppliers.person_id=people.person_id'); - $this->db->where('deleted', 0); - $this->db->distinct(); - $this->db->like("agency_name",$search); - $this->db->order_by("agency_name", "asc"); - $by_agency_name = $this->db->get(); - foreach($by_agency_name->result() as $row) - { - $suggestions[]=array('value' => $row->person_id, 'label' => $row->agency_name); - } - - - $this->db->from('suppliers'); - $this->db->join('people','suppliers.person_id=people.person_id'); - $this->db->where("(first_name LIKE '%".$this->db->escape_like_str($search)."%' or - last_name LIKE '%".$this->db->escape_like_str($search)."%' or - CONCAT(`first_name`,' ',`last_name`) LIKE '%".$this->db->escape_like_str($search)."%') and deleted=0"); - $this->db->order_by("last_name", "asc"); - $by_name = $this->db->get(); - foreach($by_name->result() as $row) - { - $suggestions[]=array('value' => $row->person_id, 'label' => $row->first_name.' '.$row->last_name); - } - - //only return $limit suggestions - if(count($suggestions > $limit)) - { - $suggestions = array_slice($suggestions, 0,$limit); - } - return $suggestions; - - } - function get_found_rows($search) { $this->db->from('suppliers'); diff --git a/application/views/item_kits/form.php b/application/views/item_kits/form.php index 20b78b8b1..d2bab0d62 100644 --- a/application/views/item_kits/form.php +++ b/application/views/item_kits/form.php @@ -72,7 +72,7 @@ $(document).ready(function() { $("#item").autocomplete({ - source: '', + source: '', minChars:0, autoFocus: false, delay:10, @@ -87,6 +87,7 @@ $(document).ready(function() $("#item_kit_items").append("" + ui.item.label + ""); } $("#item").val(""); + return false; } }); diff --git a/application/views/item_kits/manage.php b/application/views/item_kits/manage.php index 03223458f..6ade44a14 100644 --- a/application/views/item_kits/manage.php +++ b/application/views/item_kits/manage.php @@ -7,7 +7,7 @@ $(document).ready(function() enable_select_all(); enable_checkboxes(); enable_row_selection(); - enable_search({suggest_url : '', + enable_search({suggest_url : '', confirm_message : 'lang->line("common_confirm_search")?>'}); enable_delete('lang->line($controller_name."_confirm_delete")?>','lang->line($controller_name."_none_selected")?>'); diff --git a/application/views/items/manage.php b/application/views/items/manage.php index 7934a9f24..d10f7db45 100644 --- a/application/views/items/manage.php +++ b/application/views/items/manage.php @@ -8,7 +8,7 @@ $(document).ready(function() enable_checkboxes(); enable_row_selection(); - var widget = enable_search({suggest_url : '', + var widget = enable_search({suggest_url : '', confirm_search_message : 'lang->line("common_confirm_search")?>', extra_params : { 'is_deleted' : function () { diff --git a/application/views/partial/header.php b/application/views/partial/header.php index 1631205af..bcd28ceeb 100644 --- a/application/views/partial/header.php +++ b/application/views/partial/header.php @@ -7,6 +7,7 @@ input->cookie('debug') == "true" || $this->input->get("debug") == "true") : ?> + @@ -15,7 +16,6 @@ - @@ -64,7 +64,9 @@ + + diff --git a/application/views/people/manage.php b/application/views/people/manage.php index eedd1c290..1dca6ceaa 100644 --- a/application/views/people/manage.php +++ b/application/views/people/manage.php @@ -6,7 +6,7 @@ $(document).ready(function() init_table_sorting(); enable_select_all(); enable_row_selection(); - enable_search({ suggest_url : '', + enable_search({ suggest_url : '', confirm_search_message : 'lang->line("common_confirm_search")?>'}); enable_email(''); enable_delete('lang->line($controller_name."_confirm_delete")?>','lang->line($controller_name."_none_selected")?>'); diff --git a/application/views/receivings/form.php b/application/views/receivings/form.php index 852063bb2..731df22ef 100755 --- a/application/views/receivings/form.php +++ b/application/views/receivings/form.php @@ -22,7 +22,8 @@
lang->line('recvs_supplier'), 'supplier', array('class'=>'control-label col-xs-3')); ?>
- 'supplier_id', 'value' => $selected_supplier, 'id' => 'supplier_id', 'class'=>'form-control input-sm'));?> + 'supplier_id', 'value' => $selected_supplier_name, 'id' => 'supplier_id', 'class'=>'form-control input-sm'));?> +
@@ -110,29 +111,26 @@ $(document).ready(function() bootcssVer: 3, language: "config->item('language'); ?>" }); - - var format_item = function(row) - { - var result = [row[0], "|", row[1]].join(""); - // if more than one occurence - if (row[2] > 1 && row[3] && row[3].toString().trim()) { - // display zip code - result += ' - ' + row[3]; - } - return result; + + var fill_value = function(event, ui) { + event.preventDefault(); + $("input[name='supplier_id']").val(ui.item.value); + $("input[name='supplier_name']").val(ui.item.label); }; - var autocompleter = $("#supplier_id").autocomplete('', + + var autocompleter = $("#supplier_id").autocomplete( { + source: '', minChars: 0, delay: 15, - max: 100, cacheLength: 1, - formatItem: format_item, - formatResult: format_item + appendTo: '.modal-content', + select: fill_value, + focus: fill_value }); // declare submitHandler as an object.. will be reused - var submit_form = function(selected_supplier) + var submit_form = function() { $(this).ajaxSubmit({ success:function(response) @@ -141,7 +139,6 @@ $(document).ready(function() post_form_submit(response); }, error: function(jqXHR, textStatus, errorThrown) { - selected_supplier && autocompleter.val(selected_supplier); post_form_submit({message: errorThrown}); }, dataType:'json' @@ -151,10 +148,7 @@ $(document).ready(function() { submitHandler : function(form) { - var selected_supplier = autocompleter.val(); - var selected_supplier_id = selected_supplier.replace(/(\w)\|.*/, "$1"); - selected_supplier_id && autocompleter.val(selected_supplier_id); - submit_form.call(form, selected_supplier); + submit_form.call(form); }, rules: { diff --git a/application/views/receivings/receiving.php b/application/views/receivings/receiving.php index 9c4364e26..70cca20d2 100644 --- a/application/views/receivings/receiving.php +++ b/application/views/receivings/receiving.php @@ -369,22 +369,18 @@ if (isset($error))