2020-04-07 21:44:46 +02:00
|
|
|
class GUI {
|
2020-08-01 21:51:54 +02:00
|
|
|
async init() {
|
|
|
|
this.data = {};
|
|
|
|
this.modal = new Modal();
|
|
|
|
// load first vis window!
|
|
|
|
await this.loadForVis();
|
|
|
|
await template.loadArray([
|
|
|
|
'playlist-item',
|
|
|
|
'playlist',
|
|
|
|
'playlist-footer'
|
|
|
|
]);
|
|
|
|
this.initDropZone();
|
|
|
|
}
|
|
|
|
|
|
|
|
async loadForVis() {
|
|
|
|
let c = visual.c,
|
|
|
|
d = this.data[c];
|
|
|
|
if (d == null) {
|
|
|
|
this.data[c] = await fetch("out/gui/" + c + ".json").then((r) => r.json());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
initDropZone() {
|
|
|
|
let items = 'drag dragstart dragend dragover dragenter dragleave drop'.split(' ');
|
|
|
|
items.forEach(el => {
|
|
|
|
window.addEventListener(el, async e => {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
if (e.type === 'drop') {
|
|
|
|
if (e.dataTransfer.files.length > 0) {
|
2020-08-05 11:24:59 +02:00
|
|
|
e.dataTransfer.id = 'upload-dir';
|
2020-08-01 21:51:54 +02:00
|
|
|
player.playlist.changeFiles(e, e.dataTransfer);
|
|
|
|
} else {
|
|
|
|
alert("Sorry you need to upload files!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
class Modal {
|
|
|
|
constructor() {
|
|
|
|
let self = this;
|
|
|
|
self.currentModal = '';
|
|
|
|
self.modal = $('#modal');
|
|
|
|
self.parent = self.modal.parentNode;
|
|
|
|
self.modal.addDelegatedEventListener('click', 'header .close', this.closeModal.bind(this));
|
|
|
|
}
|
|
|
|
|
|
|
|
resetModal() {
|
|
|
|
this.renderModal('', '', '');
|
|
|
|
}
|
|
|
|
|
|
|
|
renderModal(title, content, footer) {
|
|
|
|
this.currentModal = title;
|
|
|
|
this.renderHeader(title);
|
|
|
|
this.renderContent(content);
|
|
|
|
this.renderFooter(footer);
|
|
|
|
}
|
|
|
|
|
|
|
|
renderHeader(header) {
|
|
|
|
let h = $('header .headline', this.modal);
|
|
|
|
h.innerHTML = header;
|
|
|
|
}
|
|
|
|
|
|
|
|
renderContent(content) {
|
|
|
|
let con = $('modal-content', this.modal);
|
|
|
|
con.innerHTML = content;
|
|
|
|
}
|
|
|
|
|
|
|
|
renderFooter(footer) {
|
|
|
|
let con = $('modal-footer', this.modal);
|
|
|
|
con.innerHTML = footer;
|
|
|
|
}
|
|
|
|
|
|
|
|
closeModal() {
|
|
|
|
this.parent.addClass("hide")
|
|
|
|
}
|
|
|
|
|
|
|
|
isCurrent(title) {
|
|
|
|
return title === this.currentModal;
|
|
|
|
}
|
2020-04-07 21:44:46 +02:00
|
|
|
|
2020-08-01 21:51:54 +02:00
|
|
|
showModal() {
|
|
|
|
this.parent.removeClass("hide")
|
2020-04-07 21:44:46 +02:00
|
|
|
}
|
|
|
|
}
|