Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision b1e0bbb0

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

  • ID b1e0bbb0ad6bb18a301e4c811ee2ac5de84ec387
  • Vorgänger fc876a1d
  • Nachfolger da09f329

kivi.Part.js: Part Picker Popup in ein separates widget verschoben

Unterschiede anzeigen:

js/kivi.Part.js
314 314
    var last_dummy = $dummy.val();
315 315
    var timer;
316 316

  
317
    function open_dialog () {
318
      kivi.popup_dialog({
319
        url: 'controller.pl?action=Part/part_picker_search',
320
        data: $.extend({
321
          real_id: real_id,
322
        }, ajax_data($dummy.val())),
323
        id: 'part_selection',
324
        dialog: {
325
          title: kivi.t8('Part picker'),
326
          width: 800,
327
          height: 800,
328
        }
329
      });
330
      window.clearTimeout(timer);
331
      return true;
332
    }
333

  
334 317
    function ajax_data(term) {
335 318
      var data = {
336 319
        'filter.all:substr:multi::ilike': term,
......
402 385
      }
403 386
    }
404 387

  
405
    function update_results () {
406
      $.ajax({
407
        url: 'controller.pl?action=Part/part_picker_result',
408
        data: $.extend({
409
            'real_id': $real.val(),
410
        }, ajax_data(function(){ var val = $('#part_picker_filter').val(); return val === undefined ? '' : val })),
411
        success: function(data){ $('#part_picker_result').html(data) }
412
      });
413
    }
414

  
415
    function result_timer (event) {
416
      if (!$('no_paginate').prop('checked')) {
417
        if (event.keyCode == KEY.PAGE_UP) {
418
          $('#part_picker_result a.paginate-prev').click();
419
          return;
420
        }
421
        if (event.keyCode == KEY.PAGE_DOWN) {
422
          $('#part_picker_result a.paginate-next').click();
423
          return;
424
        }
425
      }
426
      window.clearTimeout(timer);
427
      timer = window.setTimeout(update_results, 100);
428
    }
429

  
430
    function close_popup() {
431
      $('#part_selection').dialog('close');
432
    }
433

  
434 388
    function handle_changed_text(callbacks) {
435 389
      $.ajax({
436 390
        url: 'controller.pl?action=Part/ajax_autocomplete',
......
452 406
      });
453 407
    }
454 408

  
409
    function open_dialog() {
410
      // TODO: take the actual object here
411
      var dialog = new ns.PickerPopup({
412
        ajax_data: ajax_data,
413
        real_id: real_id,
414
        dummy: $dummy,
415
        real: $real,
416
        set_item: set_item
417
      });
418
    }
