2020-05-23 22:55:25 +02:00
|
|
|
import ApiUtils, { REQUEST_TYPE_POST, CONTENT_TYPE_JSON } from '../../../src/com/utils/APIUtils';
|
2019-11-22 07:36:18 +01:00
|
|
|
import NavActions from '../actions/NavActions';
|
2019-11-29 22:43:55 +01:00
|
|
|
import * as DataEvent from '../events/DataEvent';
|
|
|
|
import Notifications from '../ui/Notifications';
|
|
|
|
const notify = new Notifications();
|
2020-05-23 22:55:25 +02:00
|
|
|
const api = new ApiUtils();
|
2019-11-22 07:36:18 +01:00
|
|
|
export default class NavIndex {
|
|
|
|
//--------------------------
|
|
|
|
// constructor
|
|
|
|
//--------------------------
|
|
|
|
constructor() {
|
2020-05-23 22:55:25 +02:00
|
|
|
api.authStatus();
|
2019-11-22 07:36:18 +01:00
|
|
|
this.start();
|
|
|
|
}
|
|
|
|
//--------------------------
|
|
|
|
// methods
|
|
|
|
//--------------------------
|
|
|
|
start() {
|
|
|
|
Sortable.create(document.getElementById('nav-pages'), {
|
|
|
|
onUpdate: () => {
|
2020-05-23 22:55:25 +02:00
|
|
|
new NavActions().syncMenu().then(data => {
|
|
|
|
api.request(
|
|
|
|
'/api/v1/settings/nav-sync',
|
|
|
|
DataEvent.API_SETTINGS_WRITE,
|
|
|
|
REQUEST_TYPE_POST,
|
|
|
|
CONTENT_TYPE_JSON,
|
|
|
|
data
|
|
|
|
).then(response => {
|
2019-11-29 22:43:55 +01:00
|
|
|
let r = JSON.parse(response.request['response']);
|
|
|
|
if (r.type == DataEvent.MENU_UPDATED) {
|
|
|
|
notify.alert(r.message, true);
|
|
|
|
} else {
|
|
|
|
notify.alert(r.message, true);
|
|
|
|
}
|
2019-11-22 07:36:18 +01:00
|
|
|
});
|
2020-05-23 22:55:25 +02:00
|
|
|
});
|
2019-11-22 07:36:18 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
var nav = document.querySelectorAll('.nav-btn');
|
|
|
|
for (var i = 0, length = nav.length; i < length; i++) {
|
|
|
|
nav[i].addEventListener('click', e => this.handleNavButton(e), false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//--------------------------
|
|
|
|
// event handlers
|
|
|
|
//--------------------------
|
|
|
|
handleNavButton(e) {
|
|
|
|
let id = '';
|
|
|
|
switch (e.target.id) {
|
|
|
|
case 'remove-item':
|
|
|
|
id = e.target.getAttribute('data-id');
|
|
|
|
new NavActions().removeItem(id);
|
|
|
|
break;
|
|
|
|
case 'edit-item':
|
2019-11-29 22:43:55 +01:00
|
|
|
window.location = '/@/dashboard/pages/edit/' + e.target.getAttribute('data-id');
|
2019-11-22 07:36:18 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|