2019-11-22 07:36:18 +01:00
|
|
|
import SettingsActions from '../actions/SettingsActions';
|
2020-06-28 23:48:44 +02:00
|
|
|
import FipamoAdminAPI from '../../libraries/FipamoAdminAPI';
|
2019-11-24 01:09:37 +01:00
|
|
|
import * as DataEvent from '../../../src/com/events/DataEvent';
|
2019-11-22 07:36:18 +01:00
|
|
|
import Mailer from '../actions/Mailer';
|
2019-11-29 06:50:32 +01:00
|
|
|
import Notifications from '../ui/Notifications';
|
2020-06-28 23:48:44 +02:00
|
|
|
const admin = new FipamoAdminAPI();
|
2019-11-29 06:50:32 +01:00
|
|
|
const notify = new Notifications();
|
2019-11-29 20:12:15 +01:00
|
|
|
const mailer = new Mailer();
|
2019-11-22 07:36:18 +01:00
|
|
|
export default class SettingsIndex {
|
|
|
|
//--------------------------
|
|
|
|
// constructor
|
|
|
|
//--------------------------
|
|
|
|
constructor() {
|
|
|
|
this.start();
|
|
|
|
}
|
|
|
|
//--------------------------
|
|
|
|
// methods
|
|
|
|
//--------------------------
|
|
|
|
start() {
|
|
|
|
let self = this;
|
|
|
|
//handle save button
|
|
|
|
document.getElementById('save-toggle').addEventListener('click', () =>
|
|
|
|
new SettingsActions()
|
2020-05-23 21:40:01 +02:00
|
|
|
.getInfo()
|
|
|
|
.then(data => {
|
2020-06-28 23:48:44 +02:00
|
|
|
admin.syncSettings(data).then(r => {
|
2020-05-23 21:40:01 +02:00
|
|
|
if (r.type == DataEvent.SETTINGS_UPDATED) {
|
|
|
|
notify.alert(r.message, true);
|
|
|
|
} else {
|
|
|
|
notify.alert(r.message, true);
|
|
|
|
}
|
|
|
|
});
|
2019-11-22 07:36:18 +01:00
|
|
|
})
|
|
|
|
.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();
|
|
|
|
});
|
2020-08-18 00:05:10 +02:00
|
|
|
document.getElementById('restore-backup').addEventListener('click', () => {
|
|
|
|
document.getElementById('backup-upload').click();
|
|
|
|
});
|
2019-11-22 07:36:18 +01:00
|
|
|
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
|
|
|
|
);
|
2020-08-18 00:05:10 +02:00
|
|
|
document.getElementById('backup-upload').addEventListener(
|
|
|
|
'change',
|
|
|
|
e => {
|
|
|
|
self.handleBackup(e);
|
|
|
|
},
|
|
|
|
false
|
|
|
|
);
|
2019-11-22 07:36:18 +01:00
|
|
|
//handle privacy toggle
|
2020-07-06 23:04:29 +02:00
|
|
|
//document
|
|
|
|
//.getElementById('privacy-toggle')
|
|
|
|
//.addEventListener('click', e => this.togglePrivacy(e));
|
2019-11-29 20:12:15 +01:00
|
|
|
document
|
|
|
|
.getElementById('render-toggle')
|
|
|
|
.addEventListener('click', e => this.toggleRender(e));
|
2019-11-22 07:36:18 +01:00
|
|
|
document.getElementById('send-mail').addEventListener('click', e => this.handleMailer(e));
|
2020-05-05 21:31:32 +02:00
|
|
|
document
|
|
|
|
.getElementById('publish-pages')
|
|
|
|
.addEventListener('click', e => this.handlePublished(e));
|
2019-11-22 07:36:18 +01:00
|
|
|
//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));
|
|
|
|
}
|
2020-08-13 21:53:51 +02:00
|
|
|
//handle backup
|
|
|
|
document
|
|
|
|
.getElementById('create-backup')
|
|
|
|
.addEventListener('click', e => this.handleBackup(e));
|
2019-11-22 07:36:18 +01: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';
|
|
|
|
}
|
|
|
|
}
|
2019-11-29 20:12:15 +01:00
|
|
|
toggleRender(e) {
|
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
if (e.target.getAttribute('data-render') == 'false') {
|
|
|
|
e.target.setAttribute('data-render', 'true');
|
2020-07-06 23:04:29 +02:00
|
|
|
//e.target.innerHTML = 'RENDER PAGES ON SAVE';
|
2019-11-29 20:12:15 +01:00
|
|
|
} else {
|
|
|
|
e.target.setAttribute('data-render', 'false');
|
2020-07-06 23:04:29 +02:00
|
|
|
//e.target.innerHTML = "DON'T RENDER PAGES ON SAVE";
|
2019-11-29 20:12:15 +01:00
|
|
|
}
|
|
|
|
}
|
2019-11-22 07:36:18 +01:00
|
|
|
handleMailer() {
|
2019-11-29 20:12:15 +01:00
|
|
|
mailer.sendMail();
|
2019-11-22 07:36:18 +01: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) {
|
2020-06-28 23:48:44 +02:00
|
|
|
admin
|
|
|
|
.imageUpload(type, files)
|
2020-06-24 23:14:17 +02:00
|
|
|
.then(r => {
|
2019-11-29 06:50:32 +01:00
|
|
|
if (r.type == DataEvent.AVATAR_UPLOADED) {
|
|
|
|
notify.alert(r.message, true);
|
2019-11-22 07:36:18 +01:00
|
|
|
document.getElementById('avatar').src = r.url;
|
|
|
|
} else {
|
2019-11-29 06:50:32 +01:00
|
|
|
notify.alert(r.message, true);
|
2019-11-22 07:36:18 +01:00
|
|
|
document.getElementById('background').src = r.url;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
//console.log(err)
|
|
|
|
});
|
|
|
|
}
|
2020-05-05 21:31:32 +02:00
|
|
|
handlePublished(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
let task = { task: 'publish all pages' };
|
2020-06-28 23:48:44 +02:00
|
|
|
admin
|
|
|
|
.publishSite(task)
|
2020-06-24 23:14:17 +02:00
|
|
|
.then(r => {
|
2020-05-06 23:43:53 +02:00
|
|
|
notify.alert(r.message, true);
|
2020-05-05 21:31:32 +02:00
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
notify.alert(err, false);
|
|
|
|
});
|
|
|
|
}
|
2020-08-13 21:53:51 +02:00
|
|
|
handleBackup(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
admin
|
2020-08-18 00:05:10 +02:00
|
|
|
.handleBackup(e.target.id, e.target.files)
|
2020-08-13 21:53:51 +02:00
|
|
|
.then(r => {
|
|
|
|
notify.alert(r.message, true);
|
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
notify.alert(err, false);
|
|
|
|
});
|
|
|
|
}
|
2019-11-22 07:36:18 +01:00
|
|
|
}
|