blob: c5155bcca6e26ddf54b05b14dd41e5e55edd339e [file] [log] [blame]
Matthias Andreas Benkardae402342020-01-25 10:09:57 +01001{@eu.mulk.mulkcms2.benki.wiki.WikiPageRevision page}
Matthias Andreas Benkardd8f16442020-01-25 05:37:43 +01002
Matthias Andreas Benkardae402342020-01-25 10:09:57 +01003{#include base.html}
Matthias Andreas Benkardffb428e2020-01-25 10:47:36 +01004
Matthias Andreas Benkardae402342020-01-25 10:09:57 +01005{#title}{page.title} — Benki Wiki{/title}
Matthias Andreas Benkardc2758122020-02-09 06:46:33 +01006{#siteSection}Wiki{/siteSection}
Matthias Andreas Benkard310e71f2020-02-09 10:39:45 +01007{#wikiClass}this-page{/wikiClass}
Matthias Andreas Benkardc2758122020-02-09 06:46:33 +01008
Matthias Andreas Benkardffb428e2020-01-25 10:47:36 +01009{#head}
10<link rel="stylesheet" type="text/css" href="/web_modules/ContentTools/build/content-tools.min.css" />
Matthias Andreas Benkard4bb21a52020-02-08 10:14:40 +010011<script type="module" src="/web_modules/elix/define/ExpandablePanel.js" defer></script>
Matthias Andreas Benkard93da53a2020-02-02 20:30:36 +010012
13<style type="text/css">
14 #warning-panel {
15 background-color: lightcoral;
16 font-style: italic;
17 }
18</style>
19
Matthias Andreas Benkard4bb21a52020-02-08 10:14:40 +010020<script type="module" defer>
Matthias Andreas Benkard578c8652020-02-01 23:53:37 +010021 import ContentTools from "/web_modules/ContentTools.js";
Matthias Andreas Benkard2f537452020-01-27 21:23:00 +010022
Matthias Andreas Benkardffb428e2020-01-25 10:47:36 +010023 window.addEventListener('DOMContentLoaded', function() {
24 let editor = ContentTools.EditorApp.get();
25 editor.init('*[data-editable]', 'data-name');
Matthias Andreas Benkard2f537452020-01-27 21:23:00 +010026
Matthias Andreas Benkardd50bbb72020-01-27 05:53:07 +010027 editor.addEventListener('saved', async function (ev) {
Matthias Andreas Benkard93da53a2020-02-02 20:30:36 +010028 document.getElementById("warning-panel").close();
29
Matthias Andreas Benkardd50bbb72020-01-27 05:53:07 +010030 let regions = ev.detail().regions;
31 if (Object.getOwnPropertyNames(regions).length === 0) {
32 // Nothing changed.
33 return;
34 }
35
36 this.busy(true);
37
38 let requestParams = new URLSearchParams();
39 for (let name of Object.getOwnPropertyNames(regions)) {
40 requestParams.append(name, regions[name]);
41 }
42
Matthias Andreas Benkard97130f92020-01-27 21:03:39 +010043 let response = await fetch("/wiki/{page.title}", {
Matthias Andreas Benkardd50bbb72020-01-27 05:53:07 +010044 method: 'POST',
45 body: requestParams
46 });
Matthias Andreas Benkard97130f92020-01-27 21:03:39 +010047
Matthias Andreas Benkard93da53a2020-02-02 20:30:36 +010048 if (!response.ok) {
49 document.getElementById("warning-panel").open();
50 document.getElementById("warning-text").innerText = "Failed to save page: " + response.statusText;
51 this.busy(false);
52 return;
53 }
54
Matthias Andreas Benkard2f537452020-01-27 21:23:00 +010055 let status = await response.json();
Matthias Andreas Benkard93da53a2020-02-02 20:30:36 +010056 if (status.status !== "ok") {
57 document.getElementById("warning-panel").open();
58 document.getElementById("warning-text").innerText = "Failed to save page: " + JSON.stringify(status);
59 this.busy(false);
60 return;
61 }
62
63 if (status.hasOwnProperty("content")) {
64 document.getElementById("wiki-content").innerHTML = status.content;
Matthias Andreas Benkard2f537452020-01-27 21:23:00 +010065 }
66
Matthias Andreas Benkardd50bbb72020-01-27 05:53:07 +010067 this.busy(false);
68 });
Matthias Andreas Benkardffb428e2020-01-25 10:47:36 +010069 });
70</script>
71{/head}
72
Matthias Andreas Benkardae402342020-01-25 10:09:57 +010073{#body}
74<article id="wiki-page">
75 <header>
Matthias Andreas Benkardd50bbb72020-01-27 05:53:07 +010076 <div data-editable data-name="wiki-title">
77 <h1>{page.title}</h1>
78 </div>
Matthias Andreas Benkard93da53a2020-02-02 20:30:36 +010079
Matthias Andreas Benkardc2758122020-02-09 06:46:33 +010080 <elix-expandable-panel id="warning-panel" role="alert"><div id="warning-text"></div></elix-expandable-panel>
Matthias Andreas Benkardae402342020-01-25 10:09:57 +010081 </header>
Matthias Andreas Benkardd8f16442020-01-25 05:37:43 +010082
Matthias Andreas Benkardc2758122020-02-09 06:46:33 +010083 <section id="wiki-page-content">
Matthias Andreas Benkard2f537452020-01-27 21:23:00 +010084 <div data-editable data-name="wiki-content" id="wiki-content">
Matthias Andreas Benkard97130f92020-01-27 21:03:39 +010085 {#with page}{enrichedContent.raw}{/}
Matthias Andreas Benkardffb428e2020-01-25 10:47:36 +010086 </div>
Matthias Andreas Benkardc2758122020-02-09 06:46:33 +010087 </section>
Matthias Andreas Benkardd8f16442020-01-25 05:37:43 +010088
Matthias Andreas Benkardae402342020-01-25 10:09:57 +010089 <hr>
Matthias Andreas Benkard9222efa2020-01-24 19:11:24 +010090
Matthias Andreas Benkardae402342020-01-25 10:09:57 +010091 <footer>
92 <a href="/wiki/{page.title}/revisions">Page revisions</a>
93 </footer>
94</article>
95{/body}
Matthias Andreas Benkardffb428e2020-01-25 10:47:36 +010096
Matthias Andreas Benkardae402342020-01-25 10:09:57 +010097{/include}