Files
kimai2/assets/js/widgets/KimaiReloadPageWidget.js
Kevin Papst 31a8f887a5 Release 2.58 (#5952)
* bump version
* fix formatting locale reset after embedded controller sub-requests (#5944)
* fix GHSA-c6w6-57jj-62vh
* fix GHSA-m492-gv72-xvxj
* fix GHSA-jr9p-4h4j-6c58
* make sure to only use JS logic to call API endpoints
* fixes GHSA-r8vr-m544-qh4h
* make sure to only use JS logic to call API endpoints
* fix GHSA-rw46-qg69-vg6h
* fix GHSA-pj8j-p4g4-4vw8 - prevent kimai from rendering images via markdown
* fix GHSA-pj8j-p4g4-4vw8 - use a safe network client to prevent SSRF via images
* fix GHSA-xv4r-4885-gwpg
* fix GHSA-pgcc-vfmc-7cw5 - move GET routes to API with POST method to prevent CSRF
* fix tooltip survives page reload
* updated wizard images
* split wizard and password reset subscriber into two classes
* relax upper php limit
* added zizmor workflow scans and apply findings
* user permissions <name>_other_profile  now respect teams
* move all linting steps to new job
* updated docker image version names
* use .env.local for storing APP_SECRET
* improve build order and use given tag as ref for checkout, not default main branch
* improved APP_SECRET handling, see entrypoint.sh
* use local code for building the image for more flexibility, added dockerignore
2026-05-25 15:39:47 +02:00

72 lines
2.3 KiB
JavaScript

/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/*!
* [KIMAI] KimaiReloadPageWidget: a simple helper to reload the page on events
*/
import { Tooltip } from 'bootstrap';
export default class KimaiReloadPageWidget {
constructor(events, fullReload) {
const reloadPage = () => {
if (fullReload) {
document.location.reload();
} else {
this._loadPage(document.location);
}
};
for (const eventName of events.split(' ')) {
document.addEventListener(eventName, reloadPage);
}
}
static create(events, fullReload) {
if (fullReload === undefined || fullReload === null) {
fullReload = false;
}
return new KimaiReloadPageWidget(events, fullReload);
}
_showOverlay() {
document.dispatchEvent(new CustomEvent('kimai.reloadContent', {detail: 'div.page-wrapper'}));
}
_hideOverlay() {
document.dispatchEvent(new Event('kimai.reloadedContent'));
}
_loadPage(url) {
this._showOverlay();
window.kimai.getPlugin('fetch').fetch(url)
.then(response => {
response.text().then((text) => {
const temp = document.createElement('div');
temp.innerHTML = text;
const oldContent = document.querySelector('section.content');
// dispose all tooltips before replacing the content, otherwise an open tooltip
// would remain visible in the upper left corner after its anchor element is gone
oldContent.querySelectorAll('[data-toggle="tooltip"]').forEach((el) => {
Tooltip.getInstance(el)?.dispose();
});
const newContent = temp.querySelector('section.content');
oldContent.replaceWith(newContent);
document.dispatchEvent(new Event('kimai.reloadPage'));
this._hideOverlay();
});
})
.catch(() => {
this._hideOverlay();
document.location = url;
});
}
}