Enable bootstrap-tables for giftcards module (#293)

This commit is contained in:
jekkos
2016-04-16 23:29:51 +02:00
parent 0cd45e275e
commit 3b9ae1d807
5 changed files with 60 additions and 148 deletions

View File

@@ -11,11 +11,10 @@ class Giftcards extends Secure_area implements iData_controller
function index($limit_from=0)
{
$data['controller_name'] = $this->get_controller_name();
$lines_per_page = $this->Appconfig->get('lines_per_page');
$giftcards = $this->Giftcard->get_all($lines_per_page, $limit_from);
$data['links'] = $this->_initialize_pagination($this->Giftcard, $lines_per_page, $limit_from);
$data['manage_table'] = get_giftcards_manage_table($giftcards, $this);
$data['table_headers'] = get_giftcards_manage_table_headers();
$this->load->view('giftcards/manage', $data);
}
@@ -24,16 +23,21 @@ class Giftcards extends Secure_area implements iData_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');
$giftcards = $this->Giftcard->search($search, $lines_per_page, $limit_from);
$giftcards = $this->Giftcard->search($search, $offset, $limit);
$total_rows = $this->Giftcard->get_found_rows($search);
$links = $this->_initialize_pagination($this->Giftcard, $lines_per_page, $limit_from, $total_rows);
$data_rows = get_giftcards_manage_table_data_rows($giftcards, $this);
echo json_encode(array('total_rows' => $total_rows, 'rows' => $data_rows, 'pagination' => $links));
$links = $this->_initialize_pagination($this->Giftcard, $lines_per_page, $limit, $total_rows);
$data_rows = array();
foreach($giftcards->result() as $giftcard)
{
$data_rows[] = get_giftcard_data_row($giftcard, $this);
}
echo json_encode(array('total' => $total_rows, 'rows' => $data_rows));
}
/*
@@ -45,11 +49,10 @@ class Giftcards extends Secure_area implements iData_controller
echo json_encode($suggestions);
}
function get_row()
function get_row($row_id)
{
$giftcard_id = $this->input->post('row_id');
$data_row = get_giftcard_data_row($this->Giftcard->get_info($giftcard_id), $this);
echo $data_row;
$data_row = get_giftcard_data_row($this->Giftcard->get_info($row_id), $this);
echo json_encode($data_row);
}
function view($giftcard_id=-1)
@@ -78,19 +81,19 @@ class Giftcards extends Secure_area implements iData_controller
if($giftcard_id==-1)
{
echo json_encode(array('success'=>true, 'message'=>$this->lang->line('giftcards_successful_adding').' '.
$giftcard_data['giftcard_number'], 'giftcard_id'=>$giftcard_data['giftcard_id']));
$giftcard_data['giftcard_number'], 'id'=>$giftcard_data['giftcard_id']));
$giftcard_id = $giftcard_data['giftcard_id'];
}
else //previous giftcard
{
echo json_encode(array('success'=>true, 'message'=>$this->lang->line('giftcards_successful_updating').' '.
$giftcard_data['giftcard_number'], 'giftcard_id'=>$giftcard_id));
$giftcard_data['giftcard_number'], 'id'=>$giftcard_id));
}
}
else//failure
{
echo json_encode(array('success'=>false,'message'=>$this->lang->line('giftcards_error_adding_updating').' '.
$giftcard_data['giftcard_number'], 'giftcard_id'=>-1));
$giftcard_data['giftcard_number'], 'id'=>-1));
}
}

View File

@@ -333,69 +333,36 @@ function get_item_data_row($item,$controller)
return $table_data_row;
}
/*
Gets the html table to manage giftcards.
*/
function get_giftcards_manage_table( $giftcards, $controller )
function get_giftcards_manage_table_headers()
{
$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('common_last_name'),
$CI->lang->line('common_first_name'),
$CI->lang->line('giftcards_giftcard_number'),
$CI->lang->line('giftcards_card_value'),
'&nbsp');
$table.='<thead><tr>';
foreach($headers as $header)
{
$table.="<th>$header</th>";
}
$table.='</tr></thead><tbody>';
$table.=get_giftcards_manage_table_data_rows( $giftcards, $controller );
$table.='</tbody></table>';
return $table;
$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' => '')
);
return transform_headers($headers);
}
/*
Gets the html data rows for the giftcard.
*/
function get_giftcards_manage_table_data_rows( $giftcards, $controller )
{
$CI =& get_instance();
$table_data_rows='';
foreach($giftcards->result() as $giftcard)
{
$table_data_rows.=get_giftcard_data_row( $giftcard, $controller );
}
if($giftcards->num_rows()==0)
{
$table_data_rows.="<tr><td colspan='6'><div class='alert alert-dismissible alert-info'>".$CI->lang->line('giftcards_no_giftcards_to_display')."</div></td></tr>";
}
return $table_data_rows;
}
function get_giftcard_data_row($giftcard,$controller)
{
function get_giftcard_data_row($giftcard, $controller) {
$CI =& get_instance();
$controller_name=strtolower(get_class($CI));
$table_data_row='<tr>';
$table_data_row.="<td width='3%'><input type='checkbox' id='giftcard_$giftcard->giftcard_id' value='".$giftcard->giftcard_id."'/></td>";
$table_data_row.='<td width="15%">'.$giftcard->last_name.'</td>';
$table_data_row.='<td width="15%">'.$giftcard->first_name.'</td>';
$table_data_row.='<td width="15%">'.$giftcard->giftcard_number.'</td>';
$table_data_row.='<td width="20%">'.to_currency($giftcard->value).'</td>';
$table_data_row.='<td width="5%">'.anchor($controller_name."/view/$giftcard->giftcard_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' => $giftcard->giftcard_id,
'last_name' => character_limiter($giftcard->last_name,13),
'first_name' => character_limiter($giftcard->first_name,13),
'giftcard_number' => $giftcard->giftcard_number,
'giftcard_value' => to_currency($giftcard->value),
'edit' => anchor($controller_name."/view/$giftcard->giftcard_id", '<span class="glyphicon glyphicon-edit"></span>',
array('class'=>"modal-dlg modal-btn-submit", 'title'=>$CI->lang->line($controller_name.'_update'))
));
}
/*

View File

@@ -217,8 +217,8 @@ class Giftcard extends CI_Model
{
$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_group_start();
$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));
@@ -239,8 +239,8 @@ class Giftcard extends CI_Model
{
$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_group_start();
$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));

View File

@@ -80,11 +80,11 @@ $(document).ready(function()
success:function(response)
{
dialog_support.hide();
post_giftcard_form_submit(response);
table_support.handle_submit('<?php echo site_url($controller_name); ?>', response);
},
error: function(jqXHR, textStatus, errorThrown)
{
post_giftcard_form_submit({message: errorThrown});
table_support.handle_submit('<?php echo site_url($controller_name); ?>', {message: errorThrown});
},
dataType:'json'
});

View File

@@ -2,85 +2,27 @@
<script type="text/javascript">
$(document).ready(function()
{
init_table_sorting();
enable_select_all();
enable_checkboxes();
enable_row_selection();
enable_search({suggest_url: '<?php echo site_url("$controller_name/suggest_search")?>',
confirm_message: "<?php echo $this->lang->line("common_confirm_search")?>"});
enable_delete("<?php echo $this->lang->line($controller_name."_confirm_delete")?>","<?php echo $this->lang->line($controller_name."_none_selected")?>");
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")?>');
});
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'},
5: { sorter: 'false'}
}
});
}
}
function post_giftcard_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.giftcard_id,get_visible_checkbox_ids()) != -1)
{
update_row(response.giftcard_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.giftcard_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', 'title'=>$this->lang->line($controller_name.'_new'))); ?>
<div id="title_bar" class="btn-toolbar">
<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-heart"></span><?php echo $this->lang->line($controller_name . '_new'); ?>
</button>
</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-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="toolbar">
<div class="pull-left btn-toolbar">
<button id="delete" class="btn btn-default btn-sm" data-href='<?php echo site_url($controller_name."/delete"); ?>'><span class="glyphicon glyphicon-trash"></span>
<?php echo $this->lang->line("common_delete");?></button>
</div>
</div>
<div id="table_holder">
<?php echo $manage_table; ?>
<table id="table"></table>
</div>
<?php $this->load->view("partial/footer"); ?>