419

  
455 420
    $dummy.autocomplete({
456 421
      source: function(req, rsp) {
457 422
        $.ajax($.extend(o, {
......
540 505
      classification_id: function() { return $classification_id },
541 506
      unit:              function() { return $unit },
542 507
      convertible_unit:  function() { return $convertible_unit },
543
      update_results: update_results,
544
      result_timer:   result_timer,
545 508
      set_item:       set_item,
546 509
      reset:          make_defined_state,
547 510
      is_defined_state: function() { return state == STATES.PICKED },
548
      init_results:    function () {
549
        $('div.part_picker_part').each(function(){
550
          $(this).click(function(){
551
            set_item({
552
              id:   $(this).children('input.part_picker_id').val(),
553
              name: $(this).children('input.part_picker_description').val(),
554
              classification_id: $(this).children('input.part_picker_classification_id').val(),
555
              unit: $(this).children('input.part_picker_unit').val(),
556
              partnumber:  $(this).children('input.part_picker_partnumber').val(),
557
              description: $(this).children('input.part_picker_description').val(),
558
            });
559
            close_popup();
560
            $dummy.focus();
561
            return true;
562
          });
563
        });
564
        $('#part_selection').keydown(function(e){
565
           if (e.which == KEY.ESCAPE) {
566
             close_popup();
567
             $dummy.focus();
568
           }
569
        });
570
      }
571 511
    }
572 512
    $real.data('part_picker', pp);
573 513
    return pp;
574 514
  };
575 515

  
516
  ns.PickerPopup = function(pp) {
517
    this.timer = undefined;
518
    this.pp    = pp;
519

  
520
    this.open_dialog = function() {
521
      var self = this;
522
      kivi.popup_dialog({
523
        url: 'controller.pl?action=Part/part_picker_search',
524
        data: $.extend({
525
          real_id: self.pp.real_id,
526
        }, self.pp.ajax_data(this.pp.dummy.val())),
527
        id: 'part_selection',
528
        dialog: {
529
          title: kivi.t8('Part picker'),
530
          width: 800,
531
          height: 800,
532
        },
533
        load: function() { self.init_search(); }
534
      });
535
      window.clearTimeout(this.timer);
536
      return true;
537
    };
538

  
539
    this.init_search = function() {
540
      var self = this;
541
      $('#part_picker_filter').keypress(function(e) { self.result_timer(e) }).focus();
542
      $('#no_paginate').change(function() { self.update_results() });
543
      this.update_results();
544
    }
545

  
546
    this.update_results = function() {
547
      var self = this;
548
      $.ajax({
549
        url: 'controller.pl?action=Part/part_picker_result',
550
        data: $.extend({
551
         'real_id': self.pp.real.val(),
552
        }, self.pp.ajax_data(function(){
553
          var val = $('#part_picker_filter').val();
554
          return val === undefined ? '' : val
555
        })),
556
        success: function(data){
557
          $('#part_picker_result').html(data);
558
          self.init_results();
559
        }
560
      });
561
    };
562

  
563
    this.init_results = function() {
564
      var self = this;
565
      $('div.part_picker_part').each(function(){
566
        $(this).click(function(){
567
          self.pp.set_item({
568
            id:   $(this).children('input.part_picker_id').val(),
569
            name: $(this).children('input.part_picker_description').val(),
570
            classification_id: $(this).children('input.part_picker_classification_id').val(),
571
            unit: $(this).children('input.part_picker_unit').val(),
572
            partnumber:  $(this).children('input.part_picker_partnumber').val(),
573
            description: $(this).children('input.part_picker_description').val(),
574
          });
575
          self.close_popup();
576
          self.pp.dummy.focus();
577
          return true;
578
        });
579
      });
580
      $('#part_selection').keydown(function(e){
581
         if (e.which == KEY.ESCAPE) {
582
           self.close_popup();
583
           self.pp.dummy.focus();
584
         }
585
      });
586
    }
587

  
588
    this.result_timer = function(event) {
589
      var self = this;
590
      if (!$('no_paginate').prop('checked')) {
591
        if (event.keyCode == KEY.PAGE_UP) {
592
          $('#part_picker_result a.paginate-prev').click();
593
          return;
594
        }
595
        if (event.keyCode == KEY.PAGE_DOWN) {
596
          $('#part_picker_result a.paginate-next').click();
597
          return;
598
        }
599
      }
600
      window.clearTimeout(this.timer);
601
      this.timer = window.setTimeout(function() { self.update_results() }, 100);
602
    };
603

  
604
    this.close_popup = function() {
605
      $('#part_selection').dialog('close');
606
    };
607

  
608
    this.open_dialog();
609
  }
610

  
576 611
  ns.reinit_widgets = function() {
577 612
    kivi.run_once_for('input.part_autocomplete', 'part_picker', function(elt) {
578 613
      kivi.Part.Picker($(elt));
templates/webpages/part/_part_picker_result.html
28 28
<div style='clear:both'></div>
29 29

  
30 30
[% L.paginate_controls(target='#part_picker_result', selector='#part_picker_result', models=SELF.models) %]
31

  
32
<script type='text/javascript'>
33
  kivi.Part.Picker($('#'+$('#part_picker_real_id').val())).init_results()
34
</script>
templates/webpages/part/part_picker_search.html
15 15
<div style='clear:both'></div>
16 16
<div id='part_picker_result'></div>
17 17
</div>
18

  
19
<script type='text/javascript'>
20
  var pp = kivi.Part.Picker($('#[% FORM.real_id %]'));
21
  $(function(){
22
    $('#part_picker_filter').focus();
23
    pp.update_results();
24
  });
25
  $('#part_picker_filter').keypress(pp.result_timer);
26
  $('#no_paginate').change(pp.update_results);
27

  
28
</script>

Auch abrufbar als: Unified diff