ignore button clicks when processing requests

This commit is contained in:
Ro 2021-04-27 19:38:36 +00:00
parent 08d034a8d1
commit 7002ba8014
5 changed files with 51 additions and 4 deletions

File diff suppressed because one or more lines are too long

View file

@ -12,6 +12,7 @@ export default class Base {
// constructor // constructor
//-------------------------- //--------------------------
constructor() { constructor() {
this.processing = false;
this.start(); this.start();
} }
@ -47,14 +48,18 @@ export default class Base {
// event handlers // event handlers
//-------------------------- //--------------------------
handleLogin(e) { handleLogin(e) {
if (this.processing) return;
let self = this;
e.stopPropagation(); e.stopPropagation();
e.preventDefault(); e.preventDefault();
let authForm = data.formDataToJSON(document.getElementById("login")); let authForm = data.formDataToJSON(document.getElementById("login"));
notify.alert("Looking, hold up", null); notify.alert("Looking, hold up", null);
let api = new FipamoApi(); let api = new FipamoApi();
this.processing = true;
api api
.login(authForm) .login(authForm)
.then((response) => { .then((response) => {
self.processing = false;
if (response.type === DataEvent.REQUEST_LAME) { if (response.type === DataEvent.REQUEST_LAME) {
notify.alert(response.message, false); notify.alert(response.message, false);
} else { } else {
@ -66,21 +71,27 @@ export default class Base {
} }
}) })
.catch((err) => { .catch((err) => {
self.processing = false;
notify.alert(err, false); notify.alert(err, false);
}); });
} }
handleSetup(e) { handleSetup(e) {
if (this.processing) return;
let self = this;
e.stopPropagation(); e.stopPropagation();
e.preventDefault(); e.preventDefault();
let setUpForm = data.formDataToJSON(document.getElementById("init-form")); let setUpForm = data.formDataToJSON(document.getElementById("init-form"));
let api = new FipamoApi(); let api = new FipamoApi();
this.processing = true;
api api
.init(setUpForm) .init(setUpForm)
.then((response) => { .then((response) => {
if (response.type === DataEvent.API_INIT_LAME) { if (response.type === DataEvent.API_INIT_LAME) {
self.processing = false;
notify.alert(response.message, false); notify.alert(response.message, false);
} else { } else {
self.processing = false;
notify.alert(response.message, true); notify.alert(response.message, true);
setTimeout(() => { setTimeout(() => {
window.location = "/dashboard"; window.location = "/dashboard";
@ -88,21 +99,27 @@ export default class Base {
} }
}) })
.catch((err) => { .catch((err) => {
self.processing = false;
notify.alert(err, false); notify.alert(err, false);
}); });
} }
handleRestore(e) { handleRestore(e) {
if (this.processing) return;
let self = this;
e.stopPropagation(); e.stopPropagation();
e.preventDefault(); e.preventDefault();
let api = new FipamoApi(); let api = new FipamoApi();
var form = document.getElementById("init-restore"); var form = document.getElementById("init-restore");
this.processing = true;
api api
.handleInitRestore(form) .handleInitRestore(form)
.then((response) => { .then((response) => {
if (response.type === DataEvent.REQUEST_LAME) { if (response.type === DataEvent.REQUEST_LAME) {
self.processing = false;
notify.alert(response.message, false); notify.alert(response.message, false);
} else { } else {
self.processing = false;
notify.alert(response.message, true); notify.alert(response.message, true);
setTimeout(() => { setTimeout(() => {
window.location = "/dashboard"; window.location = "/dashboard";
@ -110,6 +127,7 @@ export default class Base {
} }
}) })
.catch((err) => { .catch((err) => {
self.processing = false;
notify.alert(err, false); notify.alert(err, false);
}); });
} }

View file

@ -10,6 +10,7 @@ export default class NavIndex {
// constructor // constructor
//-------------------------- //--------------------------
constructor() { constructor() {
this.processing = false;
this.admin = new FipamoAdminAPI(); this.admin = new FipamoAdminAPI();
this.start(); this.start();
} }
@ -41,6 +42,7 @@ export default class NavIndex {
// event handlers // event handlers
//-------------------------- //--------------------------
handleNavButton(e) { handleNavButton(e) {
if (this.processing) return;
let id = ""; let id = "";
let self = this; let self = this;
switch (e.target.id) { switch (e.target.id) {
@ -50,7 +52,9 @@ export default class NavIndex {
new NavActions().syncMenu().then((data) => { new NavActions().syncMenu().then((data) => {
data.remove = e.target.getAttribute("data-uuid"); data.remove = e.target.getAttribute("data-uuid");
notify.alert("Editing Menu", null); notify.alert("Editing Menu", null);
self.processing = true;
self.admin.syncNav(data).then((r) => { self.admin.syncNav(data).then((r) => {
self.processing = false;
if (r.type == DataEvent.MENU_UPDATED) { if (r.type == DataEvent.MENU_UPDATED) {
notify.alert(r.message, true); notify.alert(r.message, true);
} else { } else {
@ -60,6 +64,7 @@ export default class NavIndex {
}); });
break; break;
case "edit-item": case "edit-item":
self.processing = false;
window.location = window.location =
"/dashboard/page/edit/" + e.target.getAttribute("data-id"); "/dashboard/page/edit/" + e.target.getAttribute("data-id");
break; break;

View file

@ -16,6 +16,7 @@ export default class PostEditor {
// constructor // constructor
//-------------------------- //--------------------------
constructor() { constructor() {
this.processing = false;
let self = this; let self = this;
this.admin = new FipamoAdminAPI(); this.admin = new FipamoAdminAPI();
this.urlPieces = document.URL.split("/"); this.urlPieces = document.URL.split("/");
@ -136,6 +137,7 @@ export default class PostEditor {
: currentOption.setAttribute("data-active", "false"); : currentOption.setAttribute("data-active", "false");
} }
handleEditorOptions(e) { handleEditorOptions(e) {
if (this.processing) return;
let self = this; let self = this;
switch (e) { switch (e) {
case EditorEvent.EDITOR_SAVE: case EditorEvent.EDITOR_SAVE:
@ -149,10 +151,12 @@ export default class PostEditor {
document.getElementById("featured-image-upload").files[0] document.getElementById("featured-image-upload").files[0]
) )
.then((page) => { .then((page) => {
self.processing = true;
notify.alert("Writing down changes", null); notify.alert("Writing down changes", null);
self.admin self.admin
.pageActions(task, page) .pageActions(task, page)
.then((r) => { .then((r) => {
self.processing = false;
if ( if (
r.type === DataEvent.PAGE_ERROR || r.type === DataEvent.PAGE_ERROR ||
r.type === DataEvent.API_REQUEST_LAME r.type === DataEvent.API_REQUEST_LAME
@ -168,6 +172,7 @@ export default class PostEditor {
} }
}) })
.catch((err) => { .catch((err) => {
self.processing = false;
notify.alert(err, false); notify.alert(err, false);
}); });
}); });
@ -179,12 +184,15 @@ export default class PostEditor {
} }
if (confirm("AYE! You know you're deleting this post, right?")) { if (confirm("AYE! You know you're deleting this post, right?")) {
let id = { id: this.postUUID }; let id = { id: this.postUUID };
self.processing = true;
this.admin this.admin
.pageActions(TASK_PAGE_DELETE, id) .pageActions(TASK_PAGE_DELETE, id)
.then(() => { .then(() => {
self.processing = false;
window.location = "/dashboard/pages"; window.location = "/dashboard/pages";
}) })
.catch((err) => { .catch((err) => {
self.processing = false;
notify.alert(err, false); notify.alert(err, false);
}); });
} else { } else {

View file

@ -9,6 +9,7 @@ export default class SettingsIndex {
// constructor // constructor
//-------------------------- //--------------------------
constructor() { constructor() {
this.processing = false;
this.start(); this.start();
this.admin = new FipamoAdminAPI(); this.admin = new FipamoAdminAPI();
} }
@ -171,44 +172,59 @@ export default class SettingsIndex {
}); });
} }
handlePublished(e) { handlePublished(e) {
if (this.processing) return;
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
let self = this;
let task = { task: "publish all pages" }; let task = { task: "publish all pages" };
this.processing = true;
notify.alert("Publishing site...", null); notify.alert("Publishing site...", null);
this.admin this.admin
.publishSite(task) .publishSite(task)
.then((r) => { .then((r) => {
self.processing = false;
notify.alert(r.message, true); notify.alert(r.message, true);
}) })
.catch((err) => { .catch((err) => {
self.processing = false;
notify.alert(err, false); notify.alert(err, false);
}); });
} }
handleBackup(e) { handleBackup(e) {
if (this.processing) return;
let self = this;
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
notify.alert("Creating backup", null); notify.alert("Creating backup", null);
this.processing = true;
this.admin this.admin
.handleBackup(e.target.id, e.target.files) .handleBackup(e.target.id, e.target.files)
.then((r) => { .then((r) => {
self.processing = false;
notify.alert(r.message, true); notify.alert(r.message, true);
}) })
.catch((err) => { .catch((err) => {
self.processing = false;
notify.alert(err, false); notify.alert(err, false);
}); });
} }
handleReindex(e) { handleReindex(e) {
if (this.processing) return;
let self = this;
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
let task = { task: "cleanup pages indexes" }; let task = { task: "cleanup pages indexes" };
this.processing = true;
notify.alert("Cleaning up page indexes", null); notify.alert("Cleaning up page indexes", null);
this.admin this.admin
.handleReindex(task) .handleReindex(task)
.then((r) => { .then((r) => {
self.processing = false;
notify.alert(r.message, true); notify.alert(r.message, true);
}) })
.catch((err) => { .catch((err) => {
self.processing = false;
notify.alert(err, false); notify.alert(err, false);
}); });
} }