mirror of
https://github.com/itflow-org/itflow
synced 2026-12-02 09:09:01 +00:00
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:
106
includes/document_editors.php
Normal file
106
includes/document_editors.php
Normal 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>> 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 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 } ?>
|
||||
Reference in New Issue
Block a user