salix/modules/zone/front/descriptor/index.js

50 lines
1.4 KiB
JavaScript
Raw Normal View History

2018-12-04 12:18:27 +00:00
import ngModule from '../module';
2020-04-25 09:50:04 +00:00
import Descriptor from 'salix/components/descriptor';
2018-12-04 12:18:27 +00:00
2020-04-25 09:50:04 +00:00
class Controller extends Descriptor {
get zone() {
return this.entity;
2018-12-04 12:18:27 +00:00
}
set zone(value) {
this.entity = value;
}
2020-06-02 06:59:04 +00:00
onDelete() {
const $t = this.$translate.instant;
const today = new Date();
today.setHours(0, 0, 0, 0);
const filter = {where: {zoneFk: this.id, shipped: {gte: today}}};
this.$http.get(`Tickets`, {filter}).then(res => {
const ticketsAmount = res.data.length;
if (ticketsAmount) {
const params = {ticketsAmount};
const question = $t('This zone contains tickets', params, null, null, 'sanitizeParameters');
this.$.deleteZone.question = question;
this.$.deleteZone.show();
} else
this.deleteZone();
});
}
deleteZone() {
return this.$http.post(`Zones/${this.id}/deleteZone`).then(() => {
this.$state.go('zone.index');
this.vnApp.showSuccess(this.$t('Zone deleted'));
});
}
2020-06-17 09:51:57 +00:00
2020-06-02 06:59:04 +00:00
onCloneAccept() {
return this.$http.post(`Zones/${this.id}/clone`).
then(res => this.$state.go('zone.card.basicData', {id: res.data.id}));
}
2018-12-04 12:18:27 +00:00
}
2020-04-25 09:50:04 +00:00
ngModule.vnComponent('vnZoneDescriptor', {
2018-12-04 12:18:27 +00:00
template: require('./index.html'),
controller: Controller,
bindings: {
zone: '<'
}
});