Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 65690235

Von Moritz Bunkus vor fast 10 Jahren hinzugefügt

  • ID 656902356dbfe87a8f1992c0119be3912cc59eed
  • Vorgänger 83b3c64e
  • Nachfolger a7177e63

CustomerVendor: CVars bei Wechsel von Ansprechpersonen richtig befüllen

Unterschiede anzeigen:

SL/Controller/CustomerVendor.pm
543 543
  };
544 544

  
545 545
  $data->{contact_cvars} = {
546
    map(
547
      {
548
        if ( $_->config->type eq 'number' ) {
549
          $_->config->name => $::form->format_amount(\%::myconfig, $_->value, -2);
550
        } else {
551
          $_->config->name => $_->value;
552
        }
546
    map {
547
      my $cvar   = $_;
548
      my $result = { type => $cvar->config->type };
549

  
550
      if ($cvar->config->type eq 'number') {
551
        $result->{value} = $::form->format_amount(\%::myconfig, $cvar->value, -2);
552

  
553
      } elsif ($result->{type} =~ m{customer|vendor|part}) {
554
        my $object       = $cvar->value;
555
        my $method       = $result->{type} eq 'part' ? 'description' : 'name';
556

  
557
        $result->{id}    = int($cvar->number_value) || undef;
558
        $result->{value} = $object ? $object->$method // '' : '';
559

  
560
      } else {
561
        $result->{value} = $cvar->value;
553 562
      }
554
      grep(
555
        { $_->is_valid; }
556
        @{$self->{contact}->cvars_by_config}
557
      )
558
    )
563

  
564
      ( $cvar->config->name => $result )
565

  
566
    } grep { $_->is_valid } @{ $self->{contact}->cvars_by_config }
559 567
  };
560 568

  
561 569
  $self->render(\SL::JSON::to_json($data), { type => 'json', process => 0 });
js/kivi.CustomerVendor.js
41 41
    }
42 42
  };
43 43

  
44
  this.setCustomVariablesFromAJAJ = function(cvars) {
45
    for (var key in cvars) {
46
      var cvar  = cvars[key];
47
      var $ctrl = $('#contact_cvars_'+ key);
48

  
49
      console.log($ctrl, cvar);
50

  
51
      if (cvar.type == 'bool')
52
        $ctrl.prop('checked', cvar.value == 1 ? 'checked' : '');
53

  
54
      else if ((cvar.type == 'customer') || (cvar.type == 'vendor'))
55
        kivi.CustomerVendorPicker($ctrl).set_item({ id: cvar.id, name: cvar.value });
56

  
57
      else if (cvar.type == 'part')
58
        kivi.PartPicker($ctrl).set_item({ id: cvar.id, name: cvar.value });
59

  
60
      else
61
        $ctrl.val(cvar.value);
62
    }
63
  };
64

  
44 65
  this.selectContact = function(params) {
45 66
    var contactId = $('#contact_cp_id').val();
46 67

  
......
51 72
      for(var key in contact)
52 73
        $(document.getElementById('contact_'+ key)).val(contact[key])
53 74

  
54
      var cvars = data.contact_cvars;
55
      for(var key in cvars)
56
        $(document.getElementById('contact_cvars_'+ key)).val(cvars[key]);
75
      kivi.CustomerVendor.setCustomVariablesFromAJAJ(data.contact_cvars);
57 76

  
58 77
      if ( contactId )
59 78
        $('#action_delete_contact').show();

Auch abrufbar als: Unified diff