From 656902356dbfe87a8f1992c0119be3912cc59eed Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Tue, 25 Nov 2014 16:45:45 +0100 Subject: [PATCH] =?utf8?q?CustomerVendor:=20CVars=20bei=20Wechsel=20von=20?= =?utf8?q?Ansprechpersonen=20richtig=20bef=C3=BCllen?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/Controller/CustomerVendor.pm | 32 ++++++++++++++++++++------------ js/kivi.CustomerVendor.js | 25 ++++++++++++++++++++++--- 2 files changed, 42 insertions(+), 15 deletions(-) diff --git a/SL/Controller/CustomerVendor.pm b/SL/Controller/CustomerVendor.pm index 468e02618..60b26bb93 100644 --- a/SL/Controller/CustomerVendor.pm +++ b/SL/Controller/CustomerVendor.pm @@ -543,19 +543,27 @@ sub action_ajaj_get_contact { }; $data->{contact_cvars} = { - map( - { - if ( $_->config->type eq 'number' ) { - $_->config->name => $::form->format_amount(\%::myconfig, $_->value, -2); - } else { - $_->config->name => $_->value; - } + map { + my $cvar = $_; + my $result = { type => $cvar->config->type }; + + if ($cvar->config->type eq 'number') { + $result->{value} = $::form->format_amount(\%::myconfig, $cvar->value, -2); + + } elsif ($result->{type} =~ m{customer|vendor|part}) { + my $object = $cvar->value; + my $method = $result->{type} eq 'part' ? 'description' : 'name'; + + $result->{id} = int($cvar->number_value) || undef; + $result->{value} = $object ? $object->$method // '' : ''; + + } else { + $result->{value} = $cvar->value; } - grep( - { $_->is_valid; } - @{$self->{contact}->cvars_by_config} - ) - ) + + ( $cvar->config->name => $result ) + + } grep { $_->is_valid } @{ $self->{contact}->cvars_by_config } }; $self->render(\SL::JSON::to_json($data), { type => 'json', process => 0 }); diff --git a/js/kivi.CustomerVendor.js b/js/kivi.CustomerVendor.js index 1cb08db49..67820bea5 100644 --- a/js/kivi.CustomerVendor.js +++ b/js/kivi.CustomerVendor.js @@ -41,6 +41,27 @@ namespace('kivi.CustomerVendor', function(ns) { } }; + this.setCustomVariablesFromAJAJ = function(cvars) { + for (var key in cvars) { + var cvar = cvars[key]; + var $ctrl = $('#contact_cvars_'+ key); + + console.log($ctrl, cvar); + + if (cvar.type == 'bool') + $ctrl.prop('checked', cvar.value == 1 ? 'checked' : ''); + + else if ((cvar.type == 'customer') || (cvar.type == 'vendor')) + kivi.CustomerVendorPicker($ctrl).set_item({ id: cvar.id, name: cvar.value }); + + else if (cvar.type == 'part') + kivi.PartPicker($ctrl).set_item({ id: cvar.id, name: cvar.value }); + + else + $ctrl.val(cvar.value); + } + }; + this.selectContact = function(params) { var contactId = $('#contact_cp_id').val(); @@ -51,9 +72,7 @@ namespace('kivi.CustomerVendor', function(ns) { for(var key in contact) $(document.getElementById('contact_'+ key)).val(contact[key]) - var cvars = data.contact_cvars; - for(var key in cvars) - $(document.getElementById('contact_cvars_'+ key)).val(cvars[key]); + kivi.CustomerVendor.setCustomVariablesFromAJAJ(data.contact_cvars); if ( contactId ) $('#action_delete_contact').show(); -- 2.20.1