2018-12-04 12:18:27 +00:00
|
|
|
import ngModule from '../module';
|
2019-06-26 11:35:38 +00:00
|
|
|
import './style.scss';
|
2018-09-24 12:51:27 +00:00
|
|
|
|
|
|
|
class Controller {
|
2019-06-26 11:35:38 +00:00
|
|
|
constructor($element, $scope, $http, $filter, $translate, $stateParams, vnApp) {
|
2019-02-01 16:11:14 +00:00
|
|
|
this.$element = $element;
|
2019-06-26 11:35:38 +00:00
|
|
|
this.$ = $scope;
|
2019-01-21 10:45:53 +00:00
|
|
|
this.$http = $http;
|
2019-06-26 11:35:38 +00:00
|
|
|
this.$filter = $filter;
|
|
|
|
this.$translate = $translate;
|
|
|
|
this.$stateParams = $stateParams;
|
|
|
|
this.vnApp = vnApp;
|
2019-01-21 10:45:53 +00:00
|
|
|
this.stMonthDate = new Date();
|
|
|
|
this.ndMonthDate = new Date();
|
|
|
|
this.ndMonthDate.setMonth(this.ndMonthDate.getMonth() + 1);
|
2019-06-26 11:35:38 +00:00
|
|
|
this.selectedDay = {};
|
2018-11-12 10:31:58 +00:00
|
|
|
}
|
|
|
|
|
2019-01-21 10:45:53 +00:00
|
|
|
$postLink() {
|
2019-06-26 11:35:38 +00:00
|
|
|
this.stMonth = this.$.stMonth;
|
|
|
|
this.ndMonth = this.$.ndMonth;
|
2019-01-21 10:45:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get data() {
|
|
|
|
return this._data;
|
|
|
|
}
|
|
|
|
|
|
|
|
set data(value) {
|
|
|
|
this._data = value;
|
|
|
|
|
|
|
|
if (!value) return;
|
2019-06-26 11:35:38 +00:00
|
|
|
|
2019-01-21 10:45:53 +00:00
|
|
|
const events = [];
|
|
|
|
value.forEach(event => {
|
|
|
|
events.push({
|
2019-06-26 11:35:38 +00:00
|
|
|
name: `P: ${this.$filter('currency')(event.price)}`,
|
|
|
|
description: 'Price',
|
2019-04-03 09:34:58 +00:00
|
|
|
dated: event.delivered,
|
2019-06-26 11:35:38 +00:00
|
|
|
style: {backgroundColor: '#a3d131'},
|
|
|
|
data: {price: event.price}
|
2019-01-21 10:45:53 +00:00
|
|
|
});
|
2019-06-26 11:35:38 +00:00
|
|
|
events.push({
|
|
|
|
name: `B: ${this.$filter('currency')(event.bonus)}`,
|
|
|
|
description: 'Bonus',
|
|
|
|
dated: event.delivered,
|
|
|
|
data: {bonus: event.bonus}
|
2019-01-21 10:45:53 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-06-26 11:35:38 +00:00
|
|
|
this.events = events;
|
2019-01-21 10:45:53 +00:00
|
|
|
}
|
|
|
|
|
2019-06-26 11:35:38 +00:00
|
|
|
onSelection(values) {
|
|
|
|
if (values.length > 1) return false;
|
2019-01-21 10:45:53 +00:00
|
|
|
|
2019-06-26 11:35:38 +00:00
|
|
|
this.options = [
|
|
|
|
{label: 'Only this day', value: 'Only this day'},
|
|
|
|
{label: 'From this day', value: 'From this day'},
|
|
|
|
{label: 'All days', value: 'All days'}
|
|
|
|
];
|
|
|
|
const selection = values[0];
|
|
|
|
const events = selection.events;
|
|
|
|
const hasEvents = events.length > 0;
|
2019-01-21 10:45:53 +00:00
|
|
|
|
2019-06-26 11:35:38 +00:00
|
|
|
if (!hasEvents)
|
|
|
|
return this.vnApp.showMessage(this.$translate.instant(`There's no delivery for this day`));
|
2019-04-03 09:34:58 +00:00
|
|
|
|
2019-06-26 11:35:38 +00:00
|
|
|
this.selectedDay = {
|
|
|
|
delivered: selection.dated,
|
|
|
|
option: 'Only this day'
|
|
|
|
};
|
2019-01-21 10:45:53 +00:00
|
|
|
|
2019-06-26 11:35:38 +00:00
|
|
|
events.forEach(event => {
|
|
|
|
this.selectedDay = Object.assign(this.selectedDay, event.data);
|
2019-01-21 10:45:53 +00:00
|
|
|
});
|
2019-06-26 11:35:38 +00:00
|
|
|
this.$.priceDialog.show();
|
2019-01-21 10:45:53 +00:00
|
|
|
}
|
|
|
|
|
2019-06-26 11:35:38 +00:00
|
|
|
onResponse(response) {
|
|
|
|
if (response == 'ACCEPT') {
|
|
|
|
try {
|
|
|
|
const data = {
|
|
|
|
delivered: this.selectedDay.delivered,
|
|
|
|
price: this.selectedDay.price,
|
|
|
|
bonus: this.selectedDay.bonus,
|
|
|
|
option: this.selectedDay.option
|
|
|
|
};
|
|
|
|
|
|
|
|
this.$.watcher.check();
|
|
|
|
|
|
|
|
const path = `/api/Zones/${this.zone.id}/editPrices`;
|
|
|
|
this.$http.post(path, data).then(() => {
|
|
|
|
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
|
|
|
|
this.$.model.refresh();
|
|
|
|
this.card.reload();
|
|
|
|
});
|
|
|
|
} catch (e) {
|
|
|
|
this.vnApp.showError(this.$translate.instant(e.message));
|
2019-01-21 10:45:53 +00:00
|
|
|
return false;
|
2019-06-26 11:35:38 +00:00
|
|
|
}
|
|
|
|
}
|
2019-01-21 10:45:53 +00:00
|
|
|
|
2019-06-26 11:35:38 +00:00
|
|
|
return this.onClose();
|
|
|
|
}
|
2019-01-21 10:45:53 +00:00
|
|
|
|
2019-06-26 11:35:38 +00:00
|
|
|
onClose() {
|
|
|
|
this.$.watcher.updateOriginalData();
|
2019-01-21 10:45:53 +00:00
|
|
|
}
|
|
|
|
|
2019-06-26 11:35:38 +00:00
|
|
|
onMoveNext(calendars) {
|
|
|
|
calendars.forEach(calendar => {
|
|
|
|
calendar.moveNext(2);
|
|
|
|
});
|
2019-01-21 10:45:53 +00:00
|
|
|
}
|
|
|
|
|
2019-06-26 11:35:38 +00:00
|
|
|
onMovePrevious(calendars) {
|
|
|
|
calendars.forEach(calendar => {
|
|
|
|
calendar.movePrevious(2);
|
|
|
|
});
|
2018-09-24 12:51:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-26 11:35:38 +00:00
|
|
|
Controller.$inject = ['$element', '$scope', '$http', '$filter', '$translate', '$stateParams', 'vnApp'];
|
2018-09-24 12:51:27 +00:00
|
|
|
|
|
|
|
ngModule.component('vnZoneCalendar', {
|
|
|
|
template: require('./index.html'),
|
|
|
|
controller: Controller,
|
|
|
|
bindings: {
|
|
|
|
zone: '<'
|
2019-06-26 11:35:38 +00:00
|
|
|
},
|
|
|
|
require: {
|
|
|
|
card: '^vnZoneCard'
|
2018-09-24 12:51:27 +00:00
|
|
|
}
|
|
|
|
});
|