UNPKG

com.phloxui

Version:

PhloxUI Ng2+ Framework

1,406 lines (1,405 loc) 177 kB
/** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ import * as tslib_1 from "tslib"; import { Component, ElementRef, HostListener, Input, Output, EventEmitter } from '@angular/core'; import { AbstractDateTimePicker } from './AbstractDateTimePicker'; import { NeedFocusService } from '../../../service/NeedFocusService.service'; import { DateFormatter } from '../../../share/formatter/DateFormatter'; import { ValidationStatus } from '../../../component/validate/ValidationStatus'; import { FormatterFactory } from '../../../service/FormatterFactory.service'; import { MinValidator } from '../../../directive/MinValidator.directive'; import { MaxValidator } from '../../../directive/MaxValidator.directive'; import { DateTimeUtils } from '../../../share/utils/DateTimeUtils'; import { Option } from '../../../decorator/Option.decorator'; import { I18N } from '../../../decorator/I18N.decorator'; import { PhloxAppInfoService } from '../../../service/PhloxAppInfoService.service'; import { EventUtils } from '../../../share/shares'; var /** @type {?} */ TYPE_NAME = "phx-date-picker"; var /** @type {?} */ DAY_VIEW = 'DAY'; var /** @type {?} */ WEEK_VIEW = 'WEEK'; var /** @type {?} */ MONTH_VIEW = 'MONTH'; var /** @type {?} */ KEY_FORMAT = "dd/MM/yyyy"; var /** @type {?} */ MIN_DATE_TIME = MinValidator.NAME; var /** @type {?} */ MAX_DATE_TIME = MaxValidator.NAME; var /** @type {?} */ DEFAULT_FORMAT = 'dd/MM/yyyy'; var /** @type {?} */ GAP_HEIGHT = 8; var DatePicker = /** @class */ (function (_super) { tslib_1.__extends(DatePicker, _super); function DatePicker(elementRef, needFocusService, formatterFactory, phloxAppInfoService) { var _this = _super.call(this, elementRef, formatterFactory, phloxAppInfoService, needFocusService) || this; _this.MONTH_CONTENT_SELECTOR = ".month-view > .container"; _this.currentView = MONTH_VIEW; _this.monthDayContainer = []; _this.monthRowContainer = []; _this.calendarData = []; _this.monthMoreRowContainer = []; _this.active = false; _this.defaultDropdownIdx = 0; _this.defaultRowHeight = 46; _this.defaultMonthEntryWidth = 0; // as percent _this.defaultMonthEntryHeight = 15; // as pt _this.defaultMonthHeight = 20; // as percent _this.today = Date.today(); _this.changeEvent = new EventEmitter(); _this._isItemClick = false; return _this; } /** * @return {?} */ DatePicker.prototype.ngOnInit = /** * @return {?} */ function () { _super.prototype.ngOnInit.call(this); this.selectedDate = this.getDate(); this.pickerDate = this.selectedDate; this.renderPicker(); }; /** * @return {?} */ DatePicker.prototype.calculatePopupPosition = /** * @return {?} */ function () { var /** @type {?} */ popup = $(this.elementRef.nativeElement).find('.date-picker-view'); this.elementFocused = $(document.activeElement); this.positionTop = this.elementFocused.position().top + this.elementFocused.height() + GAP_HEIGHT; var /** @type {?} */ ele; // Default value this.positionLeft = 0; var /** @type {?} */ screenTop = this.elementFocused.offset().top - $(window).scrollTop() + this.elementFocused.height() + GAP_HEIGHT; var /** @type {?} */ screenBottom = screenTop + popup.height(); var /** @type {?} */ screenLeft = this.elementFocused.offset().left - $(window).scrollLeft(); var /** @type {?} */ screenRight = screenLeft + popup.width(); if (screenTop < 0) { this.positionTop += -screenTop; } else if (screenBottom > $(window).height()) { this.positionTop -= screenBottom - $(window).height(); } if (screenLeft < 0) { this.positionLeft += -screenLeft; } else if (screenRight > $(window).width()) { this.positionLeft -= screenRight - $(window).width(); } }; /** * @return {?} */ DatePicker.prototype.requestFocus = /** * @return {?} */ function () { var /** @type {?} */ input = $(this.elementRef.nativeElement).find('input[type="text"]'); input.focus(); }; /** * @param {?} date * @return {?} */ DatePicker.prototype.calendarRender = /** * @param {?} date * @return {?} */ function (date) { if (date === null || typeof date === 'undefined') { return; } this.resetMonthDayContainer(); // change text label var /** @type {?} */ firstDayOfMonth = new Date(date).moveToFirstDayOfMonth(); var /** @type {?} */ lastDayOfMonth = new Date(date).moveToLastDayOfMonth(); var /** @type {?} */ count = -1; var /** @type {?} */ allDays = this.getAllDayItems(); var /** @type {?} */ firstDayOfWeek = firstDayOfMonth.getDay(); var /** @type {?} */ minusDayOfWeek = firstDayOfWeek; var /** @type {?} */ prevDayOfMonth = new Date(date).moveToFirstDayOfMonth().addDays(-minusDayOfWeek); for (var /** @type {?} */ i = 0; i < allDays.length; i++) { if (firstDayOfWeek == i) { break; } allDays[i].day = prevDayOfMonth.toString("dd"); allDays[i].date = new Date(prevDayOfMonth); if (this.isHasOwnMinMaxDisable()) { allDays[i].minmax = this.isMinMaxDate(allDays[i].date, this.getMinDate(), this.getMaxDate()); } else { allDays[i].minmax = this.isMinMaxDirectiveDisable(allDays[i].date); } prevDayOfMonth.addDays(1); count = i; } if (count > -1) { count += 1; } else { count = 0; } while (firstDayOfMonth.isBefore(lastDayOfMonth) || firstDayOfMonth.equals(lastDayOfMonth)) { if (count === 100) { break; } if (count < allDays.length) { if (allDays[count].date === null || typeof allDays[count].date === 'undefined') { allDays[count].day = firstDayOfMonth.toString("dd"); allDays[count].date = new Date(firstDayOfMonth); if (this.isHasOwnMinMaxDisable()) { allDays[count].minmax = this.isMinMaxDate(allDays[count].date, this.getMinDate(), this.getMaxDate()); } else { allDays[count].minmax = this.isMinMaxDirectiveDisable(allDays[count].date); } } } firstDayOfMonth.addDays(1); count += 1; } var /** @type {?} */ nextMonth = new Date(lastDayOfMonth).addDays(1); while (count < allDays.length) { if (count === 100) { break; } if (allDays[count].date === null || typeof allDays[count].date === 'undefined') { allDays[count].day = nextMonth.toString("dd"); allDays[count].date = new Date(nextMonth); if (this.isHasOwnMinMaxDisable()) { allDays[count].minmax = this.isMinMaxDate(allDays[count].date, this.getMinDate(), this.getMaxDate()); } else { allDays[count].minmax = this.isMinMaxDirectiveDisable(allDays[count].date); } } nextMonth.addDays(1); count += 1; } }; /** * @return {?} */ DatePicker.prototype.getAllDayItems = /** * @return {?} */ function () { var /** @type {?} */ result = []; try { for (var _a = tslib_1.__values(this.monthDayContainer), _b = _a.next(); !_b.done; _b = _a.next()) { var row = _b.value; try { for (var row_1 = tslib_1.__values(row), row_1_1 = row_1.next(); !row_1_1.done; row_1_1 = row_1.next()) { var item = row_1_1.value; result.push(item); } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (row_1_1 && !row_1_1.done && (_c = row_1.return)) _c.call(row_1); } finally { if (e_1) throw e_1.error; } } } } catch (e_2_1) { e_2 = { error: e_2_1 }; } finally { try { if (_b && !_b.done && (_d = _a.return)) _d.call(_a); } finally { if (e_2) throw e_2.error; } } return result; var e_2, _d, e_1, _c; }; /** * @return {?} */ DatePicker.prototype.resetMonthDayContainer = /** * @return {?} */ function () { this.monthDayContainer = []; var /** @type {?} */ count = 1; for (var /** @type {?} */ i = 0; i < 6; i++) { var /** @type {?} */ container = []; for (var /** @type {?} */ j = 0; j < 7; j++) { if (count >= 32) { count = 1; } var /** @type {?} */ item = { day: '', minmax: false }; container.push(item); count += 1; } this.monthDayContainer.push(container); } }; /** * @param {?} viewName * @param {?} date * @return {?} */ DatePicker.prototype.reRenderViewData = /** * @param {?} viewName * @param {?} date * @return {?} */ function (viewName, date) { if (viewName === null || typeof viewName === 'undefined') { return; } if (MONTH_VIEW === viewName) { this.monthDataRender(date); } }; /** * @param {?} date * @return {?} */ DatePicker.prototype.monthDataRender = /** * @param {?} date * @return {?} */ function (date) { if (date === null || typeof date === 'undefined') { return; } var /** @type {?} */ indexMap = {}; var /** @type {?} */ firstDayOfCalendar = null; var /** @type {?} */ lastDayOfCalendar = null; for (var /** @type {?} */ i = 0; i < this.monthDayContainer.length; i++) { var /** @type {?} */ container = this.monthDayContainer[i]; for (var /** @type {?} */ j = 0; j < container.length; j++) { var /** @type {?} */ item = container[j]; var /** @type {?} */ date_1 = item.date; var /** @type {?} */ dateString = date_1.toString(KEY_FORMAT); if (firstDayOfCalendar === null) { firstDayOfCalendar = new Date(date_1); } else { if (firstDayOfCalendar.getMonth() !== date_1.getMonth()) { if (this.selectedDate !== null && typeof this.selectedDate !== 'undefined') { if (firstDayOfCalendar.getMonth() === this.selectedDate.getMonth()) { break; } } } } lastDayOfCalendar = new Date(date_1); if (date_1 !== null && typeof date_1 !== 'undefined') { indexMap[dateString] = { row: i, col: j, count: 0 }; } } } // first render long day var /** @type {?} */ leftMonthRowContainer = []; var /** @type {?} */ fakeEntryArray = []; try { for (var _a = tslib_1.__values(this.monthRowContainer), _b = _a.next(); !_b.done; _b = _a.next()) { var item = _b.value; var /** @type {?} */ fromTime = item.fromTime; var /** @type {?} */ toTime = item.toTime; // set til the end of calendar var /** @type {?} */ isContinueNextMonth = false; if ((fromTime.isBefore(toTime) || fromTime.equals(toTime)) && fromTime.getMonth() < toTime.getMonth()) { if (lastDayOfCalendar !== null) { toTime = new Date(lastDayOfCalendar); isContinueNextMonth = true; } } var /** @type {?} */ fDateString = fromTime.toString(KEY_FORMAT); var /** @type {?} */ tDateString = toTime.toString(KEY_FORMAT); var /** @type {?} */ clearFromTime = new Date(fromTime).clearTime(); var /** @type {?} */ clearToTime = new Date(toTime).clearTime(); if (clearFromTime.toString(KEY_FORMAT) === clearToTime.toString(KEY_FORMAT)) { leftMonthRowContainer.push(item); continue; } var /** @type {?} */ spanCol = 0; var /** @type {?} */ tIndexObj = null; if (indexMap[tDateString] !== null && typeof indexMap[tDateString] !== 'undefined') { tIndexObj = indexMap[tDateString]; } var /** @type {?} */ fIndexObj = null; if (indexMap[fDateString] !== null && typeof indexMap[fDateString] !== 'undefined') { fIndexObj = indexMap[fDateString]; } if (tIndexObj !== null && fIndexObj !== null) { var /** @type {?} */ fRow = fIndexObj.row; var /** @type {?} */ fCol = fIndexObj.col; var /** @type {?} */ tRow = tIndexObj.row; var /** @type {?} */ tCol = tIndexObj.col; var /** @type {?} */ updateCountIndex = false; if (fRow === tRow) { if (fCol < tCol) { updateCountIndex = true; } } else if (fRow < tRow) { updateCountIndex = true; } if (updateCountIndex) { var /** @type {?} */ countCol = -1; var /** @type {?} */ fakeNewLine = false; var /** @type {?} */ fakeEntry = null; var /** @type {?} */ newLine = false; for (var /** @type {?} */ key in indexMap) { var /** @type {?} */ obj = indexMap[key]; var /** @type {?} */ dateKey = Date.parseExact(key, KEY_FORMAT); if ((dateKey.isAfter(clearFromTime) || dateKey.equals(clearFromTime)) && (dateKey.isBefore(clearToTime) || dateKey.equals(clearToTime))) { obj.count = obj.count + 1; if (countCol >= 0) { if (countCol > obj.col) { newLine = true; } } countCol = obj.col; if (newLine) { // add fake var /** @type {?} */ curRow = fRow; if (fakeEntry !== null && fakeEntry.span === 7) { fakeEntry.continue = true; curRow = fakeEntry.row; fakeEntry = null; } if (fakeEntry === null) { // first time curRow = curRow + 1; fakeEntry = this.getWrapperObject(dateKey, dateKey, item.title, item.entry); fakeEntry.refFromTime = new Date(fromTime); fakeEntry.refToTime = new Date(toTime); fakeEntry.count = obj.count; fakeEntry.span = 1; fakeEntry.row = curRow; fakeEntry.col = 0; if (isContinueNextMonth) { fakeEntry.continue = true; } fakeEntryArray.push(fakeEntry); } else { fakeEntry.toTime = dateKey; fakeEntry.span = fakeEntry.span + 1; } } else { if (obj.row === fRow) { spanCol += 1; } } } } if (newLine) { item.continue = true; } } } var /** @type {?} */ newWidth = this.defaultMonthEntryWidth; if (spanCol > 0) { newWidth = this.defaultMonthEntryWidth * spanCol; } item.width = newWidth + '%'; if (isContinueNextMonth) { item.continue = true; } if (fIndexObj !== null) { var /** @type {?} */ row = fIndexObj.row; var /** @type {?} */ col = fIndexObj.col; var /** @type {?} */ count_1 = fIndexObj.count; var /** @type {?} */ marginTop = this.defaultMonthEntryHeight * count_1; var /** @type {?} */ newLeft = (this.defaultMonthEntryWidth * col); var /** @type {?} */ newTop = (this.defaultMonthHeight * row); item.left = newLeft + "%"; item.top = newTop + "%"; item.margintop = marginTop + "pt"; item.show = true; } else { item.show = false; } } } catch (e_3_1) { e_3 = { error: e_3_1 }; } finally { try { if (_b && !_b.done && (_c = _a.return)) _c.call(_a); } finally { if (e_3) throw e_3.error; } } try { // add fake to monthRowContainer for (var fakeEntryArray_1 = tslib_1.__values(fakeEntryArray), fakeEntryArray_1_1 = fakeEntryArray_1.next(); !fakeEntryArray_1_1.done; fakeEntryArray_1_1 = fakeEntryArray_1.next()) { var item = fakeEntryArray_1_1.value; var /** @type {?} */ row = item.row; var /** @type {?} */ col = item.col; var /** @type {?} */ count_2 = item.count; var /** @type {?} */ marginTop = this.defaultMonthEntryHeight * count_2; var /** @type {?} */ newWidth = this.defaultMonthEntryWidth * item.span; var /** @type {?} */ newLeft = (this.defaultMonthEntryWidth * col); var /** @type {?} */ newTop = (this.defaultMonthHeight * row); item.left = newLeft + "%"; item.top = newTop + "%"; item.margintop = marginTop + "pt"; item.width = newWidth + '%'; item.show = true; item.subentry = true; this.monthRowContainer.push(item); } } catch (e_4_1) { e_4 = { error: e_4_1 }; } finally { try { if (fakeEntryArray_1_1 && !fakeEntryArray_1_1.done && (_d = fakeEntryArray_1.return)) _d.call(fakeEntryArray_1); } finally { if (e_4) throw e_4.error; } } try { // second render in day for (var leftMonthRowContainer_1 = tslib_1.__values(leftMonthRowContainer), leftMonthRowContainer_1_1 = leftMonthRowContainer_1.next(); !leftMonthRowContainer_1_1.done; leftMonthRowContainer_1_1 = leftMonthRowContainer_1.next()) { var item = leftMonthRowContainer_1_1.value; var /** @type {?} */ fromTime = item.fromTime; var /** @type {?} */ toTime = item.toTime; var /** @type {?} */ dateString = fromTime.toString(KEY_FORMAT); var /** @type {?} */ isContinueNextMonth = false; if (fromTime.getMonth() < toTime.getMonth()) { if (lastDayOfCalendar !== null) { isContinueNextMonth = true; } } var /** @type {?} */ indexObj = null; if (indexMap[dateString] !== null && typeof indexMap[dateString] !== 'undefined') { indexObj = indexMap[dateString]; } if (indexObj !== null) { var /** @type {?} */ row = indexObj.row; var /** @type {?} */ col = indexObj.col; var /** @type {?} */ count_3 = indexObj.count; var /** @type {?} */ newLeft = (this.defaultMonthEntryWidth * col); var /** @type {?} */ newTop = (this.defaultMonthHeight * row); var /** @type {?} */ marginTop = this.defaultMonthEntryHeight * (count_3 + 1); item.left = newLeft + "%"; item.top = newTop + "%"; item.margintop = marginTop + "pt"; item.show = true; indexObj.count = count_3 + 1; } else { item.show = false; } if (isContinueNextMonth) { item.continue = true; } } } catch (e_5_1) { e_5 = { error: e_5_1 }; } finally { try { if (leftMonthRowContainer_1_1 && !leftMonthRowContainer_1_1.done && (_e = leftMonthRowContainer_1.return)) _e.call(leftMonthRowContainer_1); } finally { if (e_5) throw e_5.error; } } this.monthMoreRowContainer = []; var /** @type {?} */ removeItems = []; var /** @type {?} */ rowHeight = $(this.elementRef.nativeElement).find(this.MONTH_CONTENT_SELECTOR + " > .temp-row-container > .temp-row").height(); var /** @type {?} */ entryWrapperHeight = $(this.elementRef.nativeElement).find(this.MONTH_CONTENT_SELECTOR + " > .temp-entry-wrapper").height(); var /** @type {?} */ currentItem = null; var /** @type {?} */ count = 0; try { for (var _f = tslib_1.__values(this.monthRowContainer), _g = _f.next(); !_g.done; _g = _f.next()) { var item = _g.value; if (item.fromTime === null || typeof item.fromTime === 'undefined') { continue; } if (currentItem === null) { // first currentItem = { height: entryWrapperHeight * 2, date: item.fromTime }; } else { var /** @type {?} */ oldDate = currentItem.date; var /** @type {?} */ newDate = item.fromTime; var /** @type {?} */ oldHeight = currentItem.height; var /** @type {?} */ newHeight = oldHeight + entryWrapperHeight; if (oldDate.toString(KEY_FORMAT) !== newDate.toString(KEY_FORMAT)) { newHeight = entryWrapperHeight * 2; } var /** @type {?} */ newItem = { height: newHeight, date: newDate }; currentItem = newItem; } var /** @type {?} */ wrapperHeight = currentItem.height; if (wrapperHeight > rowHeight) { var /** @type {?} */ prevIndex = count - 1; if (prevIndex >= 0) { var /** @type {?} */ prevItem = this.monthRowContainer[prevIndex]; // find prev if (removeItems.indexOf(prevItem) <= -1) { removeItems.push(prevItem); } } removeItems.push(item); } count += 1; } } catch (e_6_1) { e_6 = { error: e_6_1 }; } finally { try { if (_g && !_g.done && (_h = _f.return)) _h.call(_f); } finally { if (e_6) throw e_6.error; } } // remove from container var /** @type {?} */ tempMap = {}; try { for (var removeItems_1 = tslib_1.__values(removeItems), removeItems_1_1 = removeItems_1.next(); !removeItems_1_1.done; removeItems_1_1 = removeItems_1.next()) { var item = removeItems_1_1.value; var /** @type {?} */ removeIdx = this.monthRowContainer.indexOf(item); if (removeIdx > -1 && removeIdx < this.monthRowContainer.length) { this.monthRowContainer.splice(removeIdx, 1); } if (item.fromTime == null || typeof item.fromTime === 'undefined') { continue; } var /** @type {?} */ key = item.fromTime.toString(KEY_FORMAT); if (tempMap[key] !== null && typeof tempMap[key] !== 'undefined') { tempMap[key].container.push(item.entry.wrapper.getData()); tempMap[key].count = tempMap[key].count + 1; } else { tempMap[key] = { date: item.fromTime, container: [item.entry.wrapper.getData()], count: 1, top: item.top, left: item.left, width: item.width, margintop: item.margintop }; this.monthMoreRowContainer.push(tempMap[key]); } } } catch (e_7_1) { e_7 = { error: e_7_1 }; } finally { try { if (removeItems_1_1 && !removeItems_1_1.done && (_j = removeItems_1.return)) _j.call(removeItems_1); } finally { if (e_7) throw e_7.error; } } var e_3, _c, e_4, _d, e_5, _e, e_6, _h, e_7, _j; }; /** * @param {?} fromDate * @param {?} toDate * @param {?} title * @param {?} calendarEntry * @return {?} */ DatePicker.prototype.getWrapperObject = /** * @param {?} fromDate * @param {?} toDate * @param {?} title * @param {?} calendarEntry * @return {?} */ function (fromDate, toDate, title, calendarEntry) { var /** @type {?} */ result = { fromTime: fromDate, toTime: toDate, title: title, top: '0pt', left: '0pt', selected: false, height: this.defaultRowHeight + 'pt', entry: calendarEntry }; return result; }; /** * @return {?} */ DatePicker.prototype.isHasOwnMinMaxDisable = /** * @return {?} */ function () { if ((this.getMinDate() !== null && this.getMinDate() !== undefined) || (this.getMaxDate() !== null && this.getMaxDate() !== undefined)) { return true; } return false; }; /** * @param {?} date * @param {?} minDate * @param {?} maxDate * @return {?} */ DatePicker.prototype.isMinMaxDate = /** * @param {?} date * @param {?} minDate * @param {?} maxDate * @return {?} */ function (date, minDate, maxDate) { var /** @type {?} */ dateRemoveTime = (date !== null && date !== undefined) ? date.clearTime() : null; var /** @type {?} */ minDateRemoveTime = (minDate !== null && minDate !== undefined) ? minDate.clearTime() : null; var /** @type {?} */ maxDateRemoveTime = (maxDate !== null && maxDate !== undefined) ? maxDate.clearTime() : null; if ((minDateRemoveTime !== null && minDateRemoveTime !== undefined) && (maxDateRemoveTime !== null && maxDateRemoveTime !== undefined)) { return dateRemoveTime < minDateRemoveTime || dateRemoveTime > maxDateRemoveTime; } else if ((minDateRemoveTime !== null && minDateRemoveTime !== undefined) && (maxDateRemoveTime === null || maxDateRemoveTime === undefined)) { return dateRemoveTime < minDateRemoveTime; } else if ((minDateRemoveTime === null || minDateRemoveTime === undefined) && (maxDateRemoveTime !== null && maxDateRemoveTime !== undefined)) { return dateRemoveTime > maxDateRemoveTime; } return false; }; /** * @param {?} date * @return {?} */ DatePicker.prototype.isMinMaxValidate = /** * @param {?} date * @return {?} */ function (date) { if (date !== null && typeof date !== 'undefined') { var /** @type {?} */ results = this.validate(date); return this.isValidFromValidationResults(results); } return false; }; /** * @param {?} date * @return {?} */ DatePicker.prototype.getValidationResults = /** * @param {?} date * @return {?} */ function (date) { var /** @type {?} */ results; if (date !== null && typeof date !== 'undefined') { results = this.validate(date); return results; } return results; }; /** * @return {?} */ DatePicker.prototype.prevMonth = /** * @return {?} */ function () { if (this.pickerDate != null && (typeof this.pickerDate !== 'undefined')) { this.pickerDate = new Date(this.pickerDate); this.pickerDate.addMonths(-1); var /** @type {?} */ tzDiff = this.getTimeZoneDiff(this.pickerDate); var /** @type {?} */ tzDiffHours = Math.floor(tzDiff / 100); var /** @type {?} */ tzDiffMins = tzDiff % 100; this.pickerDate.setHours(this.pickerDate.getHours() - tzDiffHours); this.pickerDate.setMinutes(this.pickerDate.getMinutes() - tzDiffMins); this.renderPicker(this.pickerDate); } }; /** * @return {?} */ DatePicker.prototype.nextMonth = /** * @return {?} */ function () { if (this.pickerDate != null && (typeof this.pickerDate !== 'undefined')) { this.pickerDate = new Date(this.pickerDate); this.pickerDate.addMonths(1); var /** @type {?} */ tzDiff = this.getTimeZoneDiff(this.pickerDate); var /** @type {?} */ tzDiffHours = Math.floor(tzDiff / 100); var /** @type {?} */ tzDiffMins = tzDiff % 100; this.pickerDate.setHours(this.pickerDate.getHours() - tzDiffHours); this.pickerDate.setMinutes(this.pickerDate.getMinutes() - tzDiffMins); this.renderPicker(this.pickerDate); } }; /** * @param {?} results * @return {?} */ DatePicker.prototype.isValidFromValidationResults = /** * @param {?} results * @return {?} */ function (results) { if (results !== null && typeof results !== 'undefined') { try { for (var results_1 = tslib_1.__values(results), results_1_1 = results_1.next(); !results_1_1.done; results_1_1 = results_1.next()) { var result = results_1_1.value; var /** @type {?} */ status_1 = result.status; if (result.status === ValidationStatus.ERROR) { return false; } var /** @type {?} */ msg = result.message; } } catch (e_8_1) { e_8 = { error: e_8_1 }; } finally { try { if (results_1_1 && !results_1_1.done && (_a = results_1.return)) _a.call(results_1); } finally { if (e_8) throw e_8.error; } } } return true; var e_8, _a; }; /** * @param {?} inputVal * @param {?=} $event * @param {?=} fireEvent * @return {?} */ DatePicker.prototype.setInputValue = /** * @param {?} inputVal * @param {?=} $event * @param {?=} fireEvent * @return {?} */ function (inputVal, $event, fireEvent) { var _this = this; if (fireEvent === null || fireEvent === undefined) { fireEvent = true; } var /** @type {?} */ oldValue = this.getInputValue(); EventUtils.handleBrowserEvent(this, 'beforeChangeEvent', $event, fireEvent, function ($event) { // doEvent // Set input value into data object. // doEvent // Set input value into data object. _this._setValueToData(inputVal); }, function ($event) { // emitBeforeEvent // emitBeforeEvent _this.emitBeforeChangeEvent(oldValue, inputVal, true, $event); }, function ($event) { // emitAfterEvent // emitAfterEvent _this.emitChangeEvent(oldValue, inputVal, true, $event); }, function ($event) { // doPrevented // doPrevented _this.selectedDate = oldValue; }, 'inputValue'); this._formattedData = this.getFormattedData(); }; /** * @param {?} date * @param {?=} $event * @return {?} */ DatePicker.prototype.updateSelectedDate = /** * @param {?} date * @param {?=} $event * @return {?} */ function (date, $event) { if (this.selectedDate == null || this.selectedDate == undefined) { this.selectedDate = new Date(this.today); } this.selectedDate = date; var /** @type {?} */ tzDiff = this.getTimeZoneDiff(this.selectedDate); var /** @type {?} */ tzDiffHours = Math.floor(tzDiff / 100); var /** @type {?} */ tzDiffMins = tzDiff % 100; var /** @type {?} */ hour = this.selectedDate.getHours(); var /** @type {?} */ min = this.selectedDate.getMinutes(); this.selectedDate.setHours(hour + tzDiffHours); this.selectedDate.setMinutes(min + tzDiffMins); this.setDate(this.selectedDate); this.updatePickerDate(); }; /** * @return {?} */ DatePicker.prototype.updatePickerDate = /** * @return {?} */ function () { if (this.selectedDate === null || typeof this.selectedDate === 'undefined') { return; } this.pickerDate = new Date(this.selectedDate); var /** @type {?} */ tzDiff = this.getTimeZoneDiff(this.selectedDate); var /** @type {?} */ tzDiffHours = Math.floor(tzDiff / 100); var /** @type {?} */ tzDiffMins = tzDiff % 100; this.pickerDate.setHours(this.selectedDate.getHours() - tzDiffHours); this.pickerDate.setMinutes(this.selectedDate.getMinutes() - tzDiffMins); this.renderPicker(); }; /** * @return {?} */ DatePicker.prototype._getMonthLabel = /** * @return {?} */ function () { if (this.pickerDate !== null && typeof this.pickerDate !== 'undefined') { return this.pickerDate.toString("MMMM yyyy"); } return '-'; }; /** * @param {?} item * @return {?} */ DatePicker.prototype._isDateDisable = /** * @param {?} item * @return {?} */ function (item) { if (item !== null && typeof item !== 'undefined') { var /** @type {?} */ itemDate = item.date; if (this.pickerDate !== null && typeof this.pickerDate !== 'undefined' && itemDate !== null && typeof itemDate !== 'undefined') { if (itemDate.getMonth() !== this.pickerDate.getMonth()) { return true; } } } return false; }; /** * @param {?} item * @return {?} */ DatePicker.prototype._isToday = /** * @param {?} item * @return {?} */ function (item) { if (item !== null && typeof item !== 'undefined') { if (this._isMinmax(item.minmax)) { return false; } if (item.date !== null && typeof item.date !== 'undefined') { var /** @type {?} */ copyDate = new Date(item.date).clearTime(); if (Date.equals(this.today, copyDate)) { return true; } } } return false; }; /** * @param {?} item * @return {?} */ DatePicker.prototype._isCurrentDate = /** * @param {?} item * @return {?} */ function (item) { if (item !== null && typeof item !== 'undefined') { if (this._isMinmax(item.minmax)) { return false; } if (item.date !== null && typeof item.date !== 'undefined') { if (this.selectedDate !== null && typeof this.selectedDate !== 'undefined') { var /** @type {?} */ dateCT = new Date(item.date).clearTime(); var /** @type {?} */ curDateCT = new Date(this.selectedDate).clearTime(); if (Date.equals(dateCT, curDateCT)) { return true; } } } } return false; }; /** * @param {?} minmax * @return {?} */ DatePicker.prototype._isMinmax = /** * @param {?} minmax * @return {?} */ function (minmax) { return minmax; }; /** * @param {?} $event * @return {?} */ DatePicker.prototype.onTextBoxClicked = /** * @param {?} $event * @return {?} */ function ($event) { if (!this.isActive()) { this.show($event); } }; /** * @param {?} $event * @return {?} */ DatePicker.prototype.onFocusing = /** * @param {?} $event * @return {?} */ function ($event) { this.needFocusService.setFocusingComponent(this, $event); }; /** * @param {?} $event * @return {?} */ DatePicker.prototype.onLostFocusing = /** * @param {?} $event * @return {?} */ function ($event) { var _this = this; if (this._itemLostFocusingTimeout !== null && typeof this._itemLostFocusingTimeout !== 'undefined') { clearTimeout(this._itemLostFocusingTimeout); this._itemLostFocusingTimeout = null; } this._itemLostFocusingTimeout = setTimeout(function () { if (!_this._isItemClick) { _this.doBlur($event); if (_this.needFocusService.getFocusingComponent() === _this) { _this.needFocusService.resetFocusingComponent($event); } } else { _this.requestFocus(); } _this._isItemClick = false; }, 100); }; /** * @param {?} $event * @return {?} */ DatePicker.prototype.onValueChanged = /** * @param {?} $event * @return {?} */ function ($event) { // Parse edited text to date (in case of it was changed). var /** @type {?} */ inputText = null; try { inputText = (/** @type {?} */ ($event.target)).value.toString(); } catch (/** @type {?} */ e) { } if (inputText) { // If textbox is not empty, try to parse text value -> date. var /** @type {?} */ newDate = null; try { if (this.formatter instanceof DateFormatter) { newDate = this.formatter.parse(inputText); } else { newDate = Date.parse(inputText); } } catch (/** @type {?} */ e) { } this.updateSelectedDate(newDate, $event); } else { // If textbox is empty, it means that the user does not want // to input any value. this.setDate(null); } }; /** * @param {?} $event * @return {?} */ DatePicker.prototype.onViewClicked = /** * @param {?} $event * @return {?} */ function ($event) { this._isItemClick = true; this.requestFocus(); }; /** * @param {?} $event * @return {?} */ DatePicker.prototype.onPrevMonthBtnClicked = /** * @param {?} $event * @return {?} */ function ($event) { // Set this flag to true to prevent onLostFocusing() behavior. this._isItemClick = true; // Call requestFocus() to move focus back to textbox. this.requestFocus(); this.prevMonth(); }; /** * @param {?} $event * @return {?} */ DatePicker.prototype.onNextMonthBtnClicked = /** * @param {?} $event * @return {?} */ function ($event) { // Set this flag to true to prevent onLostFocusing() behavior. this._isItemClick = true; // Call requestFocus() to move focus back to textbox. this.requestFocus(); this.nextMonth(); }; /** * @param {?} $event * @return {?} */ DatePicker.prototype.onMonthLabelClicked = /** * @param {?} $event * @return {?} */ function ($event) { // Set this flag to true to prevent onLostFocusing() behavior. this._isItemClick = true; // Call requestFocus() to move focus back to textbox. this.requestFocus(); }; /** * @param {?} $event * @param {?} item * @return {?} */ DatePicker.prototype.onDateClicked = /** * @param {?} $event * @param {?} item * @return {?} */ function ($event, item) { // Set this flag to true to prevent onLostFocusing() behavior. this._isItemClick = true; // Call requestFocus() to move focus back to textbox. this.requestFocus(); if (this.selectedDate === null || this.selectedDate === undefined) { return; } else if (this._isMinmax(item.minmax)) { return; } this.updateSelectedDate(item.date, $event); // After date is selected, hide the popup. this.hide(); }; /** * @param {?=} date * @return {?} */ DatePicker.prototype.renderPicker = /** * @param {?=} date * @return {?} */ function (date) { if (date === null || date === undefined) { date = this.pickerDate; } if (date === null || date === undefined) { return; } this.calendarRender(date); this.reRenderViewData(this.currentView, date); }; /** * @param {?} inputValue * @param {?} results * @return {?} */ DatePicker.prototype.onValidationEnd = /** * @param {?} inputValue * @param {?} results * @return {?} */ function (inputValue, results) { }; /** * @param {?} data * @param {?} inputVal * @return {?} */ DatePicker.prototype.onDataChange = /** * @param {?} data * @param {?} inputVal * @return {?} */ function (data, inputVal) { }; /** * @param {?} $event * @return {?} */ DatePicker.prototype.doFocus = /** * @param {?} $event * @return {?} */ function ($event) { if (!this.isReadOnly() && !this.isDisabled()) { // Only show popup when it is NOT read only and not disabled. this.requestFocus(); this.show(); } }; /** * @param {?} $event * @return {?} */ DatePicker.prototype.doLostFocus = /** * @param {?} $event * @return {?} */ function ($event) { this.hide(); }; /** * @return {?} */ DatePicker.prototype.doHide = /** * @return {?} */ function () { this.active = false; }; /** * @return {?} */ DatePicker.prototype.doShow = /** * @return {?} */ function () { this.active = true; this.calculatePopupPosition(); }; /** * @param {?} $event * @return {?} */ DatePicker.prototype.doBlur = /** * @param {?} $event * @return {?} */ function ($event) { $(this.elementRef.nativeElement).find(".date-picker-textbox > input").blur(); }; /** * @return {?} */ DatePicker.prototype.getPopupPositionTop = /** * @return {?} */ function () { return this.positionTop; }; /** * @return {?} */ DatePicker.prototype.getPopupPositionLeft = /** * @return {?} */ function () { return this.positionLeft; }; /** * @return {?} */ DatePicker.prototype.getDataPatternFromSetting = /** * @return {?} */ function () { return "yyyy-MM-dd"; }; /** * @param {?} date * @return {?} */ DatePicker.prototype.isMinMaxDirectiveDisable = /** * @param {?} date * @return {?} */ function (date) { if (date !== null && typeof date !== 'undefined') { if (this.minDirective === null || this.minDirective === undefined && this.maxDirective === null || this.maxDirective === undefined) { for (var /** @type {?} */ i = 0; i < this.getValidators().length; i++) { if (MIN_DATE_TIME === this.getValidators()[i].getName()) { this.minDirective = (/** @type {?} */ (this.getValidators()[i])).getMinDate(); } else if (MAX_DATE_TIME === this.getValidators()[i].getName()) { this.maxDirective = (/** @type {?} */ (this.getValidators()[i])).getMaxDate(); } } } return this.isMinMaxDate(date, this.minDirective, this.maxDirective); } }; /** * @return {?} */ DatePicker.prototype.getMinDate = /** * @return {?} */ function () { return DateTimeUtils.getDateFromAny(this.minDate); }; /** * @param {?} minDate * @return {?} */ DatePicker.prototype.setMinDate = /** * @param {?} minDate * @return {?} */ function (minDate) { this.minDate = minDate; }; /** * @return {?} */ DatePicker.prototype.getMaxDate = /** * @return {?} */ function () { return DateTimeUtils.getDateFromAny(this.maxDate); }; /** * @param {?} maxDate * @return {?} */ DatePicker.prototype.setMaxDate = /** * @param {?} maxDate * @return {?} */ function (maxDate) { this.maxDate = maxDate; }; /** * @return {?} */ DatePicker.prototype.getMonthDayContainer = /** * @return {?} */ function () { return this.monthDayContainer; }; /** * @return {?} */ DatePicker.prototype.isActive = /** * @return {?} */ function () { return this.active; }; /** * @return {?} */ DatePicker.prototype.getWidth = /** * @return {?} */ function () { return this.width; }; /** * @param {?} width * @return {?} */ DatePicker.prototype.setWidth = /** * @param {?} width * @return {?} */ function (width) { this.width = width; }; /** * @return {?} */ DatePicker.prototype.getHeight = /** * @return {?} */ function () { return this.height; }; /** * @param {?} height * @return {?} */ DatePicker.prototype.setHeight = /** * @param {?} height * @return {?} */ function (height) { this.height = height; }; /** * @return {?} */ DatePicker.prototype.getPopupWidth = /** * @return {?} */ function () { return this.popupWidth; }; /** * @param {?} popupWidth * @return {?} */ DatePicker.prototype.setPopupWidth = /** * @param {?} popupWidth * @return {?} */ function (popupWidth) { this.popupWidth = popupWidth; }; /** * @return {?} */ DatePicker.prototype.getPopupHeight = /** * @return {?} */ function () { return this.popupHeight; }; /** * @param {?} popupHeight * @return {?} */ DatePicker.prototype.setPopupHeight = /** * @param {?} popupHeight * @return {?} */ function (popupHeight) { this.popupHeight = popupHeight; }; /** * @param {?} a * @param {?} b * @return {?} */ DatePicker.prototype.compareDate = /** * @param {?} a * @param {?} b * @return {?} */ function (a, b) { if (!a && b) {