2020-03-26 22:43:44 +01:00
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2021-01-13 09:22:36 +01:00
|
|
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
2020-03-26 22:43:44 +01:00
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
|
|
|
|
2020-07-02 13:58:39 +02:00
|
|
|
import Axios from 'axios';
|
2020-03-26 22:43:44 +01:00
|
|
|
|
|
|
|
class Setup {
|
|
|
|
constructor() {
|
2020-07-02 13:58:39 +02:00
|
|
|
this.checkDbButton = document.getElementById('test-db-connection');
|
|
|
|
this.checkDbAlert = document.getElementById('database-response');
|
|
|
|
|
|
|
|
this.checkSmtpButton = document.getElementById('test-smtp-connection');
|
|
|
|
this.checkSmtpAlert = document.getElementById('smtp-response');
|
|
|
|
|
|
|
|
this.checkPdfButton = document.getElementById('test-pdf');
|
|
|
|
this.checkPdfAlert = document.getElementById('test-pdf-response');
|
2020-03-26 22:43:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
handleDatabaseCheck() {
|
2021-03-12 01:48:41 +01:00
|
|
|
let url = document.querySelector('meta[name=setup-db-check]').content,
|
|
|
|
data = {};
|
2021-03-08 10:00:11 +01:00
|
|
|
|
2021-03-12 01:48:41 +01:00
|
|
|
if (document.querySelector('input[name="db_host"]')) {
|
|
|
|
data = {
|
|
|
|
db_host: document.querySelector('input[name="db_host"]').value,
|
|
|
|
db_port: document.querySelector('input[name="db_port"]').value,
|
|
|
|
db_database: document.querySelector('input[name="db_database"]')
|
|
|
|
.value,
|
|
|
|
db_username: document.querySelector('input[name="db_username"]')
|
|
|
|
.value,
|
|
|
|
db_password: document.querySelector('input[name="db_password"]')
|
|
|
|
.value,
|
|
|
|
};
|
|
|
|
}
|
2020-03-26 22:43:44 +01:00
|
|
|
|
2021-01-04 13:36:47 +01:00
|
|
|
this.checkDbButton.disabled = true;
|
|
|
|
|
2021-03-08 10:00:11 +01:00
|
|
|
Axios.post(url, data)
|
2020-12-24 12:25:22 +01:00
|
|
|
.then((response) =>
|
|
|
|
this.handleSuccess(this.checkDbAlert, 'mail-wrapper')
|
|
|
|
)
|
2020-12-03 14:10:40 +01:00
|
|
|
.catch((e) =>
|
|
|
|
this.handleFailure(this.checkDbAlert, e.response.data.message)
|
2021-01-04 13:36:47 +01:00
|
|
|
).finally(() => this.checkDbButton.disabled = false);
|
2020-03-26 22:43:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
handleSmtpCheck() {
|
2021-03-08 10:00:11 +01:00
|
|
|
let url = document.querySelector('meta[name=setup-email-check]').content;
|
|
|
|
|
2020-03-26 22:43:44 +01:00
|
|
|
let data = {
|
2020-12-24 12:25:22 +01:00
|
|
|
mail_driver: document.querySelector('select[name="mail_driver"]')
|
|
|
|
.value,
|
2020-12-08 14:29:15 +01:00
|
|
|
mail_name: document.querySelector('input[name="mail_name"]').value,
|
|
|
|
mail_address: document.querySelector('input[name="mail_address"]')
|
2020-07-02 13:58:39 +02:00
|
|
|
.value,
|
2020-12-08 14:29:15 +01:00
|
|
|
mail_username: document.querySelector('input[name="mail_username"]')
|
2020-07-02 13:58:39 +02:00
|
|
|
.value,
|
2020-12-08 14:29:15 +01:00
|
|
|
mail_host: document.querySelector('input[name="mail_host"]').value,
|
|
|
|
mail_port: document.querySelector('input[name="mail_port"]').value,
|
2020-07-02 13:58:39 +02:00
|
|
|
encryption: document.querySelector('select[name="encryption"]')
|
|
|
|
.value,
|
2020-12-08 14:29:15 +01:00
|
|
|
mail_password: document.querySelector('input[name="mail_password"]')
|
2020-07-02 13:58:39 +02:00
|
|
|
.value,
|
|
|
|
};
|
2020-03-26 22:43:44 +01:00
|
|
|
|
2020-12-03 14:10:40 +01:00
|
|
|
this.checkSmtpButton.disabled = true;
|
|
|
|
|
2020-12-15 16:10:50 +01:00
|
|
|
if (data.mail_driver === 'log') {
|
|
|
|
this.handleSuccess(this.checkSmtpAlert, 'account-wrapper');
|
|
|
|
this.handleSuccess(this.checkSmtpAlert, 'submit-wrapper');
|
|
|
|
|
2020-12-24 12:25:22 +01:00
|
|
|
return (this.checkSmtpButton.disabled = false);
|
2020-12-15 16:10:50 +01:00
|
|
|
}
|
|
|
|
|
2021-03-08 10:00:11 +01:00
|
|
|
Axios.post(url, data)
|
2020-12-21 08:45:39 +01:00
|
|
|
.then((response) => {
|
|
|
|
this.handleSuccess(this.checkSmtpAlert, 'account-wrapper');
|
|
|
|
this.handleSuccess(this.checkSmtpAlert, 'submit-wrapper');
|
|
|
|
})
|
2020-12-03 14:10:40 +01:00
|
|
|
.catch((e) =>
|
|
|
|
this.handleFailure(this.checkSmtpAlert, e.response.data.message)
|
|
|
|
)
|
|
|
|
.finally(() => (this.checkSmtpButton.disabled = false));
|
2020-07-02 13:58:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
handleTestPdfCheck() {
|
2021-03-08 10:00:11 +01:00
|
|
|
let url = document.querySelector('meta[name=setup-pdf-check]').content;
|
2020-12-24 12:25:22 +01:00
|
|
|
this.checkPdfButton.disabled = true;
|
|
|
|
|
2021-03-08 10:00:11 +01:00
|
|
|
Axios.post(url, {})
|
2020-07-02 13:58:39 +02:00
|
|
|
.then((response) => {
|
2020-10-27 14:02:36 +01:00
|
|
|
try {
|
2021-03-13 07:45:41 +01:00
|
|
|
//let win = window.open(response.data.url, '_blank');
|
|
|
|
//win.focus();
|
2020-10-27 14:02:36 +01:00
|
|
|
|
2020-12-24 12:25:22 +01:00
|
|
|
return this.handleSuccess(
|
|
|
|
this.checkPdfAlert,
|
|
|
|
'database-wrapper'
|
|
|
|
);
|
2020-10-27 14:02:36 +01:00
|
|
|
} catch (error) {
|
2020-12-15 16:10:50 +01:00
|
|
|
this.handleSuccess(this.checkPdfAlert, 'database-wrapper');
|
2021-03-13 06:56:52 +01:00
|
|
|
this.checkPdfAlert.textContent = `Success! PDF was generated succesfully.`;
|
2020-10-27 14:02:36 +01:00
|
|
|
}
|
2020-07-02 13:58:39 +02:00
|
|
|
})
|
2020-10-27 14:02:36 +01:00
|
|
|
.catch((error) => {
|
|
|
|
console.log(error);
|
2020-12-03 14:10:40 +01:00
|
|
|
this.handleFailure(this.checkPdfAlert);
|
2020-12-24 12:25:22 +01:00
|
|
|
})
|
|
|
|
.finally(() => (this.checkPdfButton.disabled = false));
|
2020-03-26 22:43:44 +01:00
|
|
|
}
|
|
|
|
|
2020-12-15 16:10:50 +01:00
|
|
|
handleSuccess(element, nextStep = null) {
|
2020-07-02 13:58:39 +02:00
|
|
|
element.classList.remove('alert-failure');
|
|
|
|
element.innerText = 'Success!';
|
|
|
|
element.classList.add('alert-success');
|
2020-12-15 16:10:50 +01:00
|
|
|
|
|
|
|
if (nextStep) {
|
|
|
|
document.getElementById(nextStep).classList.remove('hidden');
|
2020-12-24 12:25:22 +01:00
|
|
|
document
|
|
|
|
.getElementById(nextStep)
|
2021-01-04 13:36:47 +01:00
|
|
|
.scrollIntoView({behavior: 'smooth', block: 'center'});
|
2020-12-15 16:10:50 +01:00
|
|
|
}
|
2020-03-26 22:43:44 +01:00
|
|
|
}
|
|
|
|
|
2020-10-14 13:40:00 +02:00
|
|
|
handleFailure(element, message = null) {
|
2020-07-02 13:58:39 +02:00
|
|
|
element.classList.remove('alert-success');
|
2020-12-03 14:10:40 +01:00
|
|
|
element.innerText = message
|
|
|
|
? message
|
|
|
|
: "Oops, looks like something isn't correct!";
|
2020-07-02 13:58:39 +02:00
|
|
|
element.classList.add('alert-failure');
|
2020-03-26 22:43:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
handle() {
|
2020-07-02 13:58:39 +02:00
|
|
|
this.checkDbButton.addEventListener('click', () =>
|
2020-03-26 22:43:44 +01:00
|
|
|
this.handleDatabaseCheck()
|
|
|
|
);
|
|
|
|
|
2020-07-02 13:58:39 +02:00
|
|
|
this.checkSmtpButton.addEventListener('click', () =>
|
2020-03-26 22:43:44 +01:00
|
|
|
this.handleSmtpCheck()
|
|
|
|
);
|
2020-07-02 13:58:39 +02:00
|
|
|
|
|
|
|
this.checkPdfButton.addEventListener('click', () =>
|
|
|
|
this.handleTestPdfCheck()
|
|
|
|
);
|
2020-03-26 22:43:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
new Setup().handle();
|