aboutsummaryrefslogtreecommitdiffhomepage
path: root/assets/common
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2020-10-23 12:53:49 +0200
committerArthurHoaro <arthur@hoa.ro>2020-10-27 20:11:30 +0100
commit6a716758871885e5bd045d1981f890dbf3343b1d (patch)
tree12ded5d77998b3799fe2d35854de555141d9f814 /assets/common
parentc609944cb906a2f5002cd86a808aa36d8deb2afd (diff)
downloadShaarli-6a716758871885e5bd045d1981f890dbf3343b1d.tar.gz
Shaarli-6a716758871885e5bd045d1981f890dbf3343b1d.tar.zst
Shaarli-6a716758871885e5bd045d1981f890dbf3343b1d.zip
Bulk creation: displays a progress bar when saving all displayed forms
Diffstat (limited to 'assets/common')
-rw-r--r--assets/common/js/shaare-batch.js22
1 files changed, 18 insertions, 4 deletions
diff --git a/assets/common/js/shaare-batch.js b/assets/common/js/shaare-batch.js
index 9f612993..557325ee 100644
--- a/assets/common/js/shaare-batch.js
+++ b/assets/common/js/shaare-batch.js
@@ -15,7 +15,7 @@ const sendBookmarkForm = (basePath, formElement) => {
15 alert(`An error occurred. Return code: ${xhr.status}`); 15 alert(`An error occurred. Return code: ${xhr.status}`);
16 reject(); 16 reject();
17 } else { 17 } else {
18 formElement.remove(); 18 formElement.closest('.edit-link-container').remove();
19 resolve(); 19 resolve();
20 } 20 }
21 }; 21 };
@@ -32,7 +32,7 @@ const sendBookmarkDelete = (buttonElement, formElement) => (
32 alert(`An error occurred. Return code: ${xhr.status}`); 32 alert(`An error occurred. Return code: ${xhr.status}`);
33 reject(); 33 reject();
34 } else { 34 } else {
35 formElement.remove(); 35 formElement.closest('.edit-link-container').remove();
36 resolve(); 36 resolve();
37 } 37 }
38 }; 38 };
@@ -80,9 +80,23 @@ const redirectIfEmptyBatch = (basePath, formElements, path) => {
80 saveAllButton.addEventListener('click', (e) => { 80 saveAllButton.addEventListener('click', (e) => {
81 e.preventDefault(); 81 e.preventDefault();
82 82
83 const forms = [...getForms()];
84 const nbForm = forms.length;
85 let current = 0;
86 const progressBar = document.querySelector('.progressbar > div');
87 const progressBarCurrent = document.querySelector('.progressbar-current');
88
89 document.querySelector('.dark-layer').style.display = 'block';
90 document.querySelector('.progressbar-max').innerHTML = nbForm;
91 progressBarCurrent.innerHTML = current;
92
83 const promises = []; 93 const promises = [];
84 [...getForms()].forEach((formElement) => { 94 forms.forEach((formElement) => {
85 promises.push(sendBookmarkForm(basePath, formElement)); 95 promises.push(sendBookmarkForm(basePath, formElement).then(() => {
96 current += 1;
97 progressBar.style.width = `${(current * 100) / nbForm}%`;
98 progressBarCurrent.innerHTML = current;
99 }));
86 }); 100 });
87 101
88 Promise.all(promises).then(() => { 102 Promise.all(promises).then(() => {