From af7b64a39864b5e0be504c7451c46e1b0754f963 Mon Sep 17 00:00:00 2001 From: jekkos Date: Fri, 1 Apr 2016 18:30:26 +0200 Subject: [PATCH] Migrate to bootstrap-tables in customers modules (#293) --- application/controllers/Customers.php | 29 +- application/controllers/Person_controller.php | 7 +- .../interfaces/Idata_controller.php | 2 - application/helpers/table_helper.php | 91 +-- application/language/de-CH/suppliers_lang.php | 1 - application/language/en/suppliers_lang.php | 1 - application/language/es/suppliers_lang.php | 1 - application/language/fr/suppliers_lang.php | 1 - application/language/id/suppliers_lang.php | 1 - application/language/nl-BE/suppliers_lang.php | 1 - application/language/ru/suppliers_lang.php | 1 - application/language/th/suppliers_lang.php | 1 - application/language/tr/suppliers_lang.php | 1 - application/language/zh/suppliers_lang.php | 1 - application/models/Item.php | 1 - application/views/customers/form.php | 2 +- application/views/people/manage.php | 78 +-- application/views/sales/manage.php | 2 +- css/tables.css | 7 + js/manage_tables.js | 550 +++++------------- js/nominatim.autocomplete.js | 4 +- translations/common_lang.csv | 1 + 22 files changed, 214 insertions(+), 570 deletions(-) diff --git a/application/controllers/Customers.php b/application/controllers/Customers.php index 28044eb94..d88459d37 100644 --- a/application/controllers/Customers.php +++ b/application/controllers/Customers.php @@ -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)); } } diff --git a/application/controllers/Person_controller.php b/application/controllers/Person_controller.php index d09124d56..98eced3c4 100644 --- a/application/controllers/Person_controller.php +++ b/application/controllers/Person_controller.php @@ -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); } } ?> \ No newline at end of file diff --git a/application/controllers/interfaces/Idata_controller.php b/application/controllers/interfaces/Idata_controller.php index 8721e6ed4..c366cc498 100644 --- a/application/controllers/interfaces/Idata_controller.php +++ b/application/controllers/interfaces/Idata_controller.php @@ -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(); diff --git a/application/helpers/table_helper.php b/application/helpers/table_helper.php index d865f167a..faea6ae51 100644 --- a/application/helpers/table_helper.php +++ b/application/helpers/table_helper.php @@ -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=''; - - $headers = array('', - $CI->lang->line('common_last_name'), - $CI->lang->line('common_first_name'), - $CI->lang->line('common_email'), - $CI->lang->line('common_phone_number'), - ' '); +function transform_headers($array) if($CI->Employee->has_grant('messages', $CI->session->userdata('person_id'))) { $headers[] = ' '; } - - $table.=''; - foreach($headers as $header) - { - $table.=""; - } - $table.=''; - $table.=get_people_manage_table_data_rows($people,$controller); - $table.='
$header
'; - - 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.="
".$CI->lang->line('common_no_persons_to_display')."
"; - } - - 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=''; - $table_data_row.=""; - $table_data_row.=''.character_limiter($person->last_name,13).''; - $table_data_row.=''.character_limiter($person->first_name,13).''; - $table_data_row.=''.mailto($person->email,character_limiter($person->email,22)).''; - $table_data_row.=''.character_limiter($person->phone_number,13).''; - if($CI->Employee->has_grant('messages', $CI->session->userdata('person_id'))) - { - $table_data_row.=''.anchor("Messages/view/$person->person_id", '', array('class'=>"modal-dlg modal-btn-submit", 'title'=>$CI->lang->line('messages_sms_send'))).''; - $table_data_row.=''.anchor($controller_name."/view/$person->person_id", '', array('class'=>"modal-dlg modal-btn-submit", 'title'=>$CI->lang->line($controller_name.'_update'))).''; - } - else - { - $table_data_row.=''.anchor($controller_name."/view/$person->person_id", '', array('class'=>"modal-dlg modal-btn-submit", 'title'=>$CI->lang->line($controller_name.'_update'))).''; - } - $table_data_row.=''; - - 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", '', + array('class'=>"modal-dlg modal-btn-submit", 'title'=>$CI->lang->line('messages_sms_send'))), + 'edit' => anchor($controller_name."/view/$person->person_id", '', + 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'), ' '); if($CI->Employee->has_grant('messages', $CI->session->userdata('person_id'))) { diff --git a/application/language/de-CH/suppliers_lang.php b/application/language/de-CH/suppliers_lang.php index 6b11803af..9d85fe6e6 100644 --- a/application/language/de-CH/suppliers_lang.php +++ b/application/language/de-CH/suppliers_lang.php @@ -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"; diff --git a/application/language/en/suppliers_lang.php b/application/language/en/suppliers_lang.php index a635a4ad8..b87d2cc8a 100644 --- a/application/language/en/suppliers_lang.php +++ b/application/language/en/suppliers_lang.php @@ -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"; diff --git a/application/language/es/suppliers_lang.php b/application/language/es/suppliers_lang.php index af2004303..0a554a4e6 100644 --- a/application/language/es/suppliers_lang.php +++ b/application/language/es/suppliers_lang.php @@ -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"; diff --git a/application/language/fr/suppliers_lang.php b/application/language/fr/suppliers_lang.php index ce0d49bc1..006cd5790 100644 --- a/application/language/fr/suppliers_lang.php +++ b/application/language/fr/suppliers_lang.php @@ -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"; diff --git a/application/language/id/suppliers_lang.php b/application/language/id/suppliers_lang.php index 839923586..6f7453378 100644 --- a/application/language/id/suppliers_lang.php +++ b/application/language/id/suppliers_lang.php @@ -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"; diff --git a/application/language/nl-BE/suppliers_lang.php b/application/language/nl-BE/suppliers_lang.php index d4956589c..264169cad 100755 --- a/application/language/nl-BE/suppliers_lang.php +++ b/application/language/nl-BE/suppliers_lang.php @@ -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"; diff --git a/application/language/ru/suppliers_lang.php b/application/language/ru/suppliers_lang.php index f8786e43e..f95f15b77 100644 --- a/application/language/ru/suppliers_lang.php +++ b/application/language/ru/suppliers_lang.php @@ -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"] = "Обновить поставщика"; diff --git a/application/language/th/suppliers_lang.php b/application/language/th/suppliers_lang.php index 633b07316..a77c51f9e 100644 --- a/application/language/th/suppliers_lang.php +++ b/application/language/th/suppliers_lang.php @@ -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"] = "ปรับปรุงผู้ผลิต"; diff --git a/application/language/tr/suppliers_lang.php b/application/language/tr/suppliers_lang.php index 02ab4cce4..756dcf6e1 100644 --- a/application/language/tr/suppliers_lang.php +++ b/application/language/tr/suppliers_lang.php @@ -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"; diff --git a/application/language/zh/suppliers_lang.php b/application/language/zh/suppliers_lang.php index bd2af4a2e..3a9f4df81 100755 --- a/application/language/zh/suppliers_lang.php +++ b/application/language/zh/suppliers_lang.php @@ -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"] = "更新供應商"; diff --git a/application/models/Item.php b/application/models/Item.php index 887080690..0b8efbf18 100644 --- a/application/models/Item.php +++ b/application/models/Item.php @@ -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'); diff --git a/application/views/customers/form.php b/application/views/customers/form.php index 463ae7815..9139abb9e 100644 --- a/application/views/customers/form.php +++ b/application/views/customers/form.php @@ -86,7 +86,7 @@ $(document).ready(function() success:function(response) { dialog_support.hide(); - post_person_form_submit(response); + table_support.handle_submit('', response); }, dataType:'json' }); diff --git a/application/views/people/manage.php b/application/views/people/manage.php index f7d199613..2516b87e3 100644 --- a/application/views/people/manage.php +++ b/application/views/people/manage.php @@ -2,63 +2,13 @@
- - " . $this->lang->line('common_import_excel') . "
", array('class'=>'modal-dlg modal-btn-submit', 'title'=>$this->lang->line('customers_import_items_excel'))); ?> - + " . $this->lang->line('customers_new') . "", array('class'=>'modal-dlg modal-btn-submit', 'title'=>$this->lang->line('customers_new'))); ?> @@ -83,24 +33,16 @@ function post_person_form_submit(response) ?> -'search_form', 'class'=>'form-horizontal')); ?> -
-
-
    -
  • ' . $this->lang->line("common_delete") . '
