Remove old jquery autocomplete

Remove id|name format in giftcards customer selection
Cleanup duplicated custom field suggestion in Items
Migrate table search suggestion to jQuery UI
Add jquery UI bootstrap theme
This commit is contained in:
jekkos
2016-03-07 07:56:41 +01:00
parent d78c4dec67
commit 6c29faeba1
32 changed files with 406 additions and 2328 deletions

View File

@@ -40,8 +40,14 @@ class Customers extends Person_controller
*/
function suggest()
{
$suggestions = $this->Customer->get_search_suggestions($this->input->post('q'),$this->input->post('limit'));
echo implode("\n",$suggestions);
$suggestions = $this->Customer->get_search_suggestions($this->input->post('term'), TRUE);
echo json_encode($suggestions);
}
function suggest_search()
{
$suggestions = $this->Customer->get_search_suggestions($this->input->post('term'), FALSE);
echo json_encode($suggestions);
}
/*

View File

@@ -40,8 +40,8 @@ class Employees extends Person_controller
*/
function suggest()
{
$suggestions = $this->Employee->get_search_suggestions($this->input->post('q'),$this->input->post('limit'));
echo implode("\n",$suggestions);
$suggestions = $this->Employee->get_search_suggestions($this->input->post('term'));
echo json_encode($suggestions);
}
/*

View File

@@ -41,17 +41,8 @@ class Giftcards extends Secure_area implements iData_controller
*/
function suggest()
{
$suggestions = $this->Giftcard->get_search_suggestions($this->input->post('q'), $this->input->post('limit'));
echo implode("\n",$suggestions);
}
/*
Gives search suggestions for person_id based on what is being searched for
*/
function person_search()
{
$suggestions = $this->Customer->get_customer_search_suggestions($this->input->post('q'), $this->input->post('limit'));
echo implode("\n",$suggestions);
$suggestions = $this->Giftcard->get_search_suggestions($this->input->post('term'), $this->input->post('limit'));
echo json_encode($suggestions);
}
function get_row()
@@ -65,7 +56,8 @@ class Giftcards extends Secure_area implements iData_controller
{
$giftcard_info = $this->Giftcard->get_info($giftcard_id);
$person_name=$giftcard_id > 0? $giftcard_info->first_name . ' ' . $giftcard_info->last_name : '';
$data['selected_person'] = $giftcard_id > 0 && isset($giftcard_info->person_id) ? $giftcard_info->person_id . "|" . $person_name : "";
$data['selected_person_name'] = $giftcard_id > 0 && isset($giftcard_info->person_id) ? $person_name : '';
$data['selected_person_id'] = $giftcard_info->person_id;
$data['giftcard_number'] = $giftcard_id > 0 ? $giftcard_info->giftcard_number : $this->Giftcard->get_max_number()->giftcard_number + 1;
$data['giftcard_info'] = $giftcard_info;
$this->load->view("giftcards/form",$data);

View File

@@ -73,9 +73,9 @@ class Item_kits extends Secure_area implements iData_controller
*/
function suggest()
{
$suggestions = $this->Item_kit->get_search_suggestions($this->input->post('q'), $this->input->post('limit'));
$suggestions = $this->Item_kit->get_search_suggestions($this->input->post('term'), $this->input->post('limit'));
echo implode("\n", $suggestions);
echo json_encode($suggestions);
}
function get_row()

View File

@@ -117,17 +117,17 @@ class Items extends Secure_area implements iData_controller
*/
function suggest()
{
$suggestions = $this->Item->get_search_suggestions($this->input->post('q'), $this->input->post('limit'),
$this->input->post('search_custom'), $this->input->post('is_deleted') != null);
echo implode("\n",$suggestions);
$suggestions = $this->Item->get_search_suggestions($this->input->post('term'), array(
'search_custom' => $this->input->post('search_custom'),
'is_deleted' => $this->input->post('is_deleted') != "0"),
FALSE, $this->input->post('limit'));
echo json_encode($suggestions);
}
function item_search()
{
$suggestions = $this->Item->get_item_search_suggestions($this->input->post('q'), $this->input->post('limit'));
echo implode("\n",$suggestions);
function suggest_search()
{
$suggestions = $this->Item->get_search_suggestions($this->input->post('term'), TRUE);
echo json_encode($suggestions);
}
/*
@@ -135,9 +135,9 @@ class Items extends Secure_area implements iData_controller
*/
function suggest_category()
{
$suggestions = $this->Item->get_category_suggestions($this->input->post('q'));
$suggestions = $this->Item->get_category_suggestions($this->input->post('term'));
echo implode("\n",$suggestions);
echo json_encode($suggestions);
}
/*
@@ -145,111 +145,19 @@ class Items extends Secure_area implements iData_controller
*/
function suggest_location()
{
$suggestions = $this->Item->get_location_suggestions($this->input->post('q'));
echo implode("\n",$suggestions);
$suggestions = $this->Item->get_location_suggestions($this->input->post('term'));
echo json_encode($suggestions);
}
/*
Gives search suggestions based on what is being searched for
*/
function suggest_custom1()
function suggest_custom()
{
$suggestions = $this->Item->get_custom1_suggestions($this->input->post('q'));
echo implode("\n",$suggestions);
$suggestions = $this->Item->get_custom_suggestions($this->input->post('term'), $this->input->post('field_no'));
echo json_encode($suggestions);
}
/*
Gives search suggestions based on what is being searched for
*/
function suggest_custom2()
{
$suggestions = $this->Item->get_custom2_suggestions($this->input->post('q'));
echo implode("\n",$suggestions);
}
/*
Gives search suggestions based on what is being searched for
*/
function suggest_custom3()
{
$suggestions = $this->Item->get_custom3_suggestions($this->input->post('q'));
echo implode("\n",$suggestions);
}
/*
Gives search suggestions based on what is being searched for
*/
function suggest_custom4()
{
$suggestions = $this->Item->get_custom4_suggestions($this->input->post('q'));
echo implode("\n",$suggestions);
}
/*
Gives search suggestions based on what is being searched for
*/
function suggest_custom5()
{
$suggestions = $this->Item->get_custom5_suggestions($this->input->post('q'));
echo implode("\n",$suggestions);
}
/*
Gives search suggestions based on what is being searched for
*/
function suggest_custom6()
{
$suggestions = $this->Item->get_custom6_suggestions($this->input->post('q'));
echo implode("\n",$suggestions);
}
/*
Gives search suggestions based on what is being searched for
*/
function suggest_custom7()
{
$suggestions = $this->Item->get_custom7_suggestions($this->input->post('q'));
echo implode("\n",$suggestions);
}
/*
Gives search suggestions based on what is being searched for
*/
function suggest_custom8()
{
$suggestions = $this->Item->get_custom8_suggestions($this->input->post('q'));
echo implode("\n",$suggestions);
}
/*
Gives search suggestions based on what is being searched for
*/
function suggest_custom9()
{
$suggestions = $this->Item->get_custom9_suggestions($this->input->post('q'));
echo implode("\n",$suggestions);
}
/*
Gives search suggestions based on what is being searched for
*/
function suggest_custom10()
{
$suggestions = $this->Item->get_custom10_suggestions($this->input->post('q'));
echo implode("\n",$suggestions);
}
function get_row()
{
$item_id = $this->input->post('row_id');

View File

@@ -16,15 +16,15 @@ class Receivings extends Secure_area
function item_search()
{
$suggestions = $this->Item->get_item_search_suggestions($this->input->post('q'),$this->input->post('limit'));
$suggestions = array_merge($suggestions, $this->Item_kit->get_item_kit_search_suggestions($this->input->post('q'),$this->input->post('limit')));
echo implode("\n",$suggestions);
$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('q'),$this->input->post('limit'));
echo implode("\n",$suggestions);
$suggestions = $this->Supplier->get_suppliers_search_suggestions($this->input->post('term'),$this->input->post('limit'));
echo json_encode($suggestions);
}
function select_supplier()

View File

@@ -126,36 +126,22 @@ class Sales extends Secure_area
function item_search()
{
$suggestions = array();
$search = $this->input->post('q');
$limit = $this->input->post('limit');
$search = $this->input->post('term');
if ($this->sale_lib->get_mode() == 'return' && $this->sale_lib->is_valid_receipt($search) )
{
$suggestions[] = $search;
}
$suggestions = array_merge($suggestions, $this->Item->get_item_search_suggestions($search , $limit));
$suggestions = array_merge($suggestions, $this->Item_kit->get_item_kit_search_suggestions($search, $limit));
$suggestions = array_merge($suggestions, $this->Item->get_search_suggestions($search));
$suggestions = array_merge($suggestions, $this->Item_kit->get_item_kit_search_suggestions($search));
echo implode("\n", $suggestions);
}
function customer_search()
{
$search = $this->input->post('q');
$limit = $this->input->post('limit');
$suggestions = $this->Customer->get_customer_search_suggestions($search, $limit);
echo implode("\n", $suggestions);
echo json_encode($suggestions);
}
function suggest()
{
$search = $this->input->post('q');
$limit = $this->input->post('limit');
$suggestions = $this->Sale->get_search_suggestions($search, $limit);
echo implode("\n", $suggestions);
$suggestions = $this->Sale->get_search_suggestions($this->input->post('term'));
echo json_encode($suggestions);
}
function select_customer()

View File

@@ -42,7 +42,7 @@ class Suppliers extends Person_controller
function suggest()
{
$suggestions = $this->Supplier->get_search_suggestions($this->input->post('q'),$this->input->post('limit'));
echo implode("\n",$suggestions);
echo json_encode($suggestions);
}
/*

View File

@@ -141,7 +141,7 @@ class Customer extends Person
/*
Get search suggestions to find customers
*/
function get_search_suggestions($search,$limit=25)
function get_search_suggestions($search, $unique=TRUE, $limit=25)
{
$suggestions = array();
@@ -154,41 +154,45 @@ class Customer extends Person
$by_name = $this->db->get();
foreach($by_name->result() as $row)
{
$suggestions[]=$row->first_name.' '.$row->last_name;
}
$this->db->from('customers');
$this->db->join('people','customers.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[]=$row->email;
$suggestions[]=array('value' => $row->person_id, 'label' => $row->first_name.' '.$row->last_name);
}
$this->db->from('customers');
$this->db->join('people','customers.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)
if (!$unique)
{
$suggestions[]=$row->phone_number;
}
$this->db->from('customers');
$this->db->join('people','customers.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[]=$row->account_number;
$this->db->from('customers');
$this->db->join('people','customers.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('customers');
$this->db->join('people','customers.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('customers');
$this->db->join('people','customers.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))
@@ -197,46 +201,7 @@ class Customer extends Person
}
return $suggestions;
}
/*
Get search suggestions to find customers
*/
function get_customer_search_suggestions($search,$limit=25)
{
$suggestions = array();
$this->db->from('customers');
$this->db->join('people','customers.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[]=$row->person_id.'|'.$row->first_name.' '.$row->last_name;
}
$this->db->from('customers');
$this->db->join('people','customers.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[]=$row->person_id.'|'.$row->account_number;
}
//only return $limit suggestions
if(count($suggestions > $limit))
{
$suggestions = array_slice($suggestions, 0,$limit);
}
return $suggestions;
}
function get_found_rows($search)
{
$this->db->from('customers');

View File

@@ -192,7 +192,7 @@ class Employee extends Person
$by_name = $this->db->get();
foreach($by_name->result() as $row)
{
$suggestions[]=$row->first_name.' '.$row->last_name;
$suggestions[]=array('value' => $row->person_id, 'label' => $row->first_name.' '.$row->last_name);
}
$this->db->from('employees');
@@ -203,7 +203,7 @@ class Employee extends Person
$by_email = $this->db->get();
foreach($by_email->result() as $row)
{
$suggestions[]=$row->email;
$suggestions[]=array('value' => $row->person_id, 'label' => $row->email);
}
$this->db->from('employees');
@@ -214,7 +214,7 @@ class Employee extends Person
$by_username = $this->db->get();
foreach($by_username->result() as $row)
{
$suggestions[]=$row->username;
$suggestions[]=array('value' => $row->person_id, 'label' => $row->username);
}
@@ -226,7 +226,7 @@ class Employee extends Person
$by_phone = $this->db->get();
foreach($by_phone->result() as $row)
{
$suggestions[]=$row->phone_number;
$suggestions[]=array('value' => $row->person_id, 'label' => $row->phone_number);
}

View File

@@ -184,21 +184,21 @@ class Giftcard extends CI_Model
foreach($by_number->result() as $row)
{
$suggestions[]=$row->giftcard_number;
$suggestions[]=array('label' => $row->giftcard_number);
}
$this->db->from('customers');
$this->db->join('people', 'customers.person_id=people.person_id', 'left');
$this->db->from('customers');
$this->db->join('people', 'customers.person_id=people.person_id', 'left');
$this->db->like('first_name', $this->db->escape_like_str($search));
$this->db->or_like('last_name', $this->db->escape_like_str($search));
$this->db->or_like('CONCAT(first_name, " ", last_name)', $this->db->escape_like_str($search));
$this->db->where('deleted', 0);
$this->db->order_by('last_name', 'asc');
$by_name = $this->db->get();
$this->db->where('deleted', 0);
$this->db->order_by('last_name', 'asc');
$by_name = $this->db->get();
foreach($by_name->result() as $row)
{
$suggestions[]=$row->first_name.' '.$row->last_name;
foreach($by_name->result() as $row)
{
$suggestions[]=array('label' => $row->first_name.' '.$row->last_name);
}
//only return $limit suggestions
@@ -209,49 +209,49 @@ class Giftcard extends CI_Model
return $suggestions;
}
/*
Get search suggestions to find customers
*/
function get_person_search_suggestions($search,$limit=25)
{
$suggestions = array();
$this->db->select('person_id');
/*
Get search suggestions to find customers
*/
function get_person_search_suggestions($search,$limit=25)
{
$suggestions = array();
$this->db->select('person_id');
$this->db->from('people');
$this->db->like('person_id', $this->db->escape_like_str($search));
$this->db->or_like('first_name', $this->db->escape_like_str($search));
$this->db->or_like('last_name', $this->db->escape_like_str($search));
$this->db->or_like('CONCAT(first_name, " ", last_name)', $this->db->escape_like_str($search));
$this->db->or_like('email', $this->db->escape_like_str($search));
$this->db->or_like('phone_number', $this->db->escape_like_str($search));
$this->db->order_by('person_id', 'asc');
$by_person_id = $this->db->get();
foreach($by_person_id->result() as $row)
{
$suggestions[]=$row->person_id;
}
//only return $limit suggestions
if(count($suggestions > $limit))
{
$suggestions = array_slice($suggestions, 0,$limit);
$this->db->like('person_id', $this->db->escape_like_str($search));
$this->db->or_like('first_name', $this->db->escape_like_str($search));
$this->db->or_like('last_name', $this->db->escape_like_str($search));
$this->db->or_like('CONCAT(first_name, " ", last_name)', $this->db->escape_like_str($search));
$this->db->or_like('email', $this->db->escape_like_str($search));
$this->db->or_like('phone_number', $this->db->escape_like_str($search));
$this->db->order_by('person_id', 'asc');
$by_person_id = $this->db->get();
foreach($by_person_id->result() as $row)
{
$suggestions[]=array('label' => $row->person_id);
}
return $suggestions;
//only return $limit suggestions
if(count($suggestions > $limit))
{
$suggestions = array_slice($suggestions, 0,$limit);
}
return $suggestions;
}
/*
Preform a search on giftcards
*/
function search($search, $rows = 0, $limit_from = 0)
{
$this->db->from('giftcards');
{
$this->db->from('giftcards');
$this->db->join('people', 'giftcards.person_id=people.person_id', 'left');
$this->db->like('first_name', $this->db->escape_like_str($search));
$this->db->or_like('last_name', $this->db->escape_like_str($search));
$this->db->or_like('CONCAT(first_name, " ", last_name)', $this->db->escape_like_str($search));
$this->db->like('first_name', $this->db->escape_like_str($search));
$this->db->or_like('last_name', $this->db->escape_like_str($search));
$this->db->or_like('CONCAT(first_name, " ", last_name)', $this->db->escape_like_str($search));
$this->db->or_like('giftcard_number', $this->db->escape_like_str($search));
$this->db->or_like('giftcards.person_id', $this->db->escape_like_str($search));
$this->db->where('deleted', 0);
@@ -261,7 +261,7 @@ class Giftcard extends CI_Model
{
$this->db->limit($rows, $limit_from);
}
return $this->db->get();
}

View File

@@ -263,156 +263,67 @@ class Item extends CI_Model
return $this->db->update('items', array('deleted' => 1));
}
/*
Get search suggestions to find items
*/
public function get_search_suggestions($search, $limit=25, $search_custom=0, $is_deleted=0)
public function get_search_suggestions($search, $filters, $unique = FALSE, $limit=25)
{
$suggestions = array();
$this->db->select('category');
$this->db->select('item_id, name');
$this->db->from('items');
$this->db->where('deleted', $is_deleted);
$this->db->distinct();
$this->db->like('category', $search);
$this->db->order_by('category', 'asc');
$by_category = $this->db->get();
foreach($by_category->result() as $row)
$this->db->where('deleted', $filters['is_deleted']);
$this->db->like('name', $search);
$this->db->order_by('name', 'asc');
$by_name = $this->db->get();
foreach($by_name->result() as $row)
{
$suggestions[] = $row->category;
$suggestions[] = array('value' => $row->item_id, 'label' => $row->name);
}
$this->db->select('item_id, item_number');
$this->db->from('items');
$this->db->where('deleted', $filters['is_deleted']);
$this->db->like('item_number', $search);
$this->db->order_by('item_number', 'asc');
$by_item_number = $this->db->get();
foreach($by_item_number->result() as $row)
{
$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
if( $is_deleted == 0 )
{
$this->db->where('deleted', $is_deleted);
}
$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[] = $row->company_name;
}
$this->db->select('name');
$this->db->from('items');
$this->db->like('name', $search);
$this->db->where('deleted', $is_deleted);
$this->db->order_by('name', 'asc');
$by_name = $this->db->get();
foreach($by_name->result() as $row)
{
$suggestions[] = $row->name;
}
$this->db->select('item_number');
$this->db->from('items');
$this->db->like('item_number', $search);
$this->db->where('deleted', $is_deleted);
$this->db->order_by('item_number', 'asc');
$by_item_number = $this->db->get();
foreach($by_item_number->result() as $row)
{
$suggestions[] = $row->item_number;
}
//Search by description
$this->db->select('name, description');
$this->db->from('items');
$this->db->like('description', $search);
$this->db->where('deleted', $is_deleted);
$this->db->order_by('description', 'asc');
$by_name = $this->db->get();
foreach($by_name->result() as $row)
{
if (!in_array($row->name, $suggestions))
{
$suggestions[] = $row->name;
}
}
//Search by custom fields
if ($search_custom != 0)
{
$this->db->from('items');
$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->where('deleted', $is_deleted);
$by_name = $this->db->get();
foreach($by_name->result() as $row)
{
$suggestions[] = $row->name;
}
}
//only return $limit suggestions
if(count($suggestions > $limit))
{
$suggestions = array_slice($suggestions, 0, $limit);
}
return $suggestions;
}
public function get_item_search_suggestions($search, $limit=25, $search_custom=0, $is_deleted=0)
{
$suggestions = array();
$this->db->select('item_id, name');
$this->db->from('items');
$this->db->where('deleted', $is_deleted);
$this->db->like('name', $search);
$this->db->order_by('name', 'asc');
$by_name = $this->db->get();
foreach($by_name->result() as $row)
{
$suggestions[] = $row->item_id.'|'.$row->name;
}
$this->db->select('item_id, item_number');
$this->db->from('items');
$this->db->where('deleted', $is_deleted);
$this->db->like('item_number', $search);
$this->db->order_by('item_number', 'asc');
$by_item_number = $this->db->get();
foreach($by_item_number->result() as $row)
{
$suggestions[] = $row->item_id.'|'.$row->item_number;
$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', $is_deleted);
$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 = $row->item_id.'|'.$row->name;
if (!in_array($entry, $suggestions))
{
$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 ($search_custom != 0)
if ($filters['search_custom'] != 0)
{
$this->db->from('items');
$this->db->where('deleted', $is_deleted);
$this->db->where('deleted', $filters['is_deleted']);
$this->db->like('custom1', $search);
$this->db->or_like('custom2', $search);
$this->db->or_like('custom3', $search);
@@ -426,7 +337,7 @@ class Item extends CI_Model
$by_description = $this->db->get();
foreach($by_description->result() as $row)
{
$suggestions[] = $row->item_id.'|'.$row->name;
$suggestions[] = array('value' => $row->item_id, 'label' => $row->name);
}
}
@@ -451,7 +362,7 @@ class Item extends CI_Model
$by_category = $this->db->get();
foreach($by_category->result() as $row)
{
$suggestions[] = $row->category;
$suggestions[] = array('label' => $row->category);
}
return $suggestions;
@@ -469,187 +380,26 @@ class Item extends CI_Model
$by_category = $this->db->get();
foreach($by_category->result() as $row)
{
$suggestions[] = $row->location;
$suggestions[] = array('label' => $row->location);
}
return $suggestions;
}
public function get_custom1_suggestions($search)
public function get_custom_suggestions($search, $field_no)
{
$suggestions = array();
$this->db->distinct();
$this->db->select('custom1');
$this->db->select('custom'.$field_no);
$this->db->from('items');
$this->db->like('custom1', $search);
$this->db->like('custom'.$field_no, $search);
$this->db->where('deleted', 0);
$this->db->order_by('custom1', 'asc');
$this->db->order_by('custom'.$field_no, 'asc');
$by_category = $this->db->get();
foreach($by_category->result() as $row)
{
$suggestions[] = $row->custom1;
}
return $suggestions;
}
public function get_custom2_suggestions($search)
{
$suggestions = array();
$this->db->distinct();
$this->db->select('custom2');
$this->db->from('items');
$this->db->like('custom2', $search);
$this->db->where('deleted', 0);
$this->db->order_by('custom2', 'asc');
$by_category = $this->db->get();
foreach($by_category->result() as $row)
{
$suggestions[] = $row->custom2;
}
return $suggestions;
}
public function get_custom3_suggestions($search)
{
$suggestions = array();
$this->db->distinct();
$this->db->select('custom3');
$this->db->from('items');
$this->db->like('custom3', $search);
$this->db->where('deleted', 0);
$this->db->order_by('custom3', 'asc');
$by_category = $this->db->get();
foreach($by_category->result() as $row)
{
$suggestions[] = $row->custom3;
}
return $suggestions;
}
public function get_custom4_suggestions($search)
{
$suggestions = array();
$this->db->distinct();
$this->db->select('custom4');
$this->db->from('items');
$this->db->like('custom4', $search);
$this->db->where('deleted', 0);
$this->db->order_by('custom4', 'asc');
$by_category = $this->db->get();
foreach($by_category->result() as $row)
{
$suggestions[] = $row->custom4;
}
return $suggestions;
}
public function get_custom5_suggestions($search)
{
$suggestions = array();
$this->db->distinct();
$this->db->select('custom5');
$this->db->from('items');
$this->db->like('custom5', $search);
$this->db->where('deleted', 0);
$this->db->order_by('custom5', 'asc');
$by_category = $this->db->get();
foreach($by_category->result() as $row)
{
$suggestions[] = $row->custom5;
}
return $suggestions;
}
public function get_custom6_suggestions($search)
{
$suggestions = array();
$this->db->distinct();
$this->db->select('custom6');
$this->db->from('items');
$this->db->like('custom6', $search);
$this->db->where('deleted', 0);
$this->db->order_by('custom6', 'asc');
$by_category = $this->db->get();
foreach($by_category->result() as $row)
{
$suggestions[] = $row->custom6;
}
return $suggestions;
}
public function get_custom7_suggestions($search)
{
$suggestions = array();
$this->db->distinct();
$this->db->select('custom7');
$this->db->from('items');
$this->db->like('custom7', $search);
$this->db->where('deleted', 0);
$this->db->order_by('custom7', 'asc');
$by_category = $this->db->get();
foreach($by_category->result() as $row)
{
$suggestions[] = $row->custom7;
}
return $suggestions;
}
public function get_custom8_suggestions($search)
{
$suggestions = array();
$this->db->distinct();
$this->db->select('custom8');
$this->db->from('items');
$this->db->like('custom8', $search);
$this->db->where('deleted', 0);
$this->db->order_by('custom8', 'asc');
$by_category = $this->db->get();
foreach($by_category->result() as $row)
{
$suggestions[] = $row->custom8;
}
return $suggestions;
}
public function get_custom9_suggestions($search)
{
$suggestions = array();
$this->db->distinct();
$this->db->select('custom9');
$this->db->from('items');
$this->db->like('custom9', $search);
$this->db->where('deleted', 0);
$this->db->order_by('custom9', 'asc');
$by_category = $this->db->get();
foreach($by_category->result() as $row)
{
$suggestions[] = $row->custom9;
}
return $suggestions;
}
public function get_custom10_suggestions($search)
{
$suggestions = array();
$this->db->distinct();
$this->db->select('custom10');
$this->db->from('items');
$this->db->like('custom10', $search);
$this->db->where('deleted', 0);
$this->db->order_by('custom10', 'asc');
$by_category = $this->db->get();
foreach($by_category->result() as $row)
{
$suggestions[] = $row->custom10;
$row_array = (array) $row;
$suggestions[] = array('label' => $row_array['custom'.$field_no]);
}
return $suggestions;
@@ -665,7 +415,7 @@ class Item extends CI_Model
return $this->db->get();
}
/*
* changes the cost price of a given item
* calculates the average price between received items and items on stock
@@ -673,10 +423,10 @@ class Item extends CI_Model
* $items_received : the amount of new items received
* $new_price : the cost-price for the newly received items
* $old_price (optional) : the current-cost-price
*
*
* used in receiving-process to update cost-price if changed
* caution: must be used there before item_quantities gets updated, otherwise average price is wrong!
*
*
*/
public function change_cost_price($item_id, $items_received, $new_price, $old_price = null)
{
@@ -697,7 +447,7 @@ class Item extends CI_Model
$average_price = bcdiv(bcadd(bcmul($items_received, $new_price), bcmul($old_total_quantity, $old_price)), $total_quantity);
$data = array('cost_price' => $average_price);
return $this->save($data, $item_id);
}
}

View File

@@ -118,54 +118,10 @@ class Item_kit extends CI_Model
return $this->db->delete('item_kits');
}
/*
Get search suggestions to find kits
*/
function get_search_suggestions($search, $limit=25)
{
$suggestions = array();
$this->db->from('item_kits');
//KIT #
if (stripos($search, 'KIT ') !== false)
{
$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[] = '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[] = $row->name;
}
}
//only return $limit suggestions
if(count($suggestions > $limit))
{
$suggestions = array_slice($suggestions, 0, $limit);
}
return $suggestions;
}
function get_item_kit_search_suggestions($search, $limit=25)
{
$suggestions = array();
$this->db->from('item_kits');
$this->db->like('name', $search);
$this->db->order_by('name', 'asc');
@@ -173,8 +129,7 @@ class Item_kit extends CI_Model
foreach($by_name->result() as $row)
{
// do not touch the '|' otherwise the sale search will not fetch the kit
$suggestions[] = 'KIT ' . $row->item_kit_id . '|' . $row->name;
$suggestions[] = array('value' => 'KIT ' . $row->item_kit_id, 'label' => $row->name);
}
//only return $limit suggestions

View File

@@ -85,15 +85,15 @@ class Person extends CI_Model
return $this->db->update('people',$person_data);
}
/*
Get search suggestions to find customers
*/
function get_search_suggestions($search,$limit=25)
{
$suggestions = array();
/*
Get search suggestions to find customers
*/
function get_search_suggestions($search,$limit=25)
{
$suggestions = array();
// $this->db->select("person_id");
// $this->db->from('people');
// $this->db->from('people');
// $this->db->where('deleted',0);
// $this->db->where('person_id',$this->db->escape($search));
// $this->db->like('first_name',$this->db->escape_like_str($search));
@@ -101,20 +101,20 @@ class Person extends CI_Model
// $this->db->or_like("CONCAT(`first_name`,' ',`last_name`)",$this->db->escape_like_str($search));
// $this->db->or_like('email',$search);
// $this->db->or_like('phone_number',$search);
// $this->db->order_by('last_name', "asc");
$by_person_id = $this->db->get();
// $this->db->order_by('last_name', "asc");
$by_person_id = $this->db->get();
foreach($by_person_id->result() as $row)
{
$suggestions[]=$row->person_id;
}
//only return $limit suggestions
if(count($suggestions > $limit))
{
$suggestions = array_slice($suggestions, 0,$limit);
foreach($by_person_id->result() as $row)
{
$suggestions[]=array('label' => $row->person_id);
}
//only return $limit suggestions
if(count($suggestions > $limit))
{
$suggestions = array_slice($suggestions, 0,$limit);
}
return $suggestions;
}

View File

@@ -194,7 +194,7 @@ class Sale extends CI_Model
foreach($this->db->get()->result_array() as $result)
{
$suggestions[] = $result[ 'first_name' ].' '.$result[ 'last_name' ];
$suggestions[] = array('label' => $result[ 'first_name' ].' '.$result[ 'last_name' ]);
}
}
else

View File

@@ -148,7 +148,7 @@ class Supplier extends Person
$by_company_name = $this->db->get();
foreach($by_company_name->result() as $row)
{
$suggestions[]=$row->company_name;
$suggestions[]=array('label' => $row->company_name);
}
$this->db->from('suppliers');
@@ -160,7 +160,7 @@ class Supplier extends Person
$by_agency_name = $this->db->get();
foreach($by_agency_name->result() as $row)
{
$suggestions[]=$row->agency_name;
$suggestions[]=array('label' => $row->agency_name);
}
$this->db->from('suppliers');
@@ -172,7 +172,7 @@ class Supplier extends Person
$by_name = $this->db->get();
foreach($by_name->result() as $row)
{
$suggestions[]=$row->first_name.' '.$row->last_name;
$suggestions[]=array('label' => $row->first_name.' '.$row->last_name);
}
$this->db->from('suppliers');
@@ -183,7 +183,7 @@ class Supplier extends Person
$by_email = $this->db->get();
foreach($by_email->result() as $row)
{
$suggestions[]=$row->email;
$suggestions[]=array('label' => $row->email);
}
$this->db->from('suppliers');
@@ -194,7 +194,7 @@ class Supplier extends Person
$by_phone = $this->db->get();
foreach($by_phone->result() as $row)
{
$suggestions[]=$row->phone_number;
$suggestions[]=array('label' => $row->phone_number);
}
$this->db->from('suppliers');
@@ -205,7 +205,7 @@ class Supplier extends Person
$by_account_number = $this->db->get();
foreach($by_account_number->result() as $row)
{
$suggestions[]=$row->account_number;
$suggestions[]=array('label' => $row->account_number);
}
//only return $limit suggestions
@@ -232,7 +232,7 @@ class Supplier extends Person
$by_company_name = $this->db->get();
foreach($by_company_name->result() as $row)
{
$suggestions[]=$row->person_id.'|'.$row->company_name;
$suggestions[]=array('value' => $row->person_id, 'label' => $row->company_name);
}
@@ -245,7 +245,7 @@ class Supplier extends Person
$by_agency_name = $this->db->get();
foreach($by_agency_name->result() as $row)
{
$suggestions[]=$row->person_id.'|'.$row->agency_name;
$suggestions[]=array('value' => $row->person_id, 'label' => $row->agency_name);
}
@@ -258,7 +258,7 @@ class Supplier extends Person
$by_name = $this->db->get();
foreach($by_name->result() as $row)
{
$suggestions[]=$row->person_id.'|'.$row->first_name.' '.$row->last_name;
$suggestions[]=array('value' => $row->person_id, 'label' => $row->first_name.' '.$row->last_name);
}
//only return $limit suggestions

View File

@@ -8,11 +8,12 @@
<?php echo form_label($this->lang->line('giftcards_person_id'), 'name', array('class'=>'control-label col-xs-3')); ?>
<div class='col-xs-6'>
<?php echo form_input(array(
'name'=>'person_id',
'id'=>'person_id',
'name'=>'person_name',
'id'=>'person_name',
'class'=>'form-control input-sm',
'value'=>$selected_person)
'value'=>$selected_person_name)
);?>
<?php echo form_hidden('person_id', $selected_person_id);?>
</div>
</div>
@@ -46,22 +47,25 @@
//validation and submit handling
$(document).ready(function()
{
var format_item = function(row)
{
return [row[0], "|", row[1]].join("");
var fill_value = function(event, ui) {
event.preventDefault();
$("input[name='person_id']").val(ui.item.value);
$("input[name='person_name']").val(ui.item.label);
};
var autocompleter = $("#person_id").autocomplete('<?php echo site_url("giftcards/person_search"); ?>',
var autocompleter = $("#person_name").autocomplete(
{
source: '<?php echo site_url("customers/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_person)
var submit_form = function()
{
$(this).ajaxSubmit(
{
@@ -72,7 +76,6 @@ $(document).ready(function()
},
error: function(jqXHR, textStatus, errorThrown)
{
selected_customer && autocompleter.val(selected_person);
post_giftcard_form_submit({message: errorThrown});
},
dataType:'json'
@@ -82,10 +85,7 @@ $(document).ready(function()
$('#giftcard_form').validate($.extend({
submitHandler:function(form)
{
var selected_person = autocompleter.val();
var selected_person_id = selected_person && selected_person.replace(/(\w)\|.*/, "$1");
selected_person_id && autocompleter.val(selected_person_id);
submit_form.call(form, selected_person);
submit_form.call(form)
},
rules:
{

View File

@@ -54,7 +54,7 @@
?>
<tr>
<?php $item_info = $this->Item->get_info($item_kit_item['item_id']); ?>
<td><a href='#' onclick='return deleteItemKitRow(this);'><span class='glyphicon glyphicon-trash'></span></a></td>
<td><a href='#' onclick='return delete_item_kit_row(this);'><span class='glyphicon glyphicon-trash'></span></a></td>
<td><?php echo $item_info->name; ?></td>
<td><input class='quantity form-control input-sm' id='item_kit_item_<?php echo $item_kit_item['item_id'] ?>' name=item_kit_item[<?php echo $item_kit_item['item_id'] ?>] value='<?php echo $item_kit_item['quantity'] ?>'/></td>
</tr>
@@ -67,39 +67,33 @@
<?php echo form_close(); ?>
<script type='text/javascript'>
$("#item").autocomplete('<?php echo site_url("items/item_search"); ?>',
{
minChars:0,
max:100,
selectFirst: false,
delay:10,
formatItem: function(row) {
return row[1];
}
});
$("#item").result(function(event, data, formatted)
{
$("#item").val("");
if ($("#item_kit_item_"+data[0]).length ==1)
{
$("#item_kit_item_"+data[0]).val(parseFloat($("#item_kit_item_"+data[0]).val()) + 1);
}
else
{
$("#item_kit_items").append("<tr><td><a href='#' onclick='return deleteItemKitRow(this);'><span class='glyphicon glyphicon-trash'></span></a></td><td>"+data[1]+"</td><td><input class='quantity form-control input-sm' id='item_kit_item_"+data[0]+"' type='text' name=item_kit_item["+data[0]+"] value='1'/></td></tr>");
}
});
//validation and submit handling
$(document).ready(function()
{
$("#item").autocomplete({
source: '<?php echo site_url("items/item_search"); ?>',
minChars:0,
autoFocus: false,
delay:10,
appendTo: ".modal-content",
select: function(e, ui) {
if ($("#item_kit_item_" + ui.item.value).length == 1)
{
$("#item_kit_item_" + ui.item.value).val(parseFloat( $("#item_kit_item_" + ui.item.value).val()) + 1);
}
else
{
$("#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("");
}
});
$('#item_kit_form').validate($.extend({
submitHandler:function(form)
{
$(form).ajaxSubmit({
$(form).ajaxSubmit({
success:function(response)
{
dialog_support.hide();
@@ -122,9 +116,10 @@ $(document).ready(function()
}, dialog_support.error));
});
function deleteItemKitRow(link)
function delete_item_kit_row(link)
{
$(link).parent().parent().remove();
return false;
}
</script>

View File

@@ -295,12 +295,29 @@
});
var no_op = function(event, data, formatted){};
$("#category").autocomplete("<?php echo site_url('items/suggest_category');?>",{max:100,minChars:0,delay:10}).result(no_op).search();
$("#category").autocomplete({source: "<?php echo site_url('items/suggest_category');?>",delay:10,appendTo: '.modal-content'});
<?php for ($i = 1; $i <= 10; $i++)
{
?>
$("#custom"+<?php echo $i; ?>).autocomplete("<?php echo site_url('items/suggest_custom'.$i);?>",{max:100,minChars:0,delay:10}).result(no_op).search();
$("#custom"+<?php echo $i; ?>).autocomplete({
source:function (request, response) {
$.ajax({
type: "POST",
url: "<?php echo site_url('items/suggest_custom');?>",
dataType: "json",
data: $.extend(request, {field_no: <?php echo $i; ?>}),
success: function(data) {
response($.map(data, function(item) {
return {
value: item.label
};
}))
}
});
},
delay:10,
appendTo: '.modal-content'});
<?php
}
?>

View File

@@ -177,7 +177,7 @@ function post_bulk_form_submit(response)
<img src="<?php echo base_url().'images/plus.png'; ?>" style="border:0;outline:none;padding:0px;margin:0px;position:relative;top:-5px;"></a>
</div>
<?php echo form_open("$controller_name/search", array('id'=>'search_form')); ?>
<?php echo form_open("$controller_name/search", array('id'=>'search_form', 'class'=>'form-horizontal')); ?>
<div id="search_filter_section" style="display:none;">
<?php echo form_label($this->lang->line('items_empty_upc_items').' '.':', 'empty_upc');?>
<?php echo form_checkbox(array('name'=>'empty_upc','id'=>'empty_upc','value'=>1,'checked'=> isset($empty_upc)? ( ($empty_upc)? 1 : 0) : 0)).' | ';?>

View File

@@ -15,9 +15,9 @@
<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"/>
<link rel="stylesheet" type="text/css" href="css/barcode_font.css"/>
<link rel="stylesheet" type="text/css" href="css/general.css"/>
<link rel="stylesheet" type="text/css" href="css/invoice.css"/>
@@ -50,7 +50,6 @@
<!-- endbower -->
<!-- start js template tags -->
<script type="text/javascript" src="js/jquery.ajax_queue.js" language="javascript"></script>
<script type="text/javascript" src="js/jquery.autocomplete.js" language="javascript"></script>
<script type="text/javascript" src="js/jquery.jkey-1.1.js" language="javascript"></script>
<script type="text/javascript" src="js/jquery.tablesorter.staticrow.js" language="javascript"></script>
<script type="text/javascript" src="js/common.js" language="javascript"></script>
@@ -65,10 +64,10 @@
<![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/opensourcepos.min.css?rel=f940457590"/>
<link rel="stylesheet" type="text/css" href="dist/opensourcepos.min.css?rel=63bde3dd80"/>
<!-- end mincss template tags -->
<!-- start minjs template tags -->
<script type="text/javascript" src="dist/opensourcepos.min.js?rel=906f616faa" language="javascript"></script>
<script type="text/javascript" src="dist/opensourcepos.min.js?rel=8aac97eb12" language="javascript"></script>
<!-- end minjs template tags -->
<?php endif; ?>

View File

@@ -121,25 +121,13 @@ $(document).ready(function()
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 autocompleter = $("#customer_id").autocomplete('<?php echo site_url("sales/customer_search"); ?>',
var autocompleter = $("#customer_id").autocomplete(
{
source: '<?php echo site_url("customers/suggest"); ?>',
minChars: 0,
delay: 15,
max: 100,
cacheLength: 1,
formatItem: format_item,
formatResult : format_item
appendTo: '.modal-content'
});
// declare submitHandler as an object.. will be reused
@@ -165,8 +153,8 @@ $(document).ready(function()
{
submitHandler : function(form)
{
var selected_customer = autocompleter.val();
var selected_customer_id = selected_customer.replace(/(\w)\|.*/, "$1");
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);
},

View File

@@ -39,7 +39,8 @@
"smalot-bootstrap-datetimepicker": "^2.3.8",
"bootstrap-select": "^1.10.0",
"bootstrap-table": "^1.10.1",
"bootstrap-daterangepicker": "^2.1.18"
"bootstrap-daterangepicker": "^2.1.18",
"jquery-ui-bootstrap": "^0.2.5"
},
"overrides": {
"bootswatch-dist": {

View File

@@ -1,54 +0,0 @@
.ac_results
{
padding: 0px;
border: 1px solid black;
background-color: white;
overflow: hidden;
z-index: 99999;
}
.ac_results ul
{
width: 100%;
list-style-position: outside;
list-style: none;
padding: 0;
margin: 0;
}
.ac_results li
{
margin: 0px;
padding: 2px 5px;
cursor: default;
display: block;
/*
if width will be 100% horizontal scrollbar will apear
when scroll mode will be used
*/
/*width: 100%;*/
font: menu;
font-size: 12px;
/*
it is very important, if line-height not setted or setted
in relative units scroll will be broken in firefox
*/
line-height: 16px;
overflow: hidden;
}
.ac_loading
{
background: white url('../images/spinner_small.gif') right center no-repeat;
}
.ac_odd
{
background-color: #eee;
}
.ac_over
{
background-color: #0A246A;
color: white;
}

View File

@@ -193,4 +193,4 @@ a.rollover img
{
max-height: calc(100vh - 212px);
overflow-y: auto;
}
}

833
dist/opensourcepos.js vendored
View File

@@ -50501,769 +50501,6 @@ $(function(){
return ajax.apply(this, arguments);
};
})(jQuery);;/*
* Autocomplete - jQuery plugin 1.0.2
*
* Copyright (c) 2007 Dylan Verheul, Dan G. Switzer, Anjesh Tuladhar, Jörn Zaefferer
*
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
* Revision: $Id: jquery.autocomplete.js 5747 2008-06-25 18:30:55Z joern.zaefferer $
*
*/
;(function($) {
$.fn.extend({
autocomplete: function(urlOrData, options) {
var isUrl = typeof urlOrData == "string";
options = $.extend({}, $.Autocompleter.defaults, {
url: isUrl ? urlOrData : null,
data: isUrl ? null : urlOrData,
delay: isUrl ? $.Autocompleter.defaults.delay : 10,
max: options && !options.scroll ? 10 : 150
}, options);
// if highlight is set to false, replace it with a do-nothing function
options.highlight = options.highlight || function(value) { return value; };
// if the formatMatch option is not specified, then use formatItem for backwards compatibility
options.formatMatch = options.formatMatch || options.formatItem;
return this.each(function() {
new $.Autocompleter(this, options);
});
},
result: function(handler) {
return this.bind("result", handler);
},
search: function(handler) {
return this.trigger("search", [handler]);
},
flushCache: function() {
return this.trigger("flushCache");
},
setOptions: function(options){
return this.trigger("setOptions", [options]);
},
unautocomplete: function() {
return this.trigger("unautocomplete");
}
});
$.Autocompleter = function(input, options) {
var KEY = {
UP: 38,
DOWN: 40,
DEL: 46,
TAB: 9,
RETURN: 13,
ESC: 27,
COMMA: 188,
PAGEUP: 33,
PAGEDOWN: 34,
BACKSPACE: 8
};
// Create $ object for input element
var $input = $(input).attr("autocomplete", "off").addClass(options.inputClass);
var timeout;
var previousValue = "";
var cache = $.Autocompleter.Cache(options);
var hasFocus = 0;
var lastKeyPressCode;
var config = {
mouseDownOnSelect: false
};
var select = $.Autocompleter.Select(options, input, selectCurrent, config);
var blockSubmit;
// prevent form submit in opera when selecting with return key
$.browser.opera && $(input.form).bind("submit.autocomplete", function() {
if (blockSubmit) {
blockSubmit = false;
return false;
}
});
// only opera doesn't trigger keydown multiple times while pressed, others don't work with keypress at all
$input.bind(($.browser.opera ? "keypress" : "keydown") + ".autocomplete", function(event) {
// track last key pressed
lastKeyPressCode = event.keyCode;
switch(event.keyCode) {
case KEY.UP:
event.preventDefault();
if ( select.visible() ) {
select.prev();
} else {
onChange(0, true);
}
break;
case KEY.DOWN:
event.preventDefault();
if ( select.visible() ) {
select.next();
} else {
onChange(0, true);
}
break;
case KEY.PAGEUP:
event.preventDefault();
if ( select.visible() ) {
select.pageUp();
} else {
onChange(0, true);
}
break;
case KEY.PAGEDOWN:
event.preventDefault();
if ( select.visible() ) {
select.pageDown();
} else {
onChange(0, true);
}
break;
// matches also semicolon
case options.multiple && $.trim(options.multipleSeparator) == "," && KEY.COMMA:
case KEY.TAB:
case KEY.RETURN:
if( selectCurrent() ) {
// stop default to prevent a form submit, Opera needs special handling
event.preventDefault();
blockSubmit = true;
return false;
}
break;
case KEY.ESC:
select.hide();
break;
default:
clearTimeout(timeout);
timeout = setTimeout(onChange, options.delay);
break;
}
}).focus(function(){
// track whether the field has focus, we shouldn't process any
// results if the field no longer has focus
hasFocus++;
}).blur(function() {
hasFocus = 0;
if (!config.mouseDownOnSelect) {
hideResults();
}
}).click(function() {
// show select when clicking in a focused field
if ( hasFocus++ > 1 && !select.visible() ) {
onChange(0, true);
}
}).bind("search", function() {
// TODO why not just specifying both arguments?
var fn = (arguments.length > 1) ? arguments[1] : null;
function findValueCallback(q, data) {
var result;
if( data && data.length ) {
for (var i=0; i < data.length; i++) {
if( data[i].result.toLowerCase() == q.toLowerCase() ) {
result = data[i];
break;
}
}
}
if( typeof fn == "function" ) fn(result);
else $input.trigger("result", result && [result.data, result.value]);
}
$.each(trimWords($input.val()), function(i, value) {
request(value, findValueCallback, findValueCallback);
});
}).bind("flushCache", function() {
cache.flush();
}).bind("setOptions", function() {
$.extend(options, arguments[1]);
// if we've updated the data, repopulate
if ( "data" in arguments[1] )
cache.populate();
}).bind("unautocomplete", function() {
select.unbind();
$input.unbind();
$(input.form).unbind(".autocomplete");
});
function selectCurrent() {
var selected = select.selected();
if( !selected )
return false;
var v = selected.result;
previousValue = v;
if ( options.multiple ) {
var words = trimWords($input.val());
if ( words.length > 1 ) {
v = words.slice(0, words.length - 1).join( options.multipleSeparator ) + options.multipleSeparator + v;
}
v += options.multipleSeparator;
}
$input.val(v);
hideResultsNow();
$input.trigger("result", [selected.data, selected.value]);
return true;
}
function onChange(crap, skipPrevCheck) {
if( lastKeyPressCode == KEY.DEL ) {
select.hide();
return;
}
var currentValue = $input.val();
if ( !skipPrevCheck && currentValue == previousValue )
return;
previousValue = currentValue;
currentValue = lastWord(currentValue);
if ( currentValue.length >= options.minChars) {
$input.addClass(options.loadingClass);
if (!options.matchCase)
currentValue = currentValue.toLowerCase();
request(currentValue, receiveData, hideResultsNow);
} else {
stopLoading();
select.hide();
}
};
function trimWords(value) {
if ( !value ) {
return [""];
}
var words = value.split( options.multipleSeparator );
var result = [];
$.each(words, function(i, value) {
if ( $.trim(value) )
result[i] = $.trim(value);
});
return result;
}
function lastWord(value) {
if ( !options.multiple )
return value;
var words = trimWords(value);
return words[words.length - 1];
}
// fills in the input box w/the first match (assumed to be the best match)
// q: the term entered
// sValue: the first matching result
function autoFill(q, sValue){
// autofill in the complete box w/the first match as long as the user hasn't entered in more data
// if the last user key pressed was backspace, don't autofill
if( options.autoFill && (lastWord($input.val()).toLowerCase() == q.toLowerCase()) && lastKeyPressCode != KEY.BACKSPACE ) {
// fill in the value (keep the case the user has typed)
$input.val($input.val() + sValue.substring(lastWord(previousValue).length));
// select the portion of the value not typed by the user (so the next character will erase)
$.Autocompleter.Selection(input, previousValue.length, previousValue.length + sValue.length);
}
};
function hideResults() {
clearTimeout(timeout);
timeout = setTimeout(hideResultsNow, 200);
};
function hideResultsNow() {
var wasVisible = select.visible();
select.hide();
clearTimeout(timeout);
stopLoading();
if (options.mustMatch) {
// call search and run callback
$input.search(
function (result){
// if no value found, clear the input box
if( !result ) {
if (options.multiple) {
var words = trimWords($input.val()).slice(0, -1);
$input.val( words.join(options.multipleSeparator) + (words.length ? options.multipleSeparator : "") );
}
else
$input.val( "" );
}
}
);
}
if (wasVisible)
// position cursor at end of input field
$.Autocompleter.Selection(input, input.value.length, input.value.length);
};
function receiveData(q, data) {
if ( data && data.length && hasFocus ) {
stopLoading();
select.display(data, q);
autoFill(q, data[0].value);
select.show();
} else {
hideResultsNow();
}
};
function request(term, success, failure) {
if (!options.matchCase)
term = term.toLowerCase();
var data = cache.load(term);
// recieve the cached data
if (data && data.length) {
success(term, data);
// if an AJAX url has been supplied, try loading the data now
} else if( (typeof options.url == "string") && (options.url.length > 0) ){
var extraParams = {
timestamp: +new Date()
};
$.each(options.extraParams, function(key, param) {
extraParams[key] = typeof param == "function" ? param() : param;
});
// don't add q parameter (won't work for nomantim)
var data = typeof options.extraParams == "function" ?
$.extend({}, options.extraParams()) : $.extend({
q: lastWord(term),
limit: options.max
}, extraParams);
$.ajax({
// try to leverage ajaxQueue plugin to abort previous requests
mode: "abort",
// limit abortion to this input
port: "autocomplete" + input.name,
dataType: options.dataType,
url: options.url,
type: options.type || "POST",
data: data,
success: function(data) {
var parsed = options.parse && options.parse(data) || parse(data);
cache.add(term, parsed);
success(term, parsed);
}
});
} else {
// if we have a failure, we need to empty the list -- this prevents the the [TAB] key from selecting the last successful match
select.emptyList();
failure(term);
}
};
function parse(data) {
var parsed = [];
var rows = data.split("\n");
for (var i=0; i < rows.length; i++) {
var row = $.trim(rows[i]);
if (row) {
row = row.split("|");
parsed[parsed.length] = {
data: row,
value: row[0],
result: options.formatResult && options.formatResult(row, row[0]) || row[0]
};
}
}
return parsed;
};
function stopLoading() {
$input.removeClass(options.loadingClass);
};
};
$.Autocompleter.defaults = {
inputClass: "ac_input",
resultsClass: "ac_results",
loadingClass: "ac_loading",
minChars: 1,
delay: 400,
matchCase: false,
matchSubset: true,
matchContains: false,
cacheLength: 10,
max: 100,
mustMatch: false,
extraParams: {},
selectFirst: true,
formatItem: function(row) { return row[0]; },
formatMatch: null,
autoFill: false,
width: 0,
multiple: false,
multipleSeparator: ", ",
highlight: function(value, term) {
return value.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + term.replace(/([\^\$\(\)\[\]\{\}\*\.\+\?\|\\])/gi, "\\$1") + ")(?![^<>]*>)(?![^&;]+;)", "gi"), "<strong>$1</strong>");
},
scroll: true,
scrollHeight: 180
};
$.Autocompleter.Cache = function(options) {
var data = {};
var length = 0;
function matchSubset(s, sub) {
if (!options.matchCase)
s = s.toLowerCase();
var i = s.indexOf(sub);
if (i == -1) return false;
return i == 0 || options.matchContains;
};
function add(q, value) {
if (length > options.cacheLength){
flush();
}
if (!data[q]){
length++;
}
data[q] = value;
}
function populate(){
if( !options.data ) return false;
// track the matches
var stMatchSets = {},
nullData = 0;
// no url was specified, we need to adjust the cache length to make sure it fits the local data store
if( !options.url ) options.cacheLength = 1;
// track all options for minChars = 0
stMatchSets[""] = [];
// loop through the array and create a lookup structure
for ( var i = 0, ol = options.data.length; i < ol; i++ ) {
var rawValue = options.data[i];
// if rawValue is a string, make an array otherwise just reference the array
rawValue = (typeof rawValue == "string") ? [rawValue] : rawValue;
var value = options.formatMatch(rawValue, i+1, options.data.length);
if ( value === false )
continue;
var firstChar = value.charAt(0).toLowerCase();
// if no lookup array for this character exists, look it up now
if( !stMatchSets[firstChar] )
stMatchSets[firstChar] = [];
// if the match is a string
var row = {
value: value,
data: rawValue,
result: options.formatResult && options.formatResult(rawValue) || value
};
// push the current match into the set list
stMatchSets[firstChar].push(row);
// keep track of minChars zero items
if ( nullData++ < options.max ) {
stMatchSets[""].push(row);
}
};
// add the data items to the cache
$.each(stMatchSets, function(i, value) {
// increase the cache size
options.cacheLength++;
// add to the cache
add(i, value);
});
}
// populate any existing data
setTimeout(populate, 25);
function flush(){
data = {};
length = 0;
}
return {
flush: flush,
add: add,
populate: populate,
load: function(q) {
if (!options.cacheLength || !length)
return null;
/*
* if dealing w/local data and matchContains than we must make sure
* to loop through all the data collections looking for matches
*/
if( !options.url && options.matchContains ){
// track all matches
var csub = [];
// loop through all the data grids for matches
for( var k in data ){
// don't search through the stMatchSets[""] (minChars: 0) cache
// this prevents duplicates
if( k.length > 0 ){
var c = data[k];
$.each(c, function(i, x) {
// if we've got a match, add it to the array
if (matchSubset(x.value, q)) {
csub.push(x);
}
});
}
}
return csub;
} else
// if the exact item exists, use it
if (data[q]){
return data[q];
} else
if (options.matchSubset) {
for (var i = q.length - 1; i >= options.minChars; i--) {
var c = data[q.substr(0, i)];
if (c) {
var csub = [];
$.each(c, function(i, x) {
if (matchSubset(x.value, q)) {
csub[csub.length] = x;
}
});
return csub;
}
}
}
return null;
}
};
};
$.Autocompleter.Select = function (options, input, select, config) {
var CLASSES = {
ACTIVE: "ac_over"
};
var listItems,
active = -1,
data,
term = "",
needsInit = true,
element,
list;
// Create results
function init() {
if (!needsInit)
return;
element = $("<div/>")
.hide()
.addClass(options.resultsClass)
.css("position", "absolute")
.appendTo(document.body);
list = $("<ul/>").appendTo(element).mouseover( function(event) {
if(target(event).nodeName && target(event).nodeName.toUpperCase() == 'LI') {
active = $("li", list).removeClass(CLASSES.ACTIVE).index(target(event));
$(target(event)).addClass(CLASSES.ACTIVE);
}
}).click(function(event) {
$(target(event)).addClass(CLASSES.ACTIVE);
select();
// TODO provide option to avoid setting focus again after selection? useful for cleanup-on-focus
input.focus();
return false;
}).mousedown(function() {
config.mouseDownOnSelect = true;
}).mouseup(function() {
config.mouseDownOnSelect = false;
});
if( options.width > 0 )
element.css("width", options.width);
needsInit = false;
}
function target(event) {
var element = event.target;
while(element && element.tagName != "LI")
element = element.parentNode;
// more fun with IE, sometimes event.target is empty, just ignore it then
if(!element)
return [];
return element;
}
function moveSelect(step) {
listItems.slice(active, active + 1).removeClass(CLASSES.ACTIVE);
movePosition(step);
var activeItem = listItems.slice(active, active + 1).addClass(CLASSES.ACTIVE);
if(options.scroll) {
var offset = 0;
listItems.slice(0, active).each(function() {
offset += this.offsetHeight;
});
if((offset + activeItem[0].offsetHeight - list.scrollTop()) > list[0].clientHeight) {
list.scrollTop(offset + activeItem[0].offsetHeight - list.innerHeight());
} else if(offset < list.scrollTop()) {
list.scrollTop(offset);
}
}
};
function movePosition(step) {
active += step;
if (active < 0) {
active = listItems.size() - 1;
} else if (active >= listItems.size()) {
active = 0;
}
}
function limitNumberOfItems(available) {
return options.max && options.max < available
? options.max
: available;
}
function fillList() {
list.empty();
var max = limitNumberOfItems(data.length);
for (var i=0; i < max; i++) {
if (!data[i])
continue;
var formatted = options.formatItem(data[i].data, i+1, max, data[i].value, term);
if ( formatted === false )
continue;
var li = $("<li/>").html( options.highlight(formatted, term) ).addClass(i%2 == 0 ? "ac_even" : "ac_odd").appendTo(list)[0];
$.data(li, "ac_data", data[i]);
}
listItems = list.find("li");
if ( options.selectFirst ) {
listItems.slice(0, 1).addClass(CLASSES.ACTIVE);
active = 0;
}
// apply bgiframe if available
if ( $.fn.bgiframe )
list.bgiframe();
}
return {
display: function(d, q) {
init();
data = d;
term = q;
fillList();
},
next: function() {
moveSelect(1);
},
prev: function() {
moveSelect(-1);
},
pageUp: function() {
if (active != 0 && active - 8 < 0) {
moveSelect( -active );
} else {
moveSelect(-8);
}
},
pageDown: function() {
if (active != listItems.size() - 1 && active + 8 > listItems.size()) {
moveSelect( listItems.size() - 1 - active );
} else {
moveSelect(8);
}
},
hide: function() {
element && element.hide();
listItems && listItems.removeClass(CLASSES.ACTIVE);
active = -1;
},
visible : function() {
return element && element.is(":visible");
},
current: function() {
return this.visible() && (listItems.filter("." + CLASSES.ACTIVE)[0] || options.selectFirst && listItems[0]);
},
show: function() {
var offset = $(input).offset();
element.css({
width: typeof options.width == "string" || options.width > 0 ? options.width : $(input).width(),
top: offset.top + input.offsetHeight,
left: offset.left
}).show();
if(options.scroll) {
list.scrollTop(0);
list.css({
maxHeight: options.scrollHeight,
overflow: 'auto'
});
if($.browser.msie && typeof document.body.style.maxHeight === "undefined") {
var listHeight = 0;
listItems.each(function() {
listHeight += this.offsetHeight;
});
var scrollbarsVisible = listHeight > options.scrollHeight;
list.css('height', scrollbarsVisible ? options.scrollHeight : listHeight );
if (!scrollbarsVisible) {
// IE doesn't recalculate width when scrollbar disappears
listItems.width( list.width() - parseInt(listItems.css("padding-left")) - parseInt(listItems.css("padding-right")) );
}
}
}
},
selected: function() {
var selected = listItems && listItems.filter("." + CLASSES.ACTIVE).removeClass(CLASSES.ACTIVE);
return selected && selected.length && $.data(selected[0], "ac_data");
},
emptyList: function (){
list && list.empty();
},
unbind: function() {
element && element.remove();
}
};
};
$.Autocompleter.Selection = function(field, start, end) {
if( field.createTextRange ){
var selRange = field.createTextRange();
selRange.collapse(true);
selRange.moveStart("character", start);
selRange.moveEnd("character", end);
selRange.select();
} else if( field.setSelectionRange ){
field.setSelectionRange(start, end);
} else {
if( field.selectionStart ){
field.selectionStart = start;
field.selectionEnd = end;
}
}
field.focus();
};
})(jQuery);;/*
Copyright (c) 2011 Oscar Godson ( http://oscargodson.com ) and Sebastian Nitu ( http://sebnitu.com )
@@ -51765,13 +51002,34 @@ function enable_search(options)
$(this).attr('value','');
});
var widget = $("#search").autocomplete(options.suggest_url,{max:100,delay:10, selectFirst: false,
formatItem : options.format_item, extraParams: options.extra_params});
$("#search").result(function(event, data, formatted)
{
do_search(true, options.on_complete);
});
var widget = $("#search").autocomplete({
source: function (request, response) {
var extra_params = {limit: 100};
$.each(options.extra_params, function(key, param) {
extra_params[key] = typeof param == "function" ? param() : param;
});
$.ajax({
type: "POST",
url: options.suggest_url,
dataType: "json",
data: $.extend(request, extra_params),
success: function(data) {
response($.map(data, function(item) {
return {
value: item.label,
};
}))}
});
},
delay:10,
autoFocus: false,
select: function (a, ui) {
$(this).val(ui.item.value);
do_search(true, options.on_complete);
}
});
attach_search_listener();
$('#search_form').submit(function(event)
@@ -52316,17 +51574,38 @@ dialog_support = (function() {
$.each(options.fields, function(key, value)
{
var handle_field_completion = handle_auto_completion(value.dependencies);
$("#" + key).autocomplete(url,{
max:100,
$("#" + key).autocomplete({
source: function (request, response) {
var extra_params = request_params(key, value.response && value.response.field, options.language);
$.each(options.extra_params, function(key, param) {
extra_params[key] = typeof param == "function" ? param() : param;
});
$.ajax({
type: "GET",
url: url,
dataType: "json",
data: $.extend(request, extra_params),
success: function(data) {
response($.map(data, function(item) {
return {
value: item.label
};
}))
}
});
},
minChars:3,
delay:500,
formatItem: set_field_values,
type: 'GET',
dataType:'json',
extraParams: request_params(key, value.response && value.response.field, options.language),
parse: create_parser(key, (value.response && value.response.format) || value.dependencies)
parse: create_parser(key, (value.response && value.response.format) || value.dependencies),
result: function(a, ui) {
$("#" + ui.item.value).result(handle_field_completion);
}
});
$("#" + key).result(handle_field_completion);
});
}

View File

File diff suppressed because one or more lines are too long

View File

File diff suppressed because one or more lines are too long

View File

@@ -1,764 +0,0 @@
/*
* Autocomplete - jQuery plugin 1.0.2
*
* Copyright (c) 2007 Dylan Verheul, Dan G. Switzer, Anjesh Tuladhar, Jörn Zaefferer
*
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
* Revision: $Id: jquery.autocomplete.js 5747 2008-06-25 18:30:55Z joern.zaefferer $
*
*/
;(function($) {
$.fn.extend({
autocomplete: function(urlOrData, options) {
var isUrl = typeof urlOrData == "string";
options = $.extend({}, $.Autocompleter.defaults, {
url: isUrl ? urlOrData : null,
data: isUrl ? null : urlOrData,
delay: isUrl ? $.Autocompleter.defaults.delay : 10,
max: options && !options.scroll ? 10 : 150
}, options);
// if highlight is set to false, replace it with a do-nothing function
options.highlight = options.highlight || function(value) { return value; };
// if the formatMatch option is not specified, then use formatItem for backwards compatibility
options.formatMatch = options.formatMatch || options.formatItem;
return this.each(function() {
new $.Autocompleter(this, options);
});
},
result: function(handler) {
return this.bind("result", handler);
},
search: function(handler) {
return this.trigger("search", [handler]);
},
flushCache: function() {
return this.trigger("flushCache");
},
setOptions: function(options){
return this.trigger("setOptions", [options]);
},
unautocomplete: function() {
return this.trigger("unautocomplete");
}
});
$.Autocompleter = function(input, options) {
var KEY = {
UP: 38,
DOWN: 40,
DEL: 46,
TAB: 9,
RETURN: 13,
ESC: 27,
COMMA: 188,
PAGEUP: 33,
PAGEDOWN: 34,
BACKSPACE: 8
};
// Create $ object for input element
var $input = $(input).attr("autocomplete", "off").addClass(options.inputClass);
var timeout;
var previousValue = "";
var cache = $.Autocompleter.Cache(options);
var hasFocus = 0;
var lastKeyPressCode;
var config = {
mouseDownOnSelect: false
};
var select = $.Autocompleter.Select(options, input, selectCurrent, config);
var blockSubmit;
// prevent form submit in opera when selecting with return key
$.browser.opera && $(input.form).bind("submit.autocomplete", function() {
if (blockSubmit) {
blockSubmit = false;
return false;
}
});
// only opera doesn't trigger keydown multiple times while pressed, others don't work with keypress at all
$input.bind(($.browser.opera ? "keypress" : "keydown") + ".autocomplete", function(event) {
// track last key pressed
lastKeyPressCode = event.keyCode;
switch(event.keyCode) {
case KEY.UP:
event.preventDefault();
if ( select.visible() ) {
select.prev();
} else {
onChange(0, true);
}
break;
case KEY.DOWN:
event.preventDefault();
if ( select.visible() ) {
select.next();
} else {
onChange(0, true);
}
break;
case KEY.PAGEUP:
event.preventDefault();
if ( select.visible() ) {
select.pageUp();
} else {
onChange(0, true);
}
break;
case KEY.PAGEDOWN:
event.preventDefault();
if ( select.visible() ) {
select.pageDown();
} else {
onChange(0, true);
}
break;
// matches also semicolon
case options.multiple && $.trim(options.multipleSeparator) == "," && KEY.COMMA:
case KEY.TAB:
case KEY.RETURN:
if( selectCurrent() ) {
// stop default to prevent a form submit, Opera needs special handling
event.preventDefault();
blockSubmit = true;
return false;
}
break;
case KEY.ESC:
select.hide();
break;
default:
clearTimeout(timeout);
timeout = setTimeout(onChange, options.delay);
break;
}
}).focus(function(){
// track whether the field has focus, we shouldn't process any
// results if the field no longer has focus
hasFocus++;
}).blur(function() {
hasFocus = 0;
if (!config.mouseDownOnSelect) {
hideResults();
}
}).click(function() {
// show select when clicking in a focused field
if ( hasFocus++ > 1 && !select.visible() ) {
onChange(0, true);
}
}).bind("search", function() {
// TODO why not just specifying both arguments?
var fn = (arguments.length > 1) ? arguments[1] : null;
function findValueCallback(q, data) {
var result;
if( data && data.length ) {
for (var i=0; i < data.length; i++) {
if( data[i].result.toLowerCase() == q.toLowerCase() ) {
result = data[i];
break;
}
}
}
if( typeof fn == "function" ) fn(result);
else $input.trigger("result", result && [result.data, result.value]);
}
$.each(trimWords($input.val()), function(i, value) {
request(value, findValueCallback, findValueCallback);
});
}).bind("flushCache", function() {
cache.flush();
}).bind("setOptions", function() {
$.extend(options, arguments[1]);
// if we've updated the data, repopulate
if ( "data" in arguments[1] )
cache.populate();
}).bind("unautocomplete", function() {
select.unbind();
$input.unbind();
$(input.form).unbind(".autocomplete");
});
function selectCurrent() {
var selected = select.selected();
if( !selected )
return false;
var v = selected.result;
previousValue = v;
if ( options.multiple ) {
var words = trimWords($input.val());
if ( words.length > 1 ) {
v = words.slice(0, words.length - 1).join( options.multipleSeparator ) + options.multipleSeparator + v;
}
v += options.multipleSeparator;
}
$input.val(v);
hideResultsNow();
$input.trigger("result", [selected.data, selected.value]);
return true;
}
function onChange(crap, skipPrevCheck) {
if( lastKeyPressCode == KEY.DEL ) {
select.hide();
return;
}
var currentValue = $input.val();
if ( !skipPrevCheck && currentValue == previousValue )
return;
previousValue = currentValue;
currentValue = lastWord(currentValue);
if ( currentValue.length >= options.minChars) {
$input.addClass(options.loadingClass);
if (!options.matchCase)
currentValue = currentValue.toLowerCase();
request(currentValue, receiveData, hideResultsNow);
} else {
stopLoading();
select.hide();
}
};
function trimWords(value) {
if ( !value ) {
return [""];
}
var words = value.split( options.multipleSeparator );
var result = [];
$.each(words, function(i, value) {
if ( $.trim(value) )
result[i] = $.trim(value);
});
return result;
}
function lastWord(value) {
if ( !options.multiple )
return value;
var words = trimWords(value);
return words[words.length - 1];
}
// fills in the input box w/the first match (assumed to be the best match)
// q: the term entered
// sValue: the first matching result
function autoFill(q, sValue){
// autofill in the complete box w/the first match as long as the user hasn't entered in more data
// if the last user key pressed was backspace, don't autofill
if( options.autoFill && (lastWord($input.val()).toLowerCase() == q.toLowerCase()) && lastKeyPressCode != KEY.BACKSPACE ) {
// fill in the value (keep the case the user has typed)
$input.val($input.val() + sValue.substring(lastWord(previousValue).length));
// select the portion of the value not typed by the user (so the next character will erase)
$.Autocompleter.Selection(input, previousValue.length, previousValue.length + sValue.length);
}
};
function hideResults() {
clearTimeout(timeout);
timeout = setTimeout(hideResultsNow, 200);
};
function hideResultsNow() {
var wasVisible = select.visible();
select.hide();
clearTimeout(timeout);
stopLoading();
if (options.mustMatch) {
// call search and run callback
$input.search(
function (result){
// if no value found, clear the input box
if( !result ) {
if (options.multiple) {
var words = trimWords($input.val()).slice(0, -1);
$input.val( words.join(options.multipleSeparator) + (words.length ? options.multipleSeparator : "") );
}
else
$input.val( "" );
}
}
);
}
if (wasVisible)
// position cursor at end of input field
$.Autocompleter.Selection(input, input.value.length, input.value.length);
};
function receiveData(q, data) {
if ( data && data.length && hasFocus ) {
stopLoading();
select.display(data, q);
autoFill(q, data[0].value);
select.show();
} else {
hideResultsNow();
}
};
function request(term, success, failure) {
if (!options.matchCase)
term = term.toLowerCase();
var data = cache.load(term);
// recieve the cached data
if (data && data.length) {
success(term, data);
// if an AJAX url has been supplied, try loading the data now
} else if( (typeof options.url == "string") && (options.url.length > 0) ){
var extraParams = {
timestamp: +new Date()
};
$.each(options.extraParams, function(key, param) {
extraParams[key] = typeof param == "function" ? param() : param;
});
// don't add q parameter (won't work for nomantim)
var data = typeof options.extraParams == "function" ?
$.extend({}, options.extraParams()) : $.extend({
q: lastWord(term),
limit: options.max
}, extraParams);
$.ajax({
// try to leverage ajaxQueue plugin to abort previous requests
mode: "abort",
// limit abortion to this input
port: "autocomplete" + input.name,
dataType: options.dataType,
url: options.url,
type: options.type || "POST",
data: data,
success: function(data) {
var parsed = options.parse && options.parse(data) || parse(data);
cache.add(term, parsed);
success(term, parsed);
}
});
} else {
// if we have a failure, we need to empty the list -- this prevents the the [TAB] key from selecting the last successful match
select.emptyList();
failure(term);
}
};
function parse(data) {
var parsed = [];
var rows = data.split("\n");
for (var i=0; i < rows.length; i++) {
var row = $.trim(rows[i]);
if (row) {
row = row.split("|");
parsed[parsed.length] = {
data: row,
value: row[0],
result: options.formatResult && options.formatResult(row, row[0]) || row[0]
};
}
}
return parsed;
};
function stopLoading() {
$input.removeClass(options.loadingClass);
};
};
$.Autocompleter.defaults = {
inputClass: "ac_input",
resultsClass: "ac_results",
loadingClass: "ac_loading",
minChars: 1,
delay: 400,
matchCase: false,
matchSubset: true,
matchContains: false,
cacheLength: 10,
max: 100,
mustMatch: false,
extraParams: {},
selectFirst: true,
formatItem: function(row) { return row[0]; },
formatMatch: null,
autoFill: false,
width: 0,
multiple: false,
multipleSeparator: ", ",
highlight: function(value, term) {
return value.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + term.replace(/([\^\$\(\)\[\]\{\}\*\.\+\?\|\\])/gi, "\\$1") + ")(?![^<>]*>)(?![^&;]+;)", "gi"), "<strong>$1</strong>");
},
scroll: true,
scrollHeight: 180
};
$.Autocompleter.Cache = function(options) {
var data = {};
var length = 0;
function matchSubset(s, sub) {
if (!options.matchCase)
s = s.toLowerCase();
var i = s.indexOf(sub);
if (i == -1) return false;
return i == 0 || options.matchContains;
};
function add(q, value) {
if (length > options.cacheLength){
flush();
}
if (!data[q]){
length++;
}
data[q] = value;
}
function populate(){
if( !options.data ) return false;
// track the matches
var stMatchSets = {},
nullData = 0;
// no url was specified, we need to adjust the cache length to make sure it fits the local data store
if( !options.url ) options.cacheLength = 1;
// track all options for minChars = 0
stMatchSets[""] = [];
// loop through the array and create a lookup structure
for ( var i = 0, ol = options.data.length; i < ol; i++ ) {
var rawValue = options.data[i];
// if rawValue is a string, make an array otherwise just reference the array
rawValue = (typeof rawValue == "string") ? [rawValue] : rawValue;
var value = options.formatMatch(rawValue, i+1, options.data.length);
if ( value === false )
continue;
var firstChar = value.charAt(0).toLowerCase();
// if no lookup array for this character exists, look it up now
if( !stMatchSets[firstChar] )
stMatchSets[firstChar] = [];
// if the match is a string
var row = {
value: value,
data: rawValue,
result: options.formatResult && options.formatResult(rawValue) || value
};
// push the current match into the set list
stMatchSets[firstChar].push(row);
// keep track of minChars zero items
if ( nullData++ < options.max ) {
stMatchSets[""].push(row);
}
};
// add the data items to the cache
$.each(stMatchSets, function(i, value) {
// increase the cache size
options.cacheLength++;
// add to the cache
add(i, value);
});
}
// populate any existing data
setTimeout(populate, 25);
function flush(){
data = {};
length = 0;
}
return {
flush: flush,
add: add,
populate: populate,
load: function(q) {
if (!options.cacheLength || !length)
return null;
/*
* if dealing w/local data and matchContains than we must make sure
* to loop through all the data collections looking for matches
*/
if( !options.url && options.matchContains ){
// track all matches
var csub = [];
// loop through all the data grids for matches
for( var k in data ){
// don't search through the stMatchSets[""] (minChars: 0) cache
// this prevents duplicates
if( k.length > 0 ){
var c = data[k];
$.each(c, function(i, x) {
// if we've got a match, add it to the array
if (matchSubset(x.value, q)) {
csub.push(x);
}
});
}
}
return csub;
} else
// if the exact item exists, use it
if (data[q]){
return data[q];
} else
if (options.matchSubset) {
for (var i = q.length - 1; i >= options.minChars; i--) {
var c = data[q.substr(0, i)];
if (c) {
var csub = [];
$.each(c, function(i, x) {
if (matchSubset(x.value, q)) {
csub[csub.length] = x;
}
});
return csub;
}
}
}
return null;
}
};
};
$.Autocompleter.Select = function (options, input, select, config) {
var CLASSES = {
ACTIVE: "ac_over"
};
var listItems,
active = -1,
data,
term = "",
needsInit = true,
element,
list;
// Create results
function init() {
if (!needsInit)
return;
element = $("<div/>")
.hide()
.addClass(options.resultsClass)
.css("position", "absolute")
.appendTo(document.body);
list = $("<ul/>").appendTo(element).mouseover( function(event) {
if(target(event).nodeName && target(event).nodeName.toUpperCase() == 'LI') {
active = $("li", list).removeClass(CLASSES.ACTIVE).index(target(event));
$(target(event)).addClass(CLASSES.ACTIVE);
}
}).click(function(event) {
$(target(event)).addClass(CLASSES.ACTIVE);
select();
// TODO provide option to avoid setting focus again after selection? useful for cleanup-on-focus
input.focus();
return false;
}).mousedown(function() {
config.mouseDownOnSelect = true;
}).mouseup(function() {
config.mouseDownOnSelect = false;
});
if( options.width > 0 )
element.css("width", options.width);
needsInit = false;
}
function target(event) {
var element = event.target;
while(element && element.tagName != "LI")
element = element.parentNode;
// more fun with IE, sometimes event.target is empty, just ignore it then
if(!element)
return [];
return element;
}
function moveSelect(step) {
listItems.slice(active, active + 1).removeClass(CLASSES.ACTIVE);
movePosition(step);
var activeItem = listItems.slice(active, active + 1).addClass(CLASSES.ACTIVE);
if(options.scroll) {
var offset = 0;
listItems.slice(0, active).each(function() {
offset += this.offsetHeight;
});
if((offset + activeItem[0].offsetHeight - list.scrollTop()) > list[0].clientHeight) {
list.scrollTop(offset + activeItem[0].offsetHeight - list.innerHeight());
} else if(offset < list.scrollTop()) {
list.scrollTop(offset);
}
}
};
function movePosition(step) {
active += step;
if (active < 0) {
active = listItems.size() - 1;
} else if (active >= listItems.size()) {
active = 0;
}
}
function limitNumberOfItems(available) {
return options.max && options.max < available
? options.max
: available;
}
function fillList() {
list.empty();
var max = limitNumberOfItems(data.length);
for (var i=0; i < max; i++) {
if (!data[i])
continue;
var formatted = options.formatItem(data[i].data, i+1, max, data[i].value, term);
if ( formatted === false )
continue;
var li = $("<li/>").html( options.highlight(formatted, term) ).addClass(i%2 == 0 ? "ac_even" : "ac_odd").appendTo(list)[0];
$.data(li, "ac_data", data[i]);
}
listItems = list.find("li");
if ( options.selectFirst ) {
listItems.slice(0, 1).addClass(CLASSES.ACTIVE);
active = 0;
}
// apply bgiframe if available
if ( $.fn.bgiframe )
list.bgiframe();
}
return {
display: function(d, q) {
init();
data = d;
term = q;
fillList();
},
next: function() {
moveSelect(1);
},
prev: function() {
moveSelect(-1);
},
pageUp: function() {
if (active != 0 && active - 8 < 0) {
moveSelect( -active );
} else {
moveSelect(-8);
}
},
pageDown: function() {
if (active != listItems.size() - 1 && active + 8 > listItems.size()) {
moveSelect( listItems.size() - 1 - active );
} else {
moveSelect(8);
}
},
hide: function() {
element && element.hide();
listItems && listItems.removeClass(CLASSES.ACTIVE);
active = -1;
},
visible : function() {
return element && element.is(":visible");
},
current: function() {
return this.visible() && (listItems.filter("." + CLASSES.ACTIVE)[0] || options.selectFirst && listItems[0]);
},
show: function() {
var offset = $(input).offset();
element.css({
width: typeof options.width == "string" || options.width > 0 ? options.width : $(input).width(),
top: offset.top + input.offsetHeight,
left: offset.left
}).show();
if(options.scroll) {
list.scrollTop(0);
list.css({
maxHeight: options.scrollHeight,
overflow: 'auto'
});
if($.browser.msie && typeof document.body.style.maxHeight === "undefined") {
var listHeight = 0;
listItems.each(function() {
listHeight += this.offsetHeight;
});
var scrollbarsVisible = listHeight > options.scrollHeight;
list.css('height', scrollbarsVisible ? options.scrollHeight : listHeight );
if (!scrollbarsVisible) {
// IE doesn't recalculate width when scrollbar disappears
listItems.width( list.width() - parseInt(listItems.css("padding-left")) - parseInt(listItems.css("padding-right")) );
}
}
}
},
selected: function() {
var selected = listItems && listItems.filter("." + CLASSES.ACTIVE).removeClass(CLASSES.ACTIVE);
return selected && selected.length && $.data(selected[0], "ac_data");
},
emptyList: function (){
list && list.empty();
},
unbind: function() {
element && element.remove();
}
};
};
$.Autocompleter.Selection = function(field, start, end) {
if( field.createTextRange ){
var selRange = field.createTextRange();
selRange.collapse(true);
selRange.moveStart("character", start);
selRange.moveEnd("character", end);
selRange.select();
} else if( field.setSelectionRange ){
field.setSelectionRange(start, end);
} else {
if( field.selectionStart ){
field.selectionStart = start;
field.selectionEnd = end;
}
}
field.focus();
};
})(jQuery);

View File

@@ -28,13 +28,34 @@ function enable_search(options)
$(this).attr('value','');
});
var widget = $("#search").autocomplete(options.suggest_url,{max:100,delay:10, selectFirst: false,
formatItem : options.format_item, extraParams: options.extra_params});
$("#search").result(function(event, data, formatted)
{
do_search(true, options.on_complete);
});
var widget = $("#search").autocomplete({
source: function (request, response) {
var extra_params = {limit: 100};
$.each(options.extra_params, function(key, param) {
extra_params[key] = typeof param == "function" ? param() : param;
});
$.ajax({
type: "POST",
url: options.suggest_url,
dataType: "json",
data: $.extend(request, extra_params),
success: function(data) {
response($.map(data, function(item) {
return {
value: item.label,
};
}))}
});
},
delay:10,
autoFocus: false,
select: function (a, ui) {
$(this).val(ui.item.value);
do_search(true, options.on_complete);
}
});
attach_search_listener();
$('#search_form').submit(function(event)

View File

@@ -94,17 +94,38 @@
$.each(options.fields, function(key, value)
{
var handle_field_completion = handle_auto_completion(value.dependencies);
$("#" + key).autocomplete(url,{
max:100,
$("#" + key).autocomplete({
source: function (request, response) {
var extra_params = request_params(key, value.response && value.response.field, options.language);
$.each(options.extra_params, function(key, param) {
extra_params[key] = typeof param == "function" ? param() : param;
});
$.ajax({
type: "GET",
url: url,
dataType: "json",
data: $.extend(request, extra_params),
success: function(data) {
response($.map(data, function(item) {
return {
value: item.label
};
}))
}
});
},
minChars:3,
delay:500,
formatItem: set_field_values,
type: 'GET',
dataType:'json',
extraParams: request_params(key, value.response && value.response.field, options.language),
parse: create_parser(key, (value.response && value.response.format) || value.dependencies)
parse: create_parser(key, (value.response && value.response.format) || value.dependencies),
result: function(a, ui) {
$("#" + ui.item.value).result(handle_field_completion);
}
});
$("#" + key).result(handle_field_completion);
});
}

View File

@@ -15,6 +15,7 @@
<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"/>
@@ -50,7 +51,6 @@
<!-- endbower -->
<!-- start js template tags -->
<script type="text/javascript" src="js/jquery.ajax_queue.js" language="javascript"></script>
<script type="text/javascript" src="js/jquery.autocomplete.js" language="javascript"></script>
<script type="text/javascript" src="js/jquery.jkey-1.1.js" language="javascript"></script>
<script type="text/javascript" src="js/jquery.tablesorter.staticrow.js" language="javascript"></script>
<script type="text/javascript" src="js/common.js" language="javascript"></script>
@@ -65,11 +65,11 @@
<![endif]-->
<link rel="stylesheet" type="text/css" href="templates/spacelab/css/bootstrap.min.css?rel=9ed20b1ee8"/>
<!-- start mincss template tags -->
<link rel="stylesheet" type="text/css" href="dist/opensourcepos.min.css?rel=f940457590"/>
<link rel="stylesheet" type="text/css" href="dist/opensourcepos.min.css?rel=63bde3dd80"/>
<!-- end mincss template tags -->
<link rel="stylesheet" type="text/css" href="templates/spacelab/css/style.css"/>
<!-- start minjs template tags -->
<script type="text/javascript" src="dist/opensourcepos.min.js?rel=906f616faa" language="javascript"></script>
<script type="text/javascript" src="dist/opensourcepos.min.js?rel=8aac97eb12" language="javascript"></script>
<!-- end minjs template tags -->
<?php endif; ?>