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)
This commit is contained in:
jekkos
2016-03-07 21:23:29 +01:00
parent 6c29faeba1
commit 36f825d0fe
28 changed files with 229 additions and 265 deletions

2
.gitignore vendored
View File

@@ -1,6 +1,6 @@
node_modules
bower_components
dist/*_bower.*
dist/
application/config/email.php
application/config/database.php
*.patch

View File

@@ -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: '<!-- end mincss template tags -->',
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: '<!-- end css template tags -->',
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: {

View File

@@ -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);
}

View File

@@ -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);

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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')

View File

@@ -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);

View File

@@ -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);
}

View File

@@ -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);
}
}
}

View File

@@ -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

View File

@@ -199,7 +199,7 @@ class Sale extends CI_Model
}
else
{
$suggestions[] = $search;
$suggestions[] = array('label' => $search);
}
return $suggestions;

View File

@@ -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');

View File

@@ -72,7 +72,7 @@
$(document).ready(function()
{
$("#item").autocomplete({
source: '<?php echo site_url("items/item_search"); ?>',
source: '<?php echo site_url("items/suggest"); ?>',
minChars:0,
autoFocus: false,
delay:10,
@@ -87,6 +87,7 @@ $(document).ready(function()
$("#item_kit_items").append("<tr><td><a href='#' onclick='return delete_item_kit_row(this);'><span class='glyphicon glyphicon-trash'></span></a></td><td>" + ui.item.label + "</td><td><input class='quantity form-control input-sm' id='item_kit_item_" + ui.item.value + "' type='text' name=item_kit_item[" + ui.item.value + "] value='1'/></td></tr>");
}
$("#item").val("");
return false;
}
});

View File

@@ -7,7 +7,7 @@ $(document).ready(function()
enable_select_all();
enable_checkboxes();
enable_row_selection();
enable_search({suggest_url : '<?php echo site_url("$controller_name/suggest")?>',
enable_search({suggest_url : '<?php echo site_url("$controller_name/suggest_search")?>',
confirm_message : '<?php echo $this->lang->line("common_confirm_search")?>'});
enable_delete('<?php echo $this->lang->line($controller_name."_confirm_delete")?>','<?php echo $this->lang->line($controller_name."_none_selected")?>');

View File

@@ -8,7 +8,7 @@ $(document).ready(function()
enable_checkboxes();
enable_row_selection();
var widget = enable_search({suggest_url : '<?php echo site_url("$controller_name/suggest")?>',
var widget = enable_search({suggest_url : '<?php echo site_url("$controller_name/suggest_search")?>',
confirm_search_message : '<?php echo $this->lang->line("common_confirm_search")?>',
extra_params : {
'is_deleted' : function () {

View File

@@ -7,6 +7,7 @@
<link rel="shortcut icon" type="image/x-icon" href="images/favicon.ico">
<?php if ($this->input->cookie('debug') == "true" || $this->input->get("debug") == "true") : ?>
<!-- bower:css -->
<link rel="stylesheet" href="bower_components/jquery-ui/themes/smoothness/jquery-ui.css" />
<link rel="stylesheet" href="bower_components/tablesorter/dist/css/theme.blue.min.css" />
<link rel="stylesheet" href="bower_components/bootstrap3-dialog/dist/css/bootstrap-dialog.min.css" />
<link rel="stylesheet" href="bower_components/jasny-bootstrap/dist/css/jasny-bootstrap.css" />
@@ -15,7 +16,6 @@
<link rel="stylesheet" href="bower_components/bootstrap-select/dist/css/bootstrap-select.css" />
<link rel="stylesheet" href="bower_components/bootstrap-table/src/bootstrap-table.css" />
<link rel="stylesheet" href="bower_components/bootstrap-daterangepicker/daterangepicker.css" />
<link rel="stylesheet" href="bower_components/jquery-ui-bootstrap/jquery.ui.theme.css" />
<!-- endbower -->
<!-- start css template tags -->
<link rel="stylesheet" type="text/css" href="css/barcode_font.css"/>
@@ -64,7 +64,9 @@
<![endif]-->
<!-- start mincss template tags -->
<link rel="stylesheet" type="text/css" href="dist/bootstrap.min.css?rel=9ed20b1ee8"/>
<link rel="stylesheet" type="text/css" href="dist/jquery-ui.css"/>
<link rel="stylesheet" type="text/css" href="dist/opensourcepos.min.css?rel=63bde3dd80"/>
<link rel="stylesheet" type="text/css" href="dist/opensourcepos_bower.css"/>
<!-- end mincss template tags -->
<!-- start minjs template tags -->
<script type="text/javascript" src="dist/opensourcepos.min.js?rel=8aac97eb12" language="javascript"></script>

View File

@@ -6,7 +6,7 @@ $(document).ready(function()
init_table_sorting();
enable_select_all();
enable_row_selection();
enable_search({ suggest_url : '<?php echo site_url("$controller_name/suggest")?>',
enable_search({ suggest_url : '<?php echo site_url("$controller_name/suggest_search")?>',
confirm_search_message : '<?php echo $this->lang->line("common_confirm_search")?>'});
enable_email('<?php echo site_url("$controller_name/mailto")?>');
enable_delete('<?php echo $this->lang->line($controller_name."_confirm_delete")?>','<?php echo $this->lang->line($controller_name."_none_selected")?>');

View File

@@ -22,7 +22,8 @@
<div class="form-group form-group-sm">
<?php echo form_label($this->lang->line('recvs_supplier'), 'supplier', array('class'=>'control-label col-xs-3')); ?>
<div class='col-xs-6'>
<?php echo form_input(array('name' => 'supplier_id', 'value' => $selected_supplier, 'id' => 'supplier_id', 'class'=>'form-control input-sm'));?>
<?php echo form_input(array('name' => 'supplier_id', 'value' => $selected_supplier_name, 'id' => 'supplier_id', 'class'=>'form-control input-sm'));?>
<?php echo form_hidden('supplier_id', $selected_supplier_id);?>
</div>
</div>
@@ -110,29 +111,26 @@ $(document).ready(function()
bootcssVer: 3,
language: "<?php echo $this->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('<?php echo site_url("receivings/supplier_search"); ?>',
var autocompleter = $("#supplier_id").autocomplete(
{
source: '<?php echo site_url("suppliers/suggest"); ?>',
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:
{

View File

@@ -369,22 +369,18 @@ if (isset($error))
<script type="text/javascript" language="javascript">
$(document).ready(function()
{
$("#item").autocomplete('<?php echo site_url("receivings/item_search"); ?>',
$("#item").autocomplete(
{
source: '<?php echo site_url("receivings/item_search"); ?>',
minChars:0,
max:100,
delay:10,
selectFirst: false,
formatItem: function(row) {
return row[1];
autoFocus: false,
select: function (a, ui) {
$(this).val(ui.item.value);
$("#add_item_form").submit();
}
});
$("#item").result(function(event, data, formatted)
{
$("#add_item_form").submit();
});
$('#item').focus();
$('#item').blur(function()
@@ -427,21 +423,17 @@ $(document).ready(function()
$(this).attr('value','');
});
$("#supplier").autocomplete('<?php echo site_url("receivings/supplier_search"); ?>',
$("#supplier").autocomplete(
{
source: '<?php echo site_url("suppliers/suggest"); ?>',
minChars:0,
delay:10,
max:100,
formatItem: function(row) {
return row[1];
select: function (a, ui) {
$(this).val(ui.item.value);
$("#select_supplier_form").submit();
}
});
$("#supplier").result(function(event, data, formatted)
{
$("#select_supplier_form").submit();
});
$('#supplier').blur(function()
{
$(this).attr('value',"<?php echo $this->lang->line('recvs_start_typing_supplier_name'); ?>");

View File

@@ -35,7 +35,8 @@
<div class="form-group form-group-sm">
<?php echo form_label($this->lang->line('sales_customer'), 'customer', array('class'=>'control-label col-xs-3')); ?>
<div class='col-xs-6'>
<?php echo form_input(array('name' => 'customer_id', 'value' => $selected_customer, 'id' => 'customer_id', 'class'=>'form-control input-sm'));?>
<?php echo form_input(array('name' => 'customer_name', 'value' => $selected_customer_name, 'id' => 'customer_name', 'class'=>'form-control input-sm'));?>
<?php echo form_hidden('customer_id', $selected_customer_id);?>
</div>
</div>
@@ -121,17 +122,24 @@ $(document).ready(function()
language: "<?php echo $this->config->item('language'); ?>"
});
var fill_value = function(event, ui) {
event.preventDefault();
$("input[name='customer_id']").val(ui.item.value);
$("input[name='customer_name']").val(ui.item.label);
};
var autocompleter = $("#customer_id").autocomplete(
{
source: '<?php echo site_url("customers/suggest"); ?>',
minChars: 0,
delay: 15,
cacheLength: 1,
appendTo: '.modal-content'
appendTo: '.modal-content',
select: fill_value,
focus: fill_value
});
// declare submitHandler as an object.. will be reused
var submit_form = function(selected_customer)
var submit_form = function()
{
$(this).ajaxSubmit(
{
@@ -142,7 +150,6 @@ $(document).ready(function()
},
error: function(jqXHR, textStatus, errorThrown)
{
selected_customer && autocompleter.val(selected_customer);
post_form_submit({message: errorThrown});
},
dataType: 'json'
@@ -153,10 +160,7 @@ $(document).ready(function()
{
submitHandler : function(form)
{
var selected_customer_id = autocompleter.val();
//var selected_customer_id = selected_customer.replace(/(\w)\|.*/, "$1");
selected_customer_id && autocompleter.val(selected_customer_id);
submit_form.call(form, selected_customer);
submit_form.call(form);
},
rules:
{

View File

@@ -13,7 +13,7 @@ $(document).ready(function()
};
// hook the ajax connectors on search actions, hook a on_complete action (refresh payment summaries at page bottom)
enable_search({suggest_url: '<?php echo site_url("$controller_name/suggest"); ?>',
enable_search({suggest_url: '<?php echo site_url("$controller_name/suggest_search"); ?>',
confirm_search_message: '<?php echo $this->lang->line("common_confirm_search"); ?>',
on_complete: on_complete});
enable_delete('<?php echo $this->lang->line($controller_name."_confirm_delete"); ?>', '<?php echo $this->lang->line($controller_name."_none_selected"); ?>');

View File

@@ -57,6 +57,7 @@ if (isset($success))
<label id="item_label" for="item", class='col-sm-2 control-label'><?php echo $this->lang->line('sales_find_or_scan_item_or_receipt'); ?></label>
<div class="col-sm-6">
<?php echo form_input(array('name'=>'item', 'id'=>'item', 'class'=>'form-control input-sm', 'tabindex'=>'1')); ?>
<span class="ui-helper-hidden-accessible" role="status"></span>
</div>
<?php echo anchor("items/view/-1", $this->lang->line('sales_new_item'),
@@ -438,22 +439,18 @@ if (isset($success))
<script type="text/javascript" language="javascript">
$(document).ready(function()
{
$("#item").autocomplete('<?php echo site_url("sales/item_search"); ?>',
$("#item").autocomplete(
{
source: '<?php echo site_url("sales/item_search"); ?>',
minChars:0,
max:100,
selectFirst: false,
autoFocus: false,
delay:10,
formatItem: function(row) {
return (row.length > 1 && row[1]) || row[0];
select: function (a, ui) {
$(this).val(ui.item.value);
$("#add_item_form").submit();
}
});
$("#item").result(function(event, data, formatted)
{
$("#add_item_form").submit();
});
$('#item').focus();
$('#item').blur(function()
@@ -471,21 +468,17 @@ $(document).ready(function()
$('#item, #customer').click(clear_fields);
$("#customer").autocomplete('<?php echo site_url("sales/customer_search"); ?>',
$("#customer").autocomplete(
{
source: '<?php echo site_url("customers/suggest"); ?>',
minChars:0,
delay:10,
max:100,
formatItem: function(row) {
return row[1];
select: function (a, ui) {
$(this).val(ui.item.value);
$("#select_customer_form").submit();
}
});
$("#customer").result(function(event, data, formatted)
{
$("#select_customer_form").submit();
});
$('#customer').blur(function()
{
$(this).val("<?php echo $this->lang->line('sales_start_typing_customer_name'); ?>");

View File

@@ -6,7 +6,7 @@ $(document).ready(function()
init_table_sorting();
enable_select_all();
enable_row_selection();
enable_search({suggest_url : '<?php echo site_url("$controller_name/suggest")?>', confirm_search_message : '<?php echo $this->lang->line("common_confirm_search")?>'});
enable_search({suggest_url : '<?php echo site_url("$controller_name/suggest_search")?>', confirm_search_message : '<?php echo $this->lang->line("common_confirm_search")?>'});
enable_email('<?php echo site_url("$controller_name/mailto")?>');
enable_delete('<?php echo $this->lang->line($controller_name."_confirm_delete")?>','<?php echo $this->lang->line($controller_name."_none_selected")?>');
});

View File

@@ -39,8 +39,7 @@
"smalot-bootstrap-datetimepicker": "^2.3.8",
"bootstrap-select": "^1.10.0",
"bootstrap-table": "^1.10.1",
"bootstrap-daterangepicker": "^2.1.18",
"jquery-ui-bootstrap": "^0.2.5"
"bootstrap-daterangepicker": "^2.1.18"
},
"overrides": {
"bootswatch-dist": {
@@ -48,6 +47,12 @@
"js/bootstrap.js",
"css/bootstrap.css"
]
},
"jquery-ui": {
"main": [
"themes/smoothness/jquery-ui.css",
"jquery-ui.js"
]
}
}
}

View File

@@ -51575,7 +51575,6 @@ dialog_support = (function() {
{
var handle_field_completion = handle_auto_completion(value.dependencies);
$("#" + key).autocomplete({
source: function (request, response) {
var extra_params = request_params(key, value.response && value.response.field, options.language);

View File

@@ -95,7 +95,6 @@
{
var handle_field_completion = handle_auto_completion(value.dependencies);
$("#" + key).autocomplete({
source: function (request, response) {
var extra_params = request_params(key, value.response && value.response.field, options.language);

View File

@@ -7,6 +7,7 @@
<link rel="shortcut icon" type="image/x-icon" href="images/favicon.ico">
<?php if ($this->input->cookie('debug') == "true" || $this->input->get("debug") == "true") : ?>
<!-- bower:css -->
<link rel="stylesheet" href="../bower_components/jquery-ui/themes/smoothness/jquery-ui.css" />
<link rel="stylesheet" href="../bower_components/tablesorter/dist/css/theme.blue.min.css" />
<link rel="stylesheet" href="../bower_components/bootstrap3-dialog/dist/css/bootstrap-dialog.min.css" />
<link rel="stylesheet" href="../bower_components/jasny-bootstrap/dist/css/jasny-bootstrap.css" />
@@ -15,7 +16,6 @@
<link rel="stylesheet" href="../bower_components/bootstrap-select/dist/css/bootstrap-select.css" />
<link rel="stylesheet" href="../bower_components/bootstrap-table/src/bootstrap-table.css" />
<link rel="stylesheet" href="../bower_components/bootstrap-daterangepicker/daterangepicker.css" />
<link rel="stylesheet" href="../bower_components/jquery-ui-bootstrap/jquery.ui.theme.css" />
<!-- endbower -->
<!-- start css template tags -->
<link rel="stylesheet" type="text/css" href="css/autocomplete.css"/>