fix templates

This commit is contained in:
Dennis Eichhorn 2024-04-17 17:45:08 +00:00
parent 1cd50ff438
commit dcf2fde55a
3 changed files with 23 additions and 11 deletions

View File

@ -1,4 +1,4 @@
import { GeneralUI } from "../../../UI/GeneralUI"; import { GeneralUI } from "../../../UI/GeneralUI.js";
/** /**
* Get value from dom. * Get value from dom.

View File

@ -164,7 +164,7 @@ export class Form
// If isOnChange(): every change results in action // If isOnChange(): every change results in action
// -> perform action on change // -> perform action on change
if (!this.forms[id].isOnChange()) { if (!this.forms[id].isOnChange()) {
toBind[i].addEventListener('change', function (evnt) { toBind[i].addEventListener('change', function () {
if (window.omsApp.state) { if (window.omsApp.state) {
window.omsApp.state.hasChanges = true; window.omsApp.state.hasChanges = true;
} }
@ -212,8 +212,8 @@ export class Form
jsOMS.preventAll(event); jsOMS.preventAll(event);
const remove = self.forms[id].getRemove()[elementIndex]; const remove = self.forms[id].getRemove()[elementIndex];
const callback = function (xhr) { const callback = function (xhr = null) {
if (xhr.status !== 200) { if (xhr !== null && xhr.status !== 200) {
self.app.notifyManager.send( self.app.notifyManager.send(
new NotificationMessage( new NotificationMessage(
NotificationLevel.ERROR, NotificationLevel.ERROR,
@ -540,7 +540,7 @@ export class Form
for (let i = 0; i < updateElementLength; ++i) { for (let i = 0; i < updateElementLength; ++i) {
updateElementNames[i] = updateElementNames[i].trim(); updateElementNames[i] = updateElementNames[i].trim();
// get the elment to update // get the element to update
// @todo maybe stupid, because same as elementContainer. however this is more general? anyway, one can be replaced // @todo maybe stupid, because same as elementContainer. however this is more general? anyway, one can be replaced
updateElements.push( updateElements.push(
formElement.querySelector(updateElementNames[i] + '[data-id="' + elementContainer.getAttribute('data-id') + '"]') formElement.querySelector(updateElementNames[i] + '[data-id="' + elementContainer.getAttribute('data-id') + '"]')
@ -569,8 +569,9 @@ export class Form
: Array.prototype.slice.call(dataOriginElement.querySelectorAll('[data-tpl-text]')) : Array.prototype.slice.call(dataOriginElement.querySelectorAll('[data-tpl-text]'))
); );
} }
/** @var {Element} elementContainer Original element */ /** @var {Element} elementContainer Original element */
const element = uiContainer.querySelector('.hidden[data-id="' + elementContainer.getAttribute('data-id') + '"]'); const element = uiContainer.querySelector('.vh[data-id="' + elementContainer.getAttribute('data-id') + '"]');
/** @var {object} remoteUrls Texts and values which come from remote sources */ /** @var {object} remoteUrls Texts and values which come from remote sources */
const remoteUrls = {}; const remoteUrls = {};
@ -637,7 +638,7 @@ export class Form
for (let i = 0; i < updateElementLength; ++i) { for (let i = 0; i < updateElementLength; ++i) {
updateElementNames[i] = updateElementNames[i].trim(); updateElementNames[i] = updateElementNames[i].trim();
// get the elment to update // get the element to update
updateElements.push( updateElements.push(
formElement.querySelector(updateElementNames[i] + '[data-id="' + externalFormElement.getAttribute('data-id') + '"]') formElement.querySelector(updateElementNames[i] + '[data-id="' + externalFormElement.getAttribute('data-id') + '"]')
); );
@ -747,7 +748,10 @@ export class Form
formActionCancel (self, event, id, elementIndex) formActionCancel (self, event, id, elementIndex)
{ {
const ele = document.getElementById(id); const ele = document.getElementById(id);
if (ele.getAttribute('data-update-form') === null && ele.tagName.toLowerCase() !== 'form') { if (ele.getAttribute('data-update-form') === null
&& ele.getAttribute('data-ui-container') !== null
&& ele.getAttribute('data-ui-element') !== null
) {
this.formActionCancelInline(self, event, id, elementIndex); this.formActionCancelInline(self, event, id, elementIndex);
} else { } else {
this.formActionCancelExternal(self, event, id, elementIndex); this.formActionCancelExternal(self, event, id, elementIndex);
@ -771,7 +775,7 @@ export class Form
const elementContainer = event.target.closest(formElement.getAttribute('data-ui-element')); const elementContainer = event.target.closest(formElement.getAttribute('data-ui-element'));
/** @var {Element} elementContainer Original element */ /** @var {Element} elementContainer Original element */
const element = uiContainer.querySelector('.hidden[data-id="' + elementContainer.getAttribute('data-id') + '"]'); const element = uiContainer.querySelector('.vh[data-id="' + elementContainer.getAttribute('data-id') + '"]');
jsOMS.removeClass(element, 'vh'); jsOMS.removeClass(element, 'vh');
@ -829,7 +833,11 @@ export class Form
const uiContainerName = formElement.getAttribute('data-ui-container'); const uiContainerName = formElement.getAttribute('data-ui-container');
/** @var {Element} elementContainer Element container that holds the data that should get updated */ /** @var {Element} elementContainer Element container that holds the data that should get updated */
const elementContainer = event.target.closest(formElement.getAttribute('data-ui-element')); let elementContainer = event.target.closest(formElement.getAttribute('data-ui-element'));
if (elementContainer === null) {
elementContainer = formElement.querySelector(formElement.getAttribute('data-ui-element'));
}
jsOMS.addClass(elementContainer, 'vh'); jsOMS.addClass(elementContainer, 'vh');
/** @var {NodeListOf<Element>} values Value elements of the element to update */ /** @var {NodeListOf<Element>} values Value elements of the element to update */
@ -1007,6 +1015,7 @@ export class Form
this.formActionAdd(self, event, id, elementIndex); this.formActionAdd(self, event, id, elementIndex);
} else if ((elementIndex = Array.from(self.forms[id].getSave()).indexOf(event.target)) !== -1) { } else if ((elementIndex = Array.from(self.forms[id].getSave()).indexOf(event.target)) !== -1) {
this.formActionSave(self, event, id, elementIndex); this.formActionSave(self, event, id, elementIndex);
//self.submit(self.forms[id], self.forms[id].getSubmit()[elementIndex]);
} else if ((elementIndex = Array.from(self.forms[id].getCancel()).indexOf(event.target)) !== -1) { } else if ((elementIndex = Array.from(self.forms[id].getCancel()).indexOf(event.target)) !== -1) {
jsOMS.preventAll(event); jsOMS.preventAll(event);
// @todo currently only handling update cancel, what about add cancel? // @todo currently only handling update cancel, what about add cancel?
@ -1039,7 +1048,7 @@ export class Form
// add // add
// save // save
// update // update
// dragndrop // drag'n drop
} }
/** /**
@ -1233,6 +1242,7 @@ export class Form
&& (statusCode === 200 || statusCode === null) && (statusCode === 200 || statusCode === null)
) { ) {
successInject(response, xhr); successInject(response, xhr);
form.setSuccess(null); // unload success
} }
if (response.get('type') !== null) { if (response.get('type') !== null) {

View File

@ -594,6 +594,8 @@ export class FormView
if (elements[i].tagName.toLowerCase() === 'canvas') { if (elements[i].tagName.toLowerCase() === 'canvas') {
elements[i].clearRect(0, 0, elements[i].width, elements[i].height); elements[i].clearRect(0, 0, elements[i].width, elements[i].height);
} else if(elements[i].tagName.toLowerCase() === 'textarea') {
elements[i].innerHTML = '';
} }
if (elements[i].getAttribute('data-value') !== null) { if (elements[i].getAttribute('data-value') !== null) {