Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 926099a8

Von Sven Schöling vor fast 8 Jahren hinzugefügt

  • ID 926099a8af011d9bd4d4616797ce5b0fa5e42add
  • Vorgänger 506a2aab
  • Nachfolger 905d9edd

PartPicker: Multipicker als separate popupklasse

Unterschiede anzeigen:

js/kivi.Part.js
177 177
    $.post("controller.pl", data, kivi.eval_json_result);
178 178
  };
179 179

  
180
  ns.set_multi_assembly_items = function(data) {
181
    data.push({ name: 'part.id',        value: $('#part_id').val() });
182
    data.push({ name: 'part.part_type', value: $('#part_part_type').val() });
183
    $.post("controller.pl?action=Part/add_multi_assembly_items", data, kivi.eval_json_result);
184
  }
185

  
186
  ns.set_multi_assortment_items = function(data) {
187
    data.push({ name: 'part.id', value: $('#part_id').val() });
188
    data.push({ name: 'part.part_type', value: $('#part_part_type').val() });
189
    $.post("controller.pl?action=Part/add_multi_assortment_items", data, kivi.eval_json_result);
190
  }
191

  
192
  ns.close_picker_dialogs = function() {
193
    $('.part_autocomplete').each(function(_, e) {
194
      var picker = $(e).data('part_picker');
195
      if (picker) picker.close_dialog();
196
    });
197
  }
198

  
180 199
  ns.redisplay_items = function(data) {
181 200
    var old_rows;
182 201
    var part_type = $("#part_part_type").val();
......
205 224
    $("#assembly_rows tr:last").find('input[type=text]').filter(':visible:first').focus();
206 225
  };
207 226

  
208
  ns.show_multi_items_dialog = function(part_type,part_id) {
209

  
210
    $('#row_table_id thead a img').remove();
211

  
212
    kivi.popup_dialog({
213
      url: 'controller.pl?action=Part/show_multi_items_dialog',
214
      data: { callback:         'Part/add_multi_' + part_type + '_items',
215
              callback_data_id: 'ic',
216
              'part.part_type': part_type,
217
              'part.id'       : part_id,
218
            },
219
      id: 'jq_multi_items_dialog',
220
      dialog: {
221
        title: kivi.t8('Add multiple items'),
222
        width:  800,
223
        height: 800
224
      }
225
    });
226
    return true;
227
  };
228

  
229
  ns.close_multi_items_dialog = function() {
230
    $('#jq_multi_items_dialog').dialog('close');
231
  };
232

  
233

  
234 227
  // makemodel
235 228
  ns.makemodel_renumber_positions = function() {
236 229
    $('.makemodel_row [name="position"]').each(function(idx, elt) {
......
296 289
    this.state              = this.STATES.PICKED;
297 290
    this.last_dummy         = this.$dummy.val();
298 291
    this.timer              = undefined;
292
    this.dialog             = undefined;
299 293

  
300 294
    this.init();
301 295
  };
......
354 348
      }
355 349
      this.annotate_state();
356 350
    },
351
    set_multi_items: function(data) {
352
      this.run_action(this.o.action.set_multi_items, [ data ]);
353
    },
357 354
    make_defined_state: function() {
358 355
      if (this.state == this.STATES.PICKED) {
359 356
        this.annotate_state();
......
438 435
      }
439 436
    },
440 437
    open_dialog: function() {
441
      new ns.PickerPopup(this);
438
      if (this.o.multiple) {
439
        this.dialog = new ns.PickerMultiPopup(this);
440
      } else {
441
        this.dialog = new ns.PickerPopup(this);
442
      }
443
    },
444
    close_dialog: function() {
445
      this.dialog.close_dialog();
446
      this.dialog = undefined;
442 447
    },
443 448
    init: function() {
444 449
      var self = this;
......
549 554
            partnumber:  $(this).children('input.part_picker_partnumber').val(),
550 555
            description: $(this).children('input.part_picker_description').val(),
551 556
          });
552
          self.close_popup();
557
          self.close_dialog();
553 558
          self.pp.$dummy.focus();
554 559
          return true;
555 560
        });
556 561
      });
557 562
      $('#part_selection').keydown(function(e){
558 563
         if (e.which == KEY.ESCAPE) {
559
           self.close_popup();
564
           self.close_dialog();
560 565
           self.pp.$dummy.focus();
561 566
         }
562 567
      });
......
580 585
        this.timer = window.setTimeout(function() { self.update_results() }, 100);
581 586
      }
582 587
    },
583
    close_popup: function() {
588
    close_dialog: function() {
584 589
      $('#part_selection').dialog('close');
585 590
    }
586 591
  };
587 592

  
593
  ns.PickerMultiPopup = function(pp) {
594
    this.pp       = pp;
595
    this.callback = 'Part/add_multi_' + this.pp.o.part_type + '_items';
596
    this.open_dialog();
597
  };
598

  
599
  ns.PickerMultiPopup.prototype = {
600
    open_dialog: function() {
601
      var self = this;
602
      $('#row_table_id thead a img').remove();
603

  
604
      kivi.popup_dialog({
605
        url: 'controller.pl?action=Part/show_multi_items_dialog',
606
        data: $.extend({
607
          real_id: self.pp.real_id,
608
        }, self.pp.ajax_data(this.pp.$dummy.val())),
609
        id: 'jq_multi_items_dialog',
610
        dialog: {
611
          title: kivi.t8('Add multiple items'),
612
          width:  800,
613
          height: 800
614
        },
615
        load: function() {
616
          self.init_search();
617
        }
618
      });
619
      return true;
620
    },
621
    init_search: function() {
622
      var self = this;
623
      $('#multi_items_filter_table input, #multi_items_filter_table select').keydown(function(event) {
624
        if(event.which == KEY.ENTER) {
625
          event.preventDefault();
626
          self.update_results();
627
          return false;
628
        }
629
      });
630

  
631
      $('#multi_items_filter_all_substr_multi_ilike').focus();
632
      $('#multi_items_filter_button').click(function(){ self.update_results() });
633
      $('#multi_items_filter_reset').click(function(){ $("#multi_items_form").resetForm() });
634
      $('#continue_button').click(function(){ self.add_multi_items() });
635
    },
636
    update_results: function() {
637
      var self = this;
638
      var data = $('#multi_items_form').serializeArray();
639
      data.push({ name: 'type', value: self.pp.type });
640
      $.ajax({
641
        url: 'controller.pl?action=Part/multi_items_update_result',
642
        data: data,
643
        method: 'post',
644
        success: function(data){
645
          $('#multi_items_result').html(data);
646
          self.init_results();
647
          self.enable_continue();
648
        }
649
      });
650
    },
651
    set_qty_to_one: function(clicked) {
652
      if ($(clicked).val() === '') {
653
        $(clicked).val(kivi.format_amount(1.00, -2));
654
      }
655
      $(clicked).select();
656
    },
657
    init_results: function() {
658
      var self = this;
659
      $('#multi_items_all_qty').change(function(event){
660
        $('.multi_items_qty').val($(event.target).val());
661
      });
662
      $('.multi_items_qty').click(function(){ self.set_qty_to_one(this) });
663
    },
664
    result_timer: function(event) {
665
    },
666
    close_dialog: function() {
667
      $('#jq_multi_items_dialog').dialog('close');
668
    },
669
    disable_continue: function() {
670
      $('#multi_items_result input').off("keydown");
671
      $('#continue_button').prop('disabled', true);
672
    },
673
    enable_continue: function() {
674
      var self = this;
675
      $('#multi_items_result input').keydown(function(event) {
676
        if(event.keyCode == KEY.ENTER) {
677
          event.preventDefault();
678
          self.add_multi_items();
679
          return false;
680
        }
681
      });
682
      $('#continue_button').prop('disabled', false);
683
    },
684
    add_multi_items: function() {
685
      // rows at all
686
      var n_rows = $('.multi_items_qty').length;
687
      if ( n_rows === 0) { return; }
688

  
689
      // filled rows
690
      n_rows = $('.multi_items_qty').filter(function() {
691
        return $(this).val().length > 0;
692
      }).length;
693
      if (n_rows === 0) { return; }
694

  
695
      this.disable_continue();
696

  
697
      var data = $('#multi_items_form').serializeArray();
698
      this.pp.set_multi_items(data);
699
    }
700
  };
701

  
588 702
  ns.reinit_widgets = function() {
589 703
    kivi.run_once_for('input.part_autocomplete', 'part_picker', function(elt) {
590 704
      if (!$(elt).data('part_picker'))
......
597 711
  }
598 712

  
599 713
  $(function(){
600

  
601
    // assortment
602
    // TODO: allow units for assortment items
603
    $('#add_assortment_item_id').on('set_item:PartPicker', function(e,o) { $('#add_item_unit').val(o.unit) });
604

  
605 714
    $('#ic').on('focusout', '.reformat_number', function(event) {
606 715
       ns.reformat_number(event);
607
    })
608

  
609
    $('.add_assortment_item_input').keydown(function(event) {
610
      if(event.keyCode == 13) {
611
        event.preventDefault();
612
        if ($("input[name='add_items[+].parts_id']").val() !== '' ) {
613
          kivi.Part.show_multi_items_dialog("assortment");
614
         // ns.add_assortment_item();
615
        }
616
        return false;
617
      }
618
    });
619

  
620
    $('.add_assembly_item_input').keydown(function(event) {
621
      if(event.keyCode == 13) {
622
        event.preventDefault();
623
        if ($("input[name='add_items[+].parts_id']").val() !== '' ) {
624
          kivi.Part.show_multi_items_dialog("assortment");
625
          // ns.add_assembly_item();
626
        }
627
        return false;
628
      }
629 716
    });
630 717

  
631 718
    $('.add_makemodel_input').keydown(function(event) {

Auch abrufbar als: Unified diff