![]() System : Linux absol.cf 5.4.0-198-generic #218-Ubuntu SMP Fri Sep 27 20:18:53 UTC 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.33 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, Directory : /var/www/html/libs/absol-full/dist/js/ |
Upload File : |
/*** module: node_modules/absol-form/js/dom/utils.js ***/ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.openFormDialog = openFormDialog; exports.documentOn = documentOn; exports.documentOff = documentOff; var _FCore = require("../core/FCore"); require("./Icons"); var _MessageDialog = _interopRequireDefault(require("absol-acomp/js/MessageDialog")); var _Modal = _interopRequireDefault(require("absol-acomp/js/Modal")); /** * @typedef FormDialogField * @property {string} name * @property {string} displayName * @property {function} [verify] * @property {function} [getValue] * * * @param {{getFormField:(function(): Array<FormDialogField>)}} adapter * @returns {Promise<unknown>} */ function openFormDialog(adapter) { return new Promise((rs, rj) => { var errorText = (0, _FCore._)({ tag: 'span', style: { color: 'red', fontSize: '0.8em' }, child: { text: '' } }); var context = {}; var formFields = adapter.getFormField(context); var verify = noError => { var formOK = formFields.every(field => { if (!field.verify) return true; var ok = field.verify(field.input); if (ok || noError) { errorText.firstChild.data = ""; } else { errorText.firstChild.data = "Invalid \"" + field.displayName + "\""; } return ok; }); dialog.$actionBtns[0].disabled = !formOK; return formOK; }; context.verify = verify; var dialog = (0, _FCore._)({ tag: _MessageDialog.default.tag, style: { fontSize: '14px' }, props: { dialogTitle: 'New Package', dialogIcon: 'span.mdi.mdi-package-variant-plus', dialogActions: [{ text: 'OK', name: 'ok' }, { text: 'Cancel', name: 'cancel' }] }, child: { class: 'as-table-grid', style: { whiteSpace: 'nowrap' }, child: formFields.map(field => ({ class: 'as-table-grid-row', attr: { 'data-field-name': field.name }, child: [{ class: 'as-table-grid-cell', style: { paddingRight: '10px', paddingBottom: '10px', verticalAlign: 'middle' }, child: { tag: 'label', child: { text: field.displayName } } }, { class: ['as-table-grid-cell', 'as-input-ctn'], style: { paddingBottom: '10px', verticalAlign: 'middle' }, child: field.input }] })).concat([{ class: 'as-table-grid-row', child: [{ class: 'as-table-grid-cell' }, { class: 'as-table-grid-cell', child: errorText }] }]) } }); var getValue = () => formFields.reduce((ac, field) => { ac[field.name] = field.getValue(field.input); return ac; }, {}); var modal = (0, _FCore._)({ tag: _Modal.default.tag, child: [dialog] }).addTo(document.body); verify(true); setTimeout(() => { var input = (0, _FCore.$)('input[type="text"]', dialog) || (0, _FCore.$)('textarea', dialog); if (input) input.focus(); }, 200); dialog.on('action', event => { if (event.action.name === 'ok') { if (verify()) { rs(getValue()); } } else if (event.action.name === 'cancel') { rj(); } modal.remove(); }); }); } var documentListeners = {}; function documentOn(name, listener) { if (!documentListeners[name]) documentListeners[name] = []; if (documentListeners[name].indexOf(listener) < 0) { documentListeners[name].push(listener); document.addEventListener(name, listener); } else {// console.warn('Dup event', name, listener); } } function documentOff(name, listener) { if (!documentListeners[name]) documentListeners[name] = []; var idx = documentListeners[name].indexOf(listener); if (idx >= 0) { documentListeners[name].splice(idx, 1); document.removeEventListener(name, listener); } else {// console.warn('Not found event', name, listener); } }