2020-03-26 22:43:44 +01:00
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @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() {
|
|
|
|
let data = {
|
|
|
|
host: document.querySelector('input[name="host"]').value,
|
|
|
|
database: document.querySelector('input[name="database"]').value,
|
|
|
|
username: document.querySelector('input[name="db_username"]').value,
|
|
|
|
password: document.querySelector('input[name="db_password"]').value,
|
2020-07-02 13:58:39 +02:00
|
|
|
};
|
2020-03-26 22:43:44 +01:00
|
|
|
|
2020-07-02 13:58:39 +02:00
|
|
|
Axios.post('/setup/check_db', data)
|
|
|
|
.then((response) => this.handleSuccess(this.checkDbAlert))
|
2020-10-14 13:40:00 +02:00
|
|
|
.catch((e) => this.handleFailure(this.checkDbAlert, e.response.data.message));
|
2020-03-26 22:43:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
handleSmtpCheck() {
|
|
|
|
let data = {
|
|
|
|
driver: document.querySelector('select[name="mail_driver"]').value,
|
|
|
|
from_name: document.querySelector('input[name="mail_name"]').value,
|
2020-07-02 13:58:39 +02:00
|
|
|
from_address: document.querySelector('input[name="mail_address"]')
|
|
|
|
.value,
|
|
|
|
username: document.querySelector('input[name="mail_username"]')
|
|
|
|
.value,
|
2020-03-26 22:43:44 +01:00
|
|
|
host: document.querySelector('input[name="mail_host"]').value,
|
|
|
|
port: document.querySelector('input[name="mail_port"]').value,
|
2020-07-02 13:58:39 +02:00
|
|
|
encryption: document.querySelector('select[name="encryption"]')
|
|
|
|
.value,
|
|
|
|
password: document.querySelector('input[name="mail_password"]')
|
|
|
|
.value,
|
|
|
|
};
|
2020-03-26 22:43:44 +01:00
|
|
|
|
2020-07-02 13:58:39 +02:00
|
|
|
Axios.post('/setup/check_mail', data)
|
|
|
|
.then((response) => this.handleSuccess(this.checkSmtpAlert))
|
|
|
|
.catch((e) => this.handleFailure(this.checkSmtpAlert));
|
|
|
|
}
|
|
|
|
|
|
|
|
handleTestPdfCheck() {
|
|
|
|
Axios.post('/setup/check_pdf', {})
|
|
|
|
.then((response) => {
|
|
|
|
let win = window.open(response.data.url, '_blank');
|
|
|
|
win.focus();
|
|
|
|
|
|
|
|
return this.handleSuccess(this.checkPdfAlert);
|
|
|
|
})
|
|
|
|
.catch((error) => this.handleFailure(this.checkPdfAlert));
|
2020-03-26 22:43:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
handleSuccess(element) {
|
2020-07-02 13:58:39 +02:00
|
|
|
element.classList.remove('alert-failure');
|
|
|
|
element.innerText = 'Success!';
|
|
|
|
element.classList.add('alert-success');
|
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-10-14 13:40:00 +02: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();
|