$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;
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;
$('#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) {
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' %]
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) {