Change address when client is selected on ticket basic data

This commit is contained in:
Joan Sanchez 2018-05-17 08:44:34 +02:00
parent 7aa2d04d00
commit 026a5b7dea
2 changed files with 19 additions and 7 deletions

View File

@ -3,20 +3,21 @@
<vn-title>Basic data</vn-title>
<vn-horizontal>
<vn-autocomplete vn-one
vn-id="client"
url="/api/Clients"
label="Client"
show-field="name"
value-field="id"
field="$ctrl.ticket.clientFk"
initial-data="$ctrl.ticket.clientFk">
initial-data="$ctrl.ticket.clientFk"
on-change="$ctrl.onChange()">
</vn-autocomplete>
<vn-autocomplete vn-one
url="/api/Addresses"
url="{{$ctrl.getAddresses()}}"
label="Address"
show-field="nickname"
value-field="id"
field="$ctrl.ticket.addressFk"
initial-data="$ctrl.ticket.addressFk">
value-field="id"
field="$ctrl.ticket.addressFk">
</vn-autocomplete>
<vn-autocomplete vn-one
url="/api/AgencyModes"

View File

@ -1,9 +1,10 @@
import ngModule from '../../module';
class Controller {
constructor($scope, $http, $translate, vnApp) {
constructor($scope, $http, $element, $translate, vnApp) {
this.$scope = $scope;
this.$http = $http;
this.$element = $element;
this.$translate = $translate;
this.vnApp = vnApp;
}
@ -12,6 +13,16 @@ class Controller {
this.data.registerChild(this);
}
onChange() {
if(this.ticket)
this.ticket.addressFk = null;
}
getAddresses() {
if (this.ticket)
return `/api/Clients/${this.ticket.clientFk}/addresses`;
}
async onStepChange(state) {
if (this.isFormInvalid())
return this.vnApp.showError(
@ -44,7 +55,7 @@ class Controller {
}
}
Controller.$inject = ['$scope', '$http', '$translate', 'vnApp'];
Controller.$inject = ['$scope', '$http', '$element', '$translate', 'vnApp'];
ngModule.component('vnTicketDataStepOne', {
template: require('./step-one.html'),