-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #538 from MaMpf-HD/mampf-next
Continuous Release 1.8.0
- Loading branch information
Showing
70 changed files
with
501 additions
and
356 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 0 additions & 24 deletions
24
app/assets/javascripts/bootstrap_modal_turbolinks_fix.coffee
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
$(document).on('turbolinks:load', function () { | ||
// show all active modals | ||
$('.activeModal').modal('show'); | ||
// remove active status (this needs to be reestablished before caching) | ||
$('.activeModal').removeClass('activeModal'); | ||
}); | ||
|
||
$(document).on('turbolinks:before-cache', function () { | ||
// if some modal is open | ||
if ($('body').hasClass('modal-open')) { | ||
$('.modal.show').addClass('activeModal'); | ||
$('.modal.show').modal('hide'); | ||
// remove the greyed out background | ||
$('.modal-backdrop').remove(); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
$(document).on('turbolinks:load', function () { | ||
initBootstrapPopovers(); | ||
}); | ||
|
||
/** | ||
* Initializes all Bootstrap popovers on the page. | ||
* | ||
* This function might be used for the first initialization of popovers as well | ||
* as for reinitialization on page changes. | ||
* | ||
* See: https://getbootstrap.com/docs/5.3/components/popovers/#enable-popovers | ||
*/ | ||
function initBootstrapPopovers() { | ||
const popoverHtmlElements = document.querySelectorAll('[data-bs-toggle="popover"]'); | ||
for (const element of popoverHtmlElements) { | ||
new bootstrap.Popover(element); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
// Initialize on page load (when js file is dynamically loaded) | ||
$(document).ready(startInitialization); | ||
|
||
// On page change (e.g. go back and forth in browser) | ||
$(document).on('turbolinks:before-cache', () => { | ||
// Remove stale datetimepickers | ||
$('.tempus-dominus-widget').remove(); | ||
}); | ||
|
||
function startInitialization() { | ||
const pickerElements = $('.td-picker'); | ||
if (pickerElements.length == 0) { | ||
console.error('No datetimepicker element found on page, although requested.'); | ||
return; | ||
} | ||
|
||
pickerElements.each((i, element) => { | ||
element = $(element); | ||
const datetimePicker = initDatetimePicker(element); | ||
registerErrorHandlers(datetimePicker, element); | ||
registerFocusHandlers(datetimePicker, element); | ||
}); | ||
} | ||
|
||
function getDateTimePickerIcons() { | ||
// At the moment: continue to use FontAwesome 5 icons | ||
// see https://getdatepicker.com/6/plugins/fa5.html | ||
// see https://github.com/Eonasdan/tempus-dominus/blob/master/dist/plugins/fa-five.js | ||
return { | ||
type: 'icons', | ||
time: 'fas fa-clock', | ||
date: 'fas fa-calendar', | ||
up: 'fas fa-arrow-up', | ||
down: 'fas fa-arrow-down', | ||
previous: 'fas fa-chevron-left', | ||
next: 'fas fa-chevron-right', | ||
today: 'fas fa-calendar-check', | ||
clear: 'fas fa-trash', | ||
close: 'fas fa-times', | ||
} | ||
} | ||
|
||
function initDatetimePicker(element) { | ||
// see https://getdatepicker.com | ||
return new tempusDominus.TempusDominus( | ||
element.get(0), | ||
{ | ||
display: { | ||
sideBySide: true, // clock to the right of the calendar | ||
icons: getDateTimePickerIcons(), | ||
}, | ||
localization: { | ||
startOfTheWeek: 1, | ||
// choose format to be compliant with backend time format | ||
format: 'yyyy-MM-dd HH:mm', | ||
hourCycle: 'h23', | ||
} | ||
} | ||
); | ||
} | ||
|
||
function registerErrorHandlers(datetimePicker, element) { | ||
// Catch Tempus Dominus error when user types in invalid date | ||
// this is rather hacky at the moment, see this discussion: | ||
// https://github.com/Eonasdan/tempus-dominus/discussions/2656 | ||
datetimePicker.dates.oldParseInput = datetimePicker.dates.parseInput; | ||
datetimePicker.dates.parseInput = (input) => { | ||
try { | ||
return datetimePicker.dates.oldParseInput(input); | ||
} catch (err) { | ||
const errorMsg = element.find('.td-error').data('td-invalid-date'); | ||
element.find('.td-error').text(errorMsg).show(); | ||
datetimePicker.dates.clear(); | ||
} | ||
}; | ||
|
||
datetimePicker.subscribe(tempusDominus.Namespace.events.change, (e) => { | ||
// see https://getdatepicker.com/6/namespace/events.html#change | ||
|
||
// Clear error message | ||
if (e.isValid && !e.isClear) { | ||
element.find('.td-error').empty(); | ||
} | ||
|
||
// If date was selected, close datetimepicker. | ||
// However: leave the datetimepicker open if user only changed time | ||
if (e.oldDate && e.date && !hasUserChangedDate(e.oldDate, e.date)) { | ||
datetimePicker.hide(); | ||
} | ||
}); | ||
} | ||
|
||
function hasUserChangedDate(oldDate, newDate) { | ||
return oldDate.getHours() != newDate.getHours() | ||
|| oldDate.getMinutes() != newDate.getMinutes(); | ||
} | ||
|
||
function registerFocusHandlers(datetimePicker, element) { | ||
// Show datetimepicker when user clicks in text field next to button | ||
// or when input field receives focus | ||
var isButtonInvokingFocus = false; | ||
|
||
element.find('.td-input').on('click focusin', (e) => { | ||
try { | ||
if (!isButtonInvokingFocus) { | ||
datetimePicker.show(); | ||
} | ||
} | ||
finally { | ||
isButtonInvokingFocus = false; | ||
} | ||
}); | ||
|
||
element.find('.td-picker-button').on('click', () => { | ||
isButtonInvokingFocus = true; | ||
element.find('.td-input').focus(); | ||
}); | ||
|
||
// Hide datetimepicker when input field loses focus | ||
element.find('.td-input').blur((e) => { | ||
if (!e.relatedTarget) { | ||
return; | ||
} | ||
datetimePicker.hide(); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.