Matthias Andreas Benkard | ae40234 | 2020-01-25 10:09:57 +0100 | [diff] [blame] | 1 | {@eu.mulk.mulkcms2.benki.wiki.WikiPageRevision page} |
Matthias Andreas Benkard | d8f1644 | 2020-01-25 05:37:43 +0100 | [diff] [blame] | 2 | |
Matthias Andreas Benkard | ae40234 | 2020-01-25 10:09:57 +0100 | [diff] [blame] | 3 | {#include base.html} |
Matthias Andreas Benkard | ffb428e | 2020-01-25 10:47:36 +0100 | [diff] [blame] | 4 | |
Matthias Andreas Benkard | ae40234 | 2020-01-25 10:09:57 +0100 | [diff] [blame] | 5 | {#title}{page.title} — Benki Wiki{/title} |
Matthias Andreas Benkard | ffb428e | 2020-01-25 10:47:36 +0100 | [diff] [blame] | 6 | |
| 7 | {#head} |
| 8 | <link rel="stylesheet" type="text/css" href="/web_modules/ContentTools/build/content-tools.min.css" /> |
Matthias Andreas Benkard | 4bb21a5 | 2020-02-08 10:14:40 +0100 | [diff] [blame^] | 9 | <script type="module" src="/web_modules/elix/define/ExpandablePanel.js" defer></script> |
Matthias Andreas Benkard | 93da53a | 2020-02-02 20:30:36 +0100 | [diff] [blame] | 10 | |
| 11 | <style type="text/css"> |
| 12 | #warning-panel { |
| 13 | background-color: lightcoral; |
| 14 | font-style: italic; |
| 15 | } |
| 16 | </style> |
| 17 | |
Matthias Andreas Benkard | 4bb21a5 | 2020-02-08 10:14:40 +0100 | [diff] [blame^] | 18 | <script type="module" defer> |
Matthias Andreas Benkard | 578c865 | 2020-02-01 23:53:37 +0100 | [diff] [blame] | 19 | import ContentTools from "/web_modules/ContentTools.js"; |
Matthias Andreas Benkard | 2f53745 | 2020-01-27 21:23:00 +0100 | [diff] [blame] | 20 | |
Matthias Andreas Benkard | ffb428e | 2020-01-25 10:47:36 +0100 | [diff] [blame] | 21 | window.addEventListener('DOMContentLoaded', function() { |
| 22 | let editor = ContentTools.EditorApp.get(); |
| 23 | editor.init('*[data-editable]', 'data-name'); |
Matthias Andreas Benkard | 2f53745 | 2020-01-27 21:23:00 +0100 | [diff] [blame] | 24 | |
Matthias Andreas Benkard | d50bbb7 | 2020-01-27 05:53:07 +0100 | [diff] [blame] | 25 | editor.addEventListener('saved', async function (ev) { |
Matthias Andreas Benkard | 93da53a | 2020-02-02 20:30:36 +0100 | [diff] [blame] | 26 | document.getElementById("warning-panel").close(); |
| 27 | |
Matthias Andreas Benkard | d50bbb7 | 2020-01-27 05:53:07 +0100 | [diff] [blame] | 28 | 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 Benkard | 97130f9 | 2020-01-27 21:03:39 +0100 | [diff] [blame] | 41 | let response = await fetch("/wiki/{page.title}", { |
Matthias Andreas Benkard | d50bbb7 | 2020-01-27 05:53:07 +0100 | [diff] [blame] | 42 | method: 'POST', |
| 43 | body: requestParams |
| 44 | }); |
Matthias Andreas Benkard | 97130f9 | 2020-01-27 21:03:39 +0100 | [diff] [blame] | 45 | |
Matthias Andreas Benkard | 93da53a | 2020-02-02 20:30:36 +0100 | [diff] [blame] | 46 | 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 Benkard | 2f53745 | 2020-01-27 21:23:00 +0100 | [diff] [blame] | 53 | let status = await response.json(); |
Matthias Andreas Benkard | 93da53a | 2020-02-02 20:30:36 +0100 | [diff] [blame] | 54 | 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 Benkard | 2f53745 | 2020-01-27 21:23:00 +0100 | [diff] [blame] | 63 | } |
| 64 | |
Matthias Andreas Benkard | d50bbb7 | 2020-01-27 05:53:07 +0100 | [diff] [blame] | 65 | this.busy(false); |
| 66 | }); |
Matthias Andreas Benkard | ffb428e | 2020-01-25 10:47:36 +0100 | [diff] [blame] | 67 | }); |
| 68 | </script> |
| 69 | {/head} |
| 70 | |
Matthias Andreas Benkard | ae40234 | 2020-01-25 10:09:57 +0100 | [diff] [blame] | 71 | {#body} |
| 72 | <article id="wiki-page"> |
| 73 | <header> |
Matthias Andreas Benkard | d50bbb7 | 2020-01-27 05:53:07 +0100 | [diff] [blame] | 74 | <div data-editable data-name="wiki-title"> |
| 75 | <h1>{page.title}</h1> |
| 76 | </div> |
Matthias Andreas Benkard | 93da53a | 2020-02-02 20:30:36 +0100 | [diff] [blame] | 77 | |
| 78 | <elix-expandable-panel id="warning-panel"><div id="warning-text"></div></elix-expandable-panel> |
Matthias Andreas Benkard | ae40234 | 2020-01-25 10:09:57 +0100 | [diff] [blame] | 79 | </header> |
Matthias Andreas Benkard | d8f1644 | 2020-01-25 05:37:43 +0100 | [diff] [blame] | 80 | |
Matthias Andreas Benkard | ae40234 | 2020-01-25 10:09:57 +0100 | [diff] [blame] | 81 | <main> |
Matthias Andreas Benkard | 2f53745 | 2020-01-27 21:23:00 +0100 | [diff] [blame] | 82 | <div data-editable data-name="wiki-content" id="wiki-content"> |
Matthias Andreas Benkard | 97130f9 | 2020-01-27 21:03:39 +0100 | [diff] [blame] | 83 | {#with page}{enrichedContent.raw}{/} |
Matthias Andreas Benkard | ffb428e | 2020-01-25 10:47:36 +0100 | [diff] [blame] | 84 | </div> |
Matthias Andreas Benkard | ae40234 | 2020-01-25 10:09:57 +0100 | [diff] [blame] | 85 | </main> |
Matthias Andreas Benkard | d8f1644 | 2020-01-25 05:37:43 +0100 | [diff] [blame] | 86 | |
Matthias Andreas Benkard | ae40234 | 2020-01-25 10:09:57 +0100 | [diff] [blame] | 87 | <hr> |
Matthias Andreas Benkard | 9222efa | 2020-01-24 19:11:24 +0100 | [diff] [blame] | 88 | |
Matthias Andreas Benkard | ae40234 | 2020-01-25 10:09:57 +0100 | [diff] [blame] | 89 | <footer> |
| 90 | <a href="/wiki/{page.title}/revisions">Page revisions</a> |
| 91 | </footer> |
| 92 | </article> |
| 93 | {/body} |
Matthias Andreas Benkard | ffb428e | 2020-01-25 10:47:36 +0100 | [diff] [blame] | 94 | |
Matthias Andreas Benkard | ae40234 | 2020-01-25 10:09:57 +0100 | [diff] [blame] | 95 | {/include} |