From c7eb28908f135f884ffc5157489b9ffc271b7315 Mon Sep 17 00:00:00 2001 From: cagataycivici Date: Wed, 15 May 2019 15:54:07 +0300 Subject: [PATCH] Min-Max, Disabled Dates and Navigator support for Calendar --- src/components/calendar/Calendar.vue | 61 ++++++++++++++++++++++++++-- src/views/calendar/CalendarDemo.vue | 40 +++++++++++++++++- 2 files changed, 97 insertions(+), 4 deletions(-) diff --git a/src/components/calendar/Calendar.vue b/src/components/calendar/Calendar.vue index 6256fc4b6..e98cce941 100644 --- a/src/components/calendar/Calendar.vue +++ b/src/components/calendar/Calendar.vue @@ -14,7 +14,13 @@
{{locale.monthNames[month.month]}} + {{view === 'month' ? currentYear : month.year}} +
@@ -90,8 +96,16 @@ export default { type: Boolean, default: false }, - panelClass: String, - panelStyle: null, + yearRange: { + type: String, + default: null + }, + panelClass: { + type: String + }, + panelStyle: { + type: null + }, minDate: { type: Date, value: null @@ -125,7 +139,9 @@ export default { } } }, - appendTo: null, + appendTo: { + type: null + }, showOnFocus: { type: Boolean, default: true @@ -412,6 +428,33 @@ export default { else { this.overlayVisible = false; } + }, + isDateDisabled(day, month, year) { + if (this.disabledDates) { + for (let disabledDate of this.disabledDates) { + if (disabledDate.getFullYear() === year && disabledDate.getMonth() === month && disabledDate.getDate() === day) { + return true; + } + } + } + + return false; + }, + isDayDisabled(day, month, year) { + if (this.disabledDays) { + let weekday = new Date(year, month, day); + let weekdayNumber = weekday.getDay(); + return this.disabledDays.indexOf(weekdayNumber) !== -1; + } + return false; + }, + onMonthDropdownChange(value) { + this.currentMonth = parseInt(value); + this.$emit('month-change', {month: this.currentMonth + 1, year: this.currentYear}); + }, + onYearDropdownChange(value) { + this.currentYear = parseInt(value); + this.$emit('year-change', {month: this.currentMonth + 1, year: this.currentYear}); } }, computed: { @@ -541,6 +584,18 @@ export default { }, datePattern() { return this.dateFormat || this.locale.dateFormat; + }, + yearOptions() { + const years = this.yearRange.split(':'); + const yearStart = parseInt(years[0]); + const yearEnd = parseInt(years[1]); + let yearOptions = []; + + for (let i = yearStart; i <= yearEnd; i++) { + yearOptions.push(i); + } + + return yearOptions; } }, components: { diff --git a/src/views/calendar/CalendarDemo.vue b/src/views/calendar/CalendarDemo.vue index 1ea4fb3a9..9b1425339 100644 --- a/src/views/calendar/CalendarDemo.vue +++ b/src/views/calendar/CalendarDemo.vue @@ -21,6 +21,18 @@

Icon

+
+

Min-Max

+ +
+
+

Disable Days

+ +
+
+

Navigators

+ +
@@ -32,11 +44,34 @@ import CalendarDoc from './CalendarDoc' export default { + created() { + console.log(this.es.firstDayOfWeek); + let today = new Date(); + let month = today.getMonth(); + let year = today.getFullYear(); + let prevMonth = (month === 0) ? 11 : month -1; + let prevYear = (prevMonth === 11) ? year - 1 : year; + let nextMonth = (month === 11) ? 0 : month + 1; + let nextYear = (nextMonth === 0) ? year + 1 : year; + this.minDate = new Date(); + this.minDate.setMonth(prevMonth); + this.minDate.setFullYear(prevYear); + this.maxDate = new Date(); + this.maxDate.setMonth(nextMonth); + this.maxDate.setFullYear(nextYear); + + let invalidDate = new Date(); + invalidDate.setDate(today.getDate() - 1); + this.invalidDates = [today,invalidDate]; + }, data() { return { date1: null, date2: null, date3: null, + date4: null, + date5: null, + date6: null, es: { firstDayOfWeek: 1, dayNames: [ "Domingo","Lunes","Martes","Miércoles","Jueves","Viernes","Sábado" ], @@ -47,7 +82,10 @@ export default { today: 'Hoy', clear: 'Borrar', weekHeader: 'Sm' - } + }, + minDate: null, + maxDate: null, + invalidDates: null } }, components: {