summaryrefslogtreecommitdiff
path: root/src/main/resources/META-INF
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <code@mail.matthias.benkard.de>2020-02-13 04:41:32 +0100
committerMatthias Andreas Benkard <code@mail.matthias.benkard.de>2020-02-13 04:41:32 +0100
commit6991257cd67631efae78e141b8ae7794129483c1 (patch)
treea398f490e7f0f639cd4695a253280442b9b6537f /src/main/resources/META-INF
parent65fab823eb9f6556f6cc68989e2cc7b672a711ba (diff)
Bookmark submission: Make bookmark submission form a reusable WebComponent.
Change-Id: I723d98208040db5b0d2d56d8c5e727c68399f843
Diffstat (limited to 'src/main/resources/META-INF')
-rw-r--r--src/main/resources/META-INF/resources/bookmarks/MlkBookmarkSubmissionForm.js97
-rw-r--r--src/main/resources/META-INF/resources/bookmarks/bookmarkList.js25
2 files changed, 100 insertions, 22 deletions
diff --git a/src/main/resources/META-INF/resources/bookmarks/MlkBookmarkSubmissionForm.js b/src/main/resources/META-INF/resources/bookmarks/MlkBookmarkSubmissionForm.js
new file mode 100644
index 0000000..25de54b
--- /dev/null
+++ b/src/main/resources/META-INF/resources/bookmarks/MlkBookmarkSubmissionForm.js
@@ -0,0 +1,97 @@
+import {html, render} from "../../web_modules/lit-html.js";
+import ProgressSpinner from "../web_modules/elix/define/ProgressSpinner.js";
+
+export class MlkBookmarkSubmissionForm extends HTMLElement {
+ constructor() {
+ super();
+ this.attachShadow({mode: "open"});
+ }
+
+ static get observedAttributes() {
+ return ["greetee"];
+ }
+
+ connectedCallback () {
+ this.render();
+ }
+
+ attributeChangedCallback(name, oldValue, newValue) {
+ this.render();
+ }
+
+ focus() {
+ let uriInput = this.shadowRoot.getElementById('uri-input');
+ uriInput.focus();
+ }
+
+ async onUriBlur() {
+ let titleInput = this.shadowRoot.getElementById('title-input');
+ let uriInput = this.shadowRoot.getElementById('uri-input');
+ let uriSpinner = this.shadowRoot.getElementById('uri-spinner');
+
+ if (!uriInput.value) {
+ return;
+ }
+
+ uriSpinner.hidden = false;
+ uriSpinner.playing = true;
+ let searchParams = new URLSearchParams({'uri': uriInput.value});
+ console.log(`/bookmarks/page-info?${searchParams}`);
+ let fetchUrl = new URL(`/bookmarks/page-info?${searchParams}`, document.URL);
+ let r = await fetch(fetchUrl);
+ uriSpinner.hidden = true;
+ uriSpinner.playing = false;
+
+ if (!r.ok) {
+ return;
+ }
+
+ let pageInfo = await r.json();
+ titleInput.value = pageInfo.title;
+ }
+
+ render() {
+ const template = html`
+ <link rel="stylesheet" type="text/css" href="/cms2/base.css" />
+
+ <form class="pure-form pure-form-aligned" method="post">
+ <fieldset>
+ <legend>New Bookmark</legend>
+
+ <div class="pure-control-group">
+ <label for="uri-input">URI:</label>
+ <input name="uri" id="uri-input" type="text" placeholder="URI" required
+ @blur=${this.onUriBlur.bind(this)}/>
+ <elix-progress-spinner id="uri-spinner" hidden></elix-progress-spinner>
+ </div>
+
+ <div class="pure-control-group">
+ <label for="title-input">Title:</label>
+ <input name="title" id="title-input" type="text" placeholder="Title" required/>
+ </div>
+
+ <div class="pure-control-group">
+ <label for="description-input">Description:</label>
+ <textarea name="description" id="description-input" placeholder="Description"></textarea>
+ </div>
+
+ <div class="pure-control-group">
+ <label for="visibility-input">Visibility:</label>
+ <select id="visibility-input" name="visibility" required>
+ <option value="public">Public</option>
+ <option value="semiprivate" selected>Semiprivate</option>
+ <option value="private">Private</option>
+ </select>
+ </div>
+
+ <div class="pure-controls">
+ <button type="submit" class="pure-button pure-button-primary">Submit Bookmark</button>
+ </div>
+ </fieldset>
+ </form>`;
+
+ render(template, this.shadowRoot);
+ }
+}
+
+customElements.define("mlk-bookmark-submission-form", MlkBookmarkSubmissionForm);
diff --git a/src/main/resources/META-INF/resources/bookmarks/bookmarkList.js b/src/main/resources/META-INF/resources/bookmarks/bookmarkList.js
index 4c8287a..a6f78e6 100644
--- a/src/main/resources/META-INF/resources/bookmarks/bookmarkList.js
+++ b/src/main/resources/META-INF/resources/bookmarks/bookmarkList.js
@@ -1,28 +1,9 @@
document.addEventListener('DOMContentLoaded', () => {
let bookmarkSubmissionPane = document.getElementById(
'bookmark-submission-pane');
- let titleInput = document.getElementById('title-input');
- let uriInput = document.getElementById('uri-input');
- let uriSpinner = document.getElementById('uri-spinner');
+ let bookmarkSubmissionForm = document.getElementById(
+ 'bookmark-submission-form');
- bookmarkSubmissionPane.addEventListener('opened', () => uriInput.focus());
-
- uriInput.addEventListener('blur', async () => {
- uriSpinner.hidden = false;
- uriSpinner.playing = true;
- let searchParams = new URLSearchParams({'uri': uriInput.value});
- console.log(`/bookmarks/page-info?${searchParams}`);
- let fetchUrl = new URL(`/bookmarks/page-info?${searchParams}`, document.URL);
- let r = await fetch(fetchUrl);
- uriSpinner.hidden = true;
- uriSpinner.playing = false;
-
- if (!r.ok) {
- return;
- }
-
- let pageInfo = await r.json();
- titleInput.value = pageInfo.title;
- });
+ bookmarkSubmissionPane.addEventListener('opened', () => bookmarkSubmissionForm.focus());
});