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 {
|
2020-04-30 10:48:52 +00:00
|
|
|
get zone() {
|
|
|
|
return this.entity;
|
2018-12-04 12:18:27 +00:00
|
|
|
}
|
2018-12-04 13:38:56 +00:00
|
|
|
|
2020-04-30 10:48:52 +00:00
|
|
|
set zone(value) {
|
|
|
|
this.entity = value;
|
2018-12-04 13:38:56 +00:00
|
|
|
}
|
|
|
|
|
2020-07-30 10:51:19 +00:00
|
|
|
loadData() {
|
|
|
|
const filter = {
|
|
|
|
include: [
|
|
|
|
{
|
|
|
|
relation: 'agencyMode',
|
|
|
|
scope: {
|
|
|
|
fields: ['name'],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
|
|
|
return this.getData(`Zones/${this.id}`, {filter})
|
|
|
|
.then(res => this.entity = res.data);
|
|
|
|
}
|
|
|
|
|
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 13:38:56 +00:00
|
|
|
}
|
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: '<'
|
|
|
|
}
|
|
|
|
});
|