fipamo/public/assets/scripts/dash/app/controllers/NavIndex.js
ro 3c6322ec12
actived menu editing
the last ui page that needed to be added was managing the main
navigation menu for rendered pages, so that's been turned on. menu
items can be added by pinning pages to the menu when editing them and
can be removed by unpinning them or deleting them from the navigation
edit ui

it touched quite a few systems so all of those classes needed to be
edited as well tweaking the front end script to work with the new
modular script format
2024-03-22 14:35:44 -06:00

76 lines
2.1 KiB
JavaScript

import FipamoAdminAPI, { TASK_SYNC_NAV } from '../../libraries/FipamoAdminAPI.js';
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';
const notify = new Notifications();
export default class NavIndex {
//--------------------------
// constructor
//--------------------------
constructor() {
this.processing = false;
this.admin = new FipamoAdminAPI(null);
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);
self.admin.sync(TASK_SYNC_NAV, data).then(r => {
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');
console.log('object', e);
new NavActions().removeItem(id);
new NavActions().syncMenu().then(data => {
data.remove = e.target.getAttribute('data-uuid');
notify.alert('Editing Menu', null);
self.processing = true;
self.admin.sync(TASK_SYNC_NAV, data).then(r => {
self.processing = false;
if (r.type == DataEvent.MENU_UPDATED) {
notify.alert(r.message, true);
} else {
notify.alert(r.message, false);
}
});
});
break;
case 'edit-item':
self.processing = false;
window.location =
'/dashboard/page/edit/' + e.target.getAttribute('data-id');
break;
}
}
}