', array('id'=>'delete')); ?> -
  • lang->line("common_email");?>
  • +
    +
    -
  • - 'search', 'class'=>'form-control input-sm', 'id'=>'search')); ?> - 'limit_from', 'type'=>'hidden', 'id'=>'limit_from')); ?> -
  • - -
    -
    - + ' . $this->lang->line("common_delete") . '', array('id'=>'delete')); ?> +
    lang->line("common_email");?>
    + +
    - +
    load->view("partial/footer"); ?> diff --git a/application/views/sales/manage.php b/application/views/sales/manage.php index 723dc6483..b4ca4c6ae 100755 --- a/application/views/sales/manage.php +++ b/application/views/sales/manage.php @@ -20,7 +20,7 @@ $(document).ready(function() enable_delete("lang->line($controller_name."_confirm_delete")?>","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"); diff --git a/css/tables.css b/css/tables.css index a0f2983cf..4f0337e96 100644 --- a/css/tables.css +++ b/css/tables.css @@ -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; diff --git a/js/manage_tables.js b/js/manage_tables.js index d0b850de9..539083c4a 100644 --- a/js/manage_tables.js +++ b/js/manage_tables.js @@ -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 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 = $('
    '); - $.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 = $('
    '); + $.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); + } + } + } + } + +})(); diff --git a/js/nominatim.autocomplete.js b/js/nominatim.autocomplete.js index ebc41fdf4..13d683080 100644 --- a/js/nominatim.autocomplete.js +++ b/js/nominatim.autocomplete.js @@ -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'); diff --git a/translations/common_lang.csv b/translations/common_lang.csv index 4e8ce61a0..8654ff433 100644 --- a/translations/common_lang.csv +++ b/translations/common_lang.csv @@ -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