2018-12-04 12:18:27 +00:00
|
|
|
import ngModule from '../module';
|
2019-10-01 11:45:43 +00:00
|
|
|
import Section from 'core/lib/section';
|
2019-06-26 11:35:38 +00:00
|
|
|
import './style.scss';
|
2018-09-24 12:51:27 +00:00
|
|
|
|
2019-10-01 11:45:43 +00:00
|
|
|
class Controller extends Section {
|
|
|
|
constructor($el, $, $t, $http, $state) {
|
|
|
|
super($el, $, $t, $http, $state);
|
2019-09-25 18:06:42 +00:00
|
|
|
|
|
|
|
this.excls = {};
|
|
|
|
this.resetEvents();
|
2019-01-21 10:45:53 +00:00
|
|
|
this.ndMonthDate = new Date();
|
|
|
|
this.ndMonthDate.setMonth(this.ndMonthDate.getMonth() + 1);
|
2018-11-12 10:31:58 +00:00
|
|
|
}
|
|
|
|
|
2019-10-01 11:45:43 +00:00
|
|
|
onSelection($days, $type, $weekday) {
|
|
|
|
this.emit('selection', {$days, $type, $weekday});
|
|
|
|
}
|
|
|
|
|
2019-09-25 18:06:42 +00:00
|
|
|
resetEvents() {
|
|
|
|
this.wdays = [];
|
|
|
|
this.days = {};
|
|
|
|
this.ranges = [];
|
2019-01-21 10:45:53 +00:00
|
|
|
}
|
|
|
|
|
2019-09-25 18:06:42 +00:00
|
|
|
get events() {
|
|
|
|
return this._events;
|
2019-01-21 10:45:53 +00:00
|
|
|
}
|
|
|
|
|
2019-09-25 18:06:42 +00:00
|
|
|
set events(value) {
|
|
|
|
this._events = value;
|
|
|
|
this.resetEvents();
|
2019-01-21 10:45:53 +00:00
|
|
|
if (!value) return;
|
2019-06-26 11:35:38 +00:00
|
|
|
|
2019-09-25 18:06:42 +00:00
|
|
|
function setWdays(wdays, weekDays) {
|
|
|
|
let codes = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'];
|
|
|
|
if (!weekDays) return [];
|
|
|
|
weekDays = weekDays.split(',');
|
|
|
|
for (let wday of weekDays)
|
|
|
|
wdays[codes.indexOf(wday)] = true;
|
|
|
|
return wdays;
|
|
|
|
}
|
2019-01-21 10:45:53 +00:00
|
|
|
|
2019-09-25 18:06:42 +00:00
|
|
|
for (let event of value) {
|
|
|
|
if (event.from && event.to) {
|
|
|
|
this.ranges.push({
|
|
|
|
from: new Date(event.from).setHours(0, 0, 0, 0),
|
|
|
|
to: new Date(event.to).setHours(0, 0, 0, 0),
|
|
|
|
wdays: setWdays([], event.weekDays)
|
|
|
|
});
|
|
|
|
} else if (event.from) {
|
|
|
|
let day = new Date(event.from).setHours(0, 0, 0, 0);
|
|
|
|
this.days[day] = true;
|
|
|
|
} else
|
|
|
|
setWdays(this.wdays, event.weekDays);
|
|
|
|
}
|
2019-01-21 10:45:53 +00:00
|
|
|
|
2019-09-25 18:06:42 +00:00
|
|
|
this.repaint();
|
|
|
|
}
|
2019-01-21 10:45:53 +00:00
|
|
|
|
2019-09-25 18:06:42 +00:00
|
|
|
get exclusions() {
|
|
|
|
return this._exclusions;
|
|
|
|
}
|
2019-04-03 09:34:58 +00:00
|
|
|
|
2019-09-25 18:06:42 +00:00
|
|
|
set exclusions(value) {
|
|
|
|
this._exclusions = value;
|
|
|
|
this.excls = {};
|
|
|
|
if (!value) return;
|
2019-01-21 10:45:53 +00:00
|
|
|
|
2019-09-25 18:06:42 +00:00
|
|
|
value.forEach(exclusion => {
|
|
|
|
let day = new Date(exclusion.day).setHours(0, 0, 0, 0);
|
|
|
|
this.excls[day] = true;
|
2019-01-21 10:45:53 +00:00
|
|
|
});
|
|
|
|
|
2019-09-25 18:06:42 +00:00
|
|
|
this.repaint();
|
|
|
|
}
|
2019-01-21 10:45:53 +00:00
|
|
|
|
2019-09-25 18:06:42 +00:00
|
|
|
hasRange(time, wday) {
|
|
|
|
let range = this.ranges.find(e => e.from <= time && e.to >= time);
|
|
|
|
return range && range.wdays[wday];
|
2019-06-26 11:35:38 +00:00
|
|
|
}
|
2019-01-21 10:45:53 +00:00
|
|
|
|
2019-09-25 18:06:42 +00:00
|
|
|
hasEvents(day) {
|
|
|
|
let time = day.getTime();
|
|
|
|
let wday = day.getDay();
|
|
|
|
return this.wdays[wday]
|
|
|
|
|| this.days[time]
|
|
|
|
|| this.hasRange(time, wday);
|
2019-01-21 10:45:53 +00:00
|
|
|
}
|
|
|
|
|
2019-09-25 18:06:42 +00:00
|
|
|
getClass(day) {
|
|
|
|
if (this.excls[day.getTime()])
|
|
|
|
return 'excluded';
|
2019-01-21 10:45:53 +00:00
|
|
|
}
|
|
|
|
|
2019-09-25 18:06:42 +00:00
|
|
|
repaint() {
|
|
|
|
this.$.stMonth.repaint();
|
|
|
|
this.$.ndMonth.repaint();
|
2018-09-24 12:51:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ngModule.component('vnZoneCalendar', {
|
|
|
|
template: require('./index.html'),
|
|
|
|
controller: Controller,
|
|
|
|
bindings: {
|
2019-09-25 18:06:42 +00:00
|
|
|
events: '<?',
|
|
|
|
exclusions: '<?'
|
2018-09-24 12:51:27 +00:00
|
|
|
}
|
|
|
|
});
|