UNPKG

armisa-models

Version:
215 lines (214 loc) 8.67 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DatePickerFactory = void 0; const nums2persian_1 = require("nums2persian"); class DatePickerFactory { get any() { return this; } get today() { return this.selfDateBoxFactory.value ? this.selfDateBoxFactory.value : (0, nums2persian_1.ReturnToday)(); } get currentDate() { return this._currentDate; } set currentDate(value) { this._currentDate = value; const [year, month, day] = (0, nums2persian_1.ReturnCurrentDateValue)(this._currentDate); this.currentDay = day; this.currentMonth = month; this.currentYear = year; } constructor(selfDateBoxFactory, forceUpdate) { this.selfDateBoxFactory = selfDateBoxFactory; this.forceUpdate = forceUpdate; ///** Select And Close */ this.onSelectDate = (date) => { this.currentDate = date; this.selfDateBoxFactory.setValue(this.currentDate); this.selfDateBoxFactory.mainStateFactory.elementsOfForm.closeModal(); }; ///** Only Select */ this.onSelectDateOnly = (date) => { this.currentDate = date; this.selfDateBoxFactory.setValue(this.currentDate); }; this.setMiladiDate = (date) => { this.currentDateMiladi = date; this.forceUpdate(); }; this.setCurrentDate = (date) => { this.currentDate = date; this.forceUpdate(); }; this.setCurrentTypeShow = (type) => { this.currentTypeOfShowDatePicker = type; this.forceUpdate(); }; this.onSelectMonth = (newMonth) => { this.setCurrentDate((0, nums2persian_1.ReturnFirstDayOfMonth)(this.currentYear, newMonth)); this.setCurrentTypeShow('days'); }; this.onSelectYear = (newYear) => { this.setCurrentDate((0, nums2persian_1.ReturnFirstDayOfMonth)(newYear, this.currentMonth)); this.setCurrentTypeShow('months'); }; this.onMouseEnter = (date) => { this.setMiladiDate((0, nums2persian_1.ReturnMiladyDate)(date)); }; this.onMouseOut = () => { this.setMiladiDate(''); }; this.onClickTypeShowMonth = () => { this.setCurrentTypeShow('months'); }; this.onClickTypeShowYears = () => { this.setCurrentTypeShow('years'); }; this.onClickTypeShowDays = () => { this.setCurrentTypeShow('days'); }; this.gotoNextDay = () => { this.setCurrentDate((0, nums2persian_1.ReturnNextDay)(this.currentDate)); }; this.gotoPreviousDay = () => { this.setCurrentDate((0, nums2persian_1.ReturnPreviousDay)(this.currentDate)); }; this.gotoNextWeek = () => { this.setCurrentDate((0, nums2persian_1.ReturnNextWeek)(this.currentDate)); }; this.gotoPreviousWeek = () => { this.setCurrentDate((0, nums2persian_1.ReturnPreviousWeek)(this.currentDate)); }; this.gotoNextMonth = () => { this.setCurrentDate((0, nums2persian_1.ReturnNextMonth)(this.currentDate)); }; this.gotoPreviousMonth = () => { this.setCurrentDate((0, nums2persian_1.ReturnPreviousMonth)(this.currentDate)); }; this.gotoNextSeason = () => { this.setCurrentDate((0, nums2persian_1.ReturnNextSeason)(this.currentDate)); }; this.gotoPreviousSeason = () => { this.setCurrentDate((0, nums2persian_1.ReturnPreviousSeason)(this.currentDate)); }; this.gotoToday = () => { this.setCurrentDate((0, nums2persian_1.ReturnToday)()); this.setCurrentTypeShow('days'); }; this.gotoNextYear = () => { this.setCurrentDate((0, nums2persian_1.ReturnNextYear)(this.currentDate)); }; this.gotoPreviousYear = () => { this.setCurrentDate((0, nums2persian_1.ReturnPreviousYear)(this.currentDate)); }; this.gotoNext4Year = () => { this.setCurrentDate((0, nums2persian_1.ReturnNext4Year)(this.currentDate)); }; this.gotoPrevious4Year = () => { this.setCurrentDate((0, nums2persian_1.ReturnPrevious4Year)(this.currentDate)); }; this.gotoNext10Year = () => { this.setCurrentDate((0, nums2persian_1.ReturnNext10Year)(this.currentDate)); }; this.gotoPrevious10Year = () => { this.setCurrentDate((0, nums2persian_1.ReturnPrevious10Year)(this.currentDate)); }; this.onEnterKeyHandler = () => { if (this.currentTypeOfShowDatePicker === 'days') { this.onSelectDate(this.currentDate); } else if (this.currentTypeOfShowDatePicker === 'months') { this.onClickTypeShowDays(); } else if (this.currentTypeOfShowDatePicker === 'years') { this.onClickTypeShowMonth(); } }; this.onSpaceKeyHandler = () => { if (this.currentTypeOfShowDatePicker === 'days') { this.onClickTypeShowYears(); } else if (this.currentTypeOfShowDatePicker === 'months') { this.onClickTypeShowDays(); } else if (this.currentTypeOfShowDatePicker === 'years') { this.onClickTypeShowMonth(); } }; this.onDownKeyHandler = () => { if (this.currentTypeOfShowDatePicker === 'days') { this.gotoNextWeek(); } else if (this.currentTypeOfShowDatePicker === 'months') { this.gotoNextSeason(); } else if (this.currentTypeOfShowDatePicker === 'years') { this.gotoNext4Year(); } }; this.onUpKeyHandler = () => { if (this.currentTypeOfShowDatePicker === 'days') { this.gotoPreviousWeek(); } else if (this.currentTypeOfShowDatePicker === 'months') { this.gotoPreviousSeason(); } else if (this.currentTypeOfShowDatePicker === 'years') { this.gotoPrevious4Year(); } }; this.onRightKeyHandler = () => { if (this.currentTypeOfShowDatePicker === 'days') { this.gotoPreviousDay(); } else if (this.currentTypeOfShowDatePicker === 'months') { this.gotoPreviousMonth(); } else if (this.currentTypeOfShowDatePicker === 'years') { this.gotoPreviousYear(); } }; this.onLeftKeyHandler = () => { if (this.currentTypeOfShowDatePicker === 'days') { this.gotoNextDay(); } else if (this.currentTypeOfShowDatePicker === 'months') { this.gotoNextMonth(); } else if (this.currentTypeOfShowDatePicker === 'years') { this.gotoNextYear(); } }; this.onPageUpKeyHandler = () => { if (this.currentTypeOfShowDatePicker === 'days') { this.gotoNextMonth(); } else if (this.currentTypeOfShowDatePicker === 'months') { this.gotoNextYear(); } else if (this.currentTypeOfShowDatePicker === 'years') { this.gotoNext10Year(); } }; this.onPageDownKeyHandler = () => { if (this.currentTypeOfShowDatePicker === 'days') { this.gotoPreviousMonth(); } else if (this.currentTypeOfShowDatePicker === 'months') { this.gotoPreviousYear(); } else if (this.currentTypeOfShowDatePicker === 'years') { this.gotoPrevious10Year(); } }; this.currentDateMiladi = ''; this.currentTypeOfShowDatePicker = 'days'; this._currentDate = this.today; const [year, month, day] = (0, nums2persian_1.ReturnCurrentDateValue)(this._currentDate); this.currentDay = day; this.currentMonth = month; this.currentYear = year; } } exports.DatePickerFactory = DatePickerFactory;