salix/modules/ticket/front/data/step-three/index.js

66 lines
1.7 KiB
JavaScript

import ngModule from '../../module';
class Controller {
constructor($http, $scope, $state, $translate, vnApp) {
this.$http = $http;
this.$scope = $scope;
this.$state = $state;
this.$translate = $translate;
this.vnApp = vnApp;
}
$onInit() {
this.data.registerChild(this);
}
$onChanges() {
this.ticket.option = 1;
this.ticket.hasToBeUnrouted = true;
}
onStepChange(state) {
return true;
}
onSubmit() {
if (!this.ticket.option)
return this.vnApp.showError(
this.$translate.instant('Choose an option')
);
let query = `/ticket/api/tickets/${this.ticket.id}/componentUpdate`;
let data = {
clientFk: this.ticket.clientFk,
agencyModeFk: this.ticket.agencyModeFk,
addressFk: this.ticket.addressFk,
warehouseFk: this.ticket.warehouseFk,
shipped: this.ticket.shipped,
landed: this.ticket.landed,
isDeleted: this.ticket.isDeleted,
hasToBeUnrouted: this.ticket.hasToBeUnrouted,
option: this.ticket.option
};
this.$http.post(query, data).then(res => {
if (res.data) {
this.$state.go('ticket.card.summary', {id: this.$state.params.id});
this.card.reload();
}
});
}
}
Controller.$inject = ['$http', '$scope', '$state', '$translate', 'vnApp'];
ngModule.component('vnTicketDataStepThree', {
template: require('./index.html'),
controller: Controller,
bindings: {
ticket: '<'
},
require: {
card: '^vnTicketCard',
data: '^vnTicketData'
}
});