mirror of
https://github.com/frappe/air-datepicker.git
synced 2026-01-14 11:01:22 +08:00
add ability to select multiple dates
This commit is contained in:
parent
8b65c88c82
commit
38e199d5be
33
dist/js/datepicker.js
vendored
33
dist/js/datepicker.js
vendored
@ -21,7 +21,7 @@ var Datepicker;
|
|||||||
minDate: '',
|
minDate: '',
|
||||||
maxData: '',
|
maxData: '',
|
||||||
|
|
||||||
//TODO сделать множественные даты
|
//TODO возможно добавить огрнаичивать число выделяемых дат
|
||||||
multipleDates: false,
|
multipleDates: false,
|
||||||
|
|
||||||
// navigation
|
// navigation
|
||||||
@ -29,6 +29,7 @@ var Datepicker;
|
|||||||
nextHtml: '»',
|
nextHtml: '»',
|
||||||
|
|
||||||
// events
|
// events
|
||||||
|
// TODO сделать с множественными датами
|
||||||
onChange: ''
|
onChange: ''
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -160,7 +161,10 @@ var Datepicker;
|
|||||||
|
|
||||||
selectDate: function (date) {
|
selectDate: function (date) {
|
||||||
if (this.opts.multipleDates) {
|
if (this.opts.multipleDates) {
|
||||||
// validate, push
|
if (!this._isSelected(date)) {
|
||||||
|
console.log('push');
|
||||||
|
this.selectedDates.push(date);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
this.selectedDates = [date];
|
this.selectedDates = [date];
|
||||||
}
|
}
|
||||||
@ -168,6 +172,12 @@ var Datepicker;
|
|||||||
this.views[this.currentView]._render()
|
this.views[this.currentView]._render()
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_isSelected: function (checkDate, cellType) {
|
||||||
|
return this.selectedDates.some(function (date) {
|
||||||
|
return Datepicker.isSame(date, checkDate, cellType)
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
get parsedDate() {
|
get parsedDate() {
|
||||||
return Datepicker.getParsedDate(this.date);
|
return Datepicker.getParsedDate(this.date);
|
||||||
},
|
},
|
||||||
@ -446,7 +456,7 @@ Datepicker.Cell = function () {
|
|||||||
if (this.d.isWeekend(d.day)) _class += " -weekend-";
|
if (this.d.isWeekend(d.day)) _class += " -weekend-";
|
||||||
if (d.month != this.d.parsedDate.month) _class += " -another-month-";
|
if (d.month != this.d.parsedDate.month) _class += " -another-month-";
|
||||||
if (Datepicker.isSame(currentDate, date)) _class += ' -current-';
|
if (Datepicker.isSame(currentDate, date)) _class += ' -current-';
|
||||||
if (this._isSelected(date, 'day')) _class += ' -selected-';
|
if (this.d._isSelected(date, 'day')) _class += ' -selected-';
|
||||||
|
|
||||||
return '<div class="' + _class + '" data-date="' + date.getDate() + '">' + date.getDate() + '</div>';
|
return '<div class="' + _class + '" data-date="' + date.getDate() + '">' + date.getDate() + '</div>';
|
||||||
},
|
},
|
||||||
@ -534,23 +544,6 @@ Datepicker.Cell = function () {
|
|||||||
this._renderTypes[this.type].bind(this)()
|
this._renderTypes[this.type].bind(this)()
|
||||||
},
|
},
|
||||||
|
|
||||||
_isSelected: function (cellDate, cellType) {
|
|
||||||
var selectedDates = this.d.selectedDates,
|
|
||||||
len = selectedDates.length,
|
|
||||||
result;
|
|
||||||
|
|
||||||
if (!len) return false;
|
|
||||||
|
|
||||||
for (var i = 0; i < len; i++) {
|
|
||||||
if (Datepicker.isSame(selectedDates[i], cellDate, cellType)) {
|
|
||||||
result = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
},
|
|
||||||
|
|
||||||
show: function () {
|
show: function () {
|
||||||
this.$el.addClass('active');
|
this.$el.addClass('active');
|
||||||
this.acitve = true;
|
this.acitve = true;
|
||||||
|
|||||||
@ -92,7 +92,7 @@
|
|||||||
if (this.d.isWeekend(d.day)) _class += " -weekend-";
|
if (this.d.isWeekend(d.day)) _class += " -weekend-";
|
||||||
if (d.month != this.d.parsedDate.month) _class += " -another-month-";
|
if (d.month != this.d.parsedDate.month) _class += " -another-month-";
|
||||||
if (Datepicker.isSame(currentDate, date)) _class += ' -current-';
|
if (Datepicker.isSame(currentDate, date)) _class += ' -current-';
|
||||||
if (this._isSelected(date, 'day')) _class += ' -selected-';
|
if (this.d._isSelected(date, 'day')) _class += ' -selected-';
|
||||||
|
|
||||||
return '<div class="' + _class + '" data-date="' + date.getDate() + '">' + date.getDate() + '</div>';
|
return '<div class="' + _class + '" data-date="' + date.getDate() + '">' + date.getDate() + '</div>';
|
||||||
},
|
},
|
||||||
@ -180,23 +180,6 @@
|
|||||||
this._renderTypes[this.type].bind(this)()
|
this._renderTypes[this.type].bind(this)()
|
||||||
},
|
},
|
||||||
|
|
||||||
_isSelected: function (cellDate, cellType) {
|
|
||||||
var selectedDates = this.d.selectedDates,
|
|
||||||
len = selectedDates.length,
|
|
||||||
result;
|
|
||||||
|
|
||||||
if (!len) return false;
|
|
||||||
|
|
||||||
for (var i = 0; i < len; i++) {
|
|
||||||
if (Datepicker.isSame(selectedDates[i], cellDate, cellType)) {
|
|
||||||
result = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
},
|
|
||||||
|
|
||||||
show: function () {
|
show: function () {
|
||||||
this.$el.addClass('active');
|
this.$el.addClass('active');
|
||||||
this.acitve = true;
|
this.acitve = true;
|
||||||
|
|||||||
@ -21,7 +21,7 @@ var Datepicker;
|
|||||||
minDate: '',
|
minDate: '',
|
||||||
maxData: '',
|
maxData: '',
|
||||||
|
|
||||||
//TODO сделать множественные даты
|
//TODO возможно добавить огрнаичивать число выделяемых дат
|
||||||
multipleDates: false,
|
multipleDates: false,
|
||||||
|
|
||||||
// navigation
|
// navigation
|
||||||
@ -29,6 +29,7 @@ var Datepicker;
|
|||||||
nextHtml: '»',
|
nextHtml: '»',
|
||||||
|
|
||||||
// events
|
// events
|
||||||
|
// TODO сделать с множественными датами
|
||||||
onChange: ''
|
onChange: ''
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -160,7 +161,10 @@ var Datepicker;
|
|||||||
|
|
||||||
selectDate: function (date) {
|
selectDate: function (date) {
|
||||||
if (this.opts.multipleDates) {
|
if (this.opts.multipleDates) {
|
||||||
// validate, push
|
if (!this._isSelected(date)) {
|
||||||
|
console.log('push');
|
||||||
|
this.selectedDates.push(date);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
this.selectedDates = [date];
|
this.selectedDates = [date];
|
||||||
}
|
}
|
||||||
@ -168,6 +172,12 @@ var Datepicker;
|
|||||||
this.views[this.currentView]._render()
|
this.views[this.currentView]._render()
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_isSelected: function (checkDate, cellType) {
|
||||||
|
return this.selectedDates.some(function (date) {
|
||||||
|
return Datepicker.isSame(date, checkDate, cellType)
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
get parsedDate() {
|
get parsedDate() {
|
||||||
return Datepicker.getParsedDate(this.date);
|
return Datepicker.getParsedDate(this.date);
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user