diff --git a/Message/Notification/NotificationManager.js b/Message/Notification/NotificationManager.js index bf4a3fb..a071854 100644 --- a/Message/Notification/NotificationManager.js +++ b/Message/Notification/NotificationManager.js @@ -1,6 +1,6 @@ -import { AppNotification } from '../../../jsOMS/Message/Notification/App/AppNotification.js'; -import { BrowserNotification } from '../../../jsOMS/Message/Notification/Browser/BrowserNotification.js'; -import { NotificationType } from '../../../jsOMS/Message/Notification/NotificationType.js'; +import { AppNotification } from '../../Message/Notification/App/AppNotification.js'; +import { BrowserNotification } from '../../Message/Notification/Browser/BrowserNotification.js'; +import { NotificationType } from '../../Message/Notification/NotificationType.js'; /** * Notification manager. diff --git a/Message/Request/Request.js b/Message/Request/Request.js index e211d57..0247696 100644 --- a/Message/Request/Request.js +++ b/Message/Request/Request.js @@ -1,9 +1,9 @@ -import { Logger } from '../../Log/Logger.js'; -import { UriFactory } from '../../Uri/UriFactory.js'; -import { BrowserType } from './BrowserType.js'; -import { OSType } from './OSType.js'; +import { Logger } from '../../Log/Logger.js'; +import { UriFactory } from '../../Uri/UriFactory.js'; +import { BrowserType } from './BrowserType.js'; +import { OSType } from './OSType.js'; import { RequestMethod } from './RequestMethod.js'; -import { RequestType } from './RequestType.js'; +import { RequestType } from './RequestType.js'; /** * Request class. diff --git a/UI/Component/Form.js b/UI/Component/Form.js index aad6815..345ab7e 100644 --- a/UI/Component/Form.js +++ b/UI/Component/Form.js @@ -1,12 +1,13 @@ -import { Logger } from '../../Log/Logger.js'; -import { NotificationLevel } from '../../Message/Notification/NotificationLevel.js'; +import { Logger } from '../../Log/Logger.js'; +import { NotificationLevel } from '../../Message/Notification/NotificationLevel.js'; import { NotificationMessage } from '../../Message/Notification/NotificationMessage.js'; -import { NotificationType } from '../../Message/Notification/NotificationType.js'; -import { Request } from '../../Message/Request/Request.js'; -import { RequestMethod } from '../../Message/Request/RequestMethod.js'; -import { RequestType } from '../../Message/Request/RequestType.js'; -import { Response } from '../../Message/Response/Response.js'; -import { FormView } from '../../Views/FormView.js'; +import { NotificationType } from '../../Message/Notification/NotificationType.js'; +import { Request } from '../../Message/Request/Request.js'; +import { RequestMethod } from '../../Message/Request/RequestMethod.js'; +import { RequestType } from '../../Message/Request/RequestType.js'; +import { Response } from '../../Message/Response/Response.js'; +import { FormView } from '../../Views/FormView.js'; +import { UriFactory } from '../../Uri/UriFactory.js'; /** * Form manager class. @@ -160,7 +161,7 @@ export class Form const addable = this.forms[id].getAdd(); length = addable === null ? 0 : addable.length; for (let i = 0; i < length; ++i) { - this.bindAddInline(addable[i], id); + this.bindAdd(addable[i], id); } const save = this.forms[id].getSave(); @@ -171,10 +172,6 @@ export class Form // @todo implement bindSaveExternal ??? - if (document.getElementById(id).getAttribute('data-ui-form') !== null) { - this.bindAddExternal(id); - } - const cancel = this.forms[id].getCancel(); length = cancel === null ? 0 : cancel.length; for (let i = 0; i < length; ++i) { @@ -403,115 +400,231 @@ export class Form /** * Create the ui element * - * @param {string} createForm Create form - * @param {Object} id Form id + * @param {string} create Create form button + * @param {Object} id Id * * @return {void} * * @since 1.0.0 */ - bindAddExternal(id) + bindAddExternal(create, id) { - const createForm = document.getElementById(id).getAttribute('data-ui-form'); + const self = this; /** * @todo Orange-Management/jsOMS#75 * Currently only one add button is allowed per form. Allow multiple/different add buttons in a form. */ - this.app.uiManager.getFormManager().get(createForm).injectSubmit(function () { - const formElement = document.getElementById(id); - const subMain = formElement.getAttribute('data-ui-content').charAt(0) === '#' - ? document.querySelector(formElement.getAttribute('data-ui-content')) - : formElement.querySelector(formElement.getAttribute('data-ui-content')); + create.addEventListener('click', function () { + const formElement = document.getElementById(id); + const parents = []; + const selectors = formElement.getAttribute('data-add-element').split(','), + selectorLength = selectors.length; + const addTpl = formElement.getAttribute('data-add-tpl').split(','); - /** - * @todo Orange-Management/jsOMS#76 - * In the beginning there was a fixed amount of templates required (even if some were not used) for adding new dom elements to a lest, table etc. - * This no longer works especially for inline editing - * ```js - * const newEle = subMain.getElementsByTagName('template')[0].content.cloneNode(true); - * ``` - */ - const newEle = subMain.getElementsByTagName('template')[0].content.cloneNode(true); + const subMain = formElement.getAttribute('data-add-content').charAt(0) === '#' + ? document.querySelector(formElement.getAttribute('data-add-content')) + : formElement.querySelector(formElement.getAttribute('data-add-content')); - // set internal value - let fields = newEle.querySelectorAll('[data-tpl-value]'); - let fieldLength = fields.length; - let uuid = ''; - let value = ''; + let values = []; + let text = []; + const newEle = []; - for (let j = 0; j < fieldLength; ++j) { - /** - * @todo Orange-Management/jsOMS#77 - * We need to check what kind of tag the selector above returns in order to get the correct value. - * Currently this only makes sense for input elements but for selection, checkboxes etc. - * This doesn't make sense there we need .innerHTML or [data-text=] - */ - value = document.querySelectorAll( - '#' + createForm + ' [data-tpl-value="' + fields[j].getAttribute('data-tpl-value') + '"], [data-form="' + createForm + '"][data-tpl-value="' + fields[j].getAttribute('data-tpl-value') + '"]' - )[0].getAttribute('data-value'); + for (let i = 0; i < selectorLength; ++i) { + // this handles selectors such as 'ancestor > child/or/sibling' and many more + const selector = selectors[i].trim(' ').split(' '); + const closest = selector[0].trim(); - fields[j].setAttribute('data-value', value); + let subSelector = ''; + if (selector.length !== 0) { + selector.shift(); + subSelector = selector.join(' ').trim(); + } - uuid += value; - } + newEle.push(document.querySelector(addTpl[i]).content.cloneNode(true)); - // don't allow duplicate - if (subMain.querySelectorAll('[data-tpl-uuid="' + uuid + '"').length !== 0) { - return; - } - - newEle.firstElementChild.setAttribute('data-tpl-uuid', uuid); - - // set readable text - fields = newEle.querySelectorAll('[data-tpl-text]'); - fieldLength = fields.length; - - for (let j = 0; j < fieldLength; ++j) { - /** - * @todo Orange-Management/jsOMS#77 - * We need to check what kind of tag the selector above returns in order to get the correct value. - * Currently this only makes sense for input elements but for selection, checkboxes etc. - * This doesn't make sense there we need .innerHTML or [data-text=] - */ - fields[j].appendChild( - document.createTextNode( - document.querySelectorAll( - '#' + createForm + ' [data-tpl-text="' + fields[j].getAttribute('data-tpl-text') + '"], [data-form="' + createForm + '"][data-tpl-text="' + fields[j].getAttribute('data-tpl-text') + '"]' - )[0].value - ) + parents.push( + selector.length === 0 + ? newEle[i].firstElementChild + : newEle[i].firstElementChild.querySelector(subSelector) ); + + values = values.concat( + parents[i].hasAttribute('data-tpl-value') + ? parents[i] + : Array.prototype.slice.call(parents[i].querySelectorAll('[data-tpl-value]')) + ); + text = text.concat( + parents[i].hasAttribute('data-tpl-text') + ? parents[i] + : Array.prototype.slice.call(parents[i].querySelectorAll('[data-tpl-text]')) + ); + + if (newEle[i].firstElementChild.id === null) { + let eleId = ''; + + do { + eleId = 'f' + Math.random().toString(36).substring(7); + } while (document.getElementById(eleId) !== null); + + // root element is form even if it has a different tag than