import ngModule from '../../module'; class Controller { constructor($scope, $state, vnApp, $translate, $http) { this.$http = $http; this.$ = $scope; this.$state = $state; this.vnApp = vnApp; this.$translate = $translate; this.ticket = { ticketFk: $state.params.id }; this.params = {ticketFk: $state.params.id}; } $onInit() { this.getPickerDesignedState(); } set stateFk(value) { this.params.stateFk = value; this.isPickerDesignedState = this.getIsPickerDesignedState(value); this.workerFk = window.localStorage.currentUserWorkerId; } get stateFk() { return this.params.stateFk; } set workerFk(value) { this.params.workerFk = value; } get workerFk() { return this.params.workerFk; } getPickerDesignedState() { let filter = { where: { code: 'PICKER_DESIGNED' } }; let json = encodeURIComponent(JSON.stringify(filter)); this.$http.get(`States?filter=${json}`).then(res => { if (res && res.data) this.pickerDesignedState = res.data[0].id; }); } getIsPickerDesignedState(value) { if (value == this.pickerDesignedState) return true; return false; } onSubmit() { this.$http.post(`TicketTrackings/changeState`, this.params).then(() => { this.$.watcher.updateOriginalData(); this.card.reload(); this.vnApp.showSuccess(this.$translate.instant('Data saved!')); this.$state.go('ticket.card.tracking.index'); }); } } Controller.$inject = ['$scope', '$state', 'vnApp', '$translate', '$http']; ngModule.component('vnTicketTrackingEdit', { template: require('./index.html'), controller: Controller, require: { card: '^vnTicketCard' } });