From 8cf32f4470f4bd3b896d2981a17dc4cce692960d Mon Sep 17 00:00:00 2001 From: jekkos Date: Fri, 22 Apr 2016 08:47:56 +0200 Subject: [PATCH] Fix item kits view + search, item bulk edit (#293) Refactored table_helper to add first and last column automatically --- application/controllers/Item_kits.php | 4 ++-- application/controllers/Items.php | 4 ++-- application/helpers/table_helper.php | 23 +++++++---------------- application/models/Item_kit.php | 4 ++-- application/views/item_kits/manage.php | 11 +++++++---- application/views/items/form_bulk.php | 13 ++++++------- application/views/items/manage.php | 10 ++++++---- dist/opensourcepos.js | 12 ++++++++---- js/manage_tables.js | 12 ++++++++---- 9 files changed, 48 insertions(+), 45 deletions(-) diff --git a/application/controllers/Item_kits.php b/application/controllers/Item_kits.php index 0c7f447a7..a514cd602 100644 --- a/application/controllers/Item_kits.php +++ b/application/controllers/Item_kits.php @@ -29,7 +29,7 @@ class Item_kits extends Secure_area implements iData_controller function index() { $data['controller_name'] = $this->get_controller_name(); - $data['table_headers'] = get_suppliers_manage_table_headers(); + $data['table_headers'] = get_item_kits_manage_table_headers(); $this->load->view('item_kits/manage', $data); } @@ -52,7 +52,7 @@ class Item_kits extends Secure_area implements iData_controller { // calculate the total cost and retail price of the Kit so it can be printed out in the manage table $item_kit = $this->add_totals_to_item_kit($item_kit); - $data_rows = get_item_kit_data_row($item_kits, $this); + $data_rows[] = get_item_kit_data_row($item_kit, $this); } echo json_encode(array('total' => $total_rows, 'rows' => $data_rows)); diff --git a/application/controllers/Items.php b/application/controllers/Items.php index 5ad4a5ad2..c2e4d8347 100644 --- a/application/controllers/Items.php +++ b/application/controllers/Items.php @@ -161,7 +161,7 @@ class Items extends Secure_area implements iData_controller $item_info->quantity = $item_quantity->quantity; $data_row = get_item_data_row($item_info,$this); - echo $data_row; + echo json_encode($data_row); } function view($item_id=-1) @@ -363,7 +363,7 @@ class Items extends Secure_area implements iData_controller foreach($stock_locations as $location_data) { $updated_quantity = $this->input->post('quantity_' . $location_data['location_id']); - $location_detail = array('id'=>$item_id, + $location_detail = array('item_id'=>$item_id, 'location_id'=>$location_data['location_id'], 'quantity'=>$updated_quantity); $item_quantity = $this->Item_quantity->get_item_quantity($item_id, $location_data['location_id']); diff --git a/application/helpers/table_helper.php b/application/helpers/table_helper.php index 68e5b261b..5a84389d0 100644 --- a/application/helpers/table_helper.php +++ b/application/helpers/table_helper.php @@ -140,7 +140,7 @@ function transform_headers($array) { return json_encode(array_map(function($v) { return array('field' => key($v), 'title' => current($v), 'checkbox' => (key($v) == 'checkbox')); - }, $array)); + }, array_merge(array(array('checkbox' => 'select')), $array, array(array('edit' => ''))))); } function get_people_manage_table_headers() @@ -148,13 +148,11 @@ function get_people_manage_table_headers() $CI =& get_instance(); $headers = array( - array('checkbox' => 'select'), array('id' => $CI->lang->line('common_id')), array('last_name' => $CI->lang->line('common_last_name')), array('first_name' => $CI->lang->line('common_first_name')), array('email' => $CI->lang->line('common_email')), - array('phone_number' => $CI->lang->line('common_phone_number')), - array('edit' => '') + array('phone_number' => $CI->lang->line('common_phone_number')) ); return transform_headers($headers); @@ -201,15 +199,13 @@ function get_suppliers_manage_table_headers() $CI =& get_instance(); $headers = array( - array('checkbox' => 'select'), array('id' => $CI->lang->line('common_id')), array('company_name' => $CI->lang->line('suppliers_company_name')), array('agency_name' => $CI->lang->line('suppliers_agency_name')), array('last_name' => $CI->lang->line('common_last_name')), array('first_name' => $CI->lang->line('common_first_name')), array('email' => $CI->lang->line('common_email')), - array('phone_number' => $CI->lang->line('common_phone_number')), - array('edit' => '') + array('phone_number' => $CI->lang->line('common_phone_number')) ); return transform_headers($headers); @@ -239,7 +235,6 @@ function get_items_manage_table_headers() $CI =& get_instance(); $headers = array( - array('checkbox' => 'select'), array('id' => $CI->lang->line('common_id')), array('item_number' => $CI->lang->line('items_item_number')), array('item_name' => $CI->lang->line('items_name')), @@ -251,8 +246,7 @@ function get_items_manage_table_headers() array('tax_percents' => $CI->lang->line('items_tax_percents')), array('item_pic' => $CI->lang->line('items_image')), array('inventory' => ''), - array('stock' => ''), - array('edit' => '') + array('stock' => '') ); return transform_headers($headers); @@ -286,6 +280,7 @@ function get_item_data_row($item, $controller) { 'item_number' => $item->item_number, 'item_name' => character_limiter($item->name,13), 'item_category' => character_limiter($item->category,13), + 'company_name' => character_limiter($item->company_name,20), 'cost_price' => to_currency($item->cost_price), 'unit_price' => to_currency($item->unit_price), 'quantity' => to_quantity_decimals($item->quantity), @@ -307,13 +302,11 @@ function get_giftcards_manage_table_headers() $CI =& get_instance(); $headers = array( - array('checkbox' => 'select'), array('id' => $CI->lang->line('common_id')), array('last_name' => $CI->lang->line('common_last_name')), array('first_name' => $CI->lang->line('common_first_name')), array('giftcard_number' => $CI->lang->line('giftcards_giftcard_number')), - array('giftcard_value' => $CI->lang->line('giftcards_card_value')), - array('edit' => '') + array('giftcard_value' => $CI->lang->line('giftcards_card_value')) ); return transform_headers($headers); @@ -339,13 +332,11 @@ function get_item_kits_manage_table_headers() $CI =& get_instance(); $headers = array( - array('checkbox' => 'select'), array('id' => $CI->lang->line('item_kits_kit')), array('kit_name' => $CI->lang->line('item_kits_name')), array('kit_description' => $CI->lang->line('item_kits_description')), array('cost_price' => $CI->lang->line('items_cost_price')), - array('unit_price' => $CI->lang->line('items_unit_price')), - array('edit' => '') + array('unit_price' => $CI->lang->line('items_unit_price')) ); return transform_headers($headers); diff --git a/application/models/Item_kit.php b/application/models/Item_kit.php index 91de99cf4..13b94cd5e 100644 --- a/application/models/Item_kit.php +++ b/application/models/Item_kit.php @@ -151,7 +151,7 @@ class Item_kit extends CI_Model $this->db->from('item_kits'); $this->db->like('name', $search); $this->db->or_like('description', $search); - + //KIT # if (stripos($search, 'KIT ') !== false) { @@ -173,7 +173,7 @@ class Item_kit extends CI_Model $this->db->from('item_kits'); $this->db->like('name', $search); $this->db->or_like('description', $search); - + //KIT # if (stripos($search, 'KIT ') !== false) { diff --git a/application/views/item_kits/manage.php b/application/views/item_kits/manage.php index b5d214907..800ef40bf 100644 --- a/application/views/item_kits/manage.php +++ b/application/views/item_kits/manage.php @@ -6,10 +6,13 @@ $(document).ready(function() table_support.init('', ); table_support.init_delete('lang->line($controller_name."_confirm_delete")?>'); - $('#generate_barcodes').click(function() - { - $(this).attr('href','index.php/item_kits/generate_barcodes/'+selected.join(':')); - }); + $('#generate_barcodes').click(function() + { + window.open( + 'index.php/items/generate_barcodes/'+table_support.selected_ids().join(':'), + '_blank' // <- This is what makes it open in a new window. + ); + }); }); diff --git a/application/views/items/form_bulk.php b/application/views/items/form_bulk.php index ba97abe9a..085dfa429 100644 --- a/application/views/items/form_bulk.php +++ b/application/views/items/form_bulk.php @@ -177,18 +177,17 @@ $(document).ready(function() { if(!confirm_message || confirm(confirm_message)) { - //Get the selected ids and create hidden fields to send with ajax submit. - var selected_item_ids=get_selected_values(); - for(k=0;k"); - } + $('').attr({ + type: 'hidden', + name: 'item_ids[]', + value: table_support.selected_ids().join(",") + }).appendTo(form); $(form).ajaxSubmit({ success:function(response) { dialog_support.hide(); - post_bulk_form_submit(response); + table_support.handle_submit('', response); }, dataType:'json' }); diff --git a/application/views/items/manage.php b/application/views/items/manage.php index a60158a9d..168192556 100644 --- a/application/views/items/manage.php +++ b/application/views/items/manage.php @@ -36,9 +36,11 @@ $(document).ready(function() }); table_support.init_delete('lang->line($controller_name."_confirm_delete")?>'); - var resize_thumbs = function() { - $('a.rollover').imgPreview(); - }; + var handle_submit = table_support.handle_submit; + table_support.handle_submit = function() { + debugger;; + handle_submit.apply(this, arguments) && $('a.rollover').imgPreview(); + } }); @@ -63,7 +65,7 @@ $(document).ready(function() lang->line("common_delete");?> - diff --git a/dist/opensourcepos.js b/dist/opensourcepos.js index 251af669a..a6553dc8d 100644 --- a/dist/opensourcepos.js +++ b/dist/opensourcepos.js @@ -49414,7 +49414,7 @@ $.tablesorter.addWidget({ var enable_actions = function() { var selection_empty = selected_rows().length == 0; - $("#toolbar button").attr('disabled', selection_empty); + $("#toolbar button:not(.dropdown-toggle)").attr('disabled', selection_empty); }; var table = function() { @@ -49486,6 +49486,8 @@ $.tablesorter.addWidget({ uniqueId: 'id', onCheck: enable_actions, onUncheck: enable_actions, + onCheckAll: enable_actions, + onUncheckAll: enable_actions, onLoadSuccess: load_success, queryParams: queryParams, queryParamsType: 'limit' @@ -49516,12 +49518,12 @@ $.tablesorter.addWidget({ var message = response.message; if (selected_ids().length > 0) { - selected_ids().each(function(id) { + $.each(selected_ids(), function(element, id) { $.get({ url: resource + '/get_row/' + id, success: function (response) { table().updateByUniqueId({id: response.id, row: response}); - highlight_rows();s + highlight_rows(); set_feedback(message, 'alert alert-dismissible alert-success', false); }, dataType: 'json' @@ -49529,7 +49531,9 @@ $.tablesorter.addWidget({ }); } else { // call hightlight function once after refresh - load_callback = function() { highlight_rows(id); }; + load_callback = function() { + highlight_rows(id); + }; refresh(); set_feedback(message, 'alert alert-dismissible alert-success', false); } diff --git a/js/manage_tables.js b/js/manage_tables.js index 3e6af43d6..5d767e640 100644 --- a/js/manage_tables.js +++ b/js/manage_tables.js @@ -135,7 +135,7 @@ var enable_actions = function() { var selection_empty = selected_rows().length == 0; - $("#toolbar button").attr('disabled', selection_empty); + $("#toolbar button:not(.dropdown-toggle)").attr('disabled', selection_empty); }; var table = function() { @@ -207,6 +207,8 @@ uniqueId: 'id', onCheck: enable_actions, onUncheck: enable_actions, + onCheckAll: enable_actions, + onUncheckAll: enable_actions, onLoadSuccess: load_success, queryParams: queryParams, queryParamsType: 'limit' @@ -237,12 +239,12 @@ var message = response.message; if (selected_ids().length > 0) { - selected_ids().each(function(id) { + $.each(selected_ids(), function(element, id) { $.get({ url: resource + '/get_row/' + id, success: function (response) { table().updateByUniqueId({id: response.id, row: response}); - highlight_rows();s + highlight_rows(); set_feedback(message, 'alert alert-dismissible alert-success', false); }, dataType: 'json' @@ -250,7 +252,9 @@ }); } else { // call hightlight function once after refresh - load_callback = function() { highlight_rows(id); }; + load_callback = function() { + highlight_rows(id); + }; refresh(); set_feedback(message, 'alert alert-dismissible alert-success', false); }