Write portal documents in Markdown too: New Document in the client portal gets the Rich text and Markdown switch with the Markdown toolbar, Preview and help, converting either way as it is written and remembering the way used last, and its rich text editor shows the document as it will read with headings, quotes, code, tables and lines on its toolbar; both editors and the switch are now one shared include for agents and the portal, the portal converts Markdown at its own post.php for contacts who can write documents, Markdown documents from the portal open in Markdown for agents, and an empty document is refused in either mode; 26.12.3 changelog entries

This commit is contained in:
johnnyq
2026-11-29 22:55:08 -05:00
parent 52e340b85c
commit 8479010c18
10 changed files with 296 additions and 187 deletions

View File

@@ -36,6 +36,7 @@ Update from Maintenance > Update as usual - this release has four database chang
- Admin > Settings > Single Sign-on is gone: the client portal's Microsoft 365 sign-in is now a Microsoft 365 identity provider. A contact's Login of Only with an identity provider (once called With their Microsoft account) signs in only that way, with no password, and is offered when a provider is on for client contacts.
- Printing a ticket prints a work order instead of the page as it looks on screen: your letterhead, the client and contact, the site with its access notes, the job's details, its assets, the description, the fill-ins the client can see, the tasks as boxes to tick, the public replies oldest first, and a sign-off with arrival and departure times, lines for the work done and signatures. Internal notes never print. It's Print Work Order in the ticket's menu, or the browser's own print.
- Printing an asset prints a spec sheet: its hardware, network, where it is and who has it, its interfaces, the devices in it, its licenses and services and its quick notes, with a QR code that opens it in ITFlow. Credentials and license keys never print. The new print button sits beside Copy Details.
- Writing a document in the client portal works as it does for you: the editor shows it as it will read, with headings, lists, quotes, code, tables and lines on its toolbar, or contacts can write it in Markdown, with the Markdown toolbar and Preview, switching either way as they write. The next document starts in the way they wrote last.
### Bug Fixes
@@ -71,6 +72,7 @@ Update from Maintenance > Update as usual - this release has four database chang
- login_provider.php starts a sign-in (?provider=N, a single-use state in the session, ten minutes) and takes the code back, then hands the account to login.php as ?provider_login= with $_SESSION['pending_provider_login'], which signs in through its usual success path - role choice included - with $_SESSION['signed_in_with'] = 'provider' (left out of MFA enforcement as a passkey is) and signed_in_via the provider's name. client/login_microsoft.php serves it for the migrated app's redirect address. IMAP is checked in login.php's password step ('imap'); an administrator's own password still works there.
- Admin: admin/identity_providers.php (list), admin/modals/identity_provider/identity_provider_edit.php (Add and Edit), admin/post/identity_provider.php (save_identity_provider, turn_identity_provider_on / off, delete_identity_provider - locked in the demo). The identity settings page and edit_identity_provider are gone. portalSignInMethods() and identityProviderContactsWording() take an email, to offer only the providers that sign it in; vaultLockedReason() says why the vault is locked.
- functions/print_sheet.php draws the work order (ticketWorkOrderHtml()) and spec sheet (assetSpecSheetHtml()) into their pages, hidden on screen; css .itflow-print-sheet hides the rest of the page when printing (the .container-fluid:has() rule). [data-print-page] buttons call window.print() (js/app.js). The ticket's actions bar and menu now show for every agent.
- includes/document_editors.php is a document's two editors and the switch between them, shared by agent/modals/document/document_form.php and client/document_add.php (which now posts format, content and markdown, saved through documentPostedContent()). js/document_markdown.js converts at the address its script tag gives (data-markdown-url, client/post.php markdown_to_html and html_to_markdown in the portal). itflowProseContentStyle() moved to js/tinymce_defaults.js; js/portal.js sets up .tinymce-document, and its required check looks in the Markdown box when that is shown.
## [26.12.2]

View File

@@ -14,15 +14,10 @@
* agent used last.
*
* It is written in the rich text editor or in Markdown, picked above the editor
* and switched either way as it is written (js/document_markdown.js); the form
* posts format, with content or markdown. Both show it as it will read on its
* page (.itflow-prose): the rich text editor as it is written, Markdown in its
* Preview.
* and switched either way as it is written (includes/document_editors.php). Both
* show it as it will read on its page (.itflow-prose): the rich text editor as
* it is written, Markdown in its Preview.
*/
$document_markdown_ready = documentMarkdownReady();
$document_is_markdown = $document_markdown_ready && isset($document_markdown) && $document_markdown !== null;
$document_format_uid = bin2hex(random_bytes(4));
?>
<div class="row g-3 mb-3">
@@ -70,88 +65,7 @@ $document_format_uid = bin2hex(random_bytes(4));
<?php } ?>
</div>
<div data-document-editors<?= !empty($document_format_remember) ? ' data-format-remember' : '' ?>>
<?php if ($document_markdown_ready) { ?>
<div class="d-flex flex-wrap align-items-center gap-2 mb-2">
<div class="btn-group btn-group-sm" role="group" aria-label="Write it in">
<input type="radio" class="btn-check" name="format" value="html" id="documentFormatRich<?= $document_format_uid ?>" autocomplete="off" <?= $document_is_markdown ? '' : 'checked' ?>>
<label class="btn btn-outline-secondary" for="documentFormatRich<?= $document_format_uid ?>"><i class="fas fa-fw fa-font me-1"></i>Rich text</label>
<input type="radio" class="btn-check" name="format" value="markdown" id="documentFormatMarkdown<?= $document_format_uid ?>" autocomplete="off" <?= $document_is_markdown ? 'checked' : '' ?>>
<label class="btn btn-outline-secondary" for="documentFormatMarkdown<?= $document_format_uid ?>"><i class="fab fa-fw fa-markdown me-1"></i>Markdown</label>
</div>
<span class="small" data-format-note></span>
</div>
<?php } ?>
<div data-editor-rich<?= $document_is_markdown ? ' hidden' : '' ?>>
<!-- Written as it will read on its page (.tinymce-document, js/app.js) -->
<textarea class="form-control tinymce-document" name="content" aria-label="Content"><?= $document_content ?></textarea>
</div>
<?php if ($document_markdown_ready) { ?>
<div data-editor-markdown<?= $document_is_markdown ? '' : ' hidden' ?>>
<ul class="nav nav-tabs itflow-markdown-tabs" role="tablist">
<li class="nav-item"><button type="button" class="nav-link active" data-markdown-tab="write"><i class="fas fa-fw fa-pen me-1"></i>Write</button></li>
<li class="nav-item"><button type="button" class="nav-link" data-markdown-tab="preview"><i class="fas fa-fw fa-eye me-1"></i>Preview</button></li>
</ul>
<!-- What the rich text editor's toolbar does, as Markdown - on what is picked, or where the cursor is (js/document_markdown.js) -->
<div class="itflow-markdown-toolbar" role="toolbar" aria-label="Formatting" data-markdown-toolbar>
<div class="dropdown">
<button type="button" class="itflow-markdown-button dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false" title="Heading"><i class="fas fa-fw fa-heading"></i></button>
<div class="dropdown-menu">
<button type="button" class="dropdown-item" data-md="h1"><span class="fs-5 fw-semibold">Heading 1</span></button>
<button type="button" class="dropdown-item" data-md="h2"><span class="fs-6 fw-semibold">Heading 2</span></button>
<button type="button" class="dropdown-item" data-md="h3"><span class="small fw-semibold">Heading 3</span></button>
<button type="button" class="dropdown-item" data-md="paragraph">Normal text</button>
</div>
</div>
<span class="itflow-markdown-toolbar-gap"></span>
<button type="button" class="itflow-markdown-button" data-md="bold" title="Bold (Ctrl+B)" aria-label="Bold"><i class="fas fa-fw fa-bold"></i></button>
<button type="button" class="itflow-markdown-button" data-md="italic" title="Italic (Ctrl+I)" aria-label="Italic"><i class="fas fa-fw fa-italic"></i></button>
<button type="button" class="itflow-markdown-button" data-md="strike" title="Strikethrough" aria-label="Strikethrough"><i class="fas fa-fw fa-strikethrough"></i></button>
<span class="itflow-markdown-toolbar-gap"></span>
<button type="button" class="itflow-markdown-button" data-md="link" title="Link (Ctrl+K)" aria-label="Link"><i class="fas fa-fw fa-link"></i></button>
<span class="itflow-markdown-toolbar-gap"></span>
<button type="button" class="itflow-markdown-button" data-md="bullets" title="Bulleted list" aria-label="Bulleted list"><i class="fas fa-fw fa-list-ul"></i></button>
<button type="button" class="itflow-markdown-button" data-md="numbers" title="Numbered list" aria-label="Numbered list"><i class="fas fa-fw fa-list-ol"></i></button>
<button type="button" class="itflow-markdown-button" data-md="tasks" title="Checklist" aria-label="Checklist"><i class="fas fa-fw fa-tasks"></i></button>
<span class="itflow-markdown-toolbar-gap"></span>
<button type="button" class="itflow-markdown-button" data-md="quote" title="Quote" aria-label="Quote"><i class="fas fa-fw fa-quote-right"></i></button>
<button type="button" class="itflow-markdown-button" data-md="code" title="Code" aria-label="Code"><i class="fas fa-fw fa-code"></i></button>
<button type="button" class="itflow-markdown-button" data-md="codeblock" title="Code block" aria-label="Code block"><i class="fas fa-fw fa-file-code"></i></button>
<span class="itflow-markdown-toolbar-gap"></span>
<button type="button" class="itflow-markdown-button" data-md="table" title="Table" aria-label="Table"><i class="fas fa-fw fa-table"></i></button>
<button type="button" class="itflow-markdown-button" data-md="line" title="Line across" aria-label="Line across"><i class="fas fa-fw fa-minus"></i></button>
<button type="button" class="itflow-markdown-button" data-md="picture" title="Picture" aria-label="Picture"><i class="fas fa-fw fa-image"></i></button>
<input type="file" class="d-none" accept="image/png,image/jpeg,image/gif,image/webp" multiple data-markdown-picture tabindex="-1" aria-hidden="true">
<button type="button" class="itflow-markdown-button ms-auto" data-bs-toggle="collapse" data-bs-target="#documentMarkdownHelp<?= $document_format_uid ?>" aria-expanded="false" title="Markdown help" aria-label="Markdown help"><i class="far fa-fw fa-question-circle"></i></button>
</div>
<div class="collapse" id="documentMarkdownHelp<?= $document_format_uid ?>">
<div class="table-responsive border border-top-0 small itflow-markdown-help-box">
<table class="table table-sm mb-0 itflow-markdown-help">
<tbody>
<tr><td><code># Heading</code> <code>## Smaller</code></td><td>Headings</td><td><code>**bold**</code> <code>_italic_</code> <code>~~struck~~</code></td><td>Text</td></tr>
<tr><td><code>- item</code> <code>1. item</code></td><td>Lists - indent for a list inside one</td><td><code>- [ ] to do</code> <code>- [x] done</code></td><td>Checklist</td></tr>
<tr><td><code>[words](https://...)</code></td><td>Link</td><td><code>`code`</code>, or <code>```</code> on the lines above and below</td><td>Code</td></tr>
<tr><td><code>| A | B |</code> then <code>|---|---|</code></td><td>Table</td><td><code>&gt; quote</code> <code>---</code></td><td>Quote, line</td></tr>
</tbody>
</table>
</div>
</div>
<textarea class="form-control font-monospace itflow-markdown-input" name="markdown" rows="18" aria-label="Content, in Markdown" data-markdown-input placeholder="# A heading&#10;&#10;Write here in Markdown - paste or drop a picture to add it."><?= isset($document_markdown) && $document_markdown !== null ? escapeHtml($document_markdown) : '' ?></textarea>
<div class="itflow-markdown-preview itflow-document-body itflow-prose border border-top-0 rounded-bottom" data-markdown-preview hidden></div>
</div>
<?php } ?>
</div>
<?php if ($document_markdown_ready) { ?>
<script>
// js/document_markdown.js - on a page of its own this runs before that file has loaded, and it takes the form up then
(window.itflowDocumentForms = window.itflowDocumentForms || []).push(document.currentScript.previousElementSibling);
if (window.itflowDocumentFormat) {
window.itflowDocumentFormat.start();
}
</script>
<?php } ?>
<?php require dirname(__DIR__, 3) . '/includes/document_editors.php'; ?>
<?php if ($document_form_mode === 'edit') { ?>
<div class="form-text"><i class="fas fa-history me-1"></i>Saving keeps what it says now in the document's history, so it can be put back.</div>

View File

@@ -1,11 +1,14 @@
<?php
/*
* Client Portal
* New document - written in the editor, or ?upload=1 a file (a PDF, Word or
* text document) with a name and a line on what it is. Both are shared with
* the agents straight away and show in Documents.
* New document - written in the editor or in Markdown, picked above it and
* switched either way as it is written (includes/document_editors.php, as an
* agent's New Document has), or ?upload=1 a file (a PDF, Word or text
* document) with a name and a line on what it is. Both are shared with the
* agents straight away and show in Documents.
*
* No Content-Security-Policy here: the editor needs inline styles.
* No Content-Security-Policy here: the editor needs inline styles, and the
* Markdown box an inline script.
*
* SCOPING: primary and technical contacts (portalItGate()); post.php
* (client_add_document, client_upload_document) checks the same.
@@ -16,6 +19,9 @@ require_once "includes/inc_all.php";
portalItGate();
$upload = !empty($_GET['upload']);
// Writing it - Markdown turned into HTML and back at post.php (client/includes/footer.php)
$portal_document_writer = !$upload;
?>
<a class="itflow-portal-back" href="documents.php"><i class="fas fa-chevron-left"></i>Documents</a>
@@ -66,8 +72,13 @@ $upload = !empty($_GET['upload']);
<?php } else { ?>
<div class="mb-4">
<label class="form-label">What it says <strong class="text-danger">*</strong></label>
<textarea class="form-control tinymce" name="document_content" data-required></textarea>
<div class="invalid-feedback d-block" data-editor-required-note hidden>Write something in the document.</div>
<?php
$document_content = '';
$document_markdown = null;
$document_format_remember = true;
$document_editor_required = true;
require __DIR__ . '/../includes/document_editors.php';
?>
</div>
<button type="submit" class="btn btn-primary" name="client_add_document"><i class="fas fa-check me-2"></i>Save Document</button>
<?php } ?>

View File

@@ -28,6 +28,10 @@
<!--- TinyMCE - set up on any .tinymce by js/portal.js -->
<script src="<?= staticFileUrl('/libs/tinymce/tinymce.min.js') ?>" referrerpolicy="origin"></script>
<script src="<?= staticFileUrl('/js/tinymce_defaults.js') ?>"></script>
<?php if (!empty($portal_document_writer)) { ?>
<!-- Writing a document, in Markdown too (includes/document_editors.php) - before js/portal.js sets up its editor -->
<script src="<?= staticFileUrl('/js/document_markdown.js') ?>" data-markdown-url="/client/post.php"></script>
<?php } ?>
<script src="<?= staticFileUrl('/js/pretty_content.js') ?>"></script>
<?php if (!empty($portal_document_contents)) { ?>

View File

@@ -20,7 +20,7 @@ if (!empty($_SESSION['portal_view_as']) && (isset($_GET['exit_view_as']) || isse
unset($_SESSION['portal_view_as']);
redirect($back);
}
if (portalViewingAs() && !isset($_GET['export_statement_pdf']) && !isset($_GET['kb_suggest'])) {
if (portalViewingAs() && !isset($_GET['export_statement_pdf']) && !isset($_GET['kb_suggest']) && !isset($_GET['markdown_to_html']) && !isset($_GET['html_to_markdown'])) {
flashAlert("You're viewing the portal as " . escapeHtml($portal_view_as['contact_name']) . " - nothing can be changed", 'error');
redirect();
}
@@ -28,6 +28,28 @@ if (portalViewingAs() && !isset($_GET['export_statement_pdf']) && !isset($_GET['
// Two-step sign-in required and not set up yet: client/includes/check_login.php has
// already turned away everything but setting it up, or signing out
/*
* Markdown for New Document's editors (js/document_markdown.js, includes/document_editors.php) -
* Markdown as the HTML it shows as (Preview, switching to the rich text editor, Markdown pasted
* into it) and the rich text editor's HTML as Markdown, as agent/ajax.php does for agents. For
* whoever can write a document; it changes nothing. Answers {html}, or {markdown, kept, dropped}.
*/
if (isset($_GET['markdown_to_html']) || isset($_GET['html_to_markdown'])) {
header('Content-Type: application/json');
if (!($config_module_enable_itdoc && contactCan('itdoc')) || !documentMarkdownReady()) {
exit(json_encode(['error' => 'Markdown isn\'t available here.']));
}
$text = (string) ($_POST[isset($_GET['markdown_to_html']) ? 'markdown' : 'html'] ?? '');
if (strlen($text) > 4 * 1024 * 1024) {
exit(json_encode(['error' => 'That is too long to convert - over 4 MB.']));
}
if (isset($_GET['markdown_to_html'])) {
exit(json_encode(['html' => markdownToHtml($text)]));
}
$markdown = htmlToMarkdown($text, $markdown_notes);
exit(json_encode(['markdown' => $markdown, 'kept' => $markdown_notes['kept'], 'dropped' => $markdown_notes['dropped']]));
}
/*
* The Help articles that might answer a new ticket's subject, as it is typed
* on New ticket (js/portal.js) - at most three of the ones shared with their
@@ -1748,10 +1770,12 @@ if (isset($_POST['client_add_document'])) {
// Primary and technical contacts, with IT documentation on
portalItGate();
$raw_content = (string) ($_POST['document_content'] ?? '');
// Written in the rich text editor, or in Markdown (includes/document_editors.php)
$is_markdown = documentMarkdownReady() && ($_POST['format'] ?? '') === 'markdown';
$raw_content = $is_markdown ? markdownToHtml((string) ($_POST['markdown'] ?? '')) : (string) ($_POST['content'] ?? '');
$name = trim(mb_substr((string) ($_POST['document_name'] ?? ''), 0, 200));
$description = trim(mb_substr((string) ($_POST['document_description'] ?? ''), 0, 255));
if ($name === '' || portalHtmlIsEmpty($raw_content)) {
if ($name === '' || ($is_markdown ? trim((string) ($_POST['markdown'] ?? '')) === '' : portalHtmlIsEmpty($raw_content))) {
flashAlert('Give the document a name and write something in it', 'error');
redirect('document_add.php');
}
@@ -1772,9 +1796,9 @@ if (isset($_POST['client_add_document'])) {
$document_id = mysqli_insert_id($mysqli);
// Pasted pictures are saved as files rather than kept in the HTML
$processed_content = mysqli_escape_string($mysqli, saveBase64Images($raw_content, $_SERVER['DOCUMENT_ROOT'] . "/uploads/documents/", "uploads/documents/", $document_id));
mysqli_query($mysqli, "UPDATE documents SET document_content = '$processed_content' WHERE document_id = $document_id");
// Pasted pictures are saved as files rather than kept in the HTML - or in the Markdown
[$processed_html, $markdown] = documentPostedContent($document_id);
mysqli_query($mysqli, "UPDATE documents SET document_content = '" . mysqli_real_escape_string($mysqli, $processed_html) . "'" . documentMarkdownSet($markdown) . " WHERE document_id = $document_id");
logAudit("Document", "Create", "Client contact $session_contact_name created document $document_name in the client portal", $session_client_id, $document_id);
appNotify("Document", "$session_contact_name added the document $document_name in the client portal", "/agent/document.php?document_id=$document_id", $session_client_id, $document_id);

View File

@@ -0,0 +1,106 @@
<?php
/*
* A document's two editors - the rich text editor, written as it will read on its page
* (.tinymce-document: js/app.js for agents, js/portal.js in the client portal), and Markdown with
* Write and Preview and a toolbar of its own - with the way it is written picked above them and
* switched either way as it is written (js/document_markdown.js). The form posts format, with
* content or markdown (documentPostedContent()).
*
* Used by New and Edit Document (agent/modals/document/document_form.php) and New Document in the
* client portal (client/document_add.php). Expects the escaped $document_content, and
* $document_markdown - what a Markdown document says, raw, or unset or null for rich text. With
* $document_format_remember it starts in the way of writing used last in this browser; with
* $document_editor_required something has to be written in it (js/portal.js checks).
*/
$document_markdown_ready = documentMarkdownReady();
$document_is_markdown = $document_markdown_ready && isset($document_markdown) && $document_markdown !== null;
$document_format_uid = bin2hex(random_bytes(4));
$document_editor_required = !empty($document_editor_required);
?>
<div data-document-editors<?= !empty($document_format_remember) ? ' data-format-remember' : '' ?>>
<?php if ($document_markdown_ready) { ?>
<div class="d-flex flex-wrap align-items-center gap-2 mb-2">
<div class="btn-group btn-group-sm" role="group" aria-label="Write it in">
<input type="radio" class="btn-check" name="format" value="html" id="documentFormatRich<?= $document_format_uid ?>" autocomplete="off" <?= $document_is_markdown ? '' : 'checked' ?>>
<label class="btn btn-outline-secondary" for="documentFormatRich<?= $document_format_uid ?>"><i class="fas fa-fw fa-font me-1"></i>Rich text</label>
<input type="radio" class="btn-check" name="format" value="markdown" id="documentFormatMarkdown<?= $document_format_uid ?>" autocomplete="off" <?= $document_is_markdown ? 'checked' : '' ?>>
<label class="btn btn-outline-secondary" for="documentFormatMarkdown<?= $document_format_uid ?>"><i class="fab fa-fw fa-markdown me-1"></i>Markdown</label>
</div>
<span class="small" data-format-note></span>
</div>
<?php } ?>
<div data-editor-rich<?= $document_is_markdown ? ' hidden' : '' ?>>
<!-- Written as it will read on its page (.tinymce-document, js/app.js) -->
<textarea class="form-control tinymce-document" name="content" aria-label="Content"<?= $document_editor_required ? ' data-required' : '' ?>><?= $document_content ?></textarea>
</div>
<?php if ($document_markdown_ready) { ?>
<div data-editor-markdown<?= $document_is_markdown ? '' : ' hidden' ?>>
<ul class="nav nav-tabs itflow-markdown-tabs" role="tablist">
<li class="nav-item"><button type="button" class="nav-link active" data-markdown-tab="write"><i class="fas fa-fw fa-pen me-1"></i>Write</button></li>
<li class="nav-item"><button type="button" class="nav-link" data-markdown-tab="preview"><i class="fas fa-fw fa-eye me-1"></i>Preview</button></li>
</ul>
<!-- What the rich text editor's toolbar does, as Markdown - on what is picked, or where the cursor is (js/document_markdown.js) -->
<div class="itflow-markdown-toolbar" role="toolbar" aria-label="Formatting" data-markdown-toolbar>
<div class="dropdown">
<button type="button" class="itflow-markdown-button dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false" title="Heading"><i class="fas fa-fw fa-heading"></i></button>
<div class="dropdown-menu">
<button type="button" class="dropdown-item" data-md="h1"><span class="fs-5 fw-semibold">Heading 1</span></button>
<button type="button" class="dropdown-item" data-md="h2"><span class="fs-6 fw-semibold">Heading 2</span></button>
<button type="button" class="dropdown-item" data-md="h3"><span class="small fw-semibold">Heading 3</span></button>
<button type="button" class="dropdown-item" data-md="paragraph">Normal text</button>
</div>
</div>
<span class="itflow-markdown-toolbar-gap"></span>
<button type="button" class="itflow-markdown-button" data-md="bold" title="Bold (Ctrl+B)" aria-label="Bold"><i class="fas fa-fw fa-bold"></i></button>
<button type="button" class="itflow-markdown-button" data-md="italic" title="Italic (Ctrl+I)" aria-label="Italic"><i class="fas fa-fw fa-italic"></i></button>
<button type="button" class="itflow-markdown-button" data-md="strike" title="Strikethrough" aria-label="Strikethrough"><i class="fas fa-fw fa-strikethrough"></i></button>
<span class="itflow-markdown-toolbar-gap"></span>
<button type="button" class="itflow-markdown-button" data-md="link" title="Link (Ctrl+K)" aria-label="Link"><i class="fas fa-fw fa-link"></i></button>
<span class="itflow-markdown-toolbar-gap"></span>
<button type="button" class="itflow-markdown-button" data-md="bullets" title="Bulleted list" aria-label="Bulleted list"><i class="fas fa-fw fa-list-ul"></i></button>
<button type="button" class="itflow-markdown-button" data-md="numbers" title="Numbered list" aria-label="Numbered list"><i class="fas fa-fw fa-list-ol"></i></button>
<button type="button" class="itflow-markdown-button" data-md="tasks" title="Checklist" aria-label="Checklist"><i class="fas fa-fw fa-tasks"></i></button>
<span class="itflow-markdown-toolbar-gap"></span>
<button type="button" class="itflow-markdown-button" data-md="quote" title="Quote" aria-label="Quote"><i class="fas fa-fw fa-quote-right"></i></button>
<button type="button" class="itflow-markdown-button" data-md="code" title="Code" aria-label="Code"><i class="fas fa-fw fa-code"></i></button>
<button type="button" class="itflow-markdown-button" data-md="codeblock" title="Code block" aria-label="Code block"><i class="fas fa-fw fa-file-code"></i></button>
<span class="itflow-markdown-toolbar-gap"></span>
<button type="button" class="itflow-markdown-button" data-md="table" title="Table" aria-label="Table"><i class="fas fa-fw fa-table"></i></button>
<button type="button" class="itflow-markdown-button" data-md="line" title="Line across" aria-label="Line across"><i class="fas fa-fw fa-minus"></i></button>
<button type="button" class="itflow-markdown-button" data-md="picture" title="Picture" aria-label="Picture"><i class="fas fa-fw fa-image"></i></button>
<input type="file" class="d-none" accept="image/png,image/jpeg,image/gif,image/webp" multiple data-markdown-picture tabindex="-1" aria-hidden="true">
<button type="button" class="itflow-markdown-button ms-auto" data-bs-toggle="collapse" data-bs-target="#documentMarkdownHelp<?= $document_format_uid ?>" aria-expanded="false" title="Markdown help" aria-label="Markdown help"><i class="far fa-fw fa-question-circle"></i></button>
</div>
<div class="collapse" id="documentMarkdownHelp<?= $document_format_uid ?>">
<div class="table-responsive border border-top-0 small itflow-markdown-help-box">
<table class="table table-sm mb-0 itflow-markdown-help">
<tbody>
<tr><td><code># Heading</code> <code>## Smaller</code></td><td>Headings</td><td><code>**bold**</code> <code>_italic_</code> <code>~~struck~~</code></td><td>Text</td></tr>
<tr><td><code>- item</code> <code>1. item</code></td><td>Lists - indent for a list inside one</td><td><code>- [ ] to do</code> <code>- [x] done</code></td><td>Checklist</td></tr>
<tr><td><code>[words](https://...)</code></td><td>Link</td><td><code>`code`</code>, or <code>```</code> on the lines above and below</td><td>Code</td></tr>
<tr><td><code>| A | B |</code> then <code>|---|---|</code></td><td>Table</td><td><code>&gt; quote</code> <code>---</code></td><td>Quote, line</td></tr>
</tbody>
</table>
</div>
</div>
<textarea class="form-control font-monospace itflow-markdown-input" name="markdown" rows="18" aria-label="Content, in Markdown" data-markdown-input<?= $document_editor_required ? ' data-required' : '' ?> placeholder="# A heading&#10;&#10;Write here in Markdown - paste or drop a picture to add it."><?= isset($document_markdown) && $document_markdown !== null ? escapeHtml($document_markdown) : '' ?></textarea>
<div class="itflow-markdown-preview itflow-document-body itflow-prose border border-top-0 rounded-bottom" data-markdown-preview hidden></div>
</div>
<?php } ?>
<?php if ($document_editor_required) { ?>
<div class="invalid-feedback d-block" data-editor-required-note hidden>Write something in the document.</div>
<?php } ?>
</div>
<?php if ($document_markdown_ready) { ?>
<script>
// js/document_markdown.js - on a page of its own this runs before that file has loaded, and it takes the form up then
(window.itflowDocumentForms = window.itflowDocumentForms || []).push(document.currentScript.previousElementSibling);
if (window.itflowDocumentFormat) {
window.itflowDocumentFormat.start();
}
</script>
<?php } ?>

View File

@@ -428,46 +428,6 @@ function itflowTinyMceSkin() {
};
}
/**
* A document as it reads on its page (.itflow-prose, css/itflow_custom.css), for the editing
* surface - which is an iframe, so the page's stylesheet and custom properties don't reach it
* and the values are passed in as literal text, as itflowTinyMceSkin() does.
*/
function itflowProseContentStyle() {
var root = getComputedStyle(document.documentElement);
function v(name, fallback) {
var value = root.getPropertyValue(name).trim();
return value || fallback;
}
var border = v('--bs-border-color', '#dee2e6');
var tint = v('--bs-tertiary-bg', '#f8f9fa');
var muted = v('--bs-secondary-color', '#6c757d');
var strong = v('--bs-emphasis-color', '#000');
return 'body{line-height:1.65;margin:1.25rem 1.5rem;}' +
'body>:first-child{margin-top:0;}' +
'h1,h2,h3,h4,h5,h6{margin:1.75rem 0 .6rem;font-weight:600;line-height:1.3;color:' + strong + ';}' +
'h1{font-size:1.6rem;}' +
'h2{font-size:1.3rem;padding-bottom:.35rem;border-bottom:1px solid ' + border + ';}' +
'h3{font-size:1.12rem;}' +
'h4{font-size:1rem;}' +
'h5,h6{font-size:.9rem;text-transform:uppercase;letter-spacing:.03em;color:' + muted + ';}' +
'p,ul,ol,table,pre,blockquote,figure{margin:0 0 1rem;}' +
'ul,ol{padding-left:1.5rem;}' +
'li+li{margin-top:.25rem;}' +
'hr{margin:2rem 0;border:0;border-top:1px solid ' + border + ';}' +
'img{max-width:100%;height:auto;border-radius:.375rem;}' +
'table{border-collapse:collapse;font-size:.925rem;}' +
// Every table with its lines, as on the page - not TinyMCE's dashed outline for one without a border
'table td,table th{padding:.4rem .65rem;border:1px solid ' + border + ' !important;}' +
'table th,table thead td{background-color:' + tint + ';font-weight:600;}' +
'pre{padding:.75rem 1rem;border:1px solid ' + border + ';border-radius:.375rem;background-color:' + tint + ';white-space:pre;overflow-x:auto;}' +
':not(pre)>code{padding:.1rem .3rem;border-radius:.25rem;background-color:' + tint + ';color:' + strong + ';}' +
'blockquote{margin-left:0;padding:.25rem 0 .25rem 1rem;border-left:.25rem solid ' + border + ';color:' + muted + ';}';
}
/**
* Chart.js defaults for the current colour mode.
*
@@ -677,7 +637,8 @@ function itflowInit() {
// page, and with what a document is made of on the toolbar, as the Markdown box has
const itflowDocumentWriter = {
...itflowDocumentEditor,
content_style: itflowDocumentEditor.content_style + itflowProseContentStyle(),
// js/tinymce_defaults.js - not on the few pages without the editor (Getting Started)
content_style: itflowDocumentEditor.content_style + (typeof itflowProseContentStyle === 'function' ? itflowProseContentStyle() : ''),
block_formats: 'Normal text=p; Heading 1=h1; Heading 2=h2; Heading 3=h3; Heading 4=h4',
toolbar: [
...(itflowAiOn(false) ? [{ name: 'ai', items: ['reword'] }] : []),

View File

@@ -20,7 +20,8 @@
* Markdown pasted into a document's rich text editor - copied from GitHub's source view, VS Code,
* Obsidian, an AI chat - goes in formatted. Ctrl+Shift+V pastes it as it is.
*
* Loaded on every agent page (includes/footer.php), once.
* Loaded on every agent page (includes/footer.php), once - and on New Document in the client
* portal (client/includes/footer.php), which turns Markdown into HTML at client/post.php.
*/
(function () {
'use strict';
@@ -31,8 +32,13 @@
var REMEMBER = 'itflow.documentFormat';
// Where Markdown is turned into HTML and back - agent/ajax.php, or in the client portal the
// address its <script> tag gives (data-markdown-url, client/includes/footer.php)
var script = document.currentScript;
var URL_BASE = (script && script.getAttribute('data-markdown-url')) || '/agent/ajax.php';
function post(action, data) {
return fetch('/agent/ajax.php?' + action, {
return fetch(URL_BASE + '?' + action, {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
credentials: 'same-origin',

View File

@@ -4,7 +4,8 @@
* turns inline scripts off:
*
* - Dark mode, the contact's own choice, kept in a cookie the header reads
* - The editor on any .tinymce textarea, in the light or dark skin
* - The editor on any .tinymce textarea, in the light or dark skin - and a
* document's (.tinymce-document), with headings and the rest on its toolbar
* - Attachment drop zones: drop files on [data-portal-drop] and they go into
* its file input, listed by name and size
* - A form marked data-portal-once can't be sent twice
@@ -50,14 +51,62 @@
};
}
if (window.tinymce && document.querySelector('textarea.tinymce')) {
// Something has to be written in a textarea marked data-required, which the editor hides from
// the browser's own "fill this in" - so the form is checked here instead. A document written in
// Markdown (includes/document_editors.php) is checked in its Markdown box.
function requireWritten(editor) {
editor.on('init', function () {
var textarea = editor.getElement();
textarea.removeAttribute('required');
var form = textarea.form;
if (!form || !textarea.hasAttribute('data-required') || form.hasAttribute('data-editor-checked')) {
return;
}
form.setAttribute('data-editor-checked', '');
var note = form.querySelector('[data-editor-required-note]');
var rich = textarea.closest('[data-editor-rich]');
var markdown = form.querySelector('[data-markdown-input]');
form.addEventListener('submit', function (ev) {
tinymce.triggerSave();
var inMarkdown = !!(rich && rich.hidden && markdown);
var empty = inMarkdown
? !markdown.value.trim()
: !editor.getContent({format: 'text'}).trim() && !/<img/i.test(editor.getContent());
if (empty) {
ev.preventDefault();
ev.stopImmediatePropagation();
(inMarkdown ? markdown : editor.getContainer()).classList.add('is-invalid');
if (note) {
note.hidden = false;
}
if (inMarkdown) {
markdown.focus();
} else {
editor.focus();
}
}
}, true);
function written() {
editor.getContainer().classList.remove('is-invalid');
if (markdown) {
markdown.classList.remove('is-invalid');
}
if (note) {
note.hidden = true;
}
}
editor.on('input change', written);
if (markdown) {
markdown.addEventListener('input', written);
}
});
}
if (window.tinymce && document.querySelector('textarea.tinymce, textarea.tinymce-document')) {
var skin = editorSkin();
tinymce.init({
selector: 'textarea.tinymce',
var editorBase = {
browser_spellcheck: true,
resize: true,
min_height: 220,
max_height: 600,
promotion: false,
branding: false,
menubar: false,
@@ -66,48 +115,39 @@
skin: skin.skin,
content_css: skin.content_css,
content_style: skin.content_style,
setup: requireWritten
};
tinymce.init(Object.assign({}, editorBase, {
selector: 'textarea.tinymce',
min_height: 220,
max_height: 600,
toolbar: 'bold italic forecolor | bullist numlist | link table | removeformat',
mobile: {
menubar: false,
plugins: 'autosave lists autolink',
toolbar: 'bold italic bullist numlist'
},
plugins: 'link image lists table autoresize',
setup: function (editor) {
// A required field the editor hides can't take the browser's
// own "fill this in" - so the form is checked here instead
editor.on('init', function () {
var textarea = editor.getElement();
textarea.removeAttribute('required');
var form = textarea.form;
if (form && textarea.hasAttribute('data-required') && !form.hasAttribute('data-editor-checked')) {
form.setAttribute('data-editor-checked', '');
form.addEventListener('submit', function (ev) {
tinymce.triggerSave();
var empty = !editor.getContent({format: 'text'}).trim() && !/<img/i.test(editor.getContent());
if (empty) {
ev.preventDefault();
ev.stopImmediatePropagation();
var holder = editor.getContainer();
holder.classList.add('is-invalid');
var note = form.querySelector('[data-editor-required-note]');
if (note) {
note.hidden = false;
}
editor.focus();
}
}, true);
editor.on('input change', function () {
editor.getContainer().classList.remove('is-invalid');
var note = form.querySelector('[data-editor-required-note]');
if (note) {
note.hidden = true;
}
});
}
});
}
});
plugins: 'link image lists table autoresize'
}));
// A document (client/document_add.php) - written as it will read on its page, with what a
// document is made of on the toolbar (headings, quotes, code, lines), as the Markdown box
// has; itflowProseContentStyle() is js/tinymce_defaults.js
tinymce.init(Object.assign({}, editorBase, {
selector: 'textarea.tinymce-document',
min_height: 420,
max_height: Math.max(480, Math.round(window.innerHeight * 0.6)),
content_style: skin.content_style + (typeof itflowProseContentStyle === 'function' ? itflowProseContentStyle() : ''),
block_formats: 'Normal text=p; Heading 1=h1; Heading 2=h2; Heading 3=h3; Heading 4=h4',
toolbar: 'blocks | bold italic strikethrough forecolor | link | bullist numlist | blockquote codesample table hr | undo redo',
mobile: {
menubar: false,
plugins: 'autosave lists autolink',
toolbar: 'blocks bold italic bullist numlist'
},
plugins: 'link image lists table codesample autoresize'
}));
}
// ---------- Attachments ----------

View File

@@ -90,3 +90,44 @@
}, true);
});
})();
/**
* A document as it reads on its page (.itflow-prose, css/itflow_custom.css), for the editing
* surface - which is an iframe, so the page's stylesheet and custom properties don't reach it
* and the values are passed in as literal text, as itflowTinyMceSkin() does. A document's editor
* uses it for agents (js/app.js) and in the client portal (js/portal.js), so it is here.
*/
function itflowProseContentStyle() {
var root = getComputedStyle(document.documentElement);
function v(name, fallback) {
var value = root.getPropertyValue(name).trim();
return value || fallback;
}
var border = v('--bs-border-color', '#dee2e6');
var tint = v('--bs-tertiary-bg', '#f8f9fa');
var muted = v('--bs-secondary-color', '#6c757d');
var strong = v('--bs-emphasis-color', '#000');
return 'body{line-height:1.65;margin:1.25rem 1.5rem;}' +
'body>:first-child{margin-top:0;}' +
'h1,h2,h3,h4,h5,h6{margin:1.75rem 0 .6rem;font-weight:600;line-height:1.3;color:' + strong + ';}' +
'h1{font-size:1.6rem;}' +
'h2{font-size:1.3rem;padding-bottom:.35rem;border-bottom:1px solid ' + border + ';}' +
'h3{font-size:1.12rem;}' +
'h4{font-size:1rem;}' +
'h5,h6{font-size:.9rem;text-transform:uppercase;letter-spacing:.03em;color:' + muted + ';}' +
'p,ul,ol,table,pre,blockquote,figure{margin:0 0 1rem;}' +
'ul,ol{padding-left:1.5rem;}' +
'li+li{margin-top:.25rem;}' +
'hr{margin:2rem 0;border:0;border-top:1px solid ' + border + ';}' +
'img{max-width:100%;height:auto;border-radius:.375rem;}' +
'table{border-collapse:collapse;font-size:.925rem;}' +
// Every table with its lines, as on the page - not TinyMCE's dashed outline for one without a border
'table td,table th{padding:.4rem .65rem;border:1px solid ' + border + ' !important;}' +
'table th,table thead td{background-color:' + tint + ';font-weight:600;}' +
'pre{padding:.75rem 1rem;border:1px solid ' + border + ';border-radius:.375rem;background-color:' + tint + ';white-space:pre;overflow-x:auto;}' +
':not(pre)>code{padding:.1rem .3rem;border-radius:.25rem;background-color:' + tint + ';color:' + strong + ';}' +
'blockquote{margin-left:0;padding:.25rem 0 .25rem 1rem;border-left:.25rem solid ' + border + ';color:' + muted + ';}';
}