diff options
author | ArthurHoaro <arthur@hoa.ro> | 2020-10-10 17:40:26 +0200 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2020-10-27 20:11:30 +0100 |
commit | 5d8de7587d67b5c3e5d1fed8562d9b87ecde80c1 (patch) | |
tree | 2236e571035332a63f87a09222f2278b93f63515 /assets/common/js/metadata.js | |
parent | b8e5a253ab5521ce2be6c0d3e04e0101527df3c1 (diff) | |
download | Shaarli-5d8de7587d67b5c3e5d1fed8562d9b87ecde80c1.tar.gz Shaarli-5d8de7587d67b5c3e5d1fed8562d9b87ecde80c1.tar.zst Shaarli-5d8de7587d67b5c3e5d1fed8562d9b87ecde80c1.zip |
Feature: bulk creation of bookmarks
This changes creates a new form in addlink page allowing to create
multiple bookmarks at once more easily. It focuses on re-using as much
existing code and template component as possible.
These changes includes:
- a new form in addlink (hidden behind a button by default),
containing a text area for URL, and tags/private status to apply to
created links
- this form displays a new template called editlink.batch, itself
including editlink template multiple times
- User interation in this new templates are handle by a new JS script
(shaare-batch.js) making AJAX requests, and therefore does not need page
reloading
- ManageShaareController has been split into 3 distinct controllers:
+ ShaareAdd: displays addlink template
+ ShaareManage: various operation applied on existing shaares
(change visibility, pin, deletion, etc.)
+ ShaarePublish: handles creation/edit forms and saving Shaare's
form
- Updated translations
Fixes #137
Diffstat (limited to 'assets/common/js/metadata.js')
-rw-r--r-- | assets/common/js/metadata.js | 50 |
1 files changed, 27 insertions, 23 deletions
diff --git a/assets/common/js/metadata.js b/assets/common/js/metadata.js index 2b013364..d5a28a35 100644 --- a/assets/common/js/metadata.js +++ b/assets/common/js/metadata.js | |||
@@ -56,37 +56,41 @@ function updateThumb(basePath, divElement, id) { | |||
56 | 56 | ||
57 | (() => { | 57 | (() => { |
58 | const basePath = document.querySelector('input[name="js_base_path"]').value; | 58 | const basePath = document.querySelector('input[name="js_base_path"]').value; |
59 | const loaders = document.querySelectorAll('.loading-input'); | ||
60 | 59 | ||
61 | /* | 60 | /* |
62 | * METADATA FOR EDIT BOOKMARK PAGE | 61 | * METADATA FOR EDIT BOOKMARK PAGE |
63 | */ | 62 | */ |
64 | const inputTitle = document.querySelector('input[name="lf_title"]'); | 63 | const inputTitles = document.querySelectorAll('input[name="lf_title"]'); |
65 | if (inputTitle != null) { | 64 | if (inputTitles != null) { |
66 | if (inputTitle.value.length > 0) { | 65 | [...inputTitles].forEach((inputTitle) => { |
67 | clearLoaders(loaders); | 66 | const form = inputTitle.closest('form[name="linkform"]'); |
68 | return; | 67 | const loaders = form.querySelectorAll('.loading-input'); |
69 | } | 68 | |
69 | if (inputTitle.value.length > 0) { | ||
70 | clearLoaders(loaders); | ||
71 | return; | ||
72 | } | ||
70 | 73 | ||
71 | const url = document.querySelector('input[name="lf_url"]').value; | 74 | const url = form.querySelector('input[name="lf_url"]').value; |
72 | 75 | ||
73 | const xhr = new XMLHttpRequest(); | 76 | const xhr = new XMLHttpRequest(); |
74 | xhr.open('GET', `${basePath}/admin/metadata?url=${encodeURI(url)}`, true); | 77 | xhr.open('GET', `${basePath}/admin/metadata?url=${encodeURI(url)}`, true); |
75 | xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); | 78 | xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); |
76 | xhr.onload = () => { | 79 | xhr.onload = () => { |
77 | const result = JSON.parse(xhr.response); | 80 | const result = JSON.parse(xhr.response); |
78 | Object.keys(result).forEach((key) => { | 81 | Object.keys(result).forEach((key) => { |
79 | if (result[key] !== null && result[key].length) { | 82 | if (result[key] !== null && result[key].length) { |
80 | const element = document.querySelector(`input[name="lf_${key}"], textarea[name="lf_${key}"]`); | 83 | const element = form.querySelector(`input[name="lf_${key}"], textarea[name="lf_${key}"]`); |
81 | if (element != null && element.value.length === 0) { | 84 | if (element != null && element.value.length === 0) { |
82 | element.value = he.decode(result[key]); | 85 | element.value = he.decode(result[key]); |
86 | } | ||
83 | } | 87 | } |
84 | } | 88 | }); |
85 | }); | 89 | clearLoaders(loaders); |
86 | clearLoaders(loaders); | 90 | }; |
87 | }; | ||
88 | 91 | ||
89 | xhr.send(); | 92 | xhr.send(); |
93 | }); | ||
90 | } | 94 | } |
91 | 95 | ||
92 | /* | 96 | /* |