85 lines
4.1 KiB
HTML
85 lines
4.1 KiB
HTML
{% extends "admin/base.html" %}
|
|
{% block admin_content %}
|
|
<div class="admin-panel">
|
|
<h1>{% if page %}Edit page{% else %}New page{% endif %}</h1>
|
|
|
|
<form method="post" action="{% if page %}{{ url_for('admin.page_edit', pid=page.id) }}{% else %}{{ url_for('admin.page_new') }}{% endif %}">
|
|
<input type="hidden" name="csrf_token" value="{{ csrf_token }}">
|
|
|
|
<div class="form-row">
|
|
<div class="form-group">
|
|
<label for="title">Title *</label>
|
|
<input type="text" id="title" name="title" value="{{ (page or {}).get('title', '') if page else '' }}" required>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="slug">Slug</label>
|
|
<input type="text" id="slug" name="slug" value="{{ (page or {}).get('slug', '') if page else '' }}" placeholder="auto-generated-from-title">
|
|
<span class="field-hint">URL-friendly version of the title. Leave blank to auto-generate.</span>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="published">Published</label>
|
|
<input type="checkbox" id="published" name="published" {% if page %}checked{% endif %}>
|
|
<span class="field-hint">{% if page %}Uncheck to hide this page from the navigation.{% else %}Live pages appear in the top nav.{% endif %}</span>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="content">Content <span class="field-hint">(Rich text editor — Markdown, links, images)</span></label>
|
|
<!-- Hidden field holds the stored HTML. TinyMCE loads it into #page-editor
|
|
on init and writes it back here on submit; the public pipeline passes
|
|
stored HTML straight through (render_markdown/to_html detect it). -->
|
|
<input type="hidden" id="content" name="content" value="{{ body_html|forceescape }}">
|
|
<div id="page-editor" class="tinymce-editor"></div>
|
|
</div>
|
|
|
|
<p>
|
|
<button type="submit" class="btn btn-primary">Save</button>
|
|
<a class="btn" href="{{ url_for('admin.pages') }}">Cancel</a>
|
|
</p>
|
|
</form>
|
|
</div>
|
|
|
|
<script>
|
|
// TinyMCE: load stored HTML on init, write it back to #content on submit.
|
|
document.addEventListener('DOMContentLoaded', function () {
|
|
var contentField = document.getElementById("content");
|
|
try {
|
|
tinymce.init({
|
|
base_url: '{{ js_base }}',
|
|
theme_url: '{{ js_base }}/themes/silver/theme.min.js',
|
|
icons_url: '{{ js_base }}/icons/default/icons.min.js',
|
|
model_url: '{{ js_base }}/models/dom/model.min.js',
|
|
license_key: 'gpl',
|
|
skin: 'oxide',
|
|
content_css: '/static/js/skins/ui/oxide/content.min.css',
|
|
selector: '#page-editor',
|
|
init_instance_callback: function (editor) {
|
|
editor.setContent(contentField ? contentField.value : '');
|
|
},
|
|
convert_urls: false,
|
|
plugins: 'anchor autolink charmap codesample emoticons image link lists media searchreplace table visualblocks wordcount',
|
|
toolbar: 'undo redo | blocks fontfamily fontsize | bold italic underline strikethrough | link image media table | align lineheight | numlist bullist indent outdent | emoticons charmap | removeformat',
|
|
});
|
|
} catch (e) {
|
|
console.error('[debug] page editor init FAILED:', e);
|
|
}
|
|
|
|
// Write the WYSIWYG content back to the hidden #content field on submit.
|
|
// A div-based editor does NOT save into a separate hidden field via its
|
|
// default behaviour (TinyMCE would restore the div instead), so we must
|
|
// bridge it explicitly — same pattern as post_edit.html's #body editor.
|
|
// Same bug as post_edit.html: document.querySelector('form') returns the
|
|
// logout form in the admin header, so the editor content was never copied
|
|
// into #content and saved pages had an empty body.
|
|
var form = contentField ? contentField.form : null;
|
|
if (form) {
|
|
form.addEventListener('submit', function () {
|
|
var editor = tinymce.get('page-editor') || tinymce.activeEditor;
|
|
if (editor && contentField) contentField.value = editor.getContent();
|
|
});
|
|
}
|
|
});
|
|
</script>
|
|
{% endblock %}
|