Add /bookmarks/new endpoint.
Change-Id: I903dbf5f918e1478fff82e5ebf6f3e3e2766572d
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/bookmarks/BookmarkResource.java b/src/main/java/eu/mulk/mulkcms2/benki/bookmarks/BookmarkResource.java
index a535d0d..00e2824 100644
--- a/src/main/java/eu/mulk/mulkcms2/benki/bookmarks/BookmarkResource.java
+++ b/src/main/java/eu/mulk/mulkcms2/benki/bookmarks/BookmarkResource.java
@@ -21,6 +21,8 @@
import java.time.temporal.TemporalAccessor;
import java.util.List;
import java.util.Set;
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
import javax.inject.Inject;
import javax.json.JsonObject;
import javax.json.spi.JsonProvider;
@@ -55,6 +57,10 @@
@Inject
Template bookmarkList;
+ @ResourcePath("benki/bookmarks/newBookmark.html")
+ @Inject
+ Template newBookmark;
+
@Inject SecurityIdentity identity;
@GET
@@ -83,6 +89,17 @@
return bookmarkList.data("bookmarks", bookmarks).data("authenticated", !identity.isAnonymous());
}
+ @GET
+ @Authenticated
+ @Path("new")
+ @Produces(TEXT_HTML)
+ public TemplateInstance getNewBookmarkForm(
+ @QueryParam("uri") @CheckForNull String uri,
+ @QueryParam("title") @CheckForNull String title,
+ @QueryParam("description") @CheckForNull String description) {
+ return newBookmark.data("uri", uri).data("title", title).data("description", description);
+ }
+
@POST
@Transactional
@Authenticated
diff --git a/src/main/resources/META-INF/resources/bookmarks/MlkBookmarkSubmissionForm.js b/src/main/resources/META-INF/resources/bookmarks/MlkBookmarkSubmissionForm.js
index 25de54b..313268d 100644
--- a/src/main/resources/META-INF/resources/bookmarks/MlkBookmarkSubmissionForm.js
+++ b/src/main/resources/META-INF/resources/bookmarks/MlkBookmarkSubmissionForm.js
@@ -21,7 +21,16 @@
focus() {
let uriInput = this.shadowRoot.getElementById('uri-input');
- uriInput.focus();
+ let titleInput = this.shadowRoot.getElementById('title-input');
+ let descriptionInput = this.shadowRoot.getElementById('description-input');
+
+ if (!uriInput.value) {
+ uriInput.focus();
+ } else if (!titleInput.value) {
+ titleInput.focus();
+ } else {
+ descriptionInput.focus();
+ }
}
async onUriBlur() {
@@ -54,25 +63,28 @@
const template = html`
<link rel="stylesheet" type="text/css" href="/cms2/base.css" />
- <form class="pure-form pure-form-aligned" method="post">
+ <form class="pure-form pure-form-aligned" method="post" action="/bookmarks">
<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)}/>
+ value=${this.getAttribute("uri") || ""}
+ @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/>
+ <input name="title" id="title-input" type="text" placeholder="Title" required
+ value="${this.getAttribute("title") || ""}" />
</div>
<div class="pure-control-group">
<label for="description-input">Description:</label>
- <textarea name="description" id="description-input" placeholder="Description"></textarea>
+ <textarea name="description" id="description-input" placeholder="Description"
+ >${this.getAttribute("description") || ""}</textarea>
</div>
<div class="pure-control-group">
diff --git a/src/main/resources/META-INF/resources/bookmarks/newBookmark.js b/src/main/resources/META-INF/resources/bookmarks/newBookmark.js
new file mode 100644
index 0000000..0594c67
--- /dev/null
+++ b/src/main/resources/META-INF/resources/bookmarks/newBookmark.js
@@ -0,0 +1,4 @@
+document.addEventListener('DOMContentLoaded', () => {
+ let bookmarkSubmissionForm = document.getElementById('bookmark-submission-form');
+ bookmarkSubmissionForm.focus();
+});
diff --git a/src/main/resources/templates/benki/bookmarks/newBookmark.html b/src/main/resources/templates/benki/bookmarks/newBookmark.html
new file mode 100644
index 0000000..cb3147d
--- /dev/null
+++ b/src/main/resources/templates/benki/bookmarks/newBookmark.html
@@ -0,0 +1,26 @@
+{@java.util.List<eu.mulk.mulkcms2.benki.bookmarks.Bookmark> bookmarks}
+{@java.lang.Boolean authenticated}
+
+{#include base.html}
+
+{#title}Benki Bookmarks{/title}
+{#siteSection}Bookmarks{/siteSection}
+{#bookmarksClass}this-page{/bookmarksClass}
+
+{#head}{/head}
+
+{#body}
+
+<script type="module" src="/bookmarks/MlkBookmarkSubmissionForm.js" defer></script>
+<script type="module" src="/bookmarks/newBookmark.js" defer></script>
+
+<mlk-bookmark-submission-form
+ id="bookmark-submission-form"
+ uri="{uri}"
+ title="{title}"
+ description="{description}">
+</mlk-bookmark-submission-form>
+
+{/body}
+
+{/include}