2024-07-17 23:08:10 +02:00
|
|
|
import ContentRequest, { TASK_SYNC_NAV } from '../../libraries/ContentRequest.js';
|
2024-03-22 21:35:44 +01:00
|
|
|
import NavActions from '../actions/NavActions.js';
|
|
|
|
import * as DataEvent from '../events/DataEvent.js';
|
|
|
|
import Notifications from '../ui/Notifications.js';
|
|
|
|
import Sortable from '../vendor/sortable.core.esm.js';
|
2024-03-06 18:53:40 +01:00
|
|
|
const notify = new Notifications();
|
|
|
|
|
|
|
|
export default class NavIndex {
|
|
|
|
//--------------------------
|
|
|
|
// constructor
|
|
|
|
//--------------------------
|
|
|
|
constructor() {
|
|
|
|
this.processing = false;
|
2024-07-17 23:08:10 +02:00
|
|
|
this.cr = new ContentRequest(null);
|
2024-03-06 18:53:40 +01:00
|
|
|
this.start();
|
|
|
|
}
|
|
|
|
//--------------------------
|
|
|
|
// methods
|
|
|
|
//--------------------------
|
|
|
|
start() {
|
|
|
|
//grabs elements and makes them sortables
|
|
|
|
let self = this;
|
|
|
|
Sortable.create(document.getElementById('nav-items'), {
|
|
|
|
onUpdate: () => {
|
|
|
|
new NavActions().syncMenu().then(data => {
|
|
|
|
notify.alert('Updating Menu', null);
|
2024-07-17 23:08:10 +02:00
|
|
|
self.cr.sync(TASK_SYNC_NAV, data).then(r => {
|
2024-03-06 18:53:40 +01:00
|
|
|
if (r.type == DataEvent.MENU_UPDATED) {
|
|
|
|
notify.alert(r.message, true);
|
|
|
|
} else {
|
|
|
|
notify.alert(r.message, true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
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) {
|
|
|
|
if (this.processing) return;
|
|
|
|
let id = '';
|
|
|
|
let self = this;
|
|
|
|
switch (e.target.id) {
|
|
|
|
case 'remove-item':
|
|
|
|
id = e.target.getAttribute('data-id');
|
2024-03-22 21:35:44 +01:00
|
|
|
console.log('object', e);
|
2024-03-06 18:53:40 +01:00
|
|
|
new NavActions().removeItem(id);
|
|
|
|
new NavActions().syncMenu().then(data => {
|
|
|
|
data.remove = e.target.getAttribute('data-uuid');
|
|
|
|
notify.alert('Editing Menu', null);
|
|
|
|
self.processing = true;
|
2024-07-17 23:08:10 +02:00
|
|
|
self.cr.sync(TASK_SYNC_NAV, data).then(r => {
|
2024-03-06 18:53:40 +01:00
|
|
|
self.processing = false;
|
|
|
|
if (r.type == DataEvent.MENU_UPDATED) {
|
|
|
|
notify.alert(r.message, true);
|
|
|
|
} else {
|
2024-03-22 21:35:44 +01:00
|
|
|
notify.alert(r.message, false);
|
2024-03-06 18:53:40 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
case 'edit-item':
|
|
|
|
self.processing = false;
|
|
|
|
window.location =
|
2024-07-26 23:10:37 +02:00
|
|
|
'/dashboard/page/edit/' + e.target.getAttribute('data-uuid');
|
2024-03-06 18:53:40 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|