UNPKG

ngx-bootstrap

Version:
173 lines 7.41 kB
import { Injectable } from '@angular/core'; import 'rxjs/add/operator/filter'; import 'rxjs/add/operator/map'; import { getFullYear, getMonth } from '../../bs-moment/utils/date-getters'; import { BsDatepickerActions } from './bs-datepicker.actions'; var BsDatepickerEffects = (function () { function BsDatepickerEffects(_actions) { this._actions = _actions; this._subs = []; } BsDatepickerEffects.prototype.init = function (_bsDatepickerStore) { this._store = _bsDatepickerStore; return this; }; /** setters */ BsDatepickerEffects.prototype.setValue = function (value) { this._store.dispatch(this._actions.select(value)); }; BsDatepickerEffects.prototype.setRangeValue = function (value) { this._store.dispatch(this._actions.selectRange(value)); }; BsDatepickerEffects.prototype.setMinDate = function (value) { this._store.dispatch(this._actions.minDate(value)); return this; }; BsDatepickerEffects.prototype.setMaxDate = function (value) { this._store.dispatch(this._actions.maxDate(value)); return this; }; BsDatepickerEffects.prototype.setDisabled = function (value) { this._store.dispatch(this._actions.isDisabled(value)); return this; }; /* Set rendering options */ BsDatepickerEffects.prototype.setOptions = function (_config) { this._store.dispatch(this._actions.setOptions(_config)); return this; }; /** view to mode bindings */ BsDatepickerEffects.prototype.setBindings = function (container) { container.daysCalendar = this._store .select(function (state) { return state.flaggedMonths; }) .filter(function (months) { return !!months; }); // month calendar container.monthsCalendar = this._store .select(function (state) { return state.flaggedMonthsCalendar; }) .filter(function (months) { return !!months; }); // year calendar container.yearsCalendar = this._store .select(function (state) { return state.yearsCalendarFlagged; }) .filter(function (years) { return !!years; }); container.viewMode = this._store .select(function (state) { return state.view.mode; }); container.options = this._store.select(function (state) { return state.showWeekNumbers; }) .map(function (showWeekNumbers) { return ({ showWeekNumbers: showWeekNumbers }); }); return this; }; /** event handlers*/ BsDatepickerEffects.prototype.setEventHandlers = function (container) { var _this = this; container.setViewMode = function (event) { _this._store.dispatch(_this._actions.changeViewMode(event)); }; container.navigateTo = function (event) { _this._store.dispatch(_this._actions.navigateStep(event.step)); }; container.dayHoverHandler = function (event) { var _cell = event.cell; if (_cell.isOtherMonth || _cell.isDisabled) { return; } _this._store.dispatch(_this._actions.hoverDay(event)); _cell.isHovered = event.isHovered; }; container.monthHoverHandler = function (event) { event.cell.isHovered = event.isHovered; }; container.yearHoverHandler = function (event) { event.cell.isHovered = event.isHovered; }; /** select handlers */ // container.daySelectHandler = (day: DayViewModel): void => { // if (day.isOtherMonth || day.isDisabled) { // return; // } // this._store.dispatch(this._actions.select(day.date)); // }; container.monthSelectHandler = function (event) { if (event.isDisabled) { return; } _this._store.dispatch(_this._actions.navigateTo({ unit: { month: getMonth(event.date) }, viewMode: 'day' })); }; container.yearSelectHandler = function (event) { if (event.isDisabled) { return; } _this._store.dispatch(_this._actions.navigateTo({ unit: { year: getFullYear(event.date) }, viewMode: 'month' })); }; return this; }; BsDatepickerEffects.prototype.registerDatepickerSideEffects = function () { var _this = this; this._subs.push(this._store.select(function (state) { return state.view; }) .subscribe(function (view) { _this._store.dispatch(_this._actions.calculate()); })); // format calendar values on month model change this._subs.push(this._store .select(function (state) { return state.monthsModel; }) .filter(function (monthModel) { return !!monthModel; }) .subscribe(function (month) { return _this._store.dispatch(_this._actions.format()); })); // flag day values this._subs.push(this._store .select(function (state) { return state.formattedMonths; }) .filter(function (month) { return !!month; }) .subscribe(function (month) { return _this._store.dispatch(_this._actions.flag()); })); // flag day values this._subs.push(this._store.select(function (state) { return state.selectedDate; }) .filter(function (selectedDate) { return !!selectedDate; }) .subscribe(function (selectedDate) { return _this._store.dispatch(_this._actions.flag()); })); // flag for date range picker this._subs.push(this._store.select(function (state) { return state.selectedRange; }) .filter(function (selectedRange) { return !!selectedRange; }) .subscribe(function (selectedRange) { return _this._store.dispatch(_this._actions.flag()); })); // monthsCalendar this._subs.push(this._store .select(function (state) { return state.monthsCalendar; }) .subscribe(function () { return _this._store.dispatch(_this._actions.flag()); })); // years calendar this._subs.push(this._store .select(function (state) { return state.yearsCalendarModel; }) .filter(function (state) { return !!state; }) .subscribe(function () { return _this._store.dispatch(_this._actions.flag()); })); // on hover this._subs.push(this._store.select(function (state) { return state.hoveredDate; }) .filter(function (hoveredDate) { return !!hoveredDate; }) .subscribe(function (hoveredDate) { return _this._store.dispatch(_this._actions.flag()); })); return this; }; BsDatepickerEffects.prototype.destroy = function () { for (var _i = 0, _a = this._subs; _i < _a.length; _i++) { var sub = _a[_i]; sub.unsubscribe(); } }; BsDatepickerEffects.decorators = [ { type: Injectable }, ]; /** @nocollapse */ BsDatepickerEffects.ctorParameters = function () { return [ { type: BsDatepickerActions, }, ]; }; return BsDatepickerEffects; }()); export { BsDatepickerEffects }; //# sourceMappingURL=bs-datepicker.effects.js.map