From 527a1c5dd2cd8d2983456a2fc3367609fa45ce36 Mon Sep 17 00:00:00 2001 From: johnnyq Date: Thu, 19 Nov 2026 00:37:07 -0500 Subject: [PATCH] Remove five bundled libraries: drop unused DataTables, zapcal and clipboard.js, make QR codes with TCPDF instead of libs/barcode, and replace IMask with own IP and MAC field code that leaves non-MAC text alone --- CHANGELOG.md | 3 + CONTRIBUTING.md | 2 +- admin/getting_started.php | 2 - agent/client_onboarding.php | 2 - agent/js/calendar.js | 18 +- agent/js/canned_response_picker.js | 22 +- agent/js/canned_response_save.js | 14 +- agent/user/mfa_enforcement.php | 50 +- client/includes/footer.php | 6 - client/includes/header.php | 5 - css/itflow_custom.css | 67 +- functions/format.php | 37 + functions/portal.php | 10 +- functions/share.php | 11 +- functions/user.php | 11 +- guest/includes/guest_header.php | 7 - includes/footer.php | 3 - includes/header.php | 2 - js/app.js | 122 +- js/auto_reload.js | 2 +- js/backup_restore.js | 2 +- js/confirm_modal.js | 171 +- js/invoice_bulk.js | 4 +- js/phone_inputs.js | 8 +- js/portal_datatables.js | 38 - libs/DataTables/datatables.min.css | 21 - libs/DataTables/datatables.min.js | 22 - libs/barcode/barcode.php | 3352 ---------------------- libs/clipboardjs/clipboard.min.js | 7 - libs/imask/js/imask.min.js | 2 - libs/sweetalert2/css/sweetalert2.min.css | 1 - libs/sweetalert2/js/sweetalert2.min.js | 5 - libs/zapcal/README.md | 127 - libs/zapcal/includes/date.php | 568 ---- libs/zapcal/includes/framework.php | 32 - libs/zapcal/includes/ical.php | 986 ------- libs/zapcal/includes/index.html | 6 - libs/zapcal/includes/recurringdate.php | 796 ----- libs/zapcal/includes/timezone.php | 142 - libs/zapcal/zapcallib.php | 28 - 40 files changed, 377 insertions(+), 6337 deletions(-) delete mode 100644 js/portal_datatables.js delete mode 100644 libs/DataTables/datatables.min.css delete mode 100644 libs/DataTables/datatables.min.js delete mode 100644 libs/barcode/barcode.php delete mode 100644 libs/clipboardjs/clipboard.min.js delete mode 100644 libs/imask/js/imask.min.js delete mode 100644 libs/sweetalert2/css/sweetalert2.min.css delete mode 100644 libs/sweetalert2/js/sweetalert2.min.js delete mode 100644 libs/zapcal/README.md delete mode 100644 libs/zapcal/includes/date.php delete mode 100644 libs/zapcal/includes/framework.php delete mode 100644 libs/zapcal/includes/ical.php delete mode 100644 libs/zapcal/includes/index.html delete mode 100644 libs/zapcal/includes/recurringdate.php delete mode 100644 libs/zapcal/includes/timezone.php delete mode 100644 libs/zapcal/zapcallib.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 230a50b05..ccf3fd4a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -144,6 +144,7 @@ Update from Maintenance > Update — Queue Update hands the job to cron, which u - Bookkeeping: switch it off when your books are kept somewhere else. Accounts, Transactions, Transfers, Reconcile and the statement imports go, and nobody picks an account: payments and income go into the default payment account, and expenses come out of the default expense account - both in Admin > Settings > Defaults, or the first account when there's no default. An expense is paid by The business or Paid personally. The dashboard leaves out the account balances, and the Tax Package its Accounts section. - Calendar: switched off, the calendar, its events and the calendar feeds go - a subscribed calendar stops getting them. Tickets are still booked from the ticket and on Dispatch, and booked work still shows on the dashboard. - Updated the libraries ITFlow is built on: the one that reads ticket mailboxes, the one that sends email, the text editor, the one that cleans up email and document HTML before it is shown, Stripe, the page styling, the charts, the tables, the calendar and the phone number fields. Nothing changes in how they look or work. The text editor's update fixes a security problem in its media plugin, which ITFlow doesn't use. +- Pages are a little lighter: six add-on libraries are gone - three ITFlow no longer used, and three swapped for ITFlow's own code. The "Are you sure?" windows are now ITFlow's own and match the rest of ITFlow, dark mode included; on a delete Cancel is still the button picked, and Escape still backs out. The IP and MAC address fields on assets and the QR codes for setting up MFA and for shared links work as before. ### Bug Fixes @@ -193,6 +194,7 @@ Update from Maintenance > Update — Queue Update hands the job to cron, which u - Leads: clients marked as leads showed up in nearly every list of clients to pick from - new assets, contacts, credentials, documents, invoices, trips, expenses, events, contracts and the rest - and in the client switcher, the report and transaction filters and template use, crowding out the clients you work for. Leads are left out of those now. A lead still shows where it belongs: on its own pages, where anything you add is for it; in a record that's already for it; in the quote pickers, after the clients and marked Lead; and in global search, after the clients and marked Lead. Find the rest on the Leads tab of Clients. - Across clients: as All Client Docs, it listed assets, credentials and the rest of the IT documentation with IT documentation switched off in Admin > Settings > Modules. It now has only Contacts, Locations and Vendors then, as each client's menu does. - Email sent with Microsoft 365 or Google sign-in: when the mail server turned down ITFlow's sign-in, the email failed on its From address with "Authentication required" in Maintenance > Mail Queue, as if the address were the problem. It now fails saying the sign-in didn't work. +- Assets: a MAC address field holding a note rather than an address ("see label", say) was cut down to the letters in it that pass for hex - "EE:AB:E" - as soon as the asset was opened for editing, and saved like that. It's now left as it is, as the IP address field already was. ### Developer Updates @@ -303,6 +305,7 @@ Update from Maintenance > Update — Queue Update hands the job to cron, which u - Invoice autopay shown: `invoiceAutopay()` in `functions/billing_pay.php` reads the recurring invoice's `recurring_payments` row with its saved card and provider - the method in words, a problem (provider off, or the card's expiry before the due date), the last `Stripe autopay failed` history on the invoice and when it was set up - and `invoiceAutopayStatus()` turns that and `invoiceState()` into a tone, a short label, a sentence and a detail line, for `agent/invoice.php`, `agent/invoices.php` (an `autopay` column in its query) and `guest/guest_view_invoice.php`. - Knowledge Base files, PDF and AI review; documents' own review cadence: database 3.9.8 adds `kb_article_files` (name, reference name kept under `uploads/kb/
/files/`, size, who and when; cascading with the article) and `documents.document_review_months` (NULL goes by the template, 0 is never). `kbFilesReady()`, `kbArticleFiles()`, `kbArticleSaveFiles()` (`checkFileUpload()` with `fileUploadExtensions()`, `KB_ARTICLE_MAX_FILES`), `kbArticleRemoveFile()`, `kbArticleCopyFileRows()`, `kbArticleFileRow()`, `kbFileSend()` and `kbFilesListHtml()`; the files are sent by `agent/kb_file.php`, `client/kb_file.php` (`kbClientSql()`) and `guest/kb_file.php` (`kbPublicOn()` and `kbPublicSql()`). Handlers `upload_kb_article_files`, `delete_kb_article_file`, `set_kb_article_summary` and `export_kb_article` (TCPDF, purified content) in `agent/post/kb.php`. `aiKbArticleReview()` in `functions/ai_document.php` (AI feature `kb_article_review`), through `ai_kb_article_review` in `agent/ajax.php`, with `agent/modals/kb/kb_article_review.php`; the answer parsing is now `aiReviewAnswer()`, shared with `aiDocumentReview()`, and the review window's script moved out of `document_review.php` into `js/ai_review.js`, which both use (`data-ai-review-url`, `data-ai-review-param`, `data-ai-review-id`, `data-ai-review-secrets`). `documentReviewOwnReady()` gates on 3.9.8; `documentReviewMonthsSql()` gives the cadence (own, or the current template's), which `documentReviewDueSql()` and `documentsReviewDue()` (now a LEFT JOIN on templates, with `review_months`) use; `documentReviewState()` takes `document_review_months` and returns `months` and `own`. `set_document_review` in `agent/post/document.php` keeps `document_updated_at`. - Libraries: directorytree/imapengine v1.25.6 to v1.25.12 (Composer - `libs/composer.lock`, `libs/vendor/composer/installed.json` and `installed.php` updated to match, `libs/composer.json` still asks for `^1.24`); PHPMailer 7.1.1 to 7.2.0; TinyMCE 8.9.2 to 8.10.2; HTMLPurifier 4.15.0 to 4.19.1; stripe-php 21.3.2 to 21.3.3; Bootstrap 5.3.8 to 5.3.9; AdminLTE 4.9.1 to 4.10.2; Chart.js 4.5.1 to 4.6.1; DataTables 3.1.2 to 3.1.5; intl-tel-input 29.2.3 to 29.5.11; FullCalendar 7.1.0 to 7.1.5. The files are each release's own, in the layout already in `libs/`: ImapEngine, PHPMailer and stripe-php as `git archive` of the tag (as Composer's dist zip), the rest from npm, TinyMCE keeping its `license.md` and `langs/README.md`. HTMLPurifier's standalone build is made with the release's `maintenance/generate-standalone.php`, and the three 4.15.0 definition cache files that had been committed are gone - `.gitignore` named the old `plugins/htmlpurifier/` path, and now names `libs/htmlpurifier/`. The DataTables files are the download builder's `bs5/dt-3.1.5` build, put together from the `datatables.net` and `datatables.net-bs5` packages the way the builder does (the 3.1.2 files rebuilt this way match the old ones byte for byte). ImapEngine 1.25.12 disconnects when STARTTLS fails rather than carrying on over plain TCP (the parser maps a mailbox's `tls` to `starttls`), and checks sequence sets and flags in new `Support\Assert`. PHPMailer 7.2.0 reports a rejected XOAUTH2 token sent after a 334 (any long token, so every Microsoft 365 one) as failed rather than accepted; it deprecates `parseAddresses()` and the `pcre8` validator, which ITFlow doesn't use. TinyMCE's advisory GHSA-mf2p-h6hf-fcwm is in the `media` plugin, which neither `js/app.js` nor `js/portal.js` loads. HTMLPurifier gives the same output as 4.15.0 on all 4,503 ticket replies, ticket details, articles and documents in the demo data and a set of hostile samples, with the settings ITFlow uses. Left as they are: TCPDF 6.11.3 (6.11.4 only adds a deprecation notice ahead of 7.x, a different library underneath), stripe-php 22 and 23 (major versions) and Font Awesome 5.15.4. +- Libraries removed, about 470 KB, and about 280 KB less script and stylesheet loaded on every agent page: DataTables (no table has used `.dataTables` for a while - `itflowStep('datatables')` in `js/app.js`, `js/portal_datatables.js` and the portal's never-set `$portal_load_datatables` went with it, and CONTRIBUTING no longer says lists use it); zapcal (unused since ticket visit files stopped using it); clipboard.js (only `agent/user/mfa_enforcement.php` still loaded it - it now carries a cut-down copy of `js/app.js`'s copy code, the clipboard API with the selected-textarea fallback); `libs/barcode`, as QR codes now come from new `qrCodeSvg($text, $attributes)` in `functions/format.php`, drawn from TCPDF's own `tcpdf_barcodes_2d.php` as one `` in a viewBox with a four-module quiet zone, and `userMfaQrSvg()`, `portalMfaQrSvg()` and `shareQrSvg()` use it and lose their `extension_loaded('gd')` checks; IMask, replaced by new `itflowInputMask()` in `js/app.js` on the same `data-mask` / `data-inputmask` markup, which also leaves alone a MAC field that opens holding anything but hex digits and separators; and SweetAlert2, replaced by new `itflowDialog(options)` in `js/confirm_modal.js` - a Bootstrap modal returning a Promise of `{isConfirmed, isDenied, isDismissed, value}`, taking SweetAlert2's option names (`title`, `text`, `icon`, `confirmButtonText`, `cancelButtonText`, `denyButtonText`, `showCancelButton`, `focusCancel`, `returnFocus`, `input: 'radio'` with `inputOptions` / `inputValue`) plus `danger`, and setting every piece of text as text, never HTML. It sits above any modal already open. The five `Swal.fire` callers moved over - confirm-link, the calendar, the canned response save and send checks and invoice bulk actions - SweetAlert2's overrides in `css/itflow_custom.css` became `.itflow-dialog` rules, and the hidden busy marker `js/backup_restore.js` leaves for `js/auto_reload.js` is `.itflow-busy` rather than `.swal2-container`. ## [26.11.8] diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a6ab886f7..d547d33eb 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -282,7 +282,7 @@ One removed **variable** deserves its own warning: the old `$access_permission_q **Bulk vs. single actions.** If you change the behavior of a single action (e.g. resolving a ticket), check whether a `bulk_*` counterpart exists and update it too. They are currently parallel implementations and drift between them is a known bug source. -**UI.** Bootstrap 4 / AdminLTE, modals per-module under `/modals//`, DataTables for lists, monospace styling for technical data (IPs, serials, keys) and proportional for human text. Match the page you're standing in. +**UI.** Bootstrap 4 / AdminLTE, modals per-module under `/modals//`, list pages paginated and sorted on the server like Projects, monospace styling for technical data (IPs, serials, keys) and proportional for human text. Match the page you're standing in. **Scripts and stylesheets go through `staticFileUrl()`.** Every ` - diff --git a/agent/client_onboarding.php b/agent/client_onboarding.php index dc3340dae..a45570b6b 100644 --- a/agent/client_onboarding.php +++ b/agent/client_onboarding.php @@ -95,7 +95,6 @@ define('FROM_CLIENT_ONBOARDING', true); - @@ -198,7 +197,6 @@ define('FROM_CLIENT_ONBOARDING', true); - diff --git a/agent/js/calendar.js b/agent/js/calendar.js index 717246a99..7a6d9557c 100644 --- a/agent/js/calendar.js +++ b/agent/js/calendar.js @@ -165,23 +165,10 @@ } function confirmDialog(options) { - if (typeof Swal === 'undefined') { + if (typeof itflowDialog === 'undefined') { return Promise.resolve({isConfirmed: window.confirm(options.title), isDenied: false}); } - return Swal.fire(Object.assign({ - theme: document.documentElement.getAttribute('data-bs-theme') === 'dark' ? 'dark' : 'light', - icon: 'question', - showCancelButton: true, - cancelButtonText: 'Cancel', - reverseButtons: true, - buttonsStyling: false, - customClass: { - confirmButton: 'btn btn-primary mx-1', - denyButton: 'btn btn-outline-secondary mx-1', - cancelButton: 'btn btn-secondary mx-1', - input: 'itflow-cal-swal-input' - } - }, options)); + return itflowDialog(Object.assign({icon: 'question'}, options)); } function post(data, done, fail) { @@ -469,7 +456,6 @@ confirmDialog({ title: 'Tell the ' + props.invited + ' invited?', text: event.title + ' is moving to ' + words(start, event.allDay) + '. Send the update to the ' + (props.invited === 1 ? 'person who has' : 'people who have') + ' it in their calendar?', - showDenyButton: true, confirmButtonText: 'Move and send', denyButtonText: 'Just move it' }).then(function (result) { diff --git a/agent/js/canned_response_picker.js b/agent/js/canned_response_picker.js index 28bd97f68..61aec7cde 100644 --- a/agent/js/canned_response_picker.js +++ b/agent/js/canned_response_picker.js @@ -360,7 +360,7 @@ document.addEventListener('submit', function (e) { const form = e.target; const picker = form.querySelector ? form.querySelector('[data-canned-picker]') : null; - if (!picker || !form.querySelector('input[name="canned_response_ids[]"]') || typeof Swal === 'undefined') { + if (!picker || !form.querySelector('input[name="canned_response_ids[]"]') || typeof itflowDialog === 'undefined') { return; } if (form.dataset.cannedSendAnyway === '1') { @@ -389,27 +389,17 @@ e.preventDefault(); e.stopImmediatePropagation(); const submitter = e.submitter || null; - const list = document.createElement('div'); - list.textContent = 'Your reply still has ' + left.map(function (name) { - return '[' + name + ']'; - }).join(', ') + ' in it.'; - Swal.fire({ - theme: document.documentElement.getAttribute('data-bs-theme') === 'dark' ? 'dark' : 'light', + itflowDialog({ title: 'Still to fill in', - html: list, + text: 'Your reply still has ' + left.map(function (name) { + return '[' + name + ']'; + }).join(', ') + ' in it.', icon: 'warning', - showCancelButton: true, confirmButtonText: 'Send anyway', cancelButtonText: 'Fill them in', - reverseButtons: true, focusCancel: true, // Back to the reply box, not the Send button - returnFocus: false, - buttonsStyling: false, - customClass: { - confirmButton: 'btn btn-primary mx-1', - cancelButton: 'btn btn-secondary mx-1' - } + returnFocus: false }).then(function (result) { if (result.isConfirmed) { form.dataset.cannedSendAnyway = '1'; diff --git a/agent/js/canned_response_save.js b/agent/js/canned_response_save.js index 485c42ad5..a9cda1a87 100644 --- a/agent/js/canned_response_save.js +++ b/agent/js/canned_response_save.js @@ -96,25 +96,17 @@ put(wanted); swapped.textContent = toggle.checked ? swappedText(state.placeholders) : 'As you wrote it, with this ticket\'s details in it.'; }; - if (state.lastSet === null || editor.getContent() === state.lastSet || typeof Swal === 'undefined') { + if (state.lastSet === null || editor.getContent() === state.lastSet || typeof itflowDialog === 'undefined') { go(); return; } - Swal.fire({ - theme: document.documentElement.getAttribute('data-bs-theme') === 'dark' ? 'dark' : 'light', + itflowDialog({ title: 'Start again from your reply?', text: 'What you changed here goes.', icon: 'question', - showCancelButton: true, confirmButtonText: 'Start again', cancelButtonText: 'Keep my changes', - reverseButtons: true, - focusCancel: true, - buttonsStyling: false, - customClass: { - confirmButton: 'btn btn-primary mx-1', - cancelButton: 'btn btn-secondary mx-1' - } + focusCancel: true }).then(function (result) { if (result.isConfirmed) { go(); diff --git a/agent/user/mfa_enforcement.php b/agent/user/mfa_enforcement.php index a0eae89b0..5071e6a0f 100644 --- a/agent/user/mfa_enforcement.php +++ b/agent/user/mfa_enforcement.php @@ -91,9 +91,6 @@ $mfa_secret = $_SESSION['mfa_token']; - - - - @@ -40,11 +39,6 @@ - - - - - diff --git a/client/includes/header.php b/client/includes/header.php index 8af32d144..9d41440d0 100644 --- a/client/includes/header.php +++ b/client/includes/header.php @@ -79,7 +79,6 @@ $portal_contact_name = (string) ($contact['contact_name'] ?? ''); / .bg-gradient-* families. Loads BEFORE itflow_custom.css so our own .bg- box colours still win. */ ?> - @@ -92,10 +91,6 @@ $portal_contact_name = (string) ($contact['contact_name'] ?? ''); - - - - .btn { + margin: 0; } /* --- Close button focus ring --------------------------------------------- @@ -5765,10 +5792,6 @@ img.itflow-contact-avatar { .itflow-cal-help-tabs .nav-link { white-space: nowrap; } -.swal2-radio .itflow-cal-swal-input, -.swal2-radio { - gap: 1rem; -} /* --- Dispatch (agent/dispatch.php, agent/js/dispatch.js) ------------------- */ .itflow-dispatch-cal { diff --git a/functions/format.php b/functions/format.php index a11950ba8..325d878f1 100644 --- a/functions/format.php +++ b/functions/format.php @@ -676,3 +676,40 @@ function emptyStateHtml(array $o) { . ($buttons !== '' ? '
' . $buttons . '
' : '') . ''; } + +/** + * A QR code of $text as inline SVG, drawn from the QR maker that comes with + * TCPDF (libs/TCPDF/tcpdf_barcodes_2d.php) - pure PHP, no GD. One square per + * module on a white ground with the standard four-module quiet zone, and a + * viewBox, so it scales with whatever box the CSS gives it. $attributes are + * added to the as they are (class, role, aria-label). '' if the text is + * too long for a QR code. + */ +function qrCodeSvg($text, $attributes = '') { + require_once dirname(__DIR__) . '/libs/TCPDF/tcpdf_barcodes_2d.php'; + $code = (new TCPDF2DBarcode((string) $text, 'QRCODE,L'))->getBarcodeArray(); + if (empty($code['bcode'])) { + return ''; + } + $quiet = 4; + $size = intval($code['num_cols']) + 2 * $quiet; + $path = ''; + foreach ($code['bcode'] as $y => $row) { + // Each run of dark modules in a row is one rectangle + $x = 0; + $cols = count($row); + while ($x < $cols) { + if (empty($row[$x])) { + $x++; + continue; + } + $start = $x; + while ($x < $cols && !empty($row[$x])) { + $x++; + } + $path .= 'M' . ($start + $quiet) . ' ' . ($y + $quiet) . 'h' . ($x - $start) . 'v1h-' . ($x - $start) . 'z'; + } + } + return '' + . ''; +} diff --git a/functions/portal.php b/functions/portal.php index 433360768..af169bf11 100644 --- a/functions/portal.php +++ b/functions/portal.php @@ -247,19 +247,13 @@ function portalMfaReset($user_id) { mysqli_query($mysqli, "DELETE FROM remember_tokens WHERE remember_token_user_id = $user_id"); } -/** The QR code an authenticator app scans for a portal user - an SVG, '' without GD (then the secret is typed in). */ +/** The QR code an authenticator app scans for a portal user, as inline SVG. */ function portalMfaQrSvg($secret, $email) { global $mysqli; - if (!extension_loaded('gd')) { - return ''; - } - require_once dirname(__DIR__) . '/libs/barcode/barcode.php'; $company = mysqli_fetch_row(mysqli_query($mysqli, "SELECT company_name FROM companies WHERE company_id = 1")); $issuer = trim((string) ($company[0] ?? '')) ?: 'Client portal'; $uri = 'otpauth://totp/' . rawurlencode($issuer) . ':' . rawurlencode((string) $email) . '?secret=' . rawurlencode((string) $secret) . '&issuer=' . rawurlencode($issuer); - $svg = (new barcode_generator())->render_svg('qr', $uri, ['w' => 200, 'h' => 200, 'p' => 0]); - $svg = preg_replace('/^<\?xml[^>]*>\s*/', '', (string) $svg); - return preg_replace('/render_svg('qr', $url, ['w' => 180, 'h' => 180, 'p' => 0]); - $svg = preg_replace('/^<\?xml[^>]*>\s*/', '', $svg); - return preg_replace('/ 200, 'h' => 200, 'p' => 0]); - // Shown inline in the page, not as an image - the XML prolog has to go, and it scales with its box - $svg = preg_replace('/^<\?xml[^>]*>\s*/', '', (string) $svg); - return preg_replace('/ - - diff --git a/includes/footer.php b/includes/footer.php index d655e6fa4..6674352d6 100644 --- a/includes/footer.php +++ b/includes/footer.php @@ -66,17 +66,14 @@ - - - - - '; + const body = modal.querySelector('.modal-body'); + const footer = modal.querySelector('.modal-footer'); + + if (icons[options.icon]) { + const icon = document.createElement('i'); + icon.className = 'itflow-dialog-icon ' + icons[options.icon]; + icon.setAttribute('aria-hidden', 'true'); + body.appendChild(icon); + } + const title = document.createElement('h5'); + title.className = 'modal-title'; + title.id = id; + title.textContent = options.title || 'Are you sure?'; + body.appendChild(title); + if (options.text) { + const text = document.createElement('p'); + text.className = 'itflow-dialog-text'; + text.textContent = options.text; + body.appendChild(text); + } + + const radios = []; + if (options.input === 'radio' && options.inputOptions) { + const group = document.createElement('div'); + group.className = 'itflow-dialog-radios'; + group.setAttribute('role', 'radiogroup'); + Object.keys(options.inputOptions).forEach(function (value, i) { + const wrap = document.createElement('div'); + wrap.className = 'form-check form-check-inline'; + const radio = document.createElement('input'); + radio.className = 'form-check-input'; + radio.type = 'radio'; + radio.name = id + 'Radio'; + radio.id = id + 'Radio' + i; + radio.value = value; + radio.checked = String(options.inputValue) === value; + const label = document.createElement('label'); + label.className = 'form-check-label'; + label.htmlFor = radio.id; + label.textContent = options.inputOptions[value]; + wrap.append(radio, label); + group.appendChild(wrap); + radios.push(radio); + }); + body.appendChild(group); + } + + let result = {isConfirmed: false, isDenied: false, isDismissed: true}; + const instance = new bootstrap.Modal(modal); + const button = function (label, className, answer) { + const b = document.createElement('button'); + b.type = 'button'; + b.className = 'btn ' + className; + b.textContent = label; + b.addEventListener('click', function () { + if (answer) { + result = answer(); + } + instance.hide(); + }); + footer.appendChild(b); + return b; + }; + const picked = function () { + const on = radios.filter(function (r) { return r.checked; })[0]; + return on ? on.value : undefined; + }; + const cancel = options.showCancelButton === false ? null : button(options.cancelButtonText || 'Cancel', 'btn-secondary', null); + if (options.denyButtonText) { + button(options.denyButtonText, 'btn-outline-secondary', function () { + return {isConfirmed: false, isDenied: true, isDismissed: false, value: picked()}; + }); + } + const confirm = button(options.confirmButtonText || 'Yes', options.danger ? 'btn-danger' : 'btn-primary', function () { + return {isConfirmed: true, isDenied: false, isDismissed: false, value: picked()}; + }); + + // autofocus also tells js/app.js's modal focus handler to leave it be + const first = options.focusCancel && cancel ? cancel : confirm; + first.setAttribute('autofocus', ''); + const previous = document.activeElement; + modal.addEventListener('shown.bs.modal', function () { + first.focus(); + }); + modal.addEventListener('hidden.bs.modal', function () { + instance.dispose(); + modal.remove(); + // Opened over another modal: Bootstrap takes modal-open off the + // page as this one closes, though the one below is still open + if (document.querySelector('.modal.show')) { + document.body.classList.add('modal-open'); + } + if (options.returnFocus !== false && previous && previous.isConnected && typeof previous.focus === 'function') { + previous.focus({preventScroll: true}); + } + resolve(result); + }); + + document.body.appendChild(modal); + instance.show(); + // Its backdrop goes over any modal already open (css/itflow_custom.css + // puts the dialog itself above both) + const backdrops = document.querySelectorAll('.modal-backdrop'); + if (backdrops.length) { + backdrops[backdrops.length - 1].classList.add('itflow-dialog-backdrop'); + } + }); +} + +/** + * Confirmation dialogs for confirm-link. * * Delegated on document rather than bound to the elements present at page load, * so that confirm-link also works on markup injected by an ajax modal. @@ -21,7 +171,7 @@ */ document.addEventListener('click', function (e) { const link = e.target.closest('a.confirm-link, button.confirm-link'); - if (!link || typeof Swal === 'undefined') { + if (!link || typeof bootstrap === 'undefined') { return; } e.preventDefault(); @@ -35,24 +185,13 @@ document.addEventListener('click', function (e) { const destructive = ['text-danger', 'btn-danger', 'btn-outline-danger'] .some(function (cls) { return link.classList.contains(cls); }); - Swal.fire({ - // SweetAlert2 has no idea about Bootstrap's mode - it keys its own dark - // palette off the `theme` option and defaults to 'light', so the dialog - // stayed white on a dark page. Read at fire time, not at load. - theme: document.documentElement.getAttribute('data-bs-theme') === 'dark' ? 'dark' : 'light', + itflowDialog({ title: link.dataset.confirmTitle || 'Are you sure?', text: link.dataset.confirmText || '', icon: link.dataset.confirmIcon || (destructive ? 'warning' : 'question'), - showCancelButton: true, confirmButtonText: link.dataset.confirmButton || 'Yes', - cancelButtonText: 'Cancel', - reverseButtons: true, - focusCancel: destructive, - buttonsStyling: false, - customClass: { - confirmButton: destructive ? 'btn btn-danger mx-1' : 'btn btn-primary mx-1', - cancelButton: 'btn btn-secondary mx-1' - } + danger: destructive, + focusCancel: destructive }).then(function (result) { if (!result.isConfirmed) { return; diff --git a/js/invoice_bulk.js b/js/invoice_bulk.js index be447db10..7eb8a07b3 100644 --- a/js/invoice_bulk.js +++ b/js/invoice_bulk.js @@ -35,8 +35,8 @@ document.addEventListener('click', function (event) { open.remove(); }) .catch(function () { - if (typeof Swal !== 'undefined') { - Swal.fire({ icon: 'error', title: 'That didn\'t work', text: 'The invoices ticked could not be handed over - reload the page and try again.' }); + if (typeof itflowDialog !== 'undefined') { + itflowDialog({ icon: 'error', title: 'That didn\'t work', text: 'The invoices ticked could not be handed over - reload the page and try again.', confirmButtonText: 'OK', showCancelButton: false }); } }); }); diff --git a/js/phone_inputs.js b/js/phone_inputs.js index 2744c745f..86804dc20 100644 --- a/js/phone_inputs.js +++ b/js/phone_inputs.js @@ -2,10 +2,10 @@ * ITFlow - intl-tel-input wiring, shared by the agent side and the client portal. * * Lived in js/app.js until the portal needed it too. app.js cannot be loaded in - * the portal - it calls DataTables, TinyMCE, Flatpickr and IMask - * unconditionally with no typeof guards, none of which the portal loads - so - * the choice was to copy this or to split it out. Copying it would have left - * two implementations of a subtle piece of logic to drift apart, so it is here. + * the portal - it calls TinyMCE and Flatpickr unconditionally with no typeof + * guards, neither of which the portal loads - so the choice was to copy this or + * to split it out. Copying it would have left two implementations of a subtle + * piece of logic to drift apart, so it is here. * * app.js still drives it on the agent side via itflowStep('phone-inputs', ...), * which is what re-runs it for ajax modals. The portal has no app.js, so this diff --git a/js/portal_datatables.js b/js/portal_datatables.js deleted file mode 100644 index 12fc74a3d..000000000 --- a/js/portal_datatables.js +++ /dev/null @@ -1,38 +0,0 @@ -/* - * ITFlow - DataTables for the client portal. - * - * The agent side initialises DataTables from js/app.js, which the portal cannot - * load: app.js calls TinyMCE, Flatpickr and IMask unconditionally - * and none of them exist here. This is the portal's own one-liner rather than a - * shared extraction, because unlike the phone-input logic there is no real - * behaviour to keep in step - just a constructor. - * - * A separate file, not an inline