Skip to content
Merged
Show file tree
Hide file tree
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
18 changes: 18 additions & 0 deletions app/javascript/activities.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,24 @@ document.addEventListener('turbo:load', () => {
if (element) {
const priceLists = JSON.parse(element.dataset.priceLists);

// Keep the activity's duration when the start time is changed
const startInput = element.querySelector('#activity_start_time');
const endInput = element.querySelector('#activity_end_time');
if (startInput && endInput) {
let previousStart = startInput.value;
startInput.addEventListener('change', () => {
const oldStart = new Date(previousStart);
const newStart = new Date(startInput.value);
const oldEnd = new Date(endInput.value);
previousStart = startInput.value;
if ([oldStart, newStart, oldEnd].some(d => isNaN(d))) return;

const newEnd = new Date(oldEnd.getTime() + (newStart - oldStart));
const pad = n => String(n).padStart(2, '0');
endInput.value = `${newEnd.getFullYear()}-${pad(newEnd.getMonth() + 1)}-${pad(newEnd.getDate())}T${pad(newEnd.getHours())}:${pad(newEnd.getMinutes())}`;
});
}

mountVue(element, {
data: () => ({
query: '',
Expand Down
6 changes: 4 additions & 2 deletions app/views/activities/_modal.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
</div><%= simple_form_for @activity, wrapper: :horizontal_form, html: { class: 'needs-validation' } do |f| %>
<div class="modal-body" id="activities_modal">
<%= f.input :title, label: 'Titel', placeholder: 'Titel', required: true %>
<%= f.input :start_time, as: :string, label: 'Begintijd', required: true, order: %i[hour minute day month year] %>
<%= f.input :end_time, as: :string, label: 'Eindtijd', required: true, order: %i[hour minute day month year] %>
<%= f.input :start_time, as: :string, label: 'Begintijd', required: true,
input_html: { type: 'datetime-local', step: 300, value: f.object.start_time&.strftime('%Y-%m-%dT%H:%M') } %>
<%= f.input :end_time, as: :string, label: 'Eindtijd', required: true,
input_html: { type: 'datetime-local', step: 300, value: f.object.end_time&.strftime('%Y-%m-%dT%H:%M') } %>

<div class="mb-3 row">
<label class="col-sm-3 col-form-label" for="activity_price_list">
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"@hotwired/turbo-rails": "^8.0.23",
"@popperjs/core": "^2.11.8",
"autosuggest-highlight": "^3.3.4",
"axios": "^1.13.4",
"axios": "^1.21.1",
"babel-loader": "^10.1.1",
"babel-plugin-macros": "^3.1.0",
"babel-plugin-polyfill-corejs3": "^1.0.0",
Expand Down
24 changes: 4 additions & 20 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1206,16 +1206,7 @@ __metadata:
languageName: node
linkType: hard

"@csstools/css-parser-algorithms@npm:^4.0.0":
version: 4.0.0
resolution: "@csstools/css-parser-algorithms@npm:4.0.0"
peerDependencies:
"@csstools/css-tokenizer": ^4.0.0
checksum: 10c0/94558c2428d6ef0ddef542e86e0a8376aa1263a12a59770abb13ba50d7b83086822c75433f32aa2e7fef00555e1cc88292f9ca5bce79aed232bb3fed73b1528d
languageName: node
linkType: hard

"@csstools/css-parser-algorithms@npm:^4.0.2, @csstools/css-parser-algorithms@npm:^4.0.3":
"@csstools/css-parser-algorithms@npm:^4.0.0, @csstools/css-parser-algorithms@npm:^4.0.2, @csstools/css-parser-algorithms@npm:^4.0.3":
version: 4.0.3
resolution: "@csstools/css-parser-algorithms@npm:4.0.3"
peerDependencies:
Expand All @@ -1236,14 +1227,7 @@ __metadata:
languageName: node
linkType: hard

"@csstools/css-tokenizer@npm:^4.0.0":
version: 4.0.0
resolution: "@csstools/css-tokenizer@npm:4.0.0"
checksum: 10c0/669cf3d0f9c8e1ffdf8c9955ad8beba0c8cfe03197fe29a4fcbd9ee6f7a18856cfa42c62670021a75183d9ab37f5d14a866e6a9df753a6c07f59e36797a9ea9f
languageName: node
linkType: hard

"@csstools/css-tokenizer@npm:^4.0.2, @csstools/css-tokenizer@npm:^4.0.3":
"@csstools/css-tokenizer@npm:^4.0.0, @csstools/css-tokenizer@npm:^4.0.2, @csstools/css-tokenizer@npm:^4.0.3":
version: 4.0.3
resolution: "@csstools/css-tokenizer@npm:4.0.3"
checksum: 10c0/c9c6522aac182a306caae7974c602d7158e21594adc8521f6684f688e15021ff63c586c84ca465b97584ca4c88167f13a0733305a32f6ed5399d2c2fba04e9fc
Expand Down Expand Up @@ -2922,7 +2906,7 @@ __metadata:
languageName: node
linkType: hard

"axios@npm:^1.13.4":
"axios@npm:^1.21.1":
version: 1.21.1
resolution: "axios@npm:1.21.1"
dependencies:
Expand Down Expand Up @@ -5987,7 +5971,7 @@ __metadata:
"@hotwired/turbo-rails": "npm:^8.0.23"
"@popperjs/core": "npm:^2.11.8"
autosuggest-highlight: "npm:^3.3.4"
axios: "npm:^1.13.4"
axios: "npm:^1.21.1"
babel-loader: "npm:^10.1.1"
babel-plugin-macros: "npm:^3.1.0"
babel-plugin-polyfill-corejs3: "npm:^1.0.0"
Expand Down
Loading