Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add restriction on days #6

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion timeframe.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ var Timeframe = Class.create({
this.weekOffset = this.options.get('weekOffset') || Locale.get('weekOffset');
this.maxRange = this.options.get('maxRange');

this.selectableDays = this.options.get('selectableDays') || new Array(0, 1, 2, 3, 4, 5, 6);

this.firstDayId = this.element.id + '_firstday';
this.lastDayId = this.element.id + '_lastday';

Expand Down Expand Up @@ -132,7 +134,7 @@ var Timeframe = Class.create({
calendar.select('td').each(function(day) {
day.date = new Date(iterator); // Is this expensive (we unload these later)? We could store the epoch time instead.
day.update(day.date.getDate()).writeAttribute('class', inactive || 'active');
if ((this.earliest && day.date < this.earliest) || (this.latest && day.date > this.latest))
if ((this.earliest && day.date < this.earliest) || (this.latest && day.date > this.latest) || !this.selectableDays.include(day.date.getDay()))
day.addClassName('unselectable');
else
day.addClassName('selectable');
Expand Down Expand Up @@ -284,6 +286,8 @@ var Timeframe = Class.create({
error = 'soft';
else if (fieldName == 'end' && this.range.get('start') && date < this.range.get('start'))
error = 'soft';
else if (!this.selectableDays.include(date.getDay()))
error = 'hard';
return error;
},

Expand Down