blob: 048c9b37220ccc4bee0bec7d84508766f88a4fff [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 Benkard188327d2020-04-17 21:22:57 +02009{#nav}{#navbar siteSection="Wiki" /}
Matthias Andreas Benkard371164a2020-03-23 06:21:25 +010010
Matthias Andreas Benkardffb428e2020-01-25 10:47:36 +010011{#head}
12<link rel="stylesheet" type="text/css" href="/web_modules/ContentTools/build/content-tools.min.css" />
Matthias Andreas Benkard813e5972020-06-14 19:27:42 +020013<script type="module" src="/lib.js" defer></script>
Matthias Andreas Benkard93da53a2020-02-02 20:30:36 +010014
15<style type="text/css">
16 #warning-panel {
17 background-color: lightcoral;
18 font-style: italic;
19 }
20</style>
21
Matthias Andreas Benkard4bb21a52020-02-08 10:14:40 +010022<script type="module" defer>
Matthias Andreas Benkard578c8652020-02-01 23:53:37 +010023 import ContentTools from "/web_modules/ContentTools.js";
Matthias Andreas Benkard2f537452020-01-27 21:23:00 +010024
Matthias Andreas Benkardffb428e2020-01-25 10:47:36 +010025 window.addEventListener('DOMContentLoaded', function() {
26 let editor = ContentTools.EditorApp.get();
27 editor.init('*[data-editable]', 'data-name');
Matthias Andreas Benkard2f537452020-01-27 21:23:00 +010028
Matthias Andreas Benkardd50bbb72020-01-27 05:53:07 +010029 editor.addEventListener('saved', async function (ev) {
Matthias Andreas Benkard93da53a2020-02-02 20:30:36 +010030 document.getElementById("warning-panel").close();
31
Matthias Andreas Benkardd50bbb72020-01-27 05:53:07 +010032 let regions = ev.detail().regions;
33 if (Object.getOwnPropertyNames(regions).length === 0) {
34 // Nothing changed.
35 return;
36 }
37
38 this.busy(true);
39
40 let requestParams = new URLSearchParams();
41 for (let name of Object.getOwnPropertyNames(regions)) {
42 requestParams.append(name, regions[name]);
43 }
44
Matthias Andreas Benkard97130f92020-01-27 21:03:39 +010045 let response = await fetch("/wiki/{page.title}", {
Matthias Andreas Benkardd50bbb72020-01-27 05:53:07 +010046 method: 'POST',
47 body: requestParams
48 });
Matthias Andreas Benkard97130f92020-01-27 21:03:39 +010049
Matthias Andreas Benkard93da53a2020-02-02 20:30:36 +010050 if (!response.ok) {
51 document.getElementById("warning-panel").open();
52 document.getElementById("warning-text").innerText = "Failed to save page: " + response.statusText;
53 this.busy(false);
54 return;
55 }
56
Matthias Andreas Benkard2f537452020-01-27 21:23:00 +010057 let status = await response.json();
Matthias Andreas Benkard93da53a2020-02-02 20:30:36 +010058 if (status.status !== "ok") {
59 document.getElementById("warning-panel").open();
60 document.getElementById("warning-text").innerText = "Failed to save page: " + JSON.stringify(status);
61 this.busy(false);
62 return;
63 }
64
65 if (status.hasOwnProperty("content")) {
66 document.getElementById("wiki-content").innerHTML = status.content;
Matthias Andreas Benkard2f537452020-01-27 21:23:00 +010067 }
68
Matthias Andreas Benkardd50bbb72020-01-27 05:53:07 +010069 this.busy(false);
70 });
Matthias Andreas Benkardffb428e2020-01-25 10:47:36 +010071 });
72</script>
73{/head}
74
Matthias Andreas Benkardae402342020-01-25 10:09:57 +010075{#body}
76<article id="wiki-page">
77 <header>
Matthias Andreas Benkardd50bbb72020-01-27 05:53:07 +010078 <div data-editable data-name="wiki-title">
79 <h1>{page.title}</h1>
80 </div>
Matthias Andreas Benkard93da53a2020-02-02 20:30:36 +010081
Matthias Andreas Benkardc2758122020-02-09 06:46:33 +010082 <elix-expandable-panel id="warning-panel" role="alert"><div id="warning-text"></div></elix-expandable-panel>
Matthias Andreas Benkardae402342020-01-25 10:09:57 +010083 </header>
Matthias Andreas Benkardd8f16442020-01-25 05:37:43 +010084
Matthias Andreas Benkardc2758122020-02-09 06:46:33 +010085 <section id="wiki-page-content">
Matthias Andreas Benkard2f537452020-01-27 21:23:00 +010086 <div data-editable data-name="wiki-content" id="wiki-content">
Matthias Andreas Benkard97130f92020-01-27 21:03:39 +010087 {#with page}{enrichedContent.raw}{/}
Matthias Andreas Benkardffb428e2020-01-25 10:47:36 +010088 </div>
Matthias Andreas Benkardc2758122020-02-09 06:46:33 +010089 </section>
Matthias Andreas Benkardd8f16442020-01-25 05:37:43 +010090
Matthias Andreas Benkardae402342020-01-25 10:09:57 +010091 <hr>
Matthias Andreas Benkard9222efa2020-01-24 19:11:24 +010092
Matthias Andreas Benkardae402342020-01-25 10:09:57 +010093 <footer>
94 <a href="/wiki/{page.title}/revisions">Page revisions</a>
95 </footer>
96</article>
97{/body}
Matthias Andreas Benkardffb428e2020-01-25 10:47:36 +010098
Matthias Andreas Benkardae402342020-01-25 10:09:57 +010099{/include}