Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 759e7200

Von Bernd Bleßmann vor mehr als 6 Jahren hinzugefügt

  • ID 759e7200b66eced8b4da70dba0f48739d883da2c
  • Vorgänger bba88a1b
  • Nachfolger 6cac3ff6

Auftrags-Controller: multi items dialog: JavaScript aus html-Template raus

Unterschiede anzeigen:

js/kivi.Order.js
381 381
    $.post("controller.pl", data, kivi.eval_json_result);
382 382
  };
383 383

  
384
  ns.setup_multi_items_dialog = function() {
385
    $('#multi_items_filter_table input, #multi_items_filter_table select').keydown(function(event) {
386
      if (event.keyCode == 13) {
387
        event.preventDefault();
388
        ns.multi_items_dialog_update_result();
389
        return false;
390
      }
391
    });
392

  
393
    $('#multi_items_filter_all_substr_multi_ilike').focus();
394
  };
395

  
384 396
  ns.show_multi_items_dialog = function() {
385 397
    if (!ns.check_cv()) return;
386 398

  
387 399
    $('#row_table_id thead a img').remove();
388 400

  
389 401
    kivi.popup_dialog({
390
      url: 'controller.pl?action=Order/show_multi_items_dialog',
391
      data: { type:             $('#type').val(),
392
              callback:         'Order/add_multi_items',
393
              callback_data_id: 'order_form' },
394
      id: 'jq_multi_items_dialog',
402
      url:    'controller.pl?action=Order/show_multi_items_dialog',
403
      data:   { type: $('#type').val() },
404
      id:     'jq_multi_items_dialog',
405
      load:   kivi.Order.setup_multi_items_dialog,
395 406
      dialog: {
396 407
        title:  kivi.t8('Add multiple items'),
397 408
        width:  800,
......
405 416
    $('#jq_multi_items_dialog').dialog('close');
406 417
  };
407 418

  
419
  ns.multi_items_dialog_update_result = function() {
420
    var data = $('#multi_items_form').serializeArray();
421
    data.push({ name: 'type', value: $('#type').val() });
422
    $.ajax({
423
      url:     'controller.pl?action=Order/multi_items_update_result',
424
      data:    data,
425
      method:  'post',
426
      success: function(data) {
427
        $('#multi_items_result').html(data);
428
        ns.multi_items_dialog_enable_continue();
429
        ns.multi_items_result_setup_events();
430
      }
431
    });
432
  };
433

  
434
  ns.multi_items_dialog_disable_continue = function() {
435
    // disable keydown-event and continue button to prevent
436
    // impatient users to add parts multiple times
437
    $('#multi_items_result input').off("keydown");
438
    $('#multi_items_dialog_continue_button').prop('disabled', true);
439
  };
440

  
441
  ns.multi_items_dialog_enable_continue = function()  {
442
    $('#multi_items_result input').keydown(function(event) {
443
      if(event.keyCode == 13) {
444
        event.preventDefault();
445
        ns.add_multi_items();
446
        return false;
447
      }
448
    });
449
    $('#multi_items_dialog_continue_button').prop('disabled', false);
450
  };
451

  
452
  ns.multi_items_result_setup_events = function() {
453
    $('#multi_items_all_qty').change(ns.reformat_number);
454
    $('#multi_items_all_qty').change(function(event) {
455
      $('.multi_items_qty').val($(event.target).val());
456
    });
457
    $('.multi_items_qty').change(ns.reformat_number);
458
  }
459

  
460
  ns.add_multi_items = function() {
461
    // rows at all
462
    var n_rows = $('.multi_items_qty').length;
463
    if (n_rows == 0) return;
464

  
465
    // filled rows
466
    n_rows = $('.multi_items_qty').filter(function() {
467
      return $(this).val().length > 0;
468
    }).length;
469
    if (n_rows == 0) return;
470

  
471
    ns.multi_items_dialog_disable_continue();
472

  
473
    var data = $('#order_form').serializeArray();
474
    data = data.concat($('#multi_items_form').serializeArray());
475
    data.push({ name: 'action', value: 'Order/add_multi_items' });
476
    $.post("controller.pl", data, kivi.eval_json_result);
477
  };
478

  
479
  ns.set_input_to_one = function(clicked) {
480
    if ($(clicked).val() == '') {
481
      $(clicked).val(kivi.format_amount(1.00, -2));
482
    }
483
    $(clicked).select();
484
  };
485

  
408 486
  ns.delete_order_item_row = function(clicked) {
409 487
    var row = $(clicked).parents("tbody").first();
410 488
    $(row).remove();
templates/webpages/order/tabs/_multi_items_dialog.html
11 11
  <tr>
12 12
</table>
13 13

  
14
[% L.button_tag('update_result()', LxERP.t8('Filter')) %]
14
[% L.button_tag('kivi.Order.multi_items_dialog_update_result()', LxERP.t8('Filter')) %]
15 15
[% L.button_tag('$("#multi_items_form").resetForm()', LxERP.t8('Reset')) %]
16 16

  
17 17
<hr>
18 18
<div id='multi_items_result'></div>
19 19
<hr>
20 20

  
21
[% L.button_tag('add_multi_items()', LxERP.t8('Continue'), id='continue_button') %]
21
[% L.button_tag('kivi.Order.add_multi_items()', LxERP.t8('Continue'), id='multi_items_dialog_continue_button') %]
22 22
<a href="#" onclick="kivi.Order.close_multi_items_dialog();">[%- LxERP.t8("Cancel") %]</a>
23 23

  
24
<script type='text/javascript'>
25
function update_result() {
26
  var data = $('#multi_items_form').serializeArray();
27
  data.push({ name: 'type', value: '[%- FORM.type %]' });
28
  $.ajax({
29
    url: 'controller.pl?action=Order/multi_items_update_result',
30
    data: data,
31
    method: 'post',
32
    success: function(data){
33
      $('#multi_items_result').html(data);
34
      enable_continue();
35
    }
36
  });
37
}
38

  
39
function disable_continue() {
40
  // disable keydown-event and continue button to prevent
41
  // impatient users to add parts multiple times
42
  $('#multi_items_result input').off("keydown");
43
  $('#continue_button').prop('disabled', true);
44
}
45

  
46
function enable_continue() {
47
  $('#multi_items_result input').keydown(function(event) {
48
    if(event.keyCode == 13) {
49
      event.preventDefault();
50
      add_multi_items();
51
      return false;
52
    }
53
  });
54
  $('#continue_button').prop('disabled', false);
55
}
56

  
57
function add_multi_items() {
58
  // rows at all
59
  var n_rows = $('.multi_items_qty').length;
60
  if ( n_rows == 0) { return; }
61

  
62
  // filled rows
63
  n_rows = $('.multi_items_qty').filter(function() {
64
    return $(this).val().length > 0;
65
  }).length;
66
  if ( n_rows == 0) { return; }
67

  
68
  disable_continue();
69

  
70
  var data = $('#[%- FORM.callback_data_id %]').serializeArray();
71
  data = data.concat($('#multi_items_form').serializeArray());
72
  data.push({ name: 'action', value: '[%- FORM.callback %]' });
73
  $.post("controller.pl", data, kivi.eval_json_result);
74
}
75

  
76
$('#multi_items_filter_table input, #multi_items_filter_table select').keydown(function(event) {
77
  if(event.keyCode == 13) {
78
    event.preventDefault();
79
    update_result();
80
    return false;
81
  }
82
});
83

  
84
$('#multi_items_filter_all_substr_multi_ilike').focus();
85
</script>
86 24

  
87 25
</form>
templates/webpages/order/tabs/_multi_items_result.html
14 14
      <td>
15 15
        [% L.hidden_tag("add_multi_items[+].parts_id", item.id) %]
16 16
        [% L.input_tag("add_multi_items[].qty_as_number", '', size = 5,
17
                       class = 'multi_items_qty numeric', onclick = 'set_qty_to_one(this)') %]
17
                       class = 'multi_items_qty numeric', onclick = 'kivi.Order.set_input_to_one(this)') %]
18 18
      </td>
19 19
      <td>[% HTML.escape(item.unit) %]</td>
20 20
      <td>[% HTML.escape(item.partnumber) %]</td>
......
22 22
    </tr>
23 23
  [%- END %]
24 24
</table>
25

  
26
<script type='text/javascript'>
27
  function set_qty_to_one(clicked) {
28
    if ($(clicked).val() == '') {
29
      $(clicked).val('[%- LxERP.format_amount(1.00, -2) %]');
30
    }
31
    $(clicked).select();
32
  }
33

  
34
  $('#multi_items_all_qty').change(function(event){
35
    $('.multi_items_qty').val($(event.target).val());
36
  });
37
</script>

Auch abrufbar als: Unified diff