diff --git a/CHANGELOG.md b/CHANGELOG.md index 110daf4ce..882ec300d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,9 +6,9 @@ This file documents all notable changes made to ITFlow. ### Upgrading to 26.11 -Update from Maintenance > Update — Queue Update hands the job to cron, which updates the files and applies this release's database changes (2.7.9 to 3.2.2) in the same pass. Nothing else is required. +Update from Maintenance > Update — Queue Update hands the job to cron, which updates the files and applies this release's database changes (2.7.9 to 3.2.3) in the same pass. Nothing else is required. -This is a big release, with forty-three database steps in one go, so take a backup before you update. +This is a big release, with forty-four database steps in one go, so take a backup before you update. The update also clears out data that deletes in older versions left behind, all of it pointing at something that no longer exists: @@ -45,7 +45,7 @@ What the API makes from now on - tickets, replies, clients and the rest - is sta Ticket templates keep their subject, details and tasks, and set nothing else on a ticket until you give them a category, priority, agent, due time or tags. Words in square brackets already in a template, like [Employee Name], are asked for as plain, optional text when a ticket is raised from it, until you set them up on the template's page (see New Features, Ticket templates). Tickets raised before the update don't know which template they came from, so a template's use is counted from the update on. The starter ticket templates you added from Maintenance > Starter Content stay as they are; Update on that page brings them up to the new versions, which ask what they need and come with request forms. -Canned responses keep their names, what they say and their ticket category. One whose category had been deleted is offered on every ticket, as it already was. How often each is used is counted from the update. +Canned responses keep their names, what they say and their ticket category. One whose category had been deleted is offered on every ticket, as it already was. How often each is used is counted from the update. None sets up anything on the reply until you give it a reply type, status or time worked on its Sets up tab. If you are coming from 26.08 or earlier, the database update still has to be run from the command line one time, exactly as described under Upgrading to 26.09 below. @@ -510,6 +510,10 @@ If you are coming from 26.08 or earlier, the database update still has to be run - A response can be offered on several ticket categories, or on every ticket. - [Contact], [First Name], [Client], [Ticket], [Subject], [Ticket Link], [Asset], [Site], [Project], [Agent], [Date], [Month], [Quarter] and [Year] are filled in from the ticket as a response goes into a reply. [Agent] is you, the agent replying, and [Ticket Link] is a link to the ticket, as its emails have. The response window lists them under the editor to click in where the cursor is. Anything else in square brackets - [Date of visit] - stays as it is, for you to fill in before sending. - Responses can be copied, archived - no longer offered on tickets - restored and deleted. + - Canned response above the reply box opens a list of the ones on offer to search, by name or by what they say, each with a line of it and what it sets up - Enter picks the first one. Or type / in the reply box and keep typing to narrow the list, then Enter or click to put one in. + - A response can set up the reply too, on its Sets up tab: reply as an internal note, a public note or an email reply, the ticket's status after it, and minutes added to the time worked. They are set as it goes in, a line under the picker says what was set, and you can still change them before sending. + - Sending a reply a canned response went into with something still in square brackets - [Date of visit] - asks first: Fill them in selects the first one to type over, or Send anyway. + - Update & Reply on the tickets list offers the responses for the tickets' categories and the ones for every ticket. [First Name], [Ticket], [Ticket Link] and the other placeholders in what you write there are filled in for each ticket as it is sent, and a response picked into it counts as used on each. - Admin > Categories counts the canned responses offered on each ticket category, linked to the list of them, and merging categories moves them over. - **Assets** - The asset list has: @@ -932,6 +936,7 @@ If you are coming from 26.08 or earlier, the database update still has to be run - Recurring invoices: the email went to contacts that had been archived, and could reach the same address twice. - Client Portal: the recurring card on the home page didn't show for a client with only yearly recurring invoices, and counted archived ones. - Copy buttons in many places, such as pages that already had a window open, showed Copied! but copied nothing. Copy guest URL on invoices and quotes jumped the page to the top, and copying an empty field wiped your clipboard. +- Tickets: clicking Send on a reply that didn't go - with the reply box shut - cleared its time worked. - Tickets: an agent without sales access who edited a ticket turned billable off. Email reply was offered when no mail server was set up. The timer threw an error on resolved tickets, and the due date was not shown. - Assets: editing some asset types wiped the OS, firmware, purchase and warranty fields. The add form broke when there were no OS values, and bulk assigning a contact or location could change assets of another client. - Assets: the quick look's notes could save over the wrong asset's notes, and its Credentials tab showed without permission. @@ -1468,6 +1473,10 @@ If you are coming from 26.08 or earlier, the database update still has to be run - New `functions/canned_response.php`: `CANNED_RESPONSE_PLACEHOLDERS`, `cannedResponseRow()`, `cannedResponseCategoryIds()`, `cannedResponseCategoriesFor($ids)`, `cannedResponseFields($post, &$error)` (`name`, `body`, `category_ids`), `cannedResponseSave($id, $fields)`, `cannedResponseSetCategories()`, `cannedResponseCopy()`, `cannedResponsePreview()`, `cannedResponsesForTicket($category_id)` (`category` and `general`), `cannedResponseValues($ticket_id, $agent_name)`, `cannedResponseFill($html, $ticket_id, $agent_name)` (purified, then filled through `ticketPlaceholderFill()`) and `cannedResponseRecordUses($ids, $ticket_id, $user_id)`. - Admin: `admin/canned_responses.php` takes `q`, `category` (an id, or `every`), `sort` - `canned_response_name`, `use_count` or `last_used` - `order`, `page` and `show=archived`. `admin/modals/canned_response/canned_response_form.php` is shared by `canned_response_add.php` (`category`) and `canned_response_edit.php` (`id`), with `js/canned_response_form.js`. `admin/post/canned_response.php`: `add_canned_response` and `edit_canned_response` (`canned_response_id`, `name`, `body`, `category_ids[]`), GET `copy_canned_response`, `archive_canned_response`, `restore_canned_response` and `delete_canned_response`. Audit entries are Canned Response Create, Edit, Archive, Restore and Delete. - `agent/ajax.php?get_canned_response` takes `ticket_id` and answers the body filled in for that ticket, after the client access check. The picker adds `canned_response_ids[]` to the reply form, and `add_ticket_reply` records them when there is a reply. + - Database 3.2.3: `canned_responses` gains `canned_response_reply_type` (0 internal note, 1 public note, 2 email reply - NULL leaves it), `canned_response_ticket_status` (NULL leaves it) and `canned_response_minutes`, added to the time worked. + - `functions/canned_response.php`: `CANNED_RESPONSE_REPLY_TYPES`, `CANNED_RESPONSE_MAX_MINUTES`, `cannedResponseStatuses()` (the ones a reply can set), `cannedResponseMinutesText()`, `cannedResponseSetsUpHtml($row)`, `cannedResponseActions($row)` and `cannedResponsePickerGroups($category_ids)` - label => rows, each category with any then Every ticket; `cannedResponsesForTicket()` returns it for one. `cannedResponsePlaceholders($html, $ticket_id, $agent_name)` fills without purifying, and `cannedResponseFill()` purifies then calls it. `cannedResponseFields()` takes `reply_type`, `ticket_status` and `minutes`. + - The picker: `agent/includes/inc_canned_response_picker.php` (`$canned_picker_groups`, `$canned_picker_id`, `$canned_picker_editor`, `$canned_picker_ticket_id` - 0 for Update & Reply) and `agent/js/canned_response_picker.js`, which exposes `window.itflowCannedPick(pickerId, id)` and asks before a submit with bracketed words left. `js/app.js` `itflowCannedAutocompleter(editor)` adds the / menu to the `.tinymce` and `.tinymceTicket` editors whose textarea names a picker in `data-canned-picker`. `get_canned_response` answers `found`, `id`, `name`, `body`, `reply_type`, `reply_type_name`, `ticket_status`, `status_name`, `minutes` and `minutes_text`. + - `bulk_ticket_reply` fills the placeholders for each ticket with `cannedResponsePlaceholders()` - its email too - and records `canned_response_ids[]` on each. `agent/js/ticket_time_tracking.js` resets the timer on the reply form's submit, when it isn't prevented, rather than on a click of Send. - Categories: a use in `categoryKinds()` can be a link table - `link` (`owner`, `records`, `join`). `categoryUsage()` joins it, `categoryMoveRecords()` adds the new category and takes the old ones off, and the API's `used_by` counts them under `records` (still `canned_responses`). - Empty states: every list page sets `$empty_state` before including `includes/filter_footer.php`, and `includes/inc_empty_state.php` draws it with `emptyStateHtml()` (`functions/format.php`) when the list has nothing - `thing`, `icon`, `title`, `text`, `actions` (`label`, `modal` or `href`, `size`, `icon`; the first is the main one), `archived`, `view`, `filtered`, `views`, `match_title`, `match_text` and `clear_url`. `emptyStateFiltered($views)` reads the GET string for a search or filter, leaving out paging, sorting, `client_id`, `archived` and the page's views, and `emptyStateClearUrl($views)` is the page without them. `emptyStatePill($pills, $key, $default, $good)` builds a pill's own state from the page's pill array (`label`, `icon`, `title`, `alarm`), with a tick for `alarm` pills and the keys in `$good`. Files, notifications and racks call `emptyStateHtml()` in their own layout; files and notifications set `$empty_state_skip`. A page that sets nothing still gets one, worded from `$page_title`. The pages' own empty blocks (`.itflow-asset-empty` under a list) are gone. CSS: `.itflow-empty-state` with `-icon` (a grey round tile), `-title`, `-text` and `-actions`. - Removed unused helpers and files: diff --git a/admin/canned_responses.php b/admin/canned_responses.php index 7810849f8..484a85f49 100644 --- a/admin/canned_responses.php +++ b/admin/canned_responses.php @@ -5,7 +5,8 @@ * from the picker above the reply box. Each is offered on tickets in the * ticket categories it is set to, or on every ticket, and its placeholders * are filled in from the ticket as it goes in. Each row shows what it says, - * where it is offered, and how often it has gone into a reply. A response + * where it is offered, what picking it sets up on the reply (who sees it, + * the status after it, time worked) and how often it has gone into a reply. A response * can be changed, copied as the start of another, archived - not offered on * tickets - or deleted. The work is in functions/canned_response.php; the * handlers are admin/post/canned_response.php. @@ -40,7 +41,7 @@ if ($category_filter === 'every') { $filters .= " AND EXISTS (SELECT 1 FROM canned_response_categories c WHERE c.canned_response_id = canned_responses.canned_response_id AND c.category_id = " . intval($category_filter) . ")"; } -$sql = mysqli_query($mysqli, "SELECT SQL_CALC_FOUND_ROWS canned_responses.canned_response_id, canned_response_name, canned_response_body, canned_response_created_at, canned_response_updated_at, canned_response_archived_at, +$sql = mysqli_query($mysqli, "SELECT SQL_CALC_FOUND_ROWS canned_responses.canned_response_id, canned_response_name, canned_response_body, canned_response_reply_type, canned_response_ticket_status, canned_response_minutes, canned_response_created_at, canned_response_updated_at, canned_response_archived_at, COALESCE(used.use_count, 0) AS use_count, used.last_used FROM canned_responses LEFT JOIN ( @@ -131,6 +132,7 @@ $csrf = $_SESSION['csrf_token']; }, $categories)) . '' : 'Every ticket'; $preview = cannedResponsePreview($row['canned_response_body']); + $sets_up = cannedResponseSetsUpHtml($row); ?> @@ -141,6 +143,9 @@ $csrf = $_SESSION['csrf_token'];
+ +
+
Archived
diff --git a/admin/database_updates/3.2.3.php b/admin/database_updates/3.2.3.php new file mode 100644 index 000000000..be9576f0b --- /dev/null +++ b/admin/database_updates/3.2.3.php @@ -0,0 +1,17 @@ + -
- -
- - + + +
+ +
+
+ +
+ + +
+
+ +
+ +
+ + + +
+ Tickets in these categories. Leave it empty to offer it on every ticket. +
+ +
+ + +
+ +
Filled in from the ticket as it goes in - click one to put it where the cursor is:
+
+ $means) { ?> + + +
+
Anything else in square brackets - [Date of visit] - stays as it is, and the agent is asked about it before sending.
+
+ +
+

Set on the reply when the response is picked - the agent can still change them before sending. Each is left as it is unless set here.

+ +
+ +
+ + +
+ An email reply on a ticket with nobody to email is a public note. +
+ +
+ +
+ + +
+ Resolved waits for a ticket's open tasks to be done. +
+ +
+ +
+ + + minutes +
+ Added to the reply's time worked.
-
- -
- - - -
- Tickets in these categories. Leave it empty to offer it on every ticket.
-
- - -
- -
Filled in from the ticket as it goes in - click one to put it where the cursor is:
-
- $means) { ?> - - -
-
Anything else in square brackets - [Date of visit] - stays as it is, for whoever replies to fill in.
- diff --git a/agent/ajax.php b/agent/ajax.php index 63acac28f..7f4b3d064 100644 --- a/agent/ajax.php +++ b/agent/ajax.php @@ -1045,9 +1045,24 @@ if (isset($_GET['get_canned_response'])) { } // Purified here rather than at save time, the same way ticket replies and ticket - // template details are - what lands in the editor is what would have been rendered - $response = []; - $response['body'] = $canned_row ? cannedResponseFill($canned_row['canned_response_body'], $canned_ticket_id, stripslashes($session_name)) : ''; + // template details are - what lands in the editor is what would have been rendered. + // With what picking it sets up on the reply (cannedResponseActions()) + $response = ['found' => false, 'body' => '']; + if ($canned_row) { + $actions = cannedResponseActions($canned_row); + $response = [ + 'found' => true, + 'id' => intval($canned_row['canned_response_id']), + 'name' => $canned_row['canned_response_name'], + 'body' => cannedResponseFill($canned_row['canned_response_body'], $canned_ticket_id, stripslashes($session_name)), + 'reply_type' => $actions['reply_type'], + 'reply_type_name' => $actions['reply_type'] === null ? '' : CANNED_RESPONSE_REPLY_TYPES[$actions['reply_type']][0], + 'ticket_status' => $actions['ticket_status'], + 'status_name' => $actions['status_name'], + 'minutes' => $actions['minutes'], + 'minutes_text' => $actions['minutes'] ? cannedResponseMinutesText($actions['minutes']) : '', + ]; + } echo json_encode($response); diff --git a/agent/includes/inc_canned_response_picker.php b/agent/includes/inc_canned_response_picker.php new file mode 100644 index 000000000..a1a020e28 --- /dev/null +++ b/agent/includes/inc_canned_response_picker.php @@ -0,0 +1,54 @@ + + + + 0; + } + } + + function say(picker, text, error) { + const line = picker.querySelector('[data-canned-applied]'); + if (!line) { + return; + } + line.textContent = text; + line.classList.toggle('text-danger', !!error); + line.classList.toggle('text-body-secondary', !error); + line.hidden = false; + } + + function insert(editorId, html) { + const editor = window.tinymce ? tinymce.get(editorId) : null; + if (editor) { + editor.insertContent(html); + editor.focus(); + return; + } + const textarea = document.getElementById(editorId); + if (textarea) { + textarea.value += html; + } + } + + function setSelect(select, value) { + if (select.itflowSelect) { + select.itflowSelect.setValue(value); + } else { + select.value = value; + select.dispatchEvent(new Event('change', { bubbles: true })); + } + } + + function pad(n) { + return (n < 10 ? '0' : '') + n; + } + + // Set up on the form what the response sets up - what was done, in words + function apply(form, data) { + const done = []; + if (!form) { + return done; + } + + // Who sees it: the ticket's reply types, or Update & Reply's internal box + if (data.reply_type !== null) { + const radios = form.querySelectorAll('input[name="public_reply_type"]'); + const internal = form.querySelector('input[type="checkbox"][name="bulk_private_reply"]'); + if (radios.length) { + let radio = form.querySelector('input[name="public_reply_type"][value="' + data.reply_type + '"]'); + let label = data.reply_type_name; + if (!radio && data.reply_type === 2) { + // No email address to send to - a public note is the nearest + radio = form.querySelector('input[name="public_reply_type"][value="1"]'); + label = 'Public note, as there is nobody to email'; + } + if (radio) { + if (!radio.checked) { + radio.checked = true; + radio.dispatchEvent(new Event('change', { bubbles: true })); + } + done.push('set the reply to ' + label); + } + } else if (internal) { + internal.checked = data.reply_type === 0; + done.push(data.reply_type === 0 ? 'marked it internal' : 'made it a public reply'); + } + } + + // The status after it + if (data.ticket_status !== null) { + const select = form.querySelector('select[name="status"], select[name="bulk_status"]'); + if (select && select.querySelector('option[value="' + data.ticket_status + '"]')) { + setSelect(select, String(data.ticket_status)); + done.push('set the status to ' + data.status_name); + } else if (select) { + done.push('left the status - ' + data.status_name + ' isn\'t on offer here'); + } + } + + // Time worked, added: the reply's hours, minutes and seconds (the timer + // reads them back on change), or Update & Reply's HH:MM:SS + if (data.minutes > 0) { + const hours = form.querySelector('input[name="hours"]'); + const minutes = form.querySelector('input[name="minutes"]'); + const seconds = form.querySelector('input[name="seconds"]'); + const time = form.querySelector('input[name="time"]'); + let total = null; + if (hours && minutes && seconds) { + total = (parseInt(hours.value, 10) || 0) * 3600 + (parseInt(minutes.value, 10) || 0) * 60 + (parseInt(seconds.value, 10) || 0) + data.minutes * 60; + hours.value = pad(Math.floor(total / 3600)); + minutes.value = pad(Math.floor(total % 3600 / 60)); + seconds.value = pad(total % 60); + minutes.dispatchEvent(new Event('change', { bubbles: true })); + } else if (time) { + const parts = time.value.split(':').map(function (part) { + return parseInt(part, 10) || 0; + }); + total = (parts[0] || 0) * 3600 + (parts[1] || 0) * 60 + (parts[2] || 0) + data.minutes * 60; + time.value = pad(Math.min(23, Math.floor(total / 3600))) + ':' + pad(Math.floor(total % 3600 / 60)) + ':' + pad(total % 60); + } + if (total !== null) { + done.push('added ' + data.minutes_text + ' to the time worked'); + } + } + return done; + } + + function pick(picker, id) { + const toggle = picker.querySelector('[data-canned-toggle]'); + if (toggle && window.bootstrap) { + bootstrap.Dropdown.getOrCreateInstance(toggle).hide(); + } + return fetch('/agent/ajax.php?get_canned_response=' + encodeURIComponent(id) + '&ticket_id=' + encodeURIComponent(picker.dataset.ticketId || '0'), { credentials: 'same-origin' }) + .then(function (response) { + if (!response.ok) { + throw new Error('HTTP ' + response.status); + } + return response.json(); + }) + .then(function (data) { + if (!data.found) { + say(picker, 'That canned response is gone - it may have been archived or deleted.', true); + return; + } + const form = picker.closest('form'); + if (form && !form.querySelector('input[name="canned_response_ids[]"][value="' + data.id + '"]')) { + const used = document.createElement('input'); + used.type = 'hidden'; + used.name = 'canned_response_ids[]'; + used.value = data.id; + form.appendChild(used); + } + insert(picker.dataset.editor, data.body); + const done = apply(form, data); + say(picker, data.name + ' went in' + (done.length ? ', and ' + done.join(', ') : '') + '.'); + }) + .catch(function () { + say(picker, 'Could not load that canned response.', true); + }); + } + + // For the / menu in the reply box (js/app.js) + window.itflowCannedPick = function (pickerId, id) { + const picker = document.getElementById(pickerId); + if (picker) { + pick(picker, id); + } + }; + + // Search as you type + document.addEventListener('input', function (e) { + const search = e.target.closest('[data-canned-search]'); + if (search) { + filter(search.closest('[data-canned-picker]'), search.value); + } + }); + + // Opened: an empty search, ready to type into + document.addEventListener('shown.bs.dropdown', function (e) { + const picker = e.target.closest ? e.target.closest('[data-canned-picker]') : null; + if (!picker) { + return; + } + const search = picker.querySelector('[data-canned-search]'); + search.value = ''; + filter(picker, ''); + search.focus(); + }); + + // Enter picks the first one shown; the down arrow goes into the list + document.addEventListener('keydown', function (e) { + const search = e.target.closest ? e.target.closest('[data-canned-search]') : null; + if (!search) { + return; + } + const picker = search.closest('[data-canned-picker]'); + const first = itemsOf(picker).find(function (item) { + return !item.hidden; + }); + if (e.key === 'Enter') { + e.preventDefault(); + if (first) { + pick(picker, first.dataset.cannedId); + } + } else if (e.key === 'ArrowDown' && first) { + e.preventDefault(); + first.focus(); + } + }); + + // A click on one picks it + document.addEventListener('click', function (e) { + const item = e.target.closest('[data-canned-picker] [data-canned-id]'); + if (item) { + e.preventDefault(); + pick(item.closest('[data-canned-picker]'), item.dataset.cannedId); + } + }); + + // The first [word] left in the reply, selected for typing over + function selectBracket(editor, name) { + const pattern = new RegExp('\\[' + name.split(/[  ]+/).map(function (word) { + return word.replace(/[.*+?^${}()|[\]\\\/-]/g, '\\$&'); + }).join('[ \\u00a0]+') + '\\]'); + const walker = editor.getDoc().createTreeWalker(editor.getBody(), NodeFilter.SHOW_TEXT); + let node; + while ((node = walker.nextNode())) { + const match = pattern.exec(node.nodeValue); + if (match) { + const range = editor.dom.createRng(); + range.setStart(node, match.index); + range.setEnd(node, match.index + match[0].length); + editor.selection.setRng(range); + editor.selection.scrollIntoView(); + break; + } + } + editor.focus(); + } + + // Sending a reply a response went into with [words] still in it asks first + 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') { + return; + } + if (form.dataset.cannedSendAnyway === '1') { + delete form.dataset.cannedSendAnyway; + return; + } + const editor = window.tinymce ? tinymce.get(picker.dataset.editor) : null; + const textarea = document.getElementById(picker.dataset.editor); + const text = editor ? editor.getContent({ format: 'text' }) : (textarea ? textarea.value : ''); + // In Update & Reply these are filled in for each ticket as it is sent + const filledLater = (picker.dataset.ticketId === '0' ? (picker.dataset.cannedFilled || '').split('|') : []).map(function (name) { + return name.toLowerCase(); + }); + const left = []; + let match; + BRACKETS.lastIndex = 0; + while ((match = BRACKETS.exec(text)) !== null) { + const name = match[1].replace(/[  ]+/g, ' ').trim(); + if (filledLater.indexOf(name.toLowerCase()) === -1 && left.indexOf(name) === -1) { + left.push(name); + } + } + if (!left.length) { + return; + } + 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', + title: 'Still to fill in', + html: list, + 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' + } + }).then(function (result) { + if (result.isConfirmed) { + form.dataset.cannedSendAnyway = '1'; + if (form.requestSubmit) { + form.requestSubmit(submitter); + } else { + form.submit(); + } + } else if (editor) { + setTimeout(function () { + selectBracket(editor, left[0]); + }, 0); + } + }); + }, true); +})(); diff --git a/agent/js/ticket_time_tracking.js b/agent/js/ticket_time_tracking.js index 17bf38f5e..f25d5acc1 100644 --- a/agent/js/ticket_time_tracking.js +++ b/agent/js/ticket_time_tracking.js @@ -190,10 +190,16 @@ }); } + // Reset once the reply actually goes - not on a click of Send that is held back (the + // composer shut, or a canned response's [word] still to fill in), which lost the time const addReplyBtn = document.getElementById("ticket_add_reply"); - if (addReplyBtn) { - addReplyBtn.addEventListener('click', function() { - setTimeout(forceResetTimer, 100); + if (addReplyBtn && addReplyBtn.form) { + addReplyBtn.form.addEventListener('submit', function(e) { + setTimeout(function() { + if (!e.defaultPrevented) { + forceResetTimer(); + } + }, 0); }); } diff --git a/agent/modals/ticket/ticket_bulk_reply.php b/agent/modals/ticket/ticket_bulk_reply.php index 63de672b1..2cf3c1c58 100644 --- a/agent/modals/ticket/ticket_bulk_reply.php +++ b/agent/modals/ticket/ticket_bulk_reply.php @@ -8,6 +8,19 @@ $ticket_ids = array_map('intval', $_GET['ticket_ids'] ?? []); $count = count($ticket_ids); +// The canned responses for the tickets' categories, and the ones for every ticket - filled in for each ticket as it is sent +$bulk_category_ids = []; +if ($ticket_ids) { + $sql_bulk_categories = mysqli_query($mysqli, "SELECT DISTINCT ticket_category FROM tickets WHERE ticket_id IN (" . implode(',', array_filter($ticket_ids) ?: [0]) . ")"); + while ($row = mysqli_fetch_row($sql_bulk_categories)) { + $bulk_category_ids[] = intval($row[0]); + } +} +$canned_picker_groups = cannedResponsePickerGroups($bulk_category_ids); +$canned_picker_id = 'cannedPickerBulk'; +$canned_picker_editor = 'bulkReplyDetails'; +$canned_picker_ticket_id = 0; + ob_start(); ?> @@ -41,9 +54,12 @@ ob_start();
-
- + + +
+
+
[First Name], [Ticket], [Subject] and the other placeholders are filled in for each ticket as it is sent.
diff --git a/agent/post/ticket.php b/agent/post/ticket.php index d4cd888f3..ddc7f83d0 100644 --- a/agent/post/ticket.php +++ b/agent/post/ticket.php @@ -843,7 +843,9 @@ if (isset($_POST['bulk_ticket_reply'])) { validateCSRFToken(); - $reply = mysqli_real_escape_string($mysqli, (string) ($_POST['bulk_reply_details'] ?? '')); + // The placeholders are filled in for each ticket, below + $reply_raw = (string) ($_POST['bulk_reply_details'] ?? ''); + $canned_response_ids = (array) ($_POST['canned_response_ids'] ?? []); $status_input = intval($_POST['bulk_status'] ?? 0); $time_worked = escapeSql(ticketTimeWorked($_POST['time'] ?? '')); $private_note = intval($_POST['bulk_private_reply'] ?? 0); @@ -870,7 +872,10 @@ if (isset($_POST['bulk_ticket_reply'])) { setTicketFirstResponse($ticket_id); } + $reply_text = cannedResponsePlaceholders($reply_raw, $ticket_id, stripslashes($session_name)); + $reply = mysqli_real_escape_string($mysqli, $reply_text); mysqli_query($mysqli, "INSERT INTO ticket_replies SET ticket_reply = '$reply', ticket_reply_time_worked = '$time_worked', ticket_reply_type = '$reply_type', ticket_reply_by = $session_user_id, ticket_reply_ticket_id = $ticket_id"); + cannedResponseRecordUses($canned_response_ids, $ticket_id, $session_user_id); mysqli_query($mysqli, "UPDATE tickets SET ticket_status = $ticket_status, ticket_updated_at = NOW() WHERE ticket_id = $ticket_id"); syncTicketSlaClock($ticket_id); @@ -894,7 +899,7 @@ if (isset($_POST['bulk_ticket_reply'])) { // Email the client and watchers about a public update if (!$private_note) { - ticketMailReply($ticket_id, (string) ($_POST['bulk_reply_details'] ?? ''), stripslashes($session_name)); + ticketMailReply($ticket_id, $reply_text, stripslashes($session_name)); } // Tell the agent it is assigned to, and whoever opened it diff --git a/agent/ticket.php b/agent/ticket.php index 02ac984a8..42244d3ae 100644 --- a/agent/ticket.php +++ b/agent/ticket.php @@ -748,44 +748,22 @@ if (isset($_GET['ticket_id'])) {
- -
- -
- - + $canned_picker_groups = cannedResponsesForTicket(intval($ticket_category)); + $canned_picker_id = 'cannedPickerReply'; + $canned_picker_editor = 'ticket_reply'; + $canned_picker_ticket_id = intval($ticket_id); + require __DIR__ . "/includes/inc_canned_response_picker.php"; + ?>
- +
@@ -1786,53 +1764,6 @@ if (!empty($can_edit_ticket) && !empty($ticket_is_open)) { ?> }); } - // Canned responses - insert at the cursor rather than replacing, so picking one into a - // half-written reply adds to it. The body is fetched on demand, filled in for this - // ticket; TinyMCE owns the field by now, so setting the textarea value directly would - // do nothing visible. The reply carries which ones went in, for how often each is used. - const cannedPicker = document.getElementById('canned_response_picker'); - if (cannedPicker) { - cannedPicker.addEventListener('change', function () { - const cannedId = cannedPicker.value; - if (!cannedId) return; - - cannedPicker.disabled = true; - - fetch('ajax.php?get_canned_response=' + encodeURIComponent(cannedId) + '&ticket_id=' + encodeURIComponent(cannedPicker.dataset.ticketId || '')) - .then(response => response.json()) - .then(data => { - const form = cannedPicker.closest('form'); - if (form && !form.querySelector('input[name="canned_response_ids[]"][value="' + cannedId + '"]')) { - const used = document.createElement('input'); - used.type = 'hidden'; - used.name = 'canned_response_ids[]'; - used.value = cannedId; - form.appendChild(used); - } - - const editor = window.tinymce ? tinymce.get('ticket_reply') : null; - - if (editor) { - editor.insertContent(data.body); - editor.focus(); - } else { - // TinyMCE failed to load - fall back to the plain textarea - const textarea = document.getElementById('ticket_reply'); - if (textarea) { - textarea.value += data.body; - } - } - }) - .catch(() => { - alert('Could not load that canned response.'); - }) - .finally(() => { - cannedPicker.disabled = false; - cannedPicker.value = ''; - }); - }); - } - // Reply composer - the type buttons above are the entry point. The composer stays // collapsed until one is picked, so the conversation is not pushed down the page and // a public reply is never the default. diff --git a/css/itflow_custom.css b/css/itflow_custom.css index da71a2e80..f86cbf056 100644 --- a/css/itflow_custom.css +++ b/css/itflow_custom.css @@ -3131,6 +3131,40 @@ a:focus-visible .itflow-category-name { [data-category-sortable] .sortable-ghost > * { background-color: var(--bs-tertiary-bg) !important; } +/* The canned response picker above a reply box - a searchable list, each + response with a line or two of what it says - and the / menu in the reply */ +.itflow-canned-menu { + width: 30rem; + max-width: calc(100vw - 2rem); +} +.itflow-canned-list { + max-height: 22rem; + overflow-y: auto; + padding-bottom: .25rem; +} +.itflow-canned-item { + white-space: normal; + padding-top: .375rem; + padding-bottom: .375rem; +} +.itflow-canned-preview { + display: -webkit-box; + -webkit-line-clamp: 2; + -webkit-box-orient: vertical; + overflow: hidden; +} +.itflow-canned-item:active .text-body-secondary, +.itflow-canned-item.active .text-body-secondary { + color: inherit !important; +} +.tox .itflow-canned-ac-name { + font-weight: 600; +} +.tox .itflow-canned-ac-preview { + font-size: .8125rem; + opacity: .75; + white-space: normal; +} .itflow-clients-street { max-width: 16rem; } diff --git a/db.sql b/db.sql index a57610c51..e253e66bd 100644 --- a/db.sql +++ b/db.sql @@ -581,6 +581,9 @@ CREATE TABLE `canned_responses` ( `canned_response_id` int(11) NOT NULL AUTO_INCREMENT, `canned_response_name` varchar(200) NOT NULL, `canned_response_body` longtext DEFAULT NULL, + `canned_response_reply_type` tinyint(1) DEFAULT NULL, + `canned_response_ticket_status` int(11) DEFAULT NULL, + `canned_response_minutes` int(11) NOT NULL DEFAULT 0, `canned_response_created_at` datetime NOT NULL DEFAULT current_timestamp(), `canned_response_updated_at` datetime DEFAULT NULL ON UPDATE current_timestamp(), `canned_response_archived_at` datetime DEFAULT NULL, diff --git a/functions/canned_response.php b/functions/canned_response.php index cc407ab5d..f2a70e255 100644 --- a/functions/canned_response.php +++ b/functions/canned_response.php @@ -6,11 +6,17 @@ * categories it is set to, or on every ticket when it has none. The * placeholders in it - [Contact], [Ticket], [Agent] and the like - are filled * in from the ticket as it goes in, and each time one goes into a reply is - * kept, for how often each is used and when it last was. + * kept, for how often each is used and when it last was. A response can set + * up the reply too - who sees it, the ticket's status after it and time + * worked - when it is picked; the agent can still change them. + * + * Picked from the picker above the reply box, or by typing / in it + * (agent/includes/inc_canned_response_picker.php, agent/js/canned_response_picker.js), + * on a ticket and in Update & Reply for several tickets. * * Shared by admin/canned_responses.php, admin/modals/canned_response/*, - * admin/post/canned_response.php, agent/ticket.php, agent/ajax.php and the - * reply handler (agent/post/ticket.php). + * admin/post/canned_response.php, agent/ticket.php, the Update & Reply + * window, agent/ajax.php and the reply handlers (agent/post/ticket.php). */ /** The placeholders filled in from the ticket as a response goes in - what each becomes. */ @@ -31,6 +37,16 @@ const CANNED_RESPONSE_PLACEHOLDERS = [ 'Year' => 'the year', ]; +/** Who a reply is for, as a response can set it - the ticket page's reply types: [label, icon]. */ +const CANNED_RESPONSE_REPLY_TYPES = [ + 0 => ['Internal note', 'fa-lock'], + 1 => ['Public note', 'fa-eye'], + 2 => ['Email reply', 'fa-paper-plane'], +]; + +/** The longest time worked a response can add, in minutes - a day. */ +const CANNED_RESPONSE_MAX_MINUTES = 1440; + /** One response, archived or not, or null. */ function cannedResponseRow($canned_response_id) { global $mysqli; @@ -38,7 +54,8 @@ function cannedResponseRow($canned_response_id) { if ($canned_response_id <= 0) { return null; } - $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT canned_response_id, canned_response_name, canned_response_body, canned_response_created_at, canned_response_updated_at, canned_response_archived_at + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT canned_response_id, canned_response_name, canned_response_body, canned_response_reply_type, canned_response_ticket_status, canned_response_minutes, + canned_response_created_at, canned_response_updated_at, canned_response_archived_at FROM canned_responses WHERE canned_response_id = $canned_response_id")); return $row ?: null; } @@ -71,10 +88,28 @@ function cannedResponseCategoriesFor(array $canned_response_ids) { return $categories; } +/** The statuses a response can leave a ticket in - the ones a reply can set: ticket_status_id => [name, color], active ones but New and Closed. */ +function cannedResponseStatuses() { + global $mysqli; + static $statuses = null; + if ($statuses === null) { + $statuses = []; + $sql = mysqli_query($mysqli, "SELECT ticket_status_id, ticket_status_name, ticket_status_color FROM ticket_statuses + WHERE ticket_status_id NOT IN (1, 5) AND ticket_status_active = 1 ORDER BY ticket_status_order ASC, ticket_status_id ASC"); + while ($row = mysqli_fetch_assoc($sql)) { + $statuses[intval($row['ticket_status_id'])] = ['name' => (string) $row['ticket_status_name'], 'color' => (string) $row['ticket_status_color']]; + } + } + return $statuses; +} + /* * The response window's fields, checked - [$fields, $error]. $post: name, * body (the editor's HTML, kept as written - it is purified where it is - * shown) and category_ids[] (ticket categories; none for every ticket). + * shown), category_ids[] (ticket categories; none for every ticket), and + * what picking it sets up: reply_type ('' leaves it, or 0 1 2 as + * CANNED_RESPONSE_REPLY_TYPES), ticket_status ('' leaves it, or one of + * cannedResponseStatuses()) and minutes (added to the time worked). */ function cannedResponseFields(array $post, &$error = '') { global $mysqli; @@ -98,14 +133,27 @@ function cannedResponseFields(array $post, &$error = '') { } $category_ids = array_values(array_intersect($category_ids, $known)); } - return ['name' => $name, 'body' => (string) ($post['body'] ?? ''), 'category_ids' => $category_ids]; + $reply_type = trim((string) ($post['reply_type'] ?? '')); + $reply_type = $reply_type !== '' && isset(CANNED_RESPONSE_REPLY_TYPES[intval($reply_type)]) ? intval($reply_type) : null; + $ticket_status = intval($post['ticket_status'] ?? 0); + $ticket_status = isset(cannedResponseStatuses()[$ticket_status]) ? $ticket_status : null; + $minutes = intval($post['minutes'] ?? 0); + if ($minutes < 0 || $minutes > CANNED_RESPONSE_MAX_MINUTES) { + $error = 'The time worked it adds is up to ' . CANNED_RESPONSE_MAX_MINUTES . ' minutes - a day'; + return null; + } + return ['name' => $name, 'body' => (string) ($post['body'] ?? ''), 'category_ids' => $category_ids, + 'reply_type' => $reply_type, 'ticket_status' => $ticket_status, 'minutes' => $minutes]; } /* Save a response's fields (cannedResponseFields()) - a new one with $canned_response_id 0. Its id. */ function cannedResponseSave($canned_response_id, array $f) { global $mysqli; $canned_response_id = intval($canned_response_id); - $set = "canned_response_name = '" . escapeSql($f['name']) . "', canned_response_body = '" . mysqli_real_escape_string($mysqli, $f['body']) . "'"; + $set = "canned_response_name = '" . escapeSql($f['name']) . "', canned_response_body = '" . mysqli_real_escape_string($mysqli, $f['body']) . "', + canned_response_reply_type = " . ($f['reply_type'] === null ? 'NULL' : intval($f['reply_type'])) . ", + canned_response_ticket_status = " . ($f['ticket_status'] === null ? 'NULL' : intval($f['ticket_status'])) . ", + canned_response_minutes = " . intval($f['minutes']); if ($canned_response_id) { mysqli_query($mysqli, "UPDATE canned_responses SET $set WHERE canned_response_id = $canned_response_id"); } else { @@ -126,7 +174,7 @@ function cannedResponseSetCategories($canned_response_id, array $category_ids) { } } -/* A new response starting from this one - "Copy of", for the same categories. Its id, or 0. */ +/* A new response starting from this one - "Copy of", for the same categories, setting up the same. Its id, or 0. */ function cannedResponseCopy($canned_response_id) { $row = cannedResponseRow($canned_response_id); if (!$row) { @@ -136,6 +184,9 @@ function cannedResponseCopy($canned_response_id) { 'name' => mb_substr('Copy of ' . $row['canned_response_name'], 0, 200), 'body' => (string) $row['canned_response_body'], 'category_ids' => cannedResponseCategoryIds($row['canned_response_id']), + 'reply_type' => $row['canned_response_reply_type'] === null ? null : intval($row['canned_response_reply_type']), + 'ticket_status' => $row['canned_response_ticket_status'] === null ? null : intval($row['canned_response_ticket_status']), + 'minutes' => intval($row['canned_response_minutes']), ]); } @@ -145,29 +196,90 @@ function cannedResponsePreview($html, $length = 140) { return mb_strimwidth($text, 0, $length, '...'); } +/* "15m", "1h 30m" - time worked a response adds. */ +function cannedResponseMinutesText($minutes) { + $minutes = intval($minutes); + $hours = intdiv($minutes, 60); + return trim(($hours ? $hours . 'h ' : '') . ($minutes % 60 || !$hours ? ($minutes % 60) . 'm' : '')); +} + /* - * The responses offered on a ticket in a category - ['category' => rows for - * its category, 'general' => rows for every ticket], each by name. Current - * ones only; names, not bodies. + * What picking a response sets up on the reply, as little badges - who sees + * it, the status after it and the time it adds. HTML; '' when it sets none + * of them (a row of canned_responses). */ -function cannedResponsesForTicket($category_id) { +function cannedResponseSetsUpHtml(array $row) { + $chips = []; + $reply_type = $row['canned_response_reply_type']; + if ($reply_type !== null && isset(CANNED_RESPONSE_REPLY_TYPES[intval($reply_type)])) { + [$label, $icon] = CANNED_RESPONSE_REPLY_TYPES[intval($reply_type)]; + $chips[] = '' . $label . ''; + } + $status = cannedResponseStatuses()[intval($row['canned_response_ticket_status'])] ?? null; + if ($row['canned_response_ticket_status'] !== null && $status) { + $chips[] = ticketStatusHtml($status['name'], $status['color'], 'detail'); + } + if (intval($row['canned_response_minutes'])) { + $chips[] = '+' . cannedResponseMinutesText($row['canned_response_minutes']) . ''; + } + return $chips ? '' . implode('', $chips) . '' : ''; +} + +/* + * The responses offered on tickets in these ticket categories, for the + * picker - [label => rows], a group for each of the categories with any + * (by name), then Every ticket. Current ones only, each by name, with what + * it sets up; no bodies. One offered on several of the categories is in + * each of their groups. + */ +function cannedResponsePickerGroups(array $category_ids) { global $mysqli; - $category_id = intval($category_id); - $offered = ['category' => [], 'general' => []]; - $sql = mysqli_query($mysqli, "SELECT canned_response_id, canned_response_name, - EXISTS (SELECT 1 FROM canned_response_categories c WHERE c.canned_response_id = canned_responses.canned_response_id) AS has_categories, - EXISTS (SELECT 1 FROM canned_response_categories c WHERE c.canned_response_id = canned_responses.canned_response_id AND c.category_id = $category_id) AS in_category + $category_ids = array_values(array_unique(array_filter(array_map('intval', $category_ids)))); + $groups = []; + $general = []; + $sql = mysqli_query($mysqli, "SELECT canned_response_id, canned_response_name, canned_response_body, canned_response_reply_type, canned_response_ticket_status, canned_response_minutes, + EXISTS (SELECT 1 FROM canned_response_categories c WHERE c.canned_response_id = canned_responses.canned_response_id) AS has_categories FROM canned_responses WHERE canned_response_archived_at IS NULL ORDER BY canned_response_name ASC"); + $rows = []; while ($row = mysqli_fetch_assoc($sql)) { - if (intval($row['in_category'])) { - $offered['category'][] = $row; - } elseif (!intval($row['has_categories'])) { - $offered['general'][] = $row; + $row['preview'] = cannedResponsePreview($row['canned_response_body'], 160); + unset($row['canned_response_body']); + $rows[intval($row['canned_response_id'])] = $row; + if (!intval($row['has_categories'])) { + $general[] = $row; } } - return $offered; + if ($category_ids && $rows) { + $sql = mysqli_query($mysqli, "SELECT canned_response_id, categories.category_id, category_name FROM canned_response_categories + JOIN categories ON categories.category_id = canned_response_categories.category_id + WHERE canned_response_categories.category_id IN (" . implode(',', $category_ids) . ") + ORDER BY category_name ASC, categories.category_id ASC"); + $by_category = []; + while ($link = mysqli_fetch_assoc($sql)) { + $id = intval($link['canned_response_id']); + if (isset($rows[$id])) { + $by_category[intval($link['category_id'])]['label'] = $link['category_name']; + $by_category[intval($link['category_id'])]['rows'][$id] = $rows[$id]; + } + } + foreach ($by_category as $group) { + uasort($group['rows'], function ($a, $b) { + return strnatcasecmp($a['canned_response_name'], $b['canned_response_name']); + }); + $groups[$group['label']] = array_values($group['rows']); + } + } + if ($general) { + $groups['Every ticket'] = $general; + } + return $groups; +} + +/* The responses offered on a ticket in a category - cannedResponsePickerGroups() for one. */ +function cannedResponsesForTicket($category_id) { + return cannedResponsePickerGroups([$category_id]); } /* What the placeholders become on a ticket for $agent_name replying - lowercase name => value, as ticketPlaceholderFill() takes them; [] for no ticket. Raw. */ @@ -186,23 +298,43 @@ function cannedResponseValues($ticket_id, $agent_name) { } /* - * A response's HTML made safe and filled in for a ticket, as it goes into a - * reply: [Ticket Link] a link to the ticket (ticketEmailUrl()), the rest as - * cannedResponseValues() has them. A placeholder with nothing to put in - - * [Asset] on a ticket with no asset, or one that is no placeholder at all - - * stays as it is, for the agent to fill in. + * HTML with the placeholders filled in for a ticket and $agent_name replying: + * [Ticket Link] a link to the ticket (ticketEmailUrl()), the rest as + * cannedResponseValues() has them, escaped. A placeholder with nothing to put + * in - [Asset] on a ticket with no asset, or one that is no placeholder at + * all - stays as it is, for the agent to fill in. As it comes for no ticket. */ -function cannedResponseFill($html, $ticket_id, $agent_name) { - $html = documentHtmlPurify($html); +function cannedResponsePlaceholders($html, $ticket_id, $agent_name) { $ticket = ticketRow($ticket_id); if (!$ticket) { - return $html; + return (string) $html; } $url = escapeHtml(ticketEmailUrl($ticket)); - $html = preg_replace('/\[ticket(?: | |\x{00A0})+link\]/iu', '' . $url . '', $html); + $html = preg_replace('/\[ticket(?: | |\x{00A0})+link\]/iu', '' . $url . '', (string) $html); return ticketPlaceholderFill($html, cannedResponseValues($ticket['ticket_id'], $agent_name), true); } +/* A response's HTML made safe and filled in for a ticket, as it goes into a reply - cannedResponsePlaceholders(). */ +function cannedResponseFill($html, $ticket_id, $agent_name) { + return cannedResponsePlaceholders(documentHtmlPurify($html), $ticket_id, $agent_name); +} + +/* + * What picking a response sets up, for the picker - reply_type (0 1 2, or + * null to leave it), ticket_status (an id, or null) with status_name, and + * minutes. + */ +function cannedResponseActions(array $row) { + $status = $row['canned_response_ticket_status'] === null ? null : intval($row['canned_response_ticket_status']); + $statuses = cannedResponseStatuses(); + return [ + 'reply_type' => $row['canned_response_reply_type'] === null ? null : intval($row['canned_response_reply_type']), + 'ticket_status' => $status !== null && isset($statuses[$status]) ? $status : null, + 'status_name' => $status !== null && isset($statuses[$status]) ? $statuses[$status]['name'] : '', + 'minutes' => intval($row['canned_response_minutes']), + ]; +} + /* Keep that these responses went into a reply on a ticket - each once, the ones that are there. */ function cannedResponseRecordUses(array $canned_response_ids, $ticket_id, $user_id) { global $mysqli; diff --git a/js/app.js b/js/app.js index 136d5d6f4..c42a59647 100644 --- a/js/app.js +++ b/js/app.js @@ -24,6 +24,65 @@ function itflowStep(name, fn) { } } +/** + * Typing / in a reply box offers the canned responses of the picker above it + * (agent/includes/inc_canned_response_picker.php) - its textarea names the + * picker in data-canned-picker. The list narrows as you type after the /; + * picking one takes the / and what was typed out again and puts the response + * in, as the picker does (agent/js/canned_response_picker.js). Called from the + * reply editors' setup, so it is there before the editor is drawn. + */ +function itflowCannedAutocompleter(editor) { + var element = editor.getElement ? editor.getElement() : null; + var pickerId = element && element.dataset ? element.dataset.cannedPicker : ''; + if (!pickerId) { + return; + } + editor.ui.registry.addAutocompleter('itflowCanned', { + trigger: '/', + minChars: 0, + columns: 1, + highlightOn: ['canned_name'], + fetch: function (pattern) { + var picker = document.getElementById(pickerId); + var words = String(pattern || '').toLowerCase().split(/\s+/).filter(Boolean); + var items = picker ? Array.prototype.slice.call(picker.querySelectorAll('[data-canned-id]')) : []; + var seen = {}; + return Promise.resolve(items.filter(function (item) { + if (seen[item.dataset.cannedId]) { + return false; + } + seen[item.dataset.cannedId] = true; + return words.every(function (word) { + return item.dataset.cannedSearchText.indexOf(word) !== -1; + }); + }).slice(0, 8).map(function (item) { + return { + type: 'cardmenuitem', + value: item.dataset.cannedId, + label: item.dataset.cannedName, + items: [{ + type: 'cardcontainer', + direction: 'vertical', + items: [ + { type: 'cardtext', text: item.dataset.cannedName, name: 'canned_name', classes: ['itflow-canned-ac-name'] }, + { type: 'cardtext', text: (item.dataset.cannedPreview || '').slice(0, 90), classes: ['itflow-canned-ac-preview'] } + ] + }] + }; + })); + }, + onAction: function (api, range, value) { + api.hide(); + editor.selection.setRng(range); + editor.insertContent(''); + if (window.itflowCannedPick) { + window.itflowCannedPick(pickerId, value); + } + } + }); +} + /** * TinyMCE skin options for the current colour mode. * @@ -244,6 +303,7 @@ function itflowInit() { plugins: 'link image lists table code codesample fullscreen autoresize', license_key: 'gpl', setup: function(editor) { + itflowCannedAutocompleter(editor); editor.on('init', function() { // When the modal closes, mark editor clean const modal = editor.getContainer()?.closest('.modal'); @@ -365,6 +425,7 @@ function itflowInit() { plugins: 'link image lists table code codesample fullscreen autoresize code', license_key: 'gpl', setup: function(editor) { + itflowCannedAutocompleter(editor); editor.on('init', function() { // When the modal closes, mark editor clean const modal = editor.getContainer()?.closest('.modal');