mirror of
https://github.com/opensourcepos/opensourcepos.git
synced 2026-02-25 11:27:21 -05:00
Minimal working OpenStreetMap autocomplete
Refactor jkey F-key bindings
This commit is contained in:
@@ -268,17 +268,14 @@ class Items extends Secure_area implements iData_controller
|
||||
|
||||
function generate_barcodes($item_ids)
|
||||
{
|
||||
$this->load->library('barcode_lib');
|
||||
$result = array();
|
||||
|
||||
$item_ids = explode(':', $item_ids);
|
||||
foreach ($item_ids as $item_id)
|
||||
{
|
||||
$item_info = $this->Item->get_info($item_id);
|
||||
|
||||
$result[] = array('name' =>$item_info->name, 'id'=> $item_id, 'item_number'=> $item_info->item_number, 'unit_price'=>$item_info->unit_price);
|
||||
}
|
||||
$result = $this->Item->get_multiple_info($item_ids)->result_array();
|
||||
|
||||
$data['items'] = $result;
|
||||
$data['barcode_config'] = $this->barcode_lib->get_barcode_config();
|
||||
$this->load->view("barcode_sheet", $data);
|
||||
}
|
||||
|
||||
@@ -305,6 +302,8 @@ class Items extends Secure_area implements iData_controller
|
||||
|
||||
function save($item_id=-1)
|
||||
{
|
||||
$upload_success = $this->_handle_image_upload();
|
||||
$upload_data = $this->upload->data();
|
||||
//Save item data
|
||||
$item_data = array(
|
||||
'name'=>$this->input->post('name'),
|
||||
@@ -331,25 +330,24 @@ class Items extends Secure_area implements iData_controller
|
||||
'custom10'=>$this->input->post('custom10')/**GARRISON ADDED 4/21/2013**/
|
||||
);
|
||||
|
||||
if (!empty($upload_data['orig_name']))
|
||||
{
|
||||
$item_data['pic_id'] = $upload_data['raw_name'];
|
||||
}
|
||||
|
||||
$employee_id=$this->Employee->get_logged_in_employee_info()->person_id;
|
||||
$cur_item_info = $this->Item->get_info($item_id);
|
||||
|
||||
$new_item = FALSE;
|
||||
if($this->Item->save($item_data,$item_id))
|
||||
{
|
||||
$success = TRUE;
|
||||
$new_item = FALSE;
|
||||
//New item
|
||||
if($item_id==-1)
|
||||
{
|
||||
echo json_encode(array('success'=>true,'message'=>$this->lang->line('items_successful_adding').' '.
|
||||
$item_data['name'],'item_id'=>$item_data['item_id']));
|
||||
$item_id = $item_data['item_id'];
|
||||
$new_item = TRUE;
|
||||
}
|
||||
else //previous item
|
||||
{
|
||||
echo json_encode(array('success'=>true,'message'=>$this->lang->line('items_successful_updating').' '.
|
||||
$item_data['name'],'item_id'=>$item_id));
|
||||
}
|
||||
|
||||
$items_taxes_data = array();
|
||||
$tax_names = $this->input->post('tax_names');
|
||||
@@ -361,7 +359,7 @@ class Items extends Secure_area implements iData_controller
|
||||
$items_taxes_data[] = array('name'=>$tax_names[$k], 'percent'=>$tax_percents[$k] );
|
||||
}
|
||||
}
|
||||
$this->Item_taxes->save($items_taxes_data, $item_id);
|
||||
$success &= $this->Item_taxes->save($items_taxes_data, $item_id);
|
||||
|
||||
|
||||
//Save item quantity
|
||||
@@ -375,7 +373,7 @@ class Items extends Secure_area implements iData_controller
|
||||
$item_quantity = $this->Item_quantities->get_item_quantity($item_id, $location_data['location_id']);
|
||||
if ($item_quantity->quantity != $updated_quantity || $new_item)
|
||||
{
|
||||
$this->Item_quantities->save($location_detail, $item_id, $location_data['location_id']);
|
||||
$success &= $this->Item_quantities->save($location_detail, $item_id, $location_data['location_id']);
|
||||
|
||||
$inv_data = array
|
||||
(
|
||||
@@ -386,18 +384,50 @@ class Items extends Secure_area implements iData_controller
|
||||
'trans_comment'=>$this->lang->line('items_manually_editing_of_quantity'),
|
||||
'trans_inventory'=>$updated_quantity - $item_quantity->quantity
|
||||
);
|
||||
$this->Inventory->insert($inv_data);
|
||||
$success &= $this->Inventory->insert($inv_data);
|
||||
}
|
||||
}
|
||||
|
||||
if ($success && $upload_success)
|
||||
{
|
||||
$success_message = $this->lang->line('items_successful_' . ($new_item ? 'adding' : 'updating')) .' '. $item_data['name'];
|
||||
echo json_encode(array('success'=>true,'message'=>$success_message,'item_id'=>$item_id));
|
||||
}
|
||||
else
|
||||
{
|
||||
$error_message = $upload_success ?
|
||||
$this->lang->line('items_error_adding_updating') .' '. $item_data['name'] :
|
||||
$this->upload->display_errors();
|
||||
echo json_encode(array('success'=>false,'message'=>$error_message,'item_id'=>$item_id));
|
||||
}
|
||||
|
||||
}
|
||||
else//failure
|
||||
{
|
||||
echo json_encode(array('success'=>false,'message'=>$this->lang->line('items_error_adding_updating').' '.
|
||||
$item_data['name'],'item_id'=>-1));
|
||||
$item_data['name'],'item_id'=>-1));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function _handle_image_upload()
|
||||
{
|
||||
$this->load->helper('directory');
|
||||
$map = directory_map('./uploads/item_pics/', 1);
|
||||
// load upload library
|
||||
$config = array('upload_path' => './uploads/item_pics/',
|
||||
'allowed_types' => 'gif|jpg|png',
|
||||
'max_size' => '100',
|
||||
'max_width' => '640',
|
||||
'max_height' => '480',
|
||||
'file_name' => sizeof($map));
|
||||
$this->load->library('upload', $config);
|
||||
$this->upload->do_upload('item_image');
|
||||
return strlen($this->upload->display_errors()) == 0 ||
|
||||
!strcmp($this->upload->display_errors(),
|
||||
'<p>'.$this->lang->line('upload_no_file_selected').'</p>');
|
||||
}
|
||||
|
||||
//Ramel Inventory Tracking
|
||||
function save_inventory($item_id=-1)
|
||||
{
|
||||
@@ -671,7 +701,7 @@ class Items extends Secure_area implements iData_controller
|
||||
*/
|
||||
function get_form_width()
|
||||
{
|
||||
return 360;
|
||||
return 400;
|
||||
}
|
||||
|
||||
function item_number_check($item_number)
|
||||
|
||||
@@ -85,7 +85,7 @@
|
||||
<div class='form_field'>
|
||||
<?php echo form_input(array(
|
||||
'name'=>'zip',
|
||||
'id'=>'zip',
|
||||
'id'=>'postcode',
|
||||
'value'=>$person_info->zip));?>
|
||||
</div>
|
||||
</div>
|
||||
@@ -111,4 +111,121 @@
|
||||
'cols'=>'17')
|
||||
);?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script type='text/javascript' language="javascript">
|
||||
//validation and submit handling
|
||||
$(document).ready(function()
|
||||
{
|
||||
|
||||
var handle_auto_completion = function(fields) {
|
||||
return function(event, results, formatted) {
|
||||
if (results != null && results.length > 0) {
|
||||
// handle auto completion
|
||||
for(var i in fields) {
|
||||
$("#" + fields[i]).val(results[i]);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
};
|
||||
|
||||
var set_field_values = function(results) {
|
||||
return results[0] + ' - ' + results[1];
|
||||
};
|
||||
|
||||
var create_parser = function(field_name, parse_format)
|
||||
{
|
||||
return function(data)
|
||||
{
|
||||
var parsed = [];
|
||||
$.each(data, function(index, value)
|
||||
{
|
||||
var address = value.address;
|
||||
var row = [];
|
||||
$.each(parse_format, function(key, value)
|
||||
{
|
||||
row.push(address[value]);
|
||||
});
|
||||
parsed[index] = {
|
||||
data: row,
|
||||
value: address[field_name],
|
||||
result: address[field_name]
|
||||
};
|
||||
});
|
||||
return parsed;
|
||||
};
|
||||
};
|
||||
|
||||
var request_params = function()
|
||||
{
|
||||
return {
|
||||
format: 'json',
|
||||
limit: 5,
|
||||
street: $("#address_1").val(),
|
||||
city: $("#city").val(),
|
||||
postalcode: $("#postcode").val(),
|
||||
addressdetails: 1,
|
||||
country: 'Belgium',
|
||||
state: $("#state").val()
|
||||
};
|
||||
};
|
||||
|
||||
var url = 'http://nominatim.openstreetmap.org/search';
|
||||
|
||||
var handle_city_completion = handle_auto_completion(["postcode", "city", "state", "country"]);
|
||||
$("#postcode").autocomplete(url,{
|
||||
max:100,
|
||||
minChars:3,
|
||||
delay:500,
|
||||
formatItem: set_field_values,
|
||||
type: 'GET',
|
||||
dataType:'json',
|
||||
extraParams: request_params,
|
||||
parse: create_parser('postcode', ["postcode", "city", "state", "country"])
|
||||
});
|
||||
$("#postcode").result(handle_city_completion);
|
||||
|
||||
$("#city").autocomplete(url,{
|
||||
max:100,
|
||||
minChars:5,
|
||||
delay:500,
|
||||
formatItem: set_field_values,
|
||||
type: 'GET',
|
||||
dataType:'json',
|
||||
extraParams: request_params,
|
||||
parse: create_parser('city', ["postcode", "city", "state", "country"])
|
||||
});
|
||||
$("#city").result(handle_city_completion);
|
||||
|
||||
$("#state").autocomplete(url, {
|
||||
max:100,
|
||||
minChars:0,
|
||||
delay:500,
|
||||
type: 'GET',
|
||||
dataType:'json',
|
||||
extraParams: request_params,
|
||||
parse: create_parser('state', ["state", "country"]),
|
||||
formatItem: function(results) {
|
||||
return results[1] + ' - ' + results[3];
|
||||
}
|
||||
});
|
||||
$("#state").result(handle_auto_completion(["state", "country"]));
|
||||
|
||||
$("#country").autocomplete(url,{
|
||||
max:100,
|
||||
minChars:3,
|
||||
delay:500,
|
||||
type: 'GET',
|
||||
dataType:'json',
|
||||
extraParams: request_params,
|
||||
parse: create_parser('country', ["country"]),
|
||||
formatItem: function(results) {
|
||||
return results[1];
|
||||
}
|
||||
});
|
||||
$("#country").result(handle_auto_completion(["country"]));
|
||||
|
||||
});
|
||||
</script>
|
||||
42
js/common.js
42
js/common.js
@@ -41,42 +41,8 @@ function set_feedback(text, classname, keep_displayed)
|
||||
}
|
||||
|
||||
//keylisteners
|
||||
|
||||
$(window).jkey('f1',function(){
|
||||
window.location = BASE_URL + '/customers/index';
|
||||
});
|
||||
|
||||
|
||||
$(window).jkey('f2',function(){
|
||||
window.location = BASE_URL + '/items/index';
|
||||
});
|
||||
|
||||
|
||||
$(window).jkey('f3',function(){
|
||||
window.location = BASE_URL + '/reports/index';
|
||||
});
|
||||
|
||||
$(window).jkey('f4',function(){
|
||||
window.location = BASE_URL + '/suppliers/index';
|
||||
});
|
||||
|
||||
$(window).jkey('f5',function(){
|
||||
window.location = BASE_URL + '/receivings/index';
|
||||
});
|
||||
|
||||
|
||||
$(window).jkey('f6',function(){
|
||||
window.location = BASE_URL + '/sales/index';
|
||||
});
|
||||
|
||||
$(window).jkey('f7',function(){
|
||||
window.location = BASE_URL + '/employees/index';
|
||||
});
|
||||
|
||||
$(window).jkey('f8',function(){
|
||||
window.location = BASE_URL + '/config/index';
|
||||
});
|
||||
|
||||
$(window).jkey('f9',function(){
|
||||
window.location = BASE_URL + '/giftcards/index';
|
||||
$.each(['customers', 'items', 'reports', 'receivings', 'sales', 'employees', 'config', 'giftcards'], function(key, value) {
|
||||
$(window).jkey('f' + (key+1), function(){
|
||||
window.location = BASE_URL + '/' + value + ' /index';
|
||||
});
|
||||
});
|
||||
|
||||
3561
js/jquery-1.2.6.min.js
vendored
3561
js/jquery-1.2.6.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -338,6 +338,13 @@ $.Autocompleter = function(input, options) {
|
||||
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",
|
||||
@@ -345,11 +352,8 @@ $.Autocompleter = function(input, options) {
|
||||
port: "autocomplete" + input.name,
|
||||
dataType: options.dataType,
|
||||
url: options.url,
|
||||
type:"POST",
|
||||
data: $.extend({
|
||||
q: lastWord(term),
|
||||
limit: options.max
|
||||
}, extraParams),
|
||||
type: options.type || "POST",
|
||||
data: data,
|
||||
success: function(data) {
|
||||
var parsed = options.parse && options.parse(data) || parse(data);
|
||||
cache.add(term, parsed);
|
||||
|
||||
Reference in New Issue
Block a user