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