0
0
Fork 0
mirror of https://github.com/kevinpapst/kimai2.git synced 2025-01-10 19:47:35 +00:00
kevinpapst_kimai2/assets/js/forms/KimaiCopyDataForm.js
Kevin Papst 17a815e5a9
updated frontend builds (#5210)
* do not rely on node_modules path
* bump eslint to v9, run eslint via npm task, remove from build task
* loosen dependencies and update all packages
* rebuild assets with latest frontend packages
* bump webpack encore and dependencies
* bump to latest stable yarn
* explicitly mention dependencies
2024-12-06 14:31:04 +01:00

71 lines
2.2 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] KimaiEditTimesheetForm: responsible for the most important form in the application
*/
import KimaiFormPlugin from "./KimaiFormPlugin";
/**
* Used for simple copy from link to input action, e.g. the time and duration dropdowns
* copy the selected values into their corresponding input.
*/
export default class KimaiCopyDataForm extends KimaiFormPlugin {
/**
* @param {HTMLFormElement} form
* @return boolean
*/
supportsForm(form) // eslint-disable-line no-unused-vars
{
return true;
}
/**
* @param {HTMLFormElement} form
*/
activateForm(form)
{
if (this._eventHandler === undefined) {
this._eventHandler = (event) => {
let element = event.target;
if (!element.matches('a[data-form-widget="copy-data"]')) {
element = element.parentNode; // mostly for icons
}
if (!element.matches('a[data-form-widget="copy-data"]') || element.dataset.target === undefined) {
return;
}
const target = document.querySelector(element.dataset.target);
if (target === null) {
return;
}
target.value = element.dataset.value;
if (element.dataset.event !== undefined) {
for (const event of element.dataset.event.split(' ')) {
target.dispatchEvent(new Event(event));
const form = target.closest('form');
if (form !== null) {
form.dispatchEvent(new Event(event));
}
}
}
event.preventDefault();
};
}
form.addEventListener('click', this._eventHandler);
}
/**
* @param {HTMLFormElement} form
*/
destroyForm(form)
{
form.removeEventListener('click', this._eventHandler);
}
}