2020-06-21 03:13:23 +02:00
|
|
|
import FipamoApi, {
|
|
|
|
REQUEST_TYPE_POST,
|
|
|
|
CONTENT_TYPE_JSON,
|
|
|
|
API_LOGIN,
|
|
|
|
API_INIT
|
|
|
|
} from '../libraries/FipamoAPI';
|
2019-12-02 22:07:16 +01:00
|
|
|
import DataUitls from './utils/DataUtils';
|
2019-11-24 01:56:28 +01:00
|
|
|
import * as DataEvent from './events/DataEvent';
|
|
|
|
import DashManager from './controllers/DashManager';
|
2019-11-25 03:39:43 +01:00
|
|
|
import Notfications from './ui/Notifications';
|
2019-11-24 01:56:28 +01:00
|
|
|
|
2020-06-18 05:47:18 +02:00
|
|
|
const api = new FipamoApi();
|
2019-12-02 22:07:16 +01:00
|
|
|
const data = new DataUitls();
|
2019-11-25 03:39:43 +01:00
|
|
|
const notify = new Notfications();
|
2019-11-22 07:36:18 +01:00
|
|
|
|
|
|
|
export default class Base {
|
|
|
|
//--------------------------
|
|
|
|
// constructor
|
|
|
|
//--------------------------
|
|
|
|
constructor() {
|
|
|
|
this.start();
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------
|
|
|
|
// methods
|
|
|
|
//--------------------------
|
|
|
|
start() {
|
2020-06-21 03:13:23 +02:00
|
|
|
if (document.getElementById('dash-form') || document.getElementById('dash-init')) {
|
|
|
|
if (document.getElementById('dash-form')) {
|
|
|
|
document
|
|
|
|
.getElementById('login-btn')
|
|
|
|
.addEventListener('click', e => this.handleLogin(e));
|
|
|
|
} else {
|
|
|
|
document
|
|
|
|
.getElementById('init-blog')
|
|
|
|
.addEventListener('click', e => this.handleSetup(e));
|
|
|
|
}
|
2019-11-22 07:36:18 +01:00
|
|
|
} else {
|
2020-06-18 05:47:18 +02:00
|
|
|
new DashManager();
|
2019-11-22 07:36:18 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
//--------------------------
|
|
|
|
// event handlers
|
|
|
|
//--------------------------
|
|
|
|
handleLogin(e) {
|
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
2019-11-24 01:56:28 +01:00
|
|
|
let authForm = data.formDataToJSON(document.getElementById('login'));
|
2019-12-02 22:07:16 +01:00
|
|
|
api.request(
|
2020-06-18 05:47:18 +02:00
|
|
|
API_LOGIN,
|
2019-11-24 01:56:28 +01:00
|
|
|
DataEvent.AUTH_STATUS,
|
|
|
|
REQUEST_TYPE_POST,
|
|
|
|
CONTENT_TYPE_JSON,
|
|
|
|
authForm
|
|
|
|
)
|
2020-06-24 23:14:17 +02:00
|
|
|
.then(response => {
|
2019-11-24 01:56:28 +01:00
|
|
|
if (response.type === DataEvent.REQUEST_LAME) {
|
2019-11-25 03:39:43 +01:00
|
|
|
notify.alert(response.message, false);
|
2019-11-22 07:36:18 +01:00
|
|
|
} else {
|
2019-11-24 01:56:28 +01:00
|
|
|
e.target.innerHTML = response.message;
|
|
|
|
setTimeout(() => {
|
|
|
|
window.location = '/@/dashboard';
|
|
|
|
}, 500);
|
2019-11-22 07:36:18 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(err => {
|
2020-06-21 06:07:06 +02:00
|
|
|
notify.alert(err, false);
|
2019-11-22 07:36:18 +01:00
|
|
|
});
|
|
|
|
}
|
2020-06-21 03:13:23 +02:00
|
|
|
|
|
|
|
handleSetup(e) {
|
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
let setUpForm = data.formDataToJSON(document.getElementById('init-form'));
|
|
|
|
api.request(API_INIT, DataEvent.API_INIT, REQUEST_TYPE_POST, CONTENT_TYPE_JSON, setUpForm)
|
2020-06-24 23:14:17 +02:00
|
|
|
.then(response => {
|
2020-06-21 03:13:23 +02:00
|
|
|
if (response.type === DataEvent.API_INIT_LAME) {
|
|
|
|
notify.alert(response.message, false);
|
|
|
|
} else {
|
|
|
|
notify.alert(response.message, true);
|
|
|
|
setTimeout(() => {
|
|
|
|
//window.location = '/@/dashboard';
|
|
|
|
}, 500);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(err => {
|
2020-06-21 06:07:06 +02:00
|
|
|
notify.alert(err, false);
|
2020-06-21 03:13:23 +02:00
|
|
|
});
|
|
|
|
}
|
2019-11-22 07:36:18 +01:00
|
|
|
}
|