ion2-calendar
Advanced tools
Comparing version 2.0.0-beta.5 to 2.0.0-beta.6
@@ -11,2 +11,3 @@ import { Injectable } from '@angular/core'; | ||
CalendarController.prototype.openCalendar = function (calendarOptions, modalOptions) { | ||
var _this = this; | ||
if (modalOptions === void 0) { modalOptions = {}; } | ||
@@ -17,25 +18,7 @@ var options = this.calSvc.safeOpt(calendarOptions); | ||
}, options), modalOptions); | ||
console.log(options); | ||
calendarModal.present(); | ||
return new Promise(function (resolve, reject) { | ||
calendarModal.onDidDismiss(function (data) { | ||
var res; | ||
if (data && Array.isArray(data)) { | ||
switch (options.pickMode) { | ||
case 'single': | ||
res = { date: data[0] }; | ||
break; | ||
case 'range': | ||
res = { | ||
from: data[0], | ||
to: data[1], | ||
}; | ||
break; | ||
case 'multi': | ||
res = data; | ||
break; | ||
default: | ||
res = data; | ||
} | ||
resolve(res); | ||
resolve(_this.calSvc.wrapResult(data, options.pickMode)); | ||
} | ||
@@ -42,0 +25,0 @@ else { |
@@ -58,2 +58,3 @@ /** | ||
from?: Date; | ||
format?: string; | ||
cssClass?: string; | ||
@@ -75,3 +76,9 @@ to?: Date | number; | ||
title?: string; | ||
defaultDate?: Date; | ||
defaultScrollTo?: Date; | ||
defaultDate?: DefaultDate; | ||
defaultDates?: DefaultDate[]; | ||
defaultDateRange?: { | ||
from: DefaultDate; | ||
to?: DefaultDate; | ||
} | null; | ||
countNextMonths?: number; | ||
@@ -81,3 +88,13 @@ showYearPicker?: boolean; | ||
} | ||
export declare class CalendarResult { | ||
time: number; | ||
unix: number; | ||
dateObj: Date; | ||
string: string; | ||
years: number; | ||
months: number; | ||
date: number; | ||
} | ||
export declare type DefaultDate = Date | string | number | null; | ||
export declare type Colors = 'primary' | 'secondary' | 'danger' | 'light' | 'dark'; | ||
export declare type PickMode = 'multi' | 'single' | 'range'; |
@@ -19,2 +19,8 @@ var CalendarMonth = (function () { | ||
export { CalendarOptions }; | ||
var CalendarResult = (function () { | ||
function CalendarResult() { | ||
} | ||
return CalendarResult; | ||
}()); | ||
export { CalendarResult }; | ||
//# sourceMappingURL=calendar.model.js.map |
@@ -1,1 +0,1 @@ | ||
[{"__symbolic":"module","version":3,"metadata":{"CalendarOriginal":{"__symbolic":"interface"},"CalendarDay":{"__symbolic":"interface"},"CalendarMonth":{"__symbolic":"class"},"DayConfig":{"__symbolic":"class"},"CalendarOptions":{"__symbolic":"class"},"ModalOptions":{"__symbolic":"interface"},"CalendarControllerOptions":{"__symbolic":"interface"}}},{"__symbolic":"module","version":1,"metadata":{"CalendarOriginal":{"__symbolic":"interface"},"CalendarDay":{"__symbolic":"interface"},"CalendarMonth":{"__symbolic":"class"},"DayConfig":{"__symbolic":"class"},"CalendarOptions":{"__symbolic":"class"},"ModalOptions":{"__symbolic":"interface"},"CalendarControllerOptions":{"__symbolic":"interface"}}}] | ||
[{"__symbolic":"module","version":3,"metadata":{"CalendarOriginal":{"__symbolic":"interface"},"CalendarDay":{"__symbolic":"interface"},"CalendarMonth":{"__symbolic":"class"},"DayConfig":{"__symbolic":"class"},"CalendarOptions":{"__symbolic":"class"},"ModalOptions":{"__symbolic":"interface"},"CalendarControllerOptions":{"__symbolic":"interface"},"CalendarResult":{"__symbolic":"class"}}},{"__symbolic":"module","version":1,"metadata":{"CalendarOriginal":{"__symbolic":"interface"},"CalendarDay":{"__symbolic":"interface"},"CalendarMonth":{"__symbolic":"class"},"DayConfig":{"__symbolic":"class"},"CalendarOptions":{"__symbolic":"class"},"ModalOptions":{"__symbolic":"interface"},"CalendarControllerOptions":{"__symbolic":"interface"},"CalendarResult":{"__symbolic":"class"}}}] |
@@ -23,3 +23,3 @@ import { ElementRef, ChangeDetectorRef, Renderer } from '@angular/core'; | ||
weekdays: Array<string>; | ||
defaultDate: Date; | ||
defaultScrollTo: Date; | ||
scrollBackwards: boolean; | ||
@@ -42,2 +42,3 @@ weekStart: number; | ||
init(): void; | ||
initDefaultDate(): void; | ||
findCssClass(): void; | ||
@@ -56,2 +57,3 @@ onChange(data: any): void; | ||
changedYearSelection(): void; | ||
_getDayTime(date: any): number; | ||
} |
@@ -23,2 +23,3 @@ import { Component, ViewChild, ElementRef, ChangeDetectorRef, Renderer } from '@angular/core'; | ||
this.getHistory(); | ||
this.initDefaultDate(); | ||
} | ||
@@ -44,3 +45,3 @@ CalendarModal.prototype.ionViewDidLoad = function () { | ||
}; | ||
this.defaultDate = this._d.defaultDate; | ||
this.defaultScrollTo = this._d.defaultScrollTo; | ||
this.scrollBackwards = this._d.canBackwardsSelected; | ||
@@ -67,5 +68,32 @@ this.weekStart = this._d.weekStart; | ||
else { | ||
this.calendarMonths = this.calSvc.createMonthsByPeriod(startTime, this.findInitMonthNumber(this.defaultDate) + this.countNextMonths, this._d); | ||
this.calendarMonths = this.calSvc.createMonthsByPeriod(startTime, this.findInitMonthNumber(this.defaultScrollTo) + this.countNextMonths, this._d); | ||
} | ||
}; | ||
CalendarModal.prototype.initDefaultDate = function () { | ||
var _this = this; | ||
switch (this._d.pickMode) { | ||
case 'single': | ||
if (this._d.defaultDate) { | ||
this.datesTemp[0] = this.calSvc.createCalendarDay(this._getDayTime(this._d.defaultDate), this._d); | ||
} | ||
break; | ||
case 'range': | ||
if (this._d.defaultDateRange) { | ||
if (this._d.defaultDateRange.from) { | ||
this.datesTemp[0] = this.calSvc.createCalendarDay(this._getDayTime(this._d.defaultDateRange.from), this._d); | ||
} | ||
if (this._d.defaultDateRange.to) { | ||
this.datesTemp[1] = this.calSvc.createCalendarDay(this._getDayTime(this._d.defaultDateRange.to), this._d); | ||
} | ||
} | ||
break; | ||
case 'multi': | ||
if (this._d.defaultDates && this._d.defaultDates.length) { | ||
this.datesTemp = this._d.defaultDates.map(function (e) { return _this.calSvc.createCalendarDay(_this._getDayTime(e), _this._d); }); | ||
} | ||
break; | ||
default: | ||
this.datesTemp = [null, null]; | ||
} | ||
}; | ||
CalendarModal.prototype.findCssClass = function () { | ||
@@ -121,3 +149,3 @@ var _this = this; | ||
if (maxYear <= 1970) { | ||
maxYear = (new Date(this.defaultDate)).getFullYear() + 10; | ||
maxYear = (new Date(this.defaultScrollTo)).getFullYear() + 10; | ||
this.options.end = new Date(maxYear, 12, 0).getTime(); | ||
@@ -134,4 +162,4 @@ } | ||
this.years.reverse(); | ||
// selection-start-year of defaultDate | ||
this.year = this.defaultDate.getFullYear(); | ||
// selection-start-year of defaultScrollTo | ||
this.year = this.defaultScrollTo.getFullYear(); | ||
var firstDayOfYear = new Date(this.year, 0, 1); | ||
@@ -147,3 +175,3 @@ var lastDayOfYear = new Date(this.year, 12, 0); | ||
// calcing the month | ||
this.calendarMonths = this.calSvc.createMonthsByPeriod(firstDayOfYear.getTime(), this.findInitMonthNumber(this.defaultDate) + this.countNextMonths, this._d); | ||
this.calendarMonths = this.calSvc.createMonthsByPeriod(firstDayOfYear.getTime(), this.findInitMonthNumber(this.defaultScrollTo) + this.countNextMonths, this._d); | ||
// sets the range new | ||
@@ -178,3 +206,3 @@ // checking whether the start is after firstDayOfYear | ||
var _this = this; | ||
var defaultDateIndex = this.findInitMonthNumber(this.defaultDate); | ||
var defaultDateIndex = this.findInitMonthNumber(this.defaultScrollTo); | ||
var defaultDateMonth = this.monthsEle.nativeElement.children["month-" + defaultDateIndex].offsetTop; | ||
@@ -206,4 +234,4 @@ if (defaultDateIndex === 0 || defaultDateMonth === 0) | ||
var startDate = moment(this.options.start); | ||
var defaultDate = moment(date); | ||
var isAfter = defaultDate.isAfter(startDate); | ||
var defaultScrollTo = moment(date); | ||
var isAfter = defaultScrollTo.isAfter(startDate); | ||
if (!isAfter) | ||
@@ -214,3 +242,3 @@ return 0; | ||
} | ||
return defaultDate.diff(startDate, 'month'); | ||
return defaultScrollTo.diff(startDate, 'month'); | ||
}; | ||
@@ -246,2 +274,5 @@ CalendarModal.prototype.changedYearSelection = function () { | ||
}; | ||
CalendarModal.prototype._getDayTime = function (date) { | ||
return moment(moment(date).format('YYYY-MM-DD')).valueOf(); | ||
}; | ||
return CalendarModal; | ||
@@ -248,0 +279,0 @@ }()); |
@@ -1,1 +0,1 @@ | ||
[{"__symbolic":"module","version":3,"metadata":{"CalendarModal":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Component"},"arguments":[{"selector":"ion-calendar-modal","template":"\n <ion-header>\n\n <ion-navbar [color]=\"_color\">\n\n <ion-buttons start [hidden]=\"!showYearPicker\">\n <ion-select [(ngModel)]=\"year\" (ngModelChange)=\"changedYearSelection()\" interface=\"popover\">\n <ion-option *ngFor=\"let y of years\" value=\"{{y}}\">{{y}}</ion-option>\n </ion-select>\n </ion-buttons>\n\n <ion-title>{{title}}</ion-title>\n\n <ion-buttons end>\n <button ion-button clear (click)=\"onCancel()\">\n <span *ngIf=\"closeLabel !== '' && !closeIcon\">{{closeLabel}}</span>\n <ion-icon *ngIf=\"closeIcon\" name=\"close\"></ion-icon>\n </button>\n <button ion-button *ngIf=\"!_d.autoDone\" clear [disabled]=\"!canDone()\" (click)=\"done()\">\n <span *ngIf=\"doneLabel !== '' && !doneIcon\">{{doneLabel}}</span>\n <ion-icon *ngIf=\"doneIcon\" name=\"checkmark\"></ion-icon>\n </button>\n </ion-buttons>\n\n </ion-navbar>\n\n <ion-calendar-week\n [color]=\"_color\"\n [weekArray]=\"weekdays\"\n [weekStart]=\"weekStart\">\n </ion-calendar-week>\n\n </ion-header>\n\n <ion-content (ionScroll)=\"onScroll($event)\" class=\"calendar-page\" [ngClass]=\"{'multi-selection': options.pickMode === 'multi'}\">\n\n <div #months>\n <div *ngFor=\"let month of calendarMonths;let i = index;\" class=\"month-box\" [attr.id]=\"'month-' + i\">\n <h4 class=\"text-center month-title\">{{month.original.date | date:monthFormatFilterStr}}</h4>\n <ion-calendar-month [month]=\"month\"\n [pickMode]=\"options.pickMode\"\n [isSaveHistory]=\"isSaveHistory\"\n [id]=\"_id\"\n [color]=\"_color\"\n (onChange)=\"onChange($event)\"\n [(ngModel)]=\"datesTemp\">\n\n </ion-calendar-month>\n </div>\n </div>\n\n <ion-infinite-scroll (ionInfinite)=\"nextMonth($event)\">\n <ion-infinite-scroll-content></ion-infinite-scroll-content>\n </ion-infinite-scroll>\n\n </ion-content>\n "}]}],"members":{"content":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"ViewChild"},"arguments":[{"__symbolic":"reference","module":"ionic-angular","name":"Content"}]}]}],"monthsEle":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"ViewChild"},"arguments":["months"]}]}],"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","module":"@angular/core","name":"Renderer"},{"__symbolic":"reference","module":"@angular/core","name":"ElementRef"},{"__symbolic":"reference","module":"ionic-angular","name":"NavParams"},{"__symbolic":"reference","module":"ionic-angular","name":"ViewController"},{"__symbolic":"reference","module":"@angular/core","name":"ChangeDetectorRef"},{"__symbolic":"reference","module":"../services/calendar.service","name":"CalendarService"}]}],"ionViewDidLoad":[{"__symbolic":"method"}],"init":[{"__symbolic":"method"}],"findCssClass":[{"__symbolic":"method"}],"onChange":[{"__symbolic":"method"}],"onCancel":[{"__symbolic":"method"}],"done":[{"__symbolic":"method"}],"canDone":[{"__symbolic":"method"}],"getHistory":[{"__symbolic":"method"}],"createYearPicker":[{"__symbolic":"method"}],"nextMonth":[{"__symbolic":"method"}],"backwardsMonth":[{"__symbolic":"method"}],"scrollToDefaultDate":[{"__symbolic":"method"}],"onScroll":[{"__symbolic":"method"}],"findInitMonthNumber":[{"__symbolic":"method"}],"changedYearSelection":[{"__symbolic":"method"}]}}}},{"__symbolic":"module","version":1,"metadata":{"CalendarModal":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Component"},"arguments":[{"selector":"ion-calendar-modal","template":"\n <ion-header>\n\n <ion-navbar [color]=\"_color\">\n\n <ion-buttons start [hidden]=\"!showYearPicker\">\n <ion-select [(ngModel)]=\"year\" (ngModelChange)=\"changedYearSelection()\" interface=\"popover\">\n <ion-option *ngFor=\"let y of years\" value=\"{{y}}\">{{y}}</ion-option>\n </ion-select>\n </ion-buttons>\n\n <ion-title>{{title}}</ion-title>\n\n <ion-buttons end>\n <button ion-button clear (click)=\"onCancel()\">\n <span *ngIf=\"closeLabel !== '' && !closeIcon\">{{closeLabel}}</span>\n <ion-icon *ngIf=\"closeIcon\" name=\"close\"></ion-icon>\n </button>\n <button ion-button *ngIf=\"!_d.autoDone\" clear [disabled]=\"!canDone()\" (click)=\"done()\">\n <span *ngIf=\"doneLabel !== '' && !doneIcon\">{{doneLabel}}</span>\n <ion-icon *ngIf=\"doneIcon\" name=\"checkmark\"></ion-icon>\n </button>\n </ion-buttons>\n\n </ion-navbar>\n\n <ion-calendar-week\n [color]=\"_color\"\n [weekArray]=\"weekdays\"\n [weekStart]=\"weekStart\">\n </ion-calendar-week>\n\n </ion-header>\n\n <ion-content (ionScroll)=\"onScroll($event)\" class=\"calendar-page\" [ngClass]=\"{'multi-selection': options.pickMode === 'multi'}\">\n\n <div #months>\n <div *ngFor=\"let month of calendarMonths;let i = index;\" class=\"month-box\" [attr.id]=\"'month-' + i\">\n <h4 class=\"text-center month-title\">{{month.original.date | date:monthFormatFilterStr}}</h4>\n <ion-calendar-month [month]=\"month\"\n [pickMode]=\"options.pickMode\"\n [isSaveHistory]=\"isSaveHistory\"\n [id]=\"_id\"\n [color]=\"_color\"\n (onChange)=\"onChange($event)\"\n [(ngModel)]=\"datesTemp\">\n\n </ion-calendar-month>\n </div>\n </div>\n\n <ion-infinite-scroll (ionInfinite)=\"nextMonth($event)\">\n <ion-infinite-scroll-content></ion-infinite-scroll-content>\n </ion-infinite-scroll>\n\n </ion-content>\n "}]}],"members":{"content":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"ViewChild"},"arguments":[{"__symbolic":"reference","module":"ionic-angular","name":"Content"}]}]}],"monthsEle":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"ViewChild"},"arguments":["months"]}]}],"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","module":"@angular/core","name":"Renderer"},{"__symbolic":"reference","module":"@angular/core","name":"ElementRef"},{"__symbolic":"reference","module":"ionic-angular","name":"NavParams"},{"__symbolic":"reference","module":"ionic-angular","name":"ViewController"},{"__symbolic":"reference","module":"@angular/core","name":"ChangeDetectorRef"},{"__symbolic":"reference","module":"../services/calendar.service","name":"CalendarService"}]}],"ionViewDidLoad":[{"__symbolic":"method"}],"init":[{"__symbolic":"method"}],"findCssClass":[{"__symbolic":"method"}],"onChange":[{"__symbolic":"method"}],"onCancel":[{"__symbolic":"method"}],"done":[{"__symbolic":"method"}],"canDone":[{"__symbolic":"method"}],"getHistory":[{"__symbolic":"method"}],"createYearPicker":[{"__symbolic":"method"}],"nextMonth":[{"__symbolic":"method"}],"backwardsMonth":[{"__symbolic":"method"}],"scrollToDefaultDate":[{"__symbolic":"method"}],"onScroll":[{"__symbolic":"method"}],"findInitMonthNumber":[{"__symbolic":"method"}],"changedYearSelection":[{"__symbolic":"method"}]}}}}] | ||
[{"__symbolic":"module","version":3,"metadata":{"CalendarModal":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Component"},"arguments":[{"selector":"ion-calendar-modal","template":"\n <ion-header>\n\n <ion-navbar [color]=\"_color\">\n\n <ion-buttons start [hidden]=\"!showYearPicker\">\n <ion-select [(ngModel)]=\"year\" (ngModelChange)=\"changedYearSelection()\" interface=\"popover\">\n <ion-option *ngFor=\"let y of years\" value=\"{{y}}\">{{y}}</ion-option>\n </ion-select>\n </ion-buttons>\n\n <ion-title>{{title}}</ion-title>\n\n <ion-buttons end>\n <button ion-button clear (click)=\"onCancel()\">\n <span *ngIf=\"closeLabel !== '' && !closeIcon\">{{closeLabel}}</span>\n <ion-icon *ngIf=\"closeIcon\" name=\"close\"></ion-icon>\n </button>\n <button ion-button *ngIf=\"!_d.autoDone\" clear [disabled]=\"!canDone()\" (click)=\"done()\">\n <span *ngIf=\"doneLabel !== '' && !doneIcon\">{{doneLabel}}</span>\n <ion-icon *ngIf=\"doneIcon\" name=\"checkmark\"></ion-icon>\n </button>\n </ion-buttons>\n\n </ion-navbar>\n\n <ion-calendar-week\n [color]=\"_color\"\n [weekArray]=\"weekdays\"\n [weekStart]=\"weekStart\">\n </ion-calendar-week>\n\n </ion-header>\n\n <ion-content (ionScroll)=\"onScroll($event)\" class=\"calendar-page\" [ngClass]=\"{'multi-selection': options.pickMode === 'multi'}\">\n\n <div #months>\n <div *ngFor=\"let month of calendarMonths;let i = index;\" class=\"month-box\" [attr.id]=\"'month-' + i\">\n <h4 class=\"text-center month-title\">{{month.original.date | date:monthFormatFilterStr}}</h4>\n <ion-calendar-month [month]=\"month\"\n [pickMode]=\"options.pickMode\"\n [isSaveHistory]=\"isSaveHistory\"\n [id]=\"_id\"\n [color]=\"_color\"\n (onChange)=\"onChange($event)\"\n [(ngModel)]=\"datesTemp\">\n\n </ion-calendar-month>\n </div>\n </div>\n\n <ion-infinite-scroll (ionInfinite)=\"nextMonth($event)\">\n <ion-infinite-scroll-content></ion-infinite-scroll-content>\n </ion-infinite-scroll>\n\n </ion-content>\n "}]}],"members":{"content":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"ViewChild"},"arguments":[{"__symbolic":"reference","module":"ionic-angular","name":"Content"}]}]}],"monthsEle":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"ViewChild"},"arguments":["months"]}]}],"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","module":"@angular/core","name":"Renderer"},{"__symbolic":"reference","module":"@angular/core","name":"ElementRef"},{"__symbolic":"reference","module":"ionic-angular","name":"NavParams"},{"__symbolic":"reference","module":"ionic-angular","name":"ViewController"},{"__symbolic":"reference","module":"@angular/core","name":"ChangeDetectorRef"},{"__symbolic":"reference","module":"../services/calendar.service","name":"CalendarService"}]}],"ionViewDidLoad":[{"__symbolic":"method"}],"init":[{"__symbolic":"method"}],"initDefaultDate":[{"__symbolic":"method"}],"findCssClass":[{"__symbolic":"method"}],"onChange":[{"__symbolic":"method"}],"onCancel":[{"__symbolic":"method"}],"done":[{"__symbolic":"method"}],"canDone":[{"__symbolic":"method"}],"getHistory":[{"__symbolic":"method"}],"createYearPicker":[{"__symbolic":"method"}],"nextMonth":[{"__symbolic":"method"}],"backwardsMonth":[{"__symbolic":"method"}],"scrollToDefaultDate":[{"__symbolic":"method"}],"onScroll":[{"__symbolic":"method"}],"findInitMonthNumber":[{"__symbolic":"method"}],"changedYearSelection":[{"__symbolic":"method"}],"_getDayTime":[{"__symbolic":"method"}]}}}},{"__symbolic":"module","version":1,"metadata":{"CalendarModal":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Component"},"arguments":[{"selector":"ion-calendar-modal","template":"\n <ion-header>\n\n <ion-navbar [color]=\"_color\">\n\n <ion-buttons start [hidden]=\"!showYearPicker\">\n <ion-select [(ngModel)]=\"year\" (ngModelChange)=\"changedYearSelection()\" interface=\"popover\">\n <ion-option *ngFor=\"let y of years\" value=\"{{y}}\">{{y}}</ion-option>\n </ion-select>\n </ion-buttons>\n\n <ion-title>{{title}}</ion-title>\n\n <ion-buttons end>\n <button ion-button clear (click)=\"onCancel()\">\n <span *ngIf=\"closeLabel !== '' && !closeIcon\">{{closeLabel}}</span>\n <ion-icon *ngIf=\"closeIcon\" name=\"close\"></ion-icon>\n </button>\n <button ion-button *ngIf=\"!_d.autoDone\" clear [disabled]=\"!canDone()\" (click)=\"done()\">\n <span *ngIf=\"doneLabel !== '' && !doneIcon\">{{doneLabel}}</span>\n <ion-icon *ngIf=\"doneIcon\" name=\"checkmark\"></ion-icon>\n </button>\n </ion-buttons>\n\n </ion-navbar>\n\n <ion-calendar-week\n [color]=\"_color\"\n [weekArray]=\"weekdays\"\n [weekStart]=\"weekStart\">\n </ion-calendar-week>\n\n </ion-header>\n\n <ion-content (ionScroll)=\"onScroll($event)\" class=\"calendar-page\" [ngClass]=\"{'multi-selection': options.pickMode === 'multi'}\">\n\n <div #months>\n <div *ngFor=\"let month of calendarMonths;let i = index;\" class=\"month-box\" [attr.id]=\"'month-' + i\">\n <h4 class=\"text-center month-title\">{{month.original.date | date:monthFormatFilterStr}}</h4>\n <ion-calendar-month [month]=\"month\"\n [pickMode]=\"options.pickMode\"\n [isSaveHistory]=\"isSaveHistory\"\n [id]=\"_id\"\n [color]=\"_color\"\n (onChange)=\"onChange($event)\"\n [(ngModel)]=\"datesTemp\">\n\n </ion-calendar-month>\n </div>\n </div>\n\n <ion-infinite-scroll (ionInfinite)=\"nextMonth($event)\">\n <ion-infinite-scroll-content></ion-infinite-scroll-content>\n </ion-infinite-scroll>\n\n </ion-content>\n "}]}],"members":{"content":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"ViewChild"},"arguments":[{"__symbolic":"reference","module":"ionic-angular","name":"Content"}]}]}],"monthsEle":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"ViewChild"},"arguments":["months"]}]}],"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","module":"@angular/core","name":"Renderer"},{"__symbolic":"reference","module":"@angular/core","name":"ElementRef"},{"__symbolic":"reference","module":"ionic-angular","name":"NavParams"},{"__symbolic":"reference","module":"ionic-angular","name":"ViewController"},{"__symbolic":"reference","module":"@angular/core","name":"ChangeDetectorRef"},{"__symbolic":"reference","module":"../services/calendar.service","name":"CalendarService"}]}],"ionViewDidLoad":[{"__symbolic":"method"}],"init":[{"__symbolic":"method"}],"initDefaultDate":[{"__symbolic":"method"}],"findCssClass":[{"__symbolic":"method"}],"onChange":[{"__symbolic":"method"}],"onCancel":[{"__symbolic":"method"}],"done":[{"__symbolic":"method"}],"canDone":[{"__symbolic":"method"}],"getHistory":[{"__symbolic":"method"}],"createYearPicker":[{"__symbolic":"method"}],"nextMonth":[{"__symbolic":"method"}],"backwardsMonth":[{"__symbolic":"method"}],"scrollToDefaultDate":[{"__symbolic":"method"}],"onScroll":[{"__symbolic":"method"}],"findInitMonthNumber":[{"__symbolic":"method"}],"changedYearSelection":[{"__symbolic":"method"}],"_getDayTime":[{"__symbolic":"method"}]}}}}] |
@@ -1,2 +0,2 @@ | ||
import { CalendarOriginal, CalendarDay, CalendarMonth, CalendarControllerOptions } from '../calendar.model'; | ||
import { CalendarOriginal, CalendarDay, CalendarMonth, CalendarControllerOptions, CalendarResult } from '../calendar.model'; | ||
export declare class CalendarService { | ||
@@ -12,2 +12,4 @@ constructor(); | ||
savedHistory(savedDates: Array<CalendarDay | null>, id: string | number): void; | ||
wrapResult(original: CalendarDay[], pickMode: string): any; | ||
_multiFormat(data: CalendarDay): CalendarResult; | ||
} |
@@ -26,3 +26,6 @@ /** | ||
isSaveHistory: isSaveHistory, | ||
defaultDate: calendarOptions.defaultDate || from, | ||
defaultScrollTo: calendarOptions.defaultScrollTo || from, | ||
defaultDate: calendarOptions.defaultDate || null, | ||
defaultDates: calendarOptions.defaultDates || null, | ||
defaultDateRange: calendarOptions.defaultDateRange || null, | ||
disableWeeks: disableWeeks, | ||
@@ -141,2 +144,35 @@ monthFormat: monthFormat, | ||
}; | ||
CalendarService.prototype.wrapResult = function (original, pickMode) { | ||
var _this = this; | ||
var result; | ||
switch (pickMode) { | ||
case 'single': | ||
result = this._multiFormat(original[0]); | ||
break; | ||
case 'range': | ||
result = { | ||
from: this._multiFormat(original[0]), | ||
to: this._multiFormat(original[1]), | ||
}; | ||
break; | ||
case 'multi': | ||
result = original.map(function (e) { return _this._multiFormat(e); }); | ||
break; | ||
default: | ||
result = original; | ||
} | ||
return result; | ||
}; | ||
CalendarService.prototype._multiFormat = function (data) { | ||
var _moment = moment(data.time); | ||
return { | ||
time: _moment.valueOf(), | ||
unix: _moment.unix(), | ||
dateObj: _moment.toDate(), | ||
string: _moment.format('YYYY-MM-DD'), | ||
years: _moment.year(), | ||
months: _moment.month() + 1, | ||
date: _moment.date() | ||
}; | ||
}; | ||
return CalendarService; | ||
@@ -143,0 +179,0 @@ }()); |
@@ -1,1 +0,1 @@ | ||
[{"__symbolic":"module","version":3,"metadata":{"CalendarService":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable"}}],"members":{"__ctor__":[{"__symbolic":"constructor"}],"safeOpt":[{"__symbolic":"method"}],"createOriginalCalendar":[{"__symbolic":"method"}],"findDayConfig":[{"__symbolic":"method"}],"createCalendarDay":[{"__symbolic":"method"}],"createCalendarMonth":[{"__symbolic":"method"}],"createMonthsByPeriod":[{"__symbolic":"method"}],"getHistory":[{"__symbolic":"method"}],"savedHistory":[{"__symbolic":"method"}]}}}},{"__symbolic":"module","version":1,"metadata":{"CalendarService":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable"}}],"members":{"__ctor__":[{"__symbolic":"constructor"}],"safeOpt":[{"__symbolic":"method"}],"createOriginalCalendar":[{"__symbolic":"method"}],"findDayConfig":[{"__symbolic":"method"}],"createCalendarDay":[{"__symbolic":"method"}],"createCalendarMonth":[{"__symbolic":"method"}],"createMonthsByPeriod":[{"__symbolic":"method"}],"getHistory":[{"__symbolic":"method"}],"savedHistory":[{"__symbolic":"method"}]}}}}] | ||
[{"__symbolic":"module","version":3,"metadata":{"CalendarService":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable"}}],"members":{"__ctor__":[{"__symbolic":"constructor"}],"safeOpt":[{"__symbolic":"method"}],"createOriginalCalendar":[{"__symbolic":"method"}],"findDayConfig":[{"__symbolic":"method"}],"createCalendarDay":[{"__symbolic":"method"}],"createCalendarMonth":[{"__symbolic":"method"}],"createMonthsByPeriod":[{"__symbolic":"method"}],"getHistory":[{"__symbolic":"method"}],"savedHistory":[{"__symbolic":"method"}],"wrapResult":[{"__symbolic":"method"}],"_multiFormat":[{"__symbolic":"method"}]}}}},{"__symbolic":"module","version":1,"metadata":{"CalendarService":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable"}}],"members":{"__ctor__":[{"__symbolic":"constructor"}],"safeOpt":[{"__symbolic":"method"}],"createOriginalCalendar":[{"__symbolic":"method"}],"findDayConfig":[{"__symbolic":"method"}],"createCalendarDay":[{"__symbolic":"method"}],"createCalendarMonth":[{"__symbolic":"method"}],"createMonthsByPeriod":[{"__symbolic":"method"}],"getHistory":[{"__symbolic":"method"}],"savedHistory":[{"__symbolic":"method"}],"wrapResult":[{"__symbolic":"method"}],"_multiFormat":[{"__symbolic":"method"}]}}}}] |
{ | ||
"name": "ion2-calendar", | ||
"version": "2.0.0-beta.5", | ||
"version": "2.0.0-beta.6", | ||
"description": "A date picker for ionic2 ", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
@@ -27,3 +27,2 @@ import { Injectable } from '@angular/core'; | ||
console.log(options) | ||
calendarModal.present(); | ||
@@ -34,27 +33,7 @@ | ||
calendarModal.onDidDismiss((data:any) => { | ||
let res: any; | ||
if (data && Array.isArray(data)) { | ||
switch (options.pickMode) { | ||
case 'single': | ||
res = { date: data[0] }; | ||
break; | ||
case 'range': | ||
res = { | ||
from: data[0], | ||
to: data[1], | ||
}; | ||
break; | ||
case 'multi': | ||
res = data; | ||
break; | ||
default: | ||
res = data; | ||
} | ||
resolve(res); | ||
resolve(this.calSvc.wrapResult(data, options.pickMode)); | ||
} else { | ||
reject('cancelled') | ||
} | ||
}); | ||
@@ -61,0 +40,0 @@ }); |
@@ -64,2 +64,3 @@ /** | ||
from?: Date; | ||
format?: string; | ||
cssClass?: string; | ||
@@ -81,3 +82,6 @@ to?: Date | number; | ||
title?: string; | ||
defaultDate?: Date; | ||
defaultScrollTo?: Date; | ||
defaultDate?: DefaultDate; | ||
defaultDates?: DefaultDate[]; | ||
defaultDateRange?: { from:DefaultDate, to?: DefaultDate } | null; | ||
countNextMonths?: number; | ||
@@ -88,3 +92,14 @@ showYearPicker?: boolean; | ||
export class CalendarResult { | ||
time: number; | ||
unix: number; | ||
dateObj: Date; | ||
string: string; | ||
years: number; | ||
months: number; | ||
date: number; | ||
} | ||
export type DefaultDate = Date | string | number | null; | ||
export type Colors = 'primary' | 'secondary' | 'danger' | 'light' | 'dark' | ||
export type PickMode = 'multi' | 'single' | 'range' |
@@ -19,3 +19,2 @@ /** | ||
calSvc: CalendarService, | ||
) { | ||
@@ -22,0 +21,0 @@ return new CalendarController(modalCtrl, calSvc); |
@@ -84,3 +84,3 @@ import {Component, ViewChild, ElementRef, ChangeDetectorRef, Renderer} from '@angular/core'; | ||
weekdays: Array<string> = []; | ||
defaultDate: Date; | ||
defaultScrollTo: Date; | ||
scrollBackwards: boolean; | ||
@@ -112,2 +112,3 @@ weekStart: number = 0; | ||
this.getHistory(); | ||
this.initDefaultDate(); | ||
} | ||
@@ -138,3 +139,3 @@ | ||
this.defaultDate = this._d.defaultDate; | ||
this.defaultScrollTo = this._d.defaultScrollTo; | ||
this.scrollBackwards = this._d.canBackwardsSelected; | ||
@@ -168,3 +169,3 @@ this.weekStart = this._d.weekStart; | ||
startTime, | ||
this.findInitMonthNumber(this.defaultDate) + this.countNextMonths, | ||
this.findInitMonthNumber(this.defaultScrollTo) + this.countNextMonths, | ||
this._d, | ||
@@ -175,2 +176,29 @@ ); | ||
initDefaultDate() { | ||
switch (this._d.pickMode) { | ||
case 'single': | ||
if (this._d.defaultDate) { | ||
this.datesTemp[0] = this.calSvc.createCalendarDay(this._getDayTime(this._d.defaultDate), this._d); | ||
} | ||
break; | ||
case 'range': | ||
if (this._d.defaultDateRange) { | ||
if (this._d.defaultDateRange.from) { | ||
this.datesTemp[0] = this.calSvc.createCalendarDay(this._getDayTime(this._d.defaultDateRange.from), this._d); | ||
} | ||
if (this._d.defaultDateRange.to) { | ||
this.datesTemp[1] = this.calSvc.createCalendarDay(this._getDayTime(this._d.defaultDateRange.to), this._d); | ||
} | ||
} | ||
break; | ||
case 'multi': | ||
if (this._d.defaultDates && this._d.defaultDates.length) { | ||
this.datesTemp = this._d.defaultDates.map(e => this.calSvc.createCalendarDay(this._getDayTime(e), this._d)); | ||
} | ||
break; | ||
default: | ||
this.datesTemp = [null, null] | ||
} | ||
} | ||
findCssClass() { | ||
@@ -236,3 +264,3 @@ let cssClass = this.params.get('cssClass'); | ||
if (maxYear <= 1970) { | ||
maxYear = (new Date(this.defaultDate)).getFullYear() + 10; | ||
maxYear = (new Date(this.defaultScrollTo)).getFullYear() + 10; | ||
this.options.end = new Date(maxYear, 12, 0).getTime(); | ||
@@ -253,4 +281,4 @@ } | ||
this.years.reverse(); | ||
// selection-start-year of defaultDate | ||
this.year = this.defaultDate.getFullYear(); | ||
// selection-start-year of defaultScrollTo | ||
this.year = this.defaultScrollTo.getFullYear(); | ||
let firstDayOfYear = new Date(this.year, 0, 1); | ||
@@ -270,3 +298,3 @@ let lastDayOfYear = new Date(this.year, 12, 0); | ||
firstDayOfYear.getTime(), | ||
this.findInitMonthNumber(this.defaultDate) + this.countNextMonths, | ||
this.findInitMonthNumber(this.defaultScrollTo) + this.countNextMonths, | ||
this._d); | ||
@@ -307,3 +335,3 @@ // sets the range new | ||
scrollToDefaultDate() { | ||
let defaultDateIndex = this.findInitMonthNumber(this.defaultDate); | ||
let defaultDateIndex = this.findInitMonthNumber(this.defaultScrollTo); | ||
let defaultDateMonth = this.monthsEle.nativeElement.children[`month-${defaultDateIndex}`].offsetTop; | ||
@@ -335,4 +363,4 @@ | ||
let startDate = moment(this.options.start); | ||
let defaultDate = moment(date); | ||
const isAfter: boolean = defaultDate.isAfter(startDate); | ||
let defaultScrollTo = moment(date); | ||
const isAfter: boolean = defaultScrollTo.isAfter(startDate); | ||
if (!isAfter) return 0; | ||
@@ -345,3 +373,3 @@ | ||
return defaultDate.diff(startDate, 'month'); | ||
return defaultScrollTo.diff(startDate, 'month'); | ||
} | ||
@@ -378,2 +406,5 @@ | ||
_getDayTime(date: any): number { | ||
return moment(moment(date).format('YYYY-MM-DD')).valueOf(); | ||
} | ||
} |
@@ -5,3 +5,3 @@ /** | ||
import { Injectable } from '@angular/core'; | ||
import { CalendarOriginal, CalendarDay, CalendarMonth, CalendarControllerOptions, DayConfig } from '../calendar.model' | ||
import {CalendarOriginal, CalendarDay, CalendarMonth, CalendarControllerOptions, DayConfig, CalendarResult} from '../calendar.model' | ||
import * as moment from 'moment'; | ||
@@ -58,3 +58,6 @@ | ||
isSaveHistory: isSaveHistory, | ||
defaultDate: calendarOptions.defaultDate || from, | ||
defaultScrollTo: calendarOptions.defaultScrollTo || from, | ||
defaultDate: calendarOptions.defaultDate || null, | ||
defaultDates: calendarOptions.defaultDates || null, | ||
defaultDateRange: calendarOptions.defaultDateRange || null, | ||
disableWeeks: disableWeeks, | ||
@@ -190,2 +193,36 @@ monthFormat: monthFormat, | ||
wrapResult(original: CalendarDay[], pickMode: string) { | ||
let result: any; | ||
switch (pickMode) { | ||
case 'single': | ||
result = this._multiFormat(original[0]); | ||
break; | ||
case 'range': | ||
result = { | ||
from: this._multiFormat(original[0]), | ||
to: this._multiFormat(original[1]), | ||
}; | ||
break; | ||
case 'multi': | ||
result = original.map(e => this._multiFormat(e)); | ||
break; | ||
default: | ||
result = original; | ||
} | ||
return result; | ||
} | ||
_multiFormat(data: CalendarDay): CalendarResult { | ||
const _moment = moment(data.time); | ||
return { | ||
time: _moment.valueOf(), | ||
unix: _moment.unix(), | ||
dateObj: _moment.toDate(), | ||
string: _moment.format('YYYY-MM-DD'), | ||
years: _moment.year(), | ||
months: _moment.month() + 1, | ||
date: _moment.date() | ||
} | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
248645
4004