Skip to content

Commit

Permalink
add endate by count (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
flug authored May 13, 2020
1 parent 30ae42a commit 3767ac9
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/Resources/translations/messages.bg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ coop_tilleuls_click_n_collect:
sunday: Нед.
rrule_schedule: Работно време
rrule_dtstart: Начална дата
rrule_dtend: Крайна дата
rrule_expert: Начин за напреднали
rrule_toggle: Смени
order_preparation_delay: Време за приготвяне на поръчката (в минути)
Expand Down
1 change: 1 addition & 0 deletions src/Resources/translations/messages.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ coop_tilleuls_click_n_collect:
sunday: Sun.
rrule_schedule: Opening hours
rrule_dtstart: Start date
rrule_dtend: End date
rrule_expert: Advanced mode
rrule_toggle: Toggle
order_preparation_delay: Order preparation delay (in minutes)
Expand Down
1 change: 1 addition & 0 deletions src/Resources/translations/messages.es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ coop_tilleuls_click_n_collect:
sunday: Dom.
rrule_schedule: Hora de apertura
rrule_dtstart: Fecha de inicio
rrule_dtend: Fecha final
rrule_expert: Modo avanzado
rrule_toggle: Alternar
order_preparation_delay: Retraso en la preparación del pedido (en minutos)
Expand Down
1 change: 1 addition & 0 deletions src/Resources/translations/messages.fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ coop_tilleuls_click_n_collect:
sunday: Dim.
rrule_schedule: Horaires d'ouverture
rrule_dtstart: Date de début
rrule_dtend: Date de fin
rrule_expert: Mode Avancé
rrule_toggle: Afficher
order_preparation_delay: Delai de préparation de commande (en minutes)
Expand Down
1 change: 1 addition & 0 deletions src/Resources/translations/messages.pl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ coop_tilleuls_click_n_collect:
sunday: Nie.
rrule_schedule: Godziny otwarcia
rrule_dtstart: Data rozpoczęcia
rrule_dtend: Data końcowa
rrule_expert: Tryb zaawansowany
rrule_toggle: Przełącz
order_preparation_delay: Opóźnienie dla przygotowania zamówienia (w minutach)
Expand Down
39 changes: 33 additions & 6 deletions src/Resources/views/Admin/Form/_scripts.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ document.addEventListener('DOMContentLoaded', function() {
date: document.querySelector('.location-rrule-date-widget'),
expert: document.querySelector('.location-rrule-expert-widget button'),
input: document.querySelector('.location-rrule-widget'),
dtend: document.querySelector('.location-rrule-dtend-widget')
}
var locationRRule = new rrule.RRule.fromString(DEFAULT_RRULE_STRING)
Expand Down Expand Up @@ -67,6 +68,10 @@ document.addEventListener('DOMContentLoaded', function() {
return hour + 'h'
}))
fields.date.value = (locationRRule.options.dtstart || new Date(Date.UTC)).toISOString().slice(0,10)
if (locationRRule.options.count !== null) {
var endDate = locationRRule.all()[locationRRule.all().length - 1]
fields.dtend.value = endDate.toISOString().slice(0, 10)
}
}
function listen() {
Expand Down Expand Up @@ -108,7 +113,7 @@ document.addEventListener('DOMContentLoaded', function() {
})
})
fields.date.addEventListener('change', function() {
fields.date.addEventListener('change', function () {
var date = new Date(this.value)
apply({
Expand All @@ -122,10 +127,28 @@ document.addEventListener('DOMContentLoaded', function() {
),
})
})
fields.dtend.addEventListener('change', function () {
var date = new Date(this.value);
if (date.toString() === 'Invalid Date') {
return;
}
apply({
endDate: new Date(
Date.UTC(
date.getFullYear(),
date.getMonth(),
date.getDate()
)
),
})
})
}
function apply(changes) {
var dtstart = (changes.dtstart || locationRRule.options.dtstart)
var endDate = (changes.endDate)
var openingHours = Array.prototype.slice.call(changes.byhour || locationRRule.options.byhour || [8])
.sort(function(a, b) {
return a - b
Expand All @@ -143,11 +166,15 @@ document.addEventListener('DOMContentLoaded', function() {
))
var dtend = new Date(dtstart)
if (locationRRule.options.freq === rrule.RRule.HOURLY) {
dtend.setUTCHours(dtstart.getUTCHours() + locationRRule.options.interval)
} else if (locationRRule.options.freq === rrule.RRule.MINUTELY) {
dtend.setUTCMinutes(dtstart.getUTCMinutes() + locationRRule.options.interval)
if (endDate instanceof Date) {
dtend = endDate
} else {
if (locationRRule.options.freq === rrule.RRule.HOURLY) {
dtend.setUTCHours(dtstart.getUTCHours() + locationRRule.options.interval)
} else if (locationRRule.options.freq === rrule.RRule.MINUTELY) {
dtend.setUTCMinutes(dtstart.getUTCMinutes() + locationRRule.options.interval)
}
}
fields.input.value = locationRRule.toString()
Expand Down
4 changes: 4 additions & 0 deletions src/Resources/views/Admin/Form/theme.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@
<label><small>{{ 'coop_tilleuls_click_n_collect.form.location.rrule_dtstart'|trans }}</small></label>
<input type="date" class="location-rrule-date-widget" />
</div>
<div class="seven wide field location-rrule-date-row">
<label><small>{{ 'coop_tilleuls_click_n_collect.form.location.rrule_dtend'|trans }}</small></label>
<input type="date" class="location-rrule-dtend-widget" />
</div>
<div class="four wide field location-rrule-expert-row">
<label><small>{{ 'coop_tilleuls_click_n_collect.form.location.rrule_expert'|trans }}</small></label>
<div class="location-rrule-expert-widget">
Expand Down

0 comments on commit 3767ac9

Please sign in to comment.