blob: e4a7d580fc121b2a492d39584c7a5aa1740709a8 [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 Benkardffb428e2020-01-25 10:47:36 +01006
7{#head}
8<link rel="stylesheet" type="text/css" href="/web_modules/ContentTools/build/content-tools.min.css" />
Matthias Andreas Benkard4bb21a52020-02-08 10:14:40 +01009<script type="module" src="/web_modules/elix/define/ExpandablePanel.js" defer></script>
Matthias Andreas Benkard93da53a2020-02-02 20:30:36 +010010
11<style type="text/css">
12 #warning-panel {
13 background-color: lightcoral;
14 font-style: italic;
15 }
16</style>
17
Matthias Andreas Benkard4bb21a52020-02-08 10:14:40 +010018<script type="module" defer>
Matthias Andreas Benkard578c8652020-02-01 23:53:37 +010019 import ContentTools from "/web_modules/ContentTools.js";
Matthias Andreas Benkard2f537452020-01-27 21:23:00 +010020
Matthias Andreas Benkardffb428e2020-01-25 10:47:36 +010021 window.addEventListener('DOMContentLoaded', function() {
22 let editor = ContentTools.EditorApp.get();
23 editor.init('*[data-editable]', 'data-name');
Matthias Andreas Benkard2f537452020-01-27 21:23:00 +010024
Matthias Andreas Benkardd50bbb72020-01-27 05:53:07 +010025 editor.addEventListener('saved', async function (ev) {
Matthias Andreas Benkard93da53a2020-02-02 20:30:36 +010026 document.getElementById("warning-panel").close();
27
Matthias Andreas Benkardd50bbb72020-01-27 05:53:07 +010028 let regions = ev.detail().regions;
29 if (Object.getOwnPropertyNames(regions).length === 0) {
30 // Nothing changed.
31 return;
32 }
33
34 this.busy(true);
35
36 let requestParams = new URLSearchParams();
37 for (let name of Object.getOwnPropertyNames(regions)) {
38 requestParams.append(name, regions[name]);
39 }
40
Matthias Andreas Benkard97130f92020-01-27 21:03:39 +010041 let response = await fetch("/wiki/{page.title}", {
Matthias Andreas Benkardd50bbb72020-01-27 05:53:07 +010042 method: 'POST',
43 body: requestParams
44 });
Matthias Andreas Benkard97130f92020-01-27 21:03:39 +010045
Matthias Andreas Benkard93da53a2020-02-02 20:30:36 +010046 if (!response.ok) {
47 document.getElementById("warning-panel").open();
48 document.getElementById("warning-text").innerText = "Failed to save page: " + response.statusText;
49 this.busy(false);
50 return;
51 }
52
Matthias Andreas Benkard2f537452020-01-27 21:23:00 +010053 let status = await response.json();
Matthias Andreas Benkard93da53a2020-02-02 20:30:36 +010054 if (status.status !== "ok") {
55 document.getElementById("warning-panel").open();
56 document.getElementById("warning-text").innerText = "Failed to save page: " + JSON.stringify(status);
57 this.busy(false);
58 return;
59 }
60
61 if (status.hasOwnProperty("content")) {
62 document.getElementById("wiki-content").innerHTML = status.content;
Matthias Andreas Benkard2f537452020-01-27 21:23:00 +010063 }
64
Matthias Andreas Benkardd50bbb72020-01-27 05:53:07 +010065 this.busy(false);
66 });
Matthias Andreas Benkardffb428e2020-01-25 10:47:36 +010067 });
68</script>
69{/head}
70
Matthias Andreas Benkardae402342020-01-25 10:09:57 +010071{#body}
72<article id="wiki-page">
73 <header>
Matthias Andreas Benkardd50bbb72020-01-27 05:53:07 +010074 <div data-editable data-name="wiki-title">
75 <h1>{page.title}</h1>
76 </div>
Matthias Andreas Benkard93da53a2020-02-02 20:30:36 +010077
78 <elix-expandable-panel id="warning-panel"><div id="warning-text"></div></elix-expandable-panel>
Matthias Andreas Benkardae402342020-01-25 10:09:57 +010079 </header>
Matthias Andreas Benkardd8f16442020-01-25 05:37:43 +010080
Matthias Andreas Benkardae402342020-01-25 10:09:57 +010081 <main>
Matthias Andreas Benkard2f537452020-01-27 21:23:00 +010082 <div data-editable data-name="wiki-content" id="wiki-content">
Matthias Andreas Benkard97130f92020-01-27 21:03:39 +010083 {#with page}{enrichedContent.raw}{/}
Matthias Andreas Benkardffb428e2020-01-25 10:47:36 +010084 </div>
Matthias Andreas Benkardae402342020-01-25 10:09:57 +010085 </main>
Matthias Andreas Benkardd8f16442020-01-25 05:37:43 +010086
Matthias Andreas Benkardae402342020-01-25 10:09:57 +010087 <hr>
Matthias Andreas Benkard9222efa2020-01-24 19:11:24 +010088
Matthias Andreas Benkardae402342020-01-25 10:09:57 +010089 <footer>
90 <a href="/wiki/{page.title}/revisions">Page revisions</a>
91 </footer>
92</article>
93{/body}
Matthias Andreas Benkardffb428e2020-01-25 10:47:36 +010094
Matthias Andreas Benkardae402342020-01-25 10:09:57 +010095{/include}