From d82b5c26bfc9141d25d7028d7c1bf9e8666614e7 Mon Sep 17 00:00:00 2001 From: Cyril Gravelier Date: Fri, 8 Jul 2011 12:03:06 +0200 Subject: [PATCH 1/6] Add restriction on days Add on option to restrict the selectable days. --- timeframe.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/timeframe.js b/timeframe.js index 96e4bf9..3401f77 100644 --- a/timeframe.js +++ b/timeframe.js @@ -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'; @@ -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'); From 9aec52611708d9783943c6570d426ed088ff6257 Mon Sep 17 00:00:00 2001 From: Cyril Gravelier Date: Fri, 8 Jul 2011 14:06:43 +0200 Subject: [PATCH 2/6] Add minRange Add an option to define the minimum range. --- timeframe.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/timeframe.js b/timeframe.js index 3401f77..91dd111 100644 --- a/timeframe.js +++ b/timeframe.js @@ -33,6 +33,7 @@ var Timeframe = Class.create({ this.format = this.options.get('format') || Locale.get('format'); this.weekOffset = this.options.get('weekOffset') || Locale.get('weekOffset'); this.maxRange = this.options.get('maxRange'); + this.minRange = this.options.get('minRange'); this.selectableDays = this.options.get('selectableDays') || new Array(0, 1, 2, 3, 4, 5, 6); @@ -437,6 +438,16 @@ var Timeframe = Class.create({ } } } + + if (this.minRange) { + var range = this.minRange; + var days = parseInt((end - start) / 86400000); + + if (days < range) { + end = new Date(this.startdrag); + end.setDate(end.getDate() + range); + } + } this.range.set('start', start); this.range.set('end', end); }, From 009637cbebea43a95e7588dedd58cc3523b7059a Mon Sep 17 00:00:00 2001 From: Cyril Gravelier Date: Fri, 8 Jul 2011 14:24:04 +0200 Subject: [PATCH 3/6] Revert d82b5c26bfc9141d25d7028d7c1bf9e8666614e7^..HEAD --- timeframe.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/timeframe.js b/timeframe.js index 91dd111..ad262f9 100644 --- a/timeframe.js +++ b/timeframe.js @@ -287,6 +287,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; }, From 6099892aa3baeaa25c14b7aba55e0b125a43feb5 Mon Sep 17 00:00:00 2001 From: Cyril Gravelier Date: Fri, 8 Jul 2011 14:24:10 +0200 Subject: [PATCH 4/6] Revert d82b5c26bfc9141d25d7028d7c1bf9e8666614e7^..HEAD --- timeframe.js | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/timeframe.js b/timeframe.js index ad262f9..96e4bf9 100644 --- a/timeframe.js +++ b/timeframe.js @@ -33,9 +33,6 @@ var Timeframe = Class.create({ this.format = this.options.get('format') || Locale.get('format'); this.weekOffset = this.options.get('weekOffset') || Locale.get('weekOffset'); this.maxRange = this.options.get('maxRange'); - this.minRange = this.options.get('minRange'); - - 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'; @@ -135,7 +132,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) || !this.selectableDays.include(day.date.getDay())) + if ((this.earliest && day.date < this.earliest) || (this.latest && day.date > this.latest)) day.addClassName('unselectable'); else day.addClassName('selectable'); @@ -287,8 +284,6 @@ 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; }, @@ -440,16 +435,6 @@ var Timeframe = Class.create({ } } } - - if (this.minRange) { - var range = this.minRange; - var days = parseInt((end - start) / 86400000); - - if (days < range) { - end = new Date(this.startdrag); - end.setDate(end.getDate() + range); - } - } this.range.set('start', start); this.range.set('end', end); }, From 699a9813442475297dadc42e4c3f8e3f11a00929 Mon Sep 17 00:00:00 2001 From: Cyril Gravelier Date: Fri, 8 Jul 2011 14:26:47 +0200 Subject: [PATCH 5/6] Add fields validation about the date restriction --- timeframe.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/timeframe.js b/timeframe.js index 96e4bf9..1024043 100644 --- a/timeframe.js +++ b/timeframe.js @@ -284,6 +284,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; }, From b33f6b4a89d0a5c26dd58af78b6625b7845a8038 Mon Sep 17 00:00:00 2001 From: Cyril Gravelier Date: Fri, 8 Jul 2011 14:43:19 +0200 Subject: [PATCH 6/6] Add restriction on days (finally I'm gonna succed in my commits.) --- timeframe.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/timeframe.js b/timeframe.js index 1024043..db15ce0 100644 --- a/timeframe.js +++ b/timeframe.js @@ -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'; @@ -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');