Migrate to bootstrap-tables in customers modules (#293)

This commit is contained in:
jekkos
2016-04-01 18:30:26 +02:00
parent 6e82c4904f
commit af7b64a398
22 changed files with 214 additions and 570 deletions

View File

@@ -11,10 +11,7 @@ class Customers extends Person_controller
function index($limit_from=0)
{
$data['controller_name'] = $this->get_controller_name();
$lines_per_page = $this->Appconfig->get('lines_per_page');
$customers = $this->Customer->get_all($lines_per_page, $limit_from);
$data['links'] = $this->_initialize_pagination($this->Customer, $lines_per_page, $limit_from);
$data['manage_table'] = get_people_manage_table($customers, $this);
$data['table_headers'] = get_people_manage_table_headers();
$this->load->view('people/manage', $data);
}
@@ -24,16 +21,22 @@ class Customers 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');
$customers = $this->Customer->search($search, $lines_per_page, $limit_from);
$customers = $this->Customer->search($search, $lines_per_page, $offset);
$total_rows = $this->Customer->get_found_rows($search);
$links = $this->_initialize_pagination($this->Customer,$lines_per_page, $limit_from, $total_rows);
$data_rows = get_people_manage_table_data_rows($customers, $this);
echo json_encode(array('total_rows' => $total_rows, 'rows' => $data_rows, 'pagination' => $links));
// updat pagination manually??
$links = $this->_initialize_pagination($this->Customer,$lines_per_page, $limit, $total_rows);
$data_rows = array();
foreach($customers->result() as $person)
{
$data_rows[] = get_person_data_row($person, $this);
}
echo json_encode(array('total' => $total_rows, 'rows' => $data_rows));
}
/*
@@ -95,18 +98,18 @@ class Customers extends Person_controller
if($customer_id==-1)
{
echo json_encode(array('success'=>true,'message'=>$this->lang->line('customers_successful_adding').' '.
$person_data['first_name'].' '.$person_data['last_name'],'person_id'=>$customer_data['person_id']));
$person_data['first_name'].' '.$person_data['last_name'], 'id' => $customer_data['person_id']));
}
else //previous customer
{
echo json_encode(array('success'=>true,'message'=>$this->lang->line('customers_successful_updating').' '.
$person_data['first_name'].' '.$person_data['last_name'],'person_id'=>$customer_id));
$person_data['first_name'].' '.$person_data['last_name'], 'id' => $customer_id));
}
}
else//failure
{
echo json_encode(array('success'=>false,'message'=>$this->lang->line('customers_error_adding_updating').' '.
$person_data['first_name'].' '.$person_data['last_name'],'person_id'=>-1));
$person_data['first_name'].' '.$person_data['last_name'], 'id' => -1));
}
}

View File

@@ -43,11 +43,10 @@ abstract class Person_controller extends Secure_area implements iPerson_controll
/*
Gets one row for a person manage table. This is called using AJAX to update one row.
*/
function get_row()
function get_row($row_id)
{
$person_id = $this->input->post('row_id');
$data_row=get_person_data_row($this->Person->get_info($person_id),$this);
echo $data_row;
$data_row=get_person_data_row($this->Person->get_info($row_id),$this);
echo json_encode($data_row);
}
}
?>

View File

@@ -6,9 +6,7 @@ as the customers, employees, and items controllers.
interface iData_controller
{
public function index();
public function search();
public function suggest_search();
public function get_row();
public function view($data_item_id=-1);
public function save($data_item_id=-1);
public function delete();

View File

@@ -132,81 +132,52 @@ function get_sales_manage_payments_summary($payments, $sales, $controller)
return $table;
}
/*
Gets the html table to manage people.
*/
function get_people_manage_table($people,$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('common_last_name'),
$CI->lang->line('common_first_name'),
$CI->lang->line('common_email'),
$CI->lang->line('common_phone_number'),
'&nbsp');
function transform_headers($array)
if($CI->Employee->has_grant('messages', $CI->session->userdata('person_id')))
{
$headers[] = '&nbsp';
}
$table.='<thead><tr>';
foreach($headers as $header)
{
$table.="<th>$header</th>";
}
$table.='</tr></thead><tbody>';
$table.=get_people_manage_table_data_rows($people,$controller);
$table.='</tbody></table>';
return $table;
{
return json_encode(array_map(function($v) {
return array('field' => key($v), 'title' => current($v), 'checkbox' => (key($v) == 'checkbox'));
}, $array));
}
/*
Gets the html data rows for the people.
Gets the html table to manage people.
*/
function get_people_manage_table_data_rows($people,$controller)
function get_people_manage_table_headers()
{
$CI =& get_instance();
$table_data_rows='';
$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' => '')
);
foreach($people->result() as $person)
{
$table_data_rows.=get_person_data_row($person,$controller);
}
if($people->num_rows()==0)
{
$table_data_rows.="<tr><td colspan='6'><div class='alert alert-dismissible alert-info'>".$CI->lang->line('common_no_persons_to_display')."</div></td></tr>";
}
return $table_data_rows;
return transform_headers($headers);
}
function get_person_data_row($person,$controller)
{
function get_person_data_row($person, $controller) {
$CI =& get_instance();
$controller_name=strtolower(get_class($CI));
$table_data_row='<tr>';
$table_data_row.="<td width='4%'><input type='checkbox' id='person_$person->person_id' value='".$person->person_id."'/></td>";
$table_data_row.='<td width="20%">'.character_limiter($person->last_name,13).'</td>';
$table_data_row.='<td width="20%">'.character_limiter($person->first_name,13).'</td>';
$table_data_row.='<td width="30%">'.mailto($person->email,character_limiter($person->email,22)).'</td>';
$table_data_row.='<td width="20%">'.character_limiter($person->phone_number,13).'</td>';
if($CI->Employee->has_grant('messages', $CI->session->userdata('person_id')))
{
$table_data_row.='<td width="3%">'.anchor("Messages/view/$person->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/$person->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/$person->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;
$row = array (
'id' => $person->person_id,
'last_name' => character_limiter($person->last_name,13),
'first_name' => character_limiter($person->first_name,13),
'email' => mailto($person->email,character_limiter($person->email,22)),
'phone_number' => character_limiter($person->phone_number,13),
'messages' => anchor("Messages/view/$person->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/$person->person_id", '<span class="glyphicon glyphicon-edit"></span>',
array('class'=>"modal-dlg modal-btn-submit", 'title'=>$CI->lang->line($controller_name.'_update'))
));
}
function get_detailed_data_row($row, $controller)
@@ -239,7 +210,7 @@ function get_supplier_manage_table($suppliers,$controller)
$CI->lang->line('common_first_name'),
$CI->lang->line('common_email'),
$CI->lang->line('common_phone_number'),
$CI->lang->line('suppliers_supplier_id'),
$CI->lang->line('common_id'),
'&nbsp');
if($CI->Employee->has_grant('messages', $CI->session->userdata('person_id')))
{

View File

@@ -14,5 +14,4 @@ $lang["suppliers_successful_adding"] = "Erfolgreich hinzugefügt";
$lang["suppliers_successful_deleted"] = "Löschung erfolgreich";
$lang["suppliers_successful_updating"] = "Änderung erfolgreich";
$lang["suppliers_supplier"] = "Lieferant";
$lang["suppliers_supplier_id"] = "ID";
$lang["suppliers_update"] = "Ändere Lieferant";

View File

@@ -14,5 +14,4 @@ $lang["suppliers_successful_adding"] = "You have successfully added supplier";
$lang["suppliers_successful_deleted"] = "You have successfully deleted";
$lang["suppliers_successful_updating"] = "You have successfully updated supplier";
$lang["suppliers_supplier"] = "Supplier";
$lang["suppliers_supplier_id"] = "Id";
$lang["suppliers_update"] = "Update Supplier";

View File

@@ -14,5 +14,4 @@ $lang["suppliers_successful_adding"] = "Has agregado el proveedor satisfactoriam
$lang["suppliers_successful_deleted"] = "Has borrado satisfactoriamente a";
$lang["suppliers_successful_updating"] = "Has actualizado el proveedor satisfactoriamente";
$lang["suppliers_supplier"] = "Proveedor";
$lang["suppliers_supplier_id"] = "Id";
$lang["suppliers_update"] = "Actualizar Proveedor";

View File

@@ -14,5 +14,4 @@ $lang["suppliers_successful_adding"] = "Fournisseur ajouté avec succès";
$lang["suppliers_successful_deleted"] = "Suppression réussie";
$lang["suppliers_successful_updating"] = "Fournisseur édité avec succès";
$lang["suppliers_supplier"] = "Fournisseur";
$lang["suppliers_supplier_id"] = "Id";
$lang["suppliers_update"] = "Éditer Fournisseur";

View File

@@ -14,5 +14,4 @@ $lang["suppliers_successful_adding"] = "Anda telah berhasil menambahkan data pem
$lang["suppliers_successful_deleted"] = "Anda telah berhasil menghapus data pemasok";
$lang["suppliers_successful_updating"] = "Anda telah berhasil memperbarui data pemasok";
$lang["suppliers_supplier"] = "Pemasok";
$lang["suppliers_supplier_id"] = "Id";
$lang["suppliers_update"] = "Ubah data Pemasok";

View File

@@ -14,5 +14,4 @@ $lang["suppliers_successful_adding"] = "Leverancier succesvol toegevoegd";
$lang["suppliers_successful_deleted"] = "Er werd(en)";
$lang["suppliers_successful_updating"] = "Wijzigingen leveranciersgegevens bewaard";
$lang["suppliers_supplier"] = "Leverancier";
$lang["suppliers_supplier_id"] = "Id";
$lang["suppliers_update"] = "Bewerk Leverancier";

View File

@@ -14,5 +14,4 @@ $lang["suppliers_successful_adding"] = "Вы успешно добавили п
$lang["suppliers_successful_deleted"] = "Вы успешно удален";
$lang["suppliers_successful_updating"] = "Вы успешно обновляли поставщиком";
$lang["suppliers_supplier"] = "поставщик";
$lang["suppliers_supplier_id"] = "Id";
$lang["suppliers_update"] = "Обновить поставщика";

View File

@@ -14,5 +14,4 @@ $lang["suppliers_successful_adding"] = "เพิ่มผู้ผลิตส
$lang["suppliers_successful_deleted"] = "ลบสำเร็จ";
$lang["suppliers_successful_updating"] = "ปรับปรุงผู้ผลิตสำเร็จ";
$lang["suppliers_supplier"] = "ผู้ผลิต";
$lang["suppliers_supplier_id"] = "Id";
$lang["suppliers_update"] = "ปรับปรุงผู้ผลิต";

View File

@@ -14,5 +14,4 @@ $lang["suppliers_successful_adding"] = "Sağlayıcı eklendi";
$lang["suppliers_successful_deleted"] = "Sağlayıcı silindi";
$lang["suppliers_successful_updating"] = "Sağlayıcı düzenlendi";
$lang["suppliers_supplier"] = "Sağlayıcı";
$lang["suppliers_supplier_id"] = "Id";
$lang["suppliers_update"] = "Sağlayıcıyı Düzenle";

View File

@@ -14,5 +14,4 @@ $lang["suppliers_successful_adding"] = "您已成功新增供應商";
$lang["suppliers_successful_deleted"] = "您已成功刪除供應商";
$lang["suppliers_successful_updating"] = "您已成功更新供應商";
$lang["suppliers_supplier"] = "供應商";
$lang["suppliers_supplier_id"] = "Id";
$lang["suppliers_update"] = "更新供應商";

View File

@@ -104,7 +104,6 @@ class Item extends CI_Model
{
$this->db->where('items.description', '');
}
// avoid duplicate entry with same name because of inventory reporting multiple changes on the same item in the same date range
$this->db->group_by('items.item_id');

View File

@@ -86,7 +86,7 @@ $(document).ready(function()
success:function(response)
{
dialog_support.hide();
post_person_form_submit(response);
table_support.handle_submit('<?php echo site_url($controller_name); ?>', response);
},
dataType:'json'
});

View File

@@ -2,63 +2,13 @@
<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")?>");
{
table_support.init('<?php echo site_url($controller_name);?>', <?php echo $table_headers; ?>);
});
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_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
if ($controller_name == 'customers')
{
@@ -66,7 +16,7 @@ function post_person_form_submit(response)
<?php echo anchor("$controller_name/excel_import",
"<div class='btn btn-info btn-sm pull-right'><span>" . $this->lang->line('common_import_excel') . "</span></div>",
array('class'=>'modal-dlg modal-btn-submit', 'title'=>$this->lang->line('customers_import_items_excel'))); ?>
<?php echo anchor("$controller_name/view/-1",
"<div class='btn btn-info btn-sm pull-right' style='margin-right: 10px;'><span>" . $this->lang->line('customers_new') . "</span></div>",
array('class'=>'modal-dlg modal-btn-submit', 'title'=>$this->lang->line('customers_new'))); ?>
@@ -83,24 +33,16 @@ function post_person_form_submit(response)
?>
</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>
<div id="toolbar">
<div class="pull-left arrow-left">
<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(); ?>
<?php echo anchor("$controller_name/delete", '<div class="btn btn-default btn-sm"><span>' . $this->lang->line("common_delete") . '</span></div>', array('id'=>'delete')); ?>
<span><a href="#" id="email"><div class="btn btn-default btn-sm"><?php echo $this->lang->line("common_email");?></div></a></span></div>
</div>
</div>
<div id="table_holder">
<?php echo $manage_table; ?>
<table id="table"></table>
</div>
<?php $this->load->view("partial/footer"); ?>

View File

@@ -20,7 +20,7 @@ $(document).ready(function()
enable_delete("<?php echo $this->lang->line($controller_name."_confirm_delete")?>","<?php echo $this->lang->line($controller_name."_none_selected")?>");
// when any filter is clicked and the dropdown window is closed
$('#filters').on('hidden.bs.select', function(e)
$('#filters').on('hidan.bs.select', function(e)
{
// reset page number when selecting a specific page number
$('#limit_from').val("0");

View File

@@ -12,6 +12,13 @@
background-repeat: no-repeat;
}
.arrow-left
{
background-color: transparent;
background-image: url(../images/checkbox_arrow.gif);
background-repeat: no-repeat;
}
#table_action_header ul
{
list-style: none;

View File

@@ -1,188 +1,3 @@
function checkbox_click(event)
{
event.stopPropagation();
do_email(enable_email.url);
if($(event.target).is(':checked'))
{
$(event.target).parent().parent().find("td").addClass('selected').css("backgroundColor","");
}
else
{
$(event.target).parent().parent().find("td").removeClass();
}
}
function enable_search(options)
{
if (!options.format_item) {
format_item = function(results) {
return results[0];
};
}
//Keep track of enable_email has been called
if(!enable_search.enabled)
enable_search.enabled=true;
$('#search').click(function()
{
$(this).attr('value','');
});
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)
{
event.preventDefault();
// reset page number when selecting a specific page number
$('#limit_from').val(0);
if(get_selected_values().length >0)
{
if(!confirm(options.confirm_search_message))
return;
}
do_search(true, options.on_complete);
});
return widget;
}
enable_search.enabled=false;
function attach_search_listener()
{
// prevent redirecting to link when search enabled
$("#pagination a").click(function(event) {
if ($("#search").val() || $("#search_form input:checked")) {
event.preventDefault();
// set limit_from to value included in the link
var uri_segments = event.currentTarget.href.split('/');
var limit_from = uri_segments.pop();
$('#limit_from').val(limit_from);
do_search(true);
}
});
}
function do_search(show_feedback,on_complete)
{
//If search is not enabled, don't do anything
if(!enable_search.enabled)
return;
if(show_feedback)
$('#search').addClass("ac_loading");
$.post(
$('#search_form').attr('action'),
// serialize all the input fields in the form
$('#search_form').serialize(),
function(response) {
$('#sortable_table tbody').html(response.rows);
if(typeof on_complete=='function')
on_complete(response);
$('#search').removeClass("ac_loading");
$('#pagination').html(response.pagination);
//re-init elements in new table, as table tbody children were replaced
dialog_support.init('#sortable_table a.modal-dlg');
$('#sortable_table tbody :checkbox').click(checkbox_click);
$("#select_all").prop('checked',false);
if (response.total_rows > 0)
{
update_sortable_table();
enable_row_selection();
}
attach_search_listener();
}, "json"
);
}
function enable_email(email_url)
{
//Keep track of enable_email has been called
if(!enable_email.enabled)
enable_email.enabled=true;
//store url in function cache
if(!enable_email.url)
{
enable_email.url=email_url;
}
$('#select_all, #sortable_table tbody :checkbox').click(checkbox_click);
}
enable_email.enabled=false;
enable_email.url=false;
function do_email(url)
{
//If email is not enabled, don't do anything
if(!enable_email.enabled)
return;
$.post(url, { 'ids[]': get_selected_values() },function(response)
{
$('#email').attr('href',response);
});
}
function enable_checkboxes()
{
$('#sortable_table tbody :checkbox').click(checkbox_click);
}
function enable_delete(confirm_message,none_selected_message)
{
//Keep track of enable_delete has been called
if(!enable_delete.enabled)
enable_delete.enabled=true;
$("#delete").click(function(event)
{
event.preventDefault();
if($("#sortable_table tbody :checkbox:checked").length >0)
{
if(confirm(confirm_message))
{
do_delete($(this).attr('href'));
} else {
return false;
}
}
else
{
alert(none_selected_message);
}
});
}
enable_delete.enabled=false;
function do_delete(url)
{
@@ -236,173 +51,6 @@ function enable_bulk_edit(none_selected_message)
}
enable_bulk_edit.enabled=false;
function enable_select_all()
{
//Keep track of enable_select_all has been called
if(!enable_select_all.enabled)
enable_select_all.enabled=true;
$('#select_all').click(function()
{
if($(this).is(':checked'))
{
$("#sortable_table tbody :checkbox").each(function()
{
$(this).prop('checked',true);
$(this).parent().parent().find("td").addClass('selected').css("backgroundColor","");
});
}
else
{
$("#sortable_table tbody :checkbox").each(function()
{
$(this).prop('checked',false);
$(this).parent().parent().find("td").removeClass();
});
}
});
}
enable_select_all.enabled=false;
function enable_row_selection(rows)
{
//Keep track of enable_row_selection has been called
if(!enable_row_selection.enabled)
enable_row_selection.enabled=true;
if(typeof rows =="undefined")
rows=$("#sortable_table tbody tr");
rows.hover(
function row_over()
{
$(this).find("td").addClass('over').css("backgroundColor","");
$(this).css("cursor","pointer");
},
function row_out()
{
if(!$(this).find("td").hasClass("selected"))
{
$(this).find("td").removeClass();
}
}
);
rows.click(function row_click(event)
{
var checkbox = $(this).find(":checkbox");
checkbox.prop('checked',!checkbox.is(':checked'));
do_email(enable_email.url);
if(checkbox.is(':checked'))
{
$(this).find("td").addClass('selected').css("backgroundColor","");
}
else
{
$(this).find("td").removeClass();
}
});
}
enable_row_selection.enabled=false;
function update_sortable_table()
{
//let tablesorter know we changed <tbody> and then triger a resort
$("#sortable_table").trigger("update");
if(typeof $("#sortable_table")[0].config!="undefined")
{
var sorting = $("#sortable_table")[0].config.sortList;
$("#sortable_table").trigger("sorton",[sorting]);
}
else
{
window['init_table_sorting'] && init_table_sorting();
}
}
function get_table_row(id)
{
id = id || $("input[name='sale_id']").val();
var $element = $("#sortable_table tbody :checkbox[value='" + id + "']");
if ($element.length === 0) {
$element = $("#sortable_table tbody a[href*='/" + id + "/']");
}
return $element;
}
function update_row(row_id,url,callback)
{
$.post(url, { 'row_id': row_id },function(response)
{
//Replace previous row
var row_to_update = get_table_row(row_id).parent().parent();
row_to_update.replaceWith(response);
reinit_row(row_id);
hightlight_row(row_id);
callback && typeof(callback) == "function" && callback();
}, 'html');
}
function reinit_row(checkbox_id)
{
var new_checkbox = $("#sortable_table tbody tr :checkbox[value="+checkbox_id+"]");
var new_row = new_checkbox.parent().parent();
enable_row_selection(new_row);
//Re-init some stuff as we replaced row
update_sortable_table();
dialog_support.init(new_row.find("a.modal-dlg"));
//re-enable email
new_checkbox.click(checkbox_click);
}
function animate_row(row,color)
{
color = color || "#e1ffdd";
row.find("td").css("backgroundColor", "#ffffff").animate({backgroundColor:color},"slow","linear")
.animate({backgroundColor:color},5000)
.animate({backgroundColor:"#ffffff"},"slow","linear");
}
function hightlight_row(checkbox_id)
{
var new_checkbox = $("#sortable_table tbody tr :checkbox[value="+checkbox_id+"]");
var new_row = new_checkbox.parent().parent();
animate_row(new_row);
}
function get_selected_values()
{
var selected_values = new Array();
$("#sortable_table tbody :checkbox:checked").each(function()
{
selected_values.push($(this).val());
});
return selected_values;
}
function get_selected_rows()
{
var selected_rows = new Array();
$("#sortable_table tbody :checkbox:checked").each(function()
{
selected_rows.push($(this).parent().parent());
});
return selected_rows;
}
function get_visible_checkbox_ids()
{
var row_ids = new Array();
$("#sortable_table tbody :checkbox").each(function()
{
row_ids.push($(this).val());
});
return row_ids;
}
dialog_support = (function() {
@@ -417,73 +65,72 @@ dialog_support = (function() {
};
var submit = function(button_id) {
return function(dlog_ref)
{
return function(dlog_ref) {
btn_id = button_id;
dialog_ref = dlog_ref;
if (button_id == 'delete')
{
if (button_id == 'delete') {
$("form[id*='delete_form']").submit();
}
else
{
} else {
$('form', dlog_ref.$modalBody).first().submit();
}
}
};
var init = function(selector) {
return $(selector).click(function(event) {
var buttons = [];
var dialog_class = 'modal-dlg';
$.each($(this).attr('class').split(/\s+/), function(classIndex, className) {
var width_class = className.split("modal-dlg-");
if (width_class && width_class.length > 1) {
dialog_class = className;
}
var btn_class = className.split("modal-btn-");
if (btn_class && btn_class.length > 1) {
var btn_name = btn_class[1];
var is_submit = btn_name == 'submit';
buttons.push({
id: btn_name,
label: btn_name.charAt(0).toUpperCase() + btn_name.slice(1),
cssClass: is_submit ? 'btn-primary' : (btn_name == 'delete' ? 'btn-danger' : ''),
hotkey: is_submit ? 13 : undefined, // Enter.
action: submit(btn_name)
});
}
});
$(selector).each(function(index, $element) {
return $(selector).off('click').on('click', function(event) {
var buttons = [];
var dialog_class = 'modal-dlg';
$.each($(this).attr('class').split(/\s+/), function(classIndex, className) {
var width_class = className.split("modal-dlg-");
if (width_class && width_class.length > 1) {
dialog_class = className;
}
var btn_class = className.split("modal-btn-");
if (btn_class && btn_class.length > 1) {
var btn_name = btn_class[1];
var is_submit = btn_name == 'submit';
buttons.push({
id: btn_name,
label: btn_name.charAt(0).toUpperCase() + btn_name.slice(1),
cssClass: is_submit ? 'btn-primary' : (btn_name == 'delete' ? 'btn-danger' : ''),
hotkey: is_submit ? 13 : undefined, // Enter.
action: submit(btn_name)
});
}
});
!buttons.length && buttons.push({
id: 'close',
label: 'Close',
cssClass: 'btn-primary',
action: function(dialog_ref) {
dialog_ref.close();
}
});
!buttons.length && buttons.push({
id: 'close',
label: 'Close',
cssClass: 'btn-primary',
action: function(dialog_ref) {
dialog_ref.close();
}
});
var $link = $(event.target);
$link = $link.is("a") ? $link : $link.parents("a");
BootstrapDialog.show({
cssClass: dialog_class,
title: $link.attr('title'),
buttons: buttons,
message: (function() {
var node = $('<div></div>');
$.get($link.attr('href'), function(data) {
node.html(data);
});
return node;
})
});
var $link = $(event.target);
$link = $link.is("a") ? $link : $link.parents("a");
BootstrapDialog.show({
cssClass: dialog_class,
title: $link.attr('title'),
buttons: buttons,
message: (function() {
var node = $('<div></div>');
$.get($link.attr('href'), function(data) {
node.html(data);
});
return node;
})
});
event.preventDefault();
event.preventDefault();
});
});
};
$(document).ready(function() {
$(document).ajaxComplete(function() {
init("a.modal-dlg");
});
@@ -496,12 +143,10 @@ dialog_support = (function() {
errorClass: "has-error",
errorLabelContainer: "#error_message_box",
wrapper: "li",
highlight: function (e)
{
highlight: function (e) {
$(e).closest('.form-group').addClass('has-error');
},
unhighlight: function (e)
{
unhighlight: function (e) {
$(e).closest('.form-group').removeClass('has-error');
}
}
@@ -509,3 +154,92 @@ dialog_support = (function() {
})();
table_support = (function() {
var init_autocomplete = function() {
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);
}
});
};
var highlight_rows = function(id, color) {
var original = $("tr.selected").css('backgroundColor');
var selector = ((id && "tr[data-uniqueid='" + id + "']")) || "tr.selected";
$(selector).removeClass("selected").animate({backgroundColor:color||'#e1ffdd'},"slow","linear")
.animate({backgroundColor:color||'#e1ffdd'},5000)
.animate({backgroundColor:original},"slow","linear");
$("tr input:checkbox:checked").prop("checked", false);
};
return {
init: function(resource, headers) {
$('#table').bootstrapTable({
columns: headers,
url: resource + '/search',
sidePagination: 'server',
striped: true,
pagination: true,
search: true,
showColumns: true,
clickToSelect: true,
toolbar: '#toolbar',
uniqueId: 'id'
});
},
handle_submit : function (resource, response) {
var $table = $("#table").data('bootstrap.table');
var id = response.id;
if(!response.success) {
set_feedback(response.message, 'alert alert-dismissible alert-danger', true);
} else {
//This is an update, just update one row
var message = response.message;
var selected_ids = $.map($table.getSelections(), function(element) {
return element.id;
});
if(jQuery.inArray(id, selected_ids) != -1) {
$.get(resource + '/get_row/' + id, function(response)
{
$table.updateByUniqueId({id: id, row: response});
highlight_rows();
set_feedback(message, 'alert alert-dismissible alert-success', false);
});
} else {
$table.refresh();
hightlight_rows(response.id);
set_feedback(message, 'alert alert-dismissible alert-success', false);
}
}
}
}
})();

View File

@@ -7,13 +7,13 @@
if (window.sessionStorage && !sessionStorage['country'])
{
$.ajax({
/*$.ajax({
type: "GET",
url: http_s('ipinfo.io/json'),
success: function(response) {
sessionStorage['country'] = response.country;
}, dataType: 'jsonp'
});
})*/;
}
var url = http_s('nominatim.openstreetmap.org/search');

View File

@@ -59,3 +59,4 @@ common_export_excel,Excel Export,Excel Export,Excel Export,Excel Export,Excel Ex
common_export_excel_yes,Igen,Yes,Yes,Yes,Yes,Yes,Yes,Yes,Yes,Yes,Yes,Sim,Da
common_export_excel_no,Nem,No,No,No,No,No,No,No,No,No,No,Não,Ne
common_required,Kötelező,Erforderlich,Required,Requerido,Required,Required,Required,Required,ต้องกรอก,Required,Required,Requerido,Potreban
common_id,ID,Id,Id,Id,Id,Id,Id,Id,Id,Id
1 label hu-HU de-CH nl-BE es en fr zh ru th tr id pt-BR hr-HR
59 common_export_excel_yes Igen Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Sim Da
60 common_export_excel_no Nem No No No No No No No No No No Não Ne
61 common_required Kötelező Erforderlich Required Requerido Required Required Required Required ต้องกรอก Required Required Requerido Potreban
62 common_id ID Id Id Id Id Id Id Id Id Id