2021-04-14 18:50:19 -07:00
|
|
|
import SettingsActions from "../actions/SettingsActions";
|
2021-07-02 14:45:35 -07:00
|
|
|
import Maintenance from "MaintenanceManager";
|
|
|
|
import FipamoAdminAPI, {
|
|
|
|
TASK_SYNC_SETTNIGS
|
|
|
|
} from "../../libraries/FipamoAdminAPI";
|
2021-04-14 18:50:19 -07:00
|
|
|
import * as DataEvent from "../../../src/com/events/DataEvent";
|
|
|
|
import Mailer from "../actions/Mailer";
|
|
|
|
import Notifications from "../ui/Notifications";
|
2019-11-28 21:50:32 -08:00
|
|
|
const notify = new Notifications();
|
2019-11-21 22:36:18 -08:00
|
|
|
export default class SettingsIndex {
|
2021-04-14 18:50:19 -07:00
|
|
|
//--------------------------
|
|
|
|
// constructor
|
|
|
|
//--------------------------
|
|
|
|
constructor() {
|
2021-04-27 19:38:36 +00:00
|
|
|
this.processing = false;
|
2021-04-14 18:50:19 -07:00
|
|
|
this.start();
|
2021-06-28 13:47:06 -07:00
|
|
|
this.admin = new FipamoAdminAPI(
|
|
|
|
null,
|
|
|
|
"fe79df250470815bf32dcea70221384c89163cad3a827a9c3da25d87159ed55a"
|
|
|
|
);
|
2021-08-02 15:34:21 -07:00
|
|
|
this.mm = new Maintenance(null, null);
|
2021-04-14 18:50:19 -07:00
|
|
|
}
|
|
|
|
//--------------------------
|
|
|
|
// methods
|
|
|
|
//--------------------------
|
|
|
|
start() {
|
|
|
|
let self = this;
|
|
|
|
//handle save button
|
|
|
|
document.getElementById("save-toggle").addEventListener("click", () =>
|
|
|
|
new SettingsActions()
|
|
|
|
.getInfo()
|
|
|
|
.then((data) => {
|
|
|
|
notify.alert("Saving Settings", null);
|
2021-07-02 14:45:35 -07:00
|
|
|
self.admin.sync(TASK_SYNC_SETTNIGS, data).then((r) => {
|
2021-04-14 18:50:19 -07:00
|
|
|
if (r.type == DataEvent.SETTINGS_UPDATED) {
|
|
|
|
notify.alert(r.message, true);
|
|
|
|
} else {
|
|
|
|
notify.alert(r.message, true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
//console.log(err);
|
|
|
|
})
|
|
|
|
);
|
|
|
|
//handle set up image uploads
|
|
|
|
document.getElementById("avatar").addEventListener("click", () => {
|
|
|
|
document.getElementById("avatar-upload").click();
|
|
|
|
});
|
|
|
|
document.getElementById("background").addEventListener("click", () => {
|
|
|
|
document.getElementById("background-upload").click();
|
|
|
|
});
|
|
|
|
document.getElementById("avatar-upload").addEventListener(
|
|
|
|
"change",
|
|
|
|
(e) => {
|
|
|
|
self.handleImageUpload(e.target.id, e.target.files);
|
|
|
|
},
|
|
|
|
false
|
|
|
|
);
|
|
|
|
document.getElementById("background-upload").addEventListener(
|
|
|
|
"change",
|
|
|
|
(e) => {
|
|
|
|
self.handleImageUpload(e.target.id, e.target.files);
|
|
|
|
},
|
|
|
|
false
|
|
|
|
);
|
2021-06-09 13:36:08 -07:00
|
|
|
//handle api access toggle
|
|
|
|
var apiButton = document.getElementById("api-access-toggle");
|
|
|
|
var apiStatus = document.getElementById("api-status");
|
|
|
|
apiButton.addEventListener("click", (e) => {
|
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
if (apiButton.getAttribute("data-enabled") == "false") {
|
|
|
|
apiButton.setAttribute("data-enabled", "true");
|
|
|
|
apiStatus.innerHTML = "EXTERNAL API ACCESS IS ENABLED";
|
|
|
|
} else {
|
|
|
|
apiButton.setAttribute("data-enabled", "false");
|
|
|
|
apiStatus.innerHTML = "EXTERNAL API ACCESS IS NOT ENABLED";
|
|
|
|
}
|
|
|
|
});
|
2021-04-27 01:28:11 +00:00
|
|
|
|
2021-04-14 18:50:19 -07:00
|
|
|
document
|
|
|
|
.getElementById("send-mail")
|
|
|
|
.addEventListener("click", (e) => this.handleMailer(e));
|
|
|
|
document
|
|
|
|
.getElementById("publish-pages")
|
|
|
|
.addEventListener("click", (e) => this.handlePublished(e));
|
|
|
|
//handle theme toggle
|
|
|
|
let themeBtns = document.querySelectorAll(".theme-select");
|
|
|
|
for (var i = 0, length = themeBtns.length; i < length; i++) {
|
|
|
|
themeBtns[i].addEventListener("click", (e) => this.handleThemes(e));
|
|
|
|
}
|
|
|
|
//handle mail options
|
|
|
|
let mailBtn = document.querySelectorAll(".mail-option");
|
|
|
|
for (i = 0, length = mailBtn.length; i < length; i++) {
|
|
|
|
mailBtn[i].addEventListener("click", (e) => this.handleMailOptions(e));
|
|
|
|
}
|
2021-06-24 11:58:55 -07:00
|
|
|
//handle backup from settings [disabled]
|
|
|
|
/*
|
2021-04-14 18:50:19 -07:00
|
|
|
document
|
|
|
|
.getElementById("create-backup")
|
|
|
|
.addEventListener("click", (e) => this.handleBackup(e));
|
2021-06-24 11:58:55 -07:00
|
|
|
*/
|
2020-09-29 22:26:30 +00:00
|
|
|
|
2021-05-24 14:42:46 -07:00
|
|
|
/*
|
2021-04-14 18:50:19 -07:00
|
|
|
document
|
|
|
|
.getElementById("reindex-pages")
|
|
|
|
.addEventListener("click", (e) => this.handleReindex(e));
|
2021-05-24 14:42:46 -07:00
|
|
|
*/
|
2021-04-14 18:50:19 -07:00
|
|
|
}
|
|
|
|
//--------------------------
|
|
|
|
// event handlers
|
|
|
|
//--------------------------
|
|
|
|
togglePrivacy(e) {
|
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
if (e.target.getAttribute("data-private") == "false") {
|
|
|
|
e.target.setAttribute("data-private", "true");
|
|
|
|
e.target.innerHTML = "SITE IS PUBLIC";
|
|
|
|
} else {
|
|
|
|
e.target.setAttribute("data-private", "false");
|
|
|
|
e.target.innerHTML = "SITE IS PRIVATE";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
toggleRender(e) {
|
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
if (e.target.getAttribute("data-render") == "false") {
|
|
|
|
e.target.setAttribute("data-render", "true");
|
|
|
|
//e.target.innerHTML = 'RENDER PAGES ON SAVE';
|
|
|
|
} else {
|
|
|
|
e.target.setAttribute("data-render", "false");
|
|
|
|
//e.target.innerHTML = "DON'T RENDER PAGES ON SAVE";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
handleMailer() {
|
2021-05-03 15:48:20 -07:00
|
|
|
let mailer = new Mailer();
|
|
|
|
mailer.testMail();
|
2021-04-27 01:28:11 +00:00
|
|
|
//mailer.sendMail();
|
2021-04-14 18:50:19 -07:00
|
|
|
}
|
|
|
|
handleThemes(e) {
|
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
let themes = document.querySelectorAll(".theme-select");
|
|
|
|
for (var i = 0, length = themes.length; i < length; i++) {
|
|
|
|
e.target.id == themes[i].id
|
|
|
|
? themes[i].setAttribute("data-enabled", "true")
|
|
|
|
: themes[i].setAttribute("data-enabled", "false");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
handleMailOptions(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
let smtp = document.getElementById("mail-smtp");
|
|
|
|
let mailgun = document.getElementById("mail-mg");
|
|
|
|
let mail = document.querySelectorAll(".mail-option");
|
|
|
|
for (var i = 0, length = mail.length; i < length; i++) {
|
|
|
|
if (e.target.id == mail[i].id) {
|
|
|
|
mail[i].setAttribute("data-enabled", "true");
|
|
|
|
if (e.target.id == "option-smtp") {
|
|
|
|
smtp.setAttribute("data-enabled", "true");
|
|
|
|
mailgun.setAttribute("data-enabled", "false");
|
|
|
|
} else if (e.target.id == "option-none") {
|
|
|
|
smtp.setAttribute("data-enabled", "false");
|
|
|
|
mailgun.setAttribute("data-enabled", "false");
|
|
|
|
} else {
|
|
|
|
smtp.setAttribute("data-enabled", "false");
|
|
|
|
mailgun.setAttribute("data-enabled", "true");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
mail[i].setAttribute("data-enabled", "false");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
handleImageUpload(type, files) {
|
|
|
|
notify.alert("Uploading Image... ", null);
|
2021-08-02 15:13:46 -07:00
|
|
|
|
|
|
|
this.mm
|
|
|
|
.imageUpload(type, files)
|
2021-04-14 18:50:19 -07:00
|
|
|
.then((r) => {
|
|
|
|
if (r.type == DataEvent.AVATAR_UPLOADED) {
|
|
|
|
notify.alert(r.message, true);
|
|
|
|
document.getElementById("avatar").src = r.url;
|
|
|
|
} else {
|
|
|
|
notify.alert(r.message, true);
|
|
|
|
document.getElementById("background").src = r.url;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
//console.log(err)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
handlePublished(e) {
|
2021-04-27 19:38:36 +00:00
|
|
|
if (this.processing) return;
|
2021-04-14 18:50:19 -07:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
2021-04-27 19:38:36 +00:00
|
|
|
let self = this;
|
2021-07-02 14:45:35 -07:00
|
|
|
let task = { task: "PUBLISH_ALL" };
|
2021-04-27 19:38:36 +00:00
|
|
|
this.processing = true;
|
2021-04-14 18:50:19 -07:00
|
|
|
notify.alert("Publishing site...", null);
|
|
|
|
this.admin
|
2021-07-02 14:45:35 -07:00
|
|
|
.publish(task)
|
2021-04-14 18:50:19 -07:00
|
|
|
.then((r) => {
|
2021-04-27 19:38:36 +00:00
|
|
|
self.processing = false;
|
2021-04-14 18:50:19 -07:00
|
|
|
notify.alert(r.message, true);
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
2021-04-27 19:38:36 +00:00
|
|
|
self.processing = false;
|
2021-04-14 18:50:19 -07:00
|
|
|
notify.alert(err, false);
|
|
|
|
});
|
|
|
|
}
|
2020-09-29 22:26:30 +00:00
|
|
|
|
2021-04-14 18:50:19 -07:00
|
|
|
handleReindex(e) {
|
2021-04-27 19:38:36 +00:00
|
|
|
if (this.processing) return;
|
|
|
|
let self = this;
|
2021-04-14 18:50:19 -07:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
let task = { task: "cleanup pages indexes" };
|
2021-04-27 19:38:36 +00:00
|
|
|
this.processing = true;
|
2021-04-14 18:50:19 -07:00
|
|
|
notify.alert("Cleaning up page indexes", null);
|
|
|
|
this.admin
|
|
|
|
.handleReindex(task)
|
|
|
|
.then((r) => {
|
2021-04-27 19:38:36 +00:00
|
|
|
self.processing = false;
|
2021-04-14 18:50:19 -07:00
|
|
|
notify.alert(r.message, true);
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
2021-04-27 19:38:36 +00:00
|
|
|
self.processing = false;
|
2021-04-14 18:50:19 -07:00
|
|
|
notify.alert(err, false);
|
|
|
|
});
|
|
|
|
}
|
2019-11-21 22:36:18 -08:00
|
|
|
}
|