From d8a1906bf172509d96f3311dc17e0609ab96bd29 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bernd=20Ble=C3=9Fmann?= Date: Wed, 10 Feb 2016 13:02:13 +0100 Subject: [PATCH] =?utf8?q?Auftrags-Controller:=20event=20bindings=20nicht?= =?utf8?q?=20mehrfach=20hinzuf=C3=BCgen.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Dazu event handler für die Positions-Zeilen mit run_once_for registrieren und in eine eigene Funktion init_row_handlers() ausgelagert. Damit kann init_row_handlers() gefahrlos immer nach dem Hinzufügen neuer Positionen aufgerufen werden, ohne einen Handler mehrmals zu registrieren. --- SL/Controller/Order.pm | 13 +-- templates/webpages/order/tabs/basic_data.html | 94 +++++++++---------- 2 files changed, 45 insertions(+), 62 deletions(-) diff --git a/SL/Controller/Order.pm b/SL/Controller/Order.pm index 6e88036e8..cd13a9289 100644 --- a/SL/Controller/Order.pm +++ b/SL/Controller/Order.pm @@ -423,12 +423,9 @@ sub action_add_item { $self->js ->append('#row_table_id', $row_as_html) ->val('.add_item_input', '') + ->run('init_row_handlers') ->run('row_table_scroll_down') - ->run('row_set_keyboard_events_by_id', $item_id) - ->run('set_unit_change_with_oldval_by_id', $item_id) ->run('renumber_positions') - ->on('.recalc', 'change', 'recalc_amounts_and_taxes') - ->on('.reformat_number', 'change', 'reformat_number') ->focus('#add_item_parts_id_name'); $self->_js_redisplay_amounts_and_taxes; @@ -483,18 +480,14 @@ sub action_add_multi_items { ALL_PRICE_FACTORS => $self->all_price_factors ); - $self->js - ->append('#row_table_id', $row_as_html) - ->run('row_set_keyboard_events_by_id', $item_id) - ->run('set_unit_change_with_oldval_by_id', $item_id); + $self->js->append('#row_table_id', $row_as_html); } $self->js ->run('close_multi_items_dialog') + ->run('init_row_handlers') ->run('row_table_scroll_down') ->run('renumber_positions') - ->on('.recalc', 'change', 'recalc_amounts_and_taxes') - ->on('.reformat_number', 'change', 'reformat_number') ->focus('#add_item_parts_id_name'); $self->_js_redisplay_amounts_and_taxes; diff --git a/templates/webpages/order/tabs/basic_data.html b/templates/webpages/order/tabs/basic_data.html index 7732c2288..8278a41ed 100644 --- a/templates/webpages/order/tabs/basic_data.html +++ b/templates/webpages/order/tabs/basic_data.html @@ -447,53 +447,6 @@ function row_table_scroll_down() { $('#row_table_scroll_id').scrollTop($('#row_table_scroll_id')[0].scrollHeight); } -function row_set_keyboard_events_by_id(item_id) { - var row = $('#item_' + item_id).parents("tbody").first(); - - row_set_keyboard_events(row); -} - -function row_set_keyboard_events(rows) { - $(rows).keydown(function(event) { - if(event.keyCode == 40 && event.shiftKey == true) { - // shift arrow down - event.preventDefault(); - var row = $(event.target).parents(".row_entry").first(); - $(row).children().not(':first').show(); - return false; - } - if(event.keyCode == 38 && event.shiftKey == true) { - // shift arrow up - event.preventDefault(); - var row = $(event.target).parents(".row_entry").first(); - $(row).children().not(':first').hide(); - return false; - } - }); - - $(rows).dblclick(function(event) { - event.preventDefault(); - var row = $(event.target).parents(".row_entry").first(); - $(row).children().not(':first').toggle(); - return false; - }); -} - -function set_unit_change_with_oldval_by_id(item_id) { - var row = $('#item_' + item_id).parents("tbody").first(); - var select_elt = $(row).find('[name="order.orderitems[].unit"]'); - - set_unit_change_with_oldval(select_elt); -} - -function set_unit_change_with_oldval(selects) { - selects.each(function(idx,elt) { - $(elt).data('oldval', $(elt).val()); - }); - - selects.change(unit_change); -} - var email_dialog; function show_email_dialog(html) { @@ -604,6 +557,47 @@ function show_longdescription_dialog(clicked) { kivi.SalesPurchase.edit_longdescription_with_params(params); } +function init_row_handlers() { + kivi.run_once_for('.recalc', 'on_change_recalc', function(elt) { + $(elt).change(recalc_amounts_and_taxes); + }); + + kivi.run_once_for('.reformat_number', 'on_change_reformat', function(elt) { + $(elt).change(reformat_number); + }); + + kivi.run_once_for('.unitselect', 'on_change_unit_with_oldval', function(elt) { + $(elt).data('oldval', $(elt).val()); + $(elt).change(unit_change); + }); + + kivi.run_once_for('.row_entry', 'on_kbd_click_show_hide', function(elt) { + $(elt).keydown(function(event) { + if(event.keyCode == 40 && event.shiftKey == true) { + // shift arrow down + event.preventDefault(); + var row = $(event.target).parents(".row_entry").first(); + $(row).children().not(':first').show(); + return false; + } + if(event.keyCode == 38 && event.shiftKey == true) { + // shift arrow up + event.preventDefault(); + var row = $(event.target).parents(".row_entry").first(); + $(row).children().not(':first').hide(); + return false; + } + }); + $(elt).dblclick(function(event) { + event.preventDefault(); + var row = $(event.target).parents(".row_entry").first(); + $(row).children().not(':first').toggle(); + return false; + }); + }); +} + + $(function(){ $('#order_[%- cv_id %]').change(reload_cv_dependend_selections); [%- IF SELF.cv == 'customer' %] @@ -620,11 +614,7 @@ $(function(){ return false; } }); - row_set_keyboard_events($('.row_entry')); - $('.recalc').change(recalc_amounts_and_taxes); - $('.reformat_number').change(reformat_number); - - set_unit_change_with_oldval($('.unitselect')); + init_row_handlers(); }); $('#row_table_id').on('sortstop', function(event, ui) { -- 2.20.1