mirror of
https://github.com/opensourcepos/opensourcepos.git
synced 2026-03-05 23:58:02 -05:00
Enable bootstrap-tables for suppliers module (#293)
Reuse generic manage view for suppliers and remove original one
This commit is contained in:
@@ -10,12 +10,9 @@ class Suppliers extends Person_controller
|
||||
function index($limit_from=0)
|
||||
{
|
||||
$data['controller_name'] = $this->get_controller_name();
|
||||
$lines_per_page = $this->Appconfig->get('lines_per_page');
|
||||
$suppliers = $this->Supplier->get_all($lines_per_page);
|
||||
|
||||
$data['links'] = $this->_initialize_pagination($this->Supplier, $lines_per_page, $limit_from);
|
||||
$data['manage_table'] = get_supplier_manage_table($suppliers, $this);
|
||||
$this->load->view('suppliers/manage', $data);
|
||||
$data['table_headers'] = get_suppliers_manage_table_headers();
|
||||
|
||||
$this->load->view('people/manage', $data);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -23,16 +20,20 @@ class Suppliers extends Person_controller
|
||||
*/
|
||||
function search()
|
||||
{
|
||||
$search = $this->input->post('search') != '' ? $this->input->post('search') : null;
|
||||
$limit_from = $this->input->post('limit_from');
|
||||
$search = $this->input->get('search');
|
||||
$limit = $this->input->get('limit');
|
||||
$offset = $this->input->get('offset');
|
||||
$lines_per_page = $this->Appconfig->get('lines_per_page');
|
||||
|
||||
$suppliers = $this->Supplier->search($search, $lines_per_page, $limit_from);
|
||||
$suppliers = $this->Supplier->search($search, $offset, $limit);
|
||||
$total_rows = $this->Supplier->get_found_rows($search);
|
||||
$links = $this->_initialize_pagination($this->Supplier, $lines_per_page, $limit_from, $total_rows);
|
||||
$data_rows = get_supplier_manage_table_data_rows($suppliers, $this);
|
||||
|
||||
echo json_encode(array('total_rows' => $total_rows, 'rows' => $data_rows, 'pagination' => $links));
|
||||
$links = $this->_initialize_pagination($this->Employee, $lines_per_page, $limit, $total_rows);
|
||||
$data_rows = array();
|
||||
foreach($suppliers->result() as $supplier)
|
||||
{
|
||||
$data_rows[] = get_supplier_data_row($supplier, $this);
|
||||
}
|
||||
echo json_encode(array('total' => $total_rows, 'rows' => $data_rows));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -89,18 +90,18 @@ class Suppliers extends Person_controller
|
||||
if($supplier_id==-1)
|
||||
{
|
||||
echo json_encode(array('success'=>true,'message'=>$this->lang->line('suppliers_successful_adding').' '.
|
||||
$supplier_data['company_name'],'person_id'=>$supplier_data['person_id']));
|
||||
$supplier_data['company_name'],'id'=>$supplier_data['person_id']));
|
||||
}
|
||||
else //previous supplier
|
||||
{
|
||||
echo json_encode(array('success'=>true,'message'=>$this->lang->line('suppliers_successful_updating').' '.
|
||||
$supplier_data['company_name'],'person_id'=>$supplier_id));
|
||||
$supplier_data['company_name'],'id'=>$supplier_id));
|
||||
}
|
||||
}
|
||||
else//failure
|
||||
{
|
||||
echo json_encode(array('success'=>false,'message'=>$this->lang->line('suppliers_error_adding_updating').' '.
|
||||
$supplier_data['company_name'],'person_id'=>-1));
|
||||
$supplier_data['company_name'],'id'=>-1));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,14 +123,5 @@ class Suppliers extends Person_controller
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Gets one row for a supplier manage table. This is called using AJAX to update one row.
|
||||
*/
|
||||
function get_row()
|
||||
{
|
||||
$person_id = $this->input->post('row_id');
|
||||
$data_row=get_supplier_data_row($this->Supplier->get_info($person_id),$this);
|
||||
echo $data_row;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -143,9 +143,6 @@ function transform_headers($array)
|
||||
}, $array));
|
||||
}
|
||||
|
||||
/*
|
||||
Gets the html table to manage people.
|
||||
*/
|
||||
function get_people_manage_table_headers()
|
||||
{
|
||||
$CI =& get_instance();
|
||||
@@ -195,87 +192,46 @@ function get_detailed_data_row($row, $controller)
|
||||
return $table_data_row;
|
||||
}
|
||||
|
||||
/*
|
||||
Gets the html table to manage suppliers.
|
||||
*/
|
||||
function get_supplier_manage_table($suppliers,$controller)
|
||||
{
|
||||
$CI =& get_instance();
|
||||
$table='<table class="tablesorter table table-striped table-hover" id="sortable_table">';
|
||||
|
||||
$headers = array('<input type="checkbox" id="select_all" />',
|
||||
$CI->lang->line('suppliers_company_name'),
|
||||
$CI->lang->line('suppliers_agency_name'),
|
||||
$CI->lang->line('common_last_name'),
|
||||
$CI->lang->line('common_first_name'),
|
||||
$CI->lang->line('common_email'),
|
||||
$CI->lang->line('common_phone_number'),
|
||||
$CI->lang->line('common_id'),
|
||||
' ');
|
||||
function get_suppliers_manage_table_headers()
|
||||
if($CI->Employee->has_grant('messages', $CI->session->userdata('person_id')))
|
||||
{
|
||||
$headers[] = ' ';
|
||||
}
|
||||
|
||||
$table.='<thead><tr>';
|
||||
foreach($headers as $header)
|
||||
{
|
||||
$table.="<th>$header</th>";
|
||||
}
|
||||
$table.='</tr></thead><tbody>';
|
||||
$table.=get_supplier_manage_table_data_rows($suppliers,$controller);
|
||||
$table.='</tbody></table>';
|
||||
|
||||
return $table;
|
||||
}
|
||||
|
||||
/*
|
||||
Gets the html data rows for the supplier.
|
||||
*/
|
||||
function get_supplier_manage_table_data_rows($suppliers,$controller)
|
||||
{
|
||||
$CI =& get_instance();
|
||||
$table_data_rows='';
|
||||
|
||||
foreach($suppliers->result() as $supplier)
|
||||
{
|
||||
$table_data_rows.=get_supplier_data_row($supplier,$controller);
|
||||
}
|
||||
|
||||
if($suppliers->num_rows()==0)
|
||||
{
|
||||
$table_data_rows.="<tr><td colspan='9'><div class='alert alert-dismissible alert-info'>".$CI->lang->line('common_no_persons_to_display')."</div></td></tr>";
|
||||
}
|
||||
|
||||
return $table_data_rows;
|
||||
|
||||
$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' => '')
|
||||
);
|
||||
|
||||
return transform_headers($headers);
|
||||
}
|
||||
|
||||
function get_supplier_data_row($supplier,$controller)
|
||||
{
|
||||
function get_supplier_data_row($supplier, $controller) {
|
||||
$CI =& get_instance();
|
||||
$controller_name=strtolower(get_class($CI));
|
||||
|
||||
$table_data_row='<tr>';
|
||||
$table_data_row.="<td width='2%'><input type='checkbox' id='person_$supplier->person_id' value='".$supplier->person_id."'/></td>";
|
||||
$table_data_row.='<td width="15%">'.character_limiter($supplier->company_name,13).'</td>';
|
||||
$table_data_row.='<td width="14%">'.character_limiter($supplier->agency_name,13).'</td>';
|
||||
$table_data_row.='<td width="15%">'.character_limiter($supplier->last_name,13).'</td>';
|
||||
$table_data_row.='<td width="15%">'.character_limiter($supplier->first_name,13).'</td>';
|
||||
$table_data_row.='<td width="20%">'.mailto($supplier->email,character_limiter($supplier->email,22)).'</td>';
|
||||
$table_data_row.='<td width="10%">'.character_limiter($supplier->phone_number,13).'</td>';
|
||||
$table_data_row.='<td width="3%">'.character_limiter($supplier->person_id,5).'</td>';
|
||||
if($CI->Employee->has_grant('messages', $CI->session->userdata('person_id')))
|
||||
{
|
||||
$table_data_row.='<td width="3%">'.anchor("Messages/view/$supplier->person_id", '<span class="glyphicon glyphicon-phone"></span>', array('class'=>"modal-dlg modal-btn-submit", 'title'=>$CI->lang->line('messages_sms_send'))).'</td>';
|
||||
$table_data_row.='<td width="3%">'.anchor($controller_name."/view/$supplier->person_id", '<span class="glyphicon glyphicon-edit"></span>', array('class'=>"modal-dlg modal-btn-submit",'title'=>$CI->lang->line($controller_name.'_update'))).'</td>';
|
||||
}
|
||||
else
|
||||
{
|
||||
$table_data_row.='<td width="6%">'.anchor($controller_name."/view/$supplier->person_id", '<span class="glyphicon glyphicon-edit"></span>', array('class'=>"modal-dlg modal-btn-submit",'title'=>$CI->lang->line($controller_name.'_update'))).'</td>';
|
||||
}
|
||||
$table_data_row.='</tr>';
|
||||
|
||||
return $table_data_row;
|
||||
return array (
|
||||
'id' => $supplier->person_id,
|
||||
'company_name' => character_limiter($supplier->company_name,13),
|
||||
'agency_name' => character_limiter($supplier->agency_name,13),
|
||||
'last_name' => character_limiter($supplier->last_name,13),
|
||||
'first_name' => character_limiter($supplier->first_name,13),
|
||||
'email' => empty($supplier->email) ? '' : mailto($supplier->email,character_limiter($supplier->email,22)),
|
||||
'phone_number' => character_limiter($supplier->phone_number,13),
|
||||
'messages' => anchor("Messages/view/$supplier->person_id", '<span class="glyphicon glyphicon-phone"></span>',
|
||||
array('class'=>"modal-dlg modal-btn-submit", 'title'=>$CI->lang->line('messages_sms_send'))),
|
||||
'edit' => anchor($controller_name."/view/$supplier->person_id", '<span class="glyphicon glyphicon-edit"></span>',
|
||||
array('class'=>"modal-dlg modal-btn-submit", 'title'=>$CI->lang->line($controller_name.'_update'))
|
||||
));
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -3,10 +3,8 @@
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function()
|
||||
{
|
||||
|
||||
table_support.init('<?php echo site_url($controller_name);?>', <?php echo $table_headers; ?>);
|
||||
table_support.init_delete('<?php echo $this->lang->line($controller_name."_confirm_delete")?>');
|
||||
|
||||
});
|
||||
|
||||
</script>
|
||||
@@ -20,22 +18,13 @@ $(document).ready(function()
|
||||
title='<?php echo $this->lang->line('customers_import_items_excel'); ?>'>
|
||||
<span class="glyphicon glyphicon-import"></span><?php echo $this->lang->line('common_import_excel'); ?>
|
||||
</button>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<button class='btn btn-info btn-sm pull-right modal-dlg modal-btn-submit' data-href='<?php echo site_url($controller_name."/view"); ?>'
|
||||
title='<?php echo $this->lang->line('customers_new'); ?>'>
|
||||
<span class="glyphicon glyphicon-user"></span><?php echo $this->lang->line('customers_new'); ?>
|
||||
<span class="glyphicon glyphicon-user"></span><?php echo $this->lang->line($controller_name. '_new'); ?>
|
||||
</button>
|
||||
<?php
|
||||
}
|
||||
else
|
||||
{
|
||||
?>
|
||||
<button class='btn btn-info btn-sm pull-right modal-dlg modal-btn-submit' data-href='<?php echo site_url($controller_name."/view"); ?>'
|
||||
title='<?php echo $this->lang->line($controller_name . '_new'); ?>'>
|
||||
<span class="glyphicon glyphicon-user"></span><?php echo $this->lang->line($controller_name . '_new'); ?>
|
||||
</button>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
|
||||
<div id="toolbar">
|
||||
|
||||
@@ -55,7 +55,7 @@ $(document).ready(function()
|
||||
success:function(response)
|
||||
{
|
||||
dialog_support.hide();
|
||||
post_person_form_submit(response);
|
||||
table_support.handle_submit('<?php echo site_url('suppliers'); ?>', response);
|
||||
},
|
||||
dataType:'json'
|
||||
});
|
||||
|
||||
@@ -1,88 +0,0 @@
|
||||
<?php $this->load->view("partial/header"); ?>
|
||||
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function()
|
||||
{
|
||||
init_table_sorting();
|
||||
enable_select_all();
|
||||
enable_row_selection();
|
||||
enable_search({suggest_url: '<?php echo site_url("$controller_name/suggest_search")?>',
|
||||
confirm_search_message: "<?php echo $this->lang->line("common_confirm_search")?>"});
|
||||
enable_email('<?php echo site_url("$controller_name/mailto")?>');
|
||||
enable_delete("<?php echo $this->lang->line($controller_name."_confirm_delete")?>","<?php echo $this->lang->line($controller_name."_none_selected")?>");
|
||||
});
|
||||
|
||||
function init_table_sorting()
|
||||
{
|
||||
//Only init if there is more than one row
|
||||
if($('.tablesorter tbody tr').length >1)
|
||||
{
|
||||
$("#sortable_table").tablesorter(
|
||||
{
|
||||
sortList: [[1,0]],
|
||||
headers:
|
||||
{
|
||||
0: { sorter: 'false'},
|
||||
8: { sorter: 'false'}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function post_person_form_submit(response)
|
||||
{
|
||||
if(!response.success)
|
||||
{
|
||||
set_feedback(response.message, 'alert alert-dismissible alert-danger', true);
|
||||
}
|
||||
else
|
||||
{
|
||||
//This is an update, just update one row
|
||||
if(jQuery.inArray(response.person_id,get_visible_checkbox_ids()) != -1)
|
||||
{
|
||||
update_row(response.person_id,'<?php echo site_url("$controller_name/get_row")?>');
|
||||
set_feedback(response.message, 'alert alert-dismissible alert-success', false);
|
||||
|
||||
}
|
||||
else //refresh entire table
|
||||
{
|
||||
do_search(true,function()
|
||||
{
|
||||
//highlight new row
|
||||
hightlight_row(response.person_id);
|
||||
set_feedback(response.message, 'alert alert-dismissible alert-success', false);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<div id="title_bar">
|
||||
<div id="pagination" class="pull-left"><?php echo $links; ?></div>
|
||||
|
||||
<?php echo anchor("$controller_name/view/-1",
|
||||
"<div class='btn btn-info btn-sm pull-right'><span>" . $this->lang->line($controller_name . '_new') . "</span></div>",
|
||||
array('class'=>'modal-dlg modal-btn-submit none', 'title'=>$this->lang->line($controller_name . '_new'))); ?>
|
||||
</div>
|
||||
|
||||
<?php echo form_open("$controller_name/search", array('id'=>'search_form', 'class'=>'form-horizontal')); ?>
|
||||
<fieldset>
|
||||
<div id="table_action_header" class="form-group">
|
||||
<ul>
|
||||
<li class="pull-left"><?php echo anchor("$controller_name/delete", '<div class="btn btn-default btn-sm"><span>' . $this->lang->line("common_delete") . '</span></div>', array('id'=>'delete')); ?></li>
|
||||
<li class="pull-left"><span><a href="#" id="email"><div class="btn btn-default btn-sm"><?php echo $this->lang->line("common_email");?></div></a></span></li>
|
||||
|
||||
<li class="pull-right">
|
||||
<?php echo form_input(array('name'=>'search', 'class'=>'form-control input-sm', 'id'=>'search')); ?>
|
||||
<?php echo form_input(array('name'=>'limit_from', 'type'=>'hidden', 'id'=>'limit_from')); ?>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</fieldset>
|
||||
<?php echo form_close(); ?>
|
||||
|
||||
<div id="table_holder">
|
||||
<?php echo $manage_table; ?>
|
||||
</div>
|
||||
|
||||
<?php $this->load->view("partial/footer"); ?>
|
||||
Reference in New Issue
Block a user