mirror of
https://github.com/itflow-org/itflow
synced 2026-12-02 00:59:03 +00:00
127 lines
7.9 KiB
PHP
127 lines
7.9 KiB
PHP
<?php
|
|
|
|
/*
|
|
* The body of New Document and Edit Document (document_add.php,
|
|
* document_edit.php): name and summary across the top, where it lives and
|
|
* whether the portal shows it under them, the editor below.
|
|
*
|
|
* Expects $document_form_mode ('add' or 'edit'), $client_id, and the
|
|
* escaped $document_name, $document_description, $document_content,
|
|
* $document_folder_id, $document_client_visible - and $document_id when
|
|
* editing, for its tags. $document_markdown is what a Markdown document says,
|
|
* raw - unset or null for one in the rich text editor - and with
|
|
* $document_format_remember (New Document) it starts in the way of writing the
|
|
* 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.
|
|
*/
|
|
|
|
$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">
|
|
<div class="col-md-6">
|
|
<label class="form-label">Name <strong class="text-danger">*</strong></label>
|
|
<div class="input-group">
|
|
<span class="input-group-text"><i class="fas fa-fw fa-file-alt"></i></span>
|
|
<input type="text" class="form-control" name="name" maxlength="200" value="<?= $document_name ?>" placeholder="Backup and recovery plan" required <?= $document_form_mode === 'add' ? 'autofocus' : '' ?>>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<label class="form-label">Summary</label>
|
|
<div class="input-group">
|
|
<span class="input-group-text"><i class="fas fa-fw fa-align-left"></i></span>
|
|
<input type="text" class="form-control" name="description" value="<?= $document_description ?>" placeholder="One line on what it covers">
|
|
</div>
|
|
</div>
|
|
|
|
<?php if ($document_form_mode === 'add') { ?>
|
|
<div class="col-md-6">
|
|
<label class="form-label">Folder</label>
|
|
<div class="input-group">
|
|
<span class="input-group-text"><i class="fas fa-fw fa-folder"></i></span>
|
|
<select class="form-select select2" name="folder">
|
|
<?= folderOptionsHtml($client_id, $document_folder_id) ?>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
<?php } ?>
|
|
|
|
<div class="col-md-6">
|
|
<?= tagFormFieldHtml('document', $document_form_mode === 'edit' ? tagIdsForRecord('document', $document_id) : [], 'Procedure, Onboarding, Needs review') ?>
|
|
</div>
|
|
|
|
<?php if (!empty($config_client_portal_enable)) { ?>
|
|
<div class="col-md-6 d-flex align-items-end">
|
|
<div class="form-check form-switch mb-2">
|
|
<input type="hidden" name="client_visible" value="0">
|
|
<input class="form-check-input" type="checkbox" role="switch" name="client_visible" value="1" id="documentFormVisible" <?= $document_client_visible ? 'checked' : '' ?>>
|
|
<label class="form-check-label" for="documentFormVisible">
|
|
<i class="fas fa-fw fa-eye text-body-secondary me-1"></i>Show in the client portal <span class="text-body-secondary small">- to their technical contacts</span>
|
|
</label>
|
|
</div>
|
|
</div>
|
|
<?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' : '' ?>>
|
|
<textarea class="form-control tinymce" name="content" aria-label="Content"><?= $document_content ?></textarea>
|
|
</div>
|
|
|
|
<?php if ($document_markdown_ready) { ?>
|
|
<div data-editor-markdown<?= $document_is_markdown ? '' : ' hidden' ?>>
|
|
<div class="d-flex flex-wrap align-items-end border-bottom">
|
|
<ul class="nav nav-tabs border-bottom-0 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>
|
|
<button type="button" class="btn btn-link btn-sm ms-auto mb-1 text-decoration-none" data-bs-toggle="collapse" data-bs-target="#documentMarkdownHelp<?= $document_format_uid ?>" aria-expanded="false"><i class="far fa-fw fa-question-circle me-1"></i>Markdown help</button>
|
|
</div>
|
|
<div class="collapse" id="documentMarkdownHelp<?= $document_format_uid ?>">
|
|
<div class="table-responsive border border-top-0 small">
|
|
<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 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 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 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>
|
|
<?php } ?>
|