fipamo/src/com/controllers/NavIndex.js

55 lines
1.4 KiB
JavaScript
Raw Normal View History

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();
export default class NavIndex {
//--------------------------
// constructor
//--------------------------
constructor() {
this.start();
//this.dataUtils = new DataUtils();
}
//--------------------------
// methods
//--------------------------
start() {
Sortable.create(document.getElementById('nav-pages'), {
onUpdate: () => {
new NavActions()
.save()
2019-11-29 22:43:55 +01:00
.then(response => {
let r = JSON.parse(response.request['response']);
if (r.type == DataEvent.MENU_UPDATED) {
notify.alert(r.message, true);
} else {
notify.alert(r.message, true);
}
})
.catch(() => {
//console.log(err);
});
}
});
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');
break;
}
}
}