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 template.loadArray([
|
|
|
|
'playlist-item',
|
|
|
|
'playlist',
|
2020-08-06 23:44:37 +02:00
|
|
|
'playlist-footer',
|
|
|
|
'audio-information',
|
|
|
|
'inputs/color',
|
|
|
|
'inputs/input',
|
|
|
|
'inputs/slider',
|
|
|
|
'inputs/switch',
|
|
|
|
'inputs/select',
|
|
|
|
'inputs/option'
|
2020-08-01 21:51:54 +02:00
|
|
|
]);
|
|
|
|
this.initDropZone();
|
|
|
|
}
|
|
|
|
|
|
|
|
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!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-08-06 23:44:37 +02:00
|
|
|
// create config Inputs from JSON
|
|
|
|
class GUIHelper {
|
|
|
|
static fromJSON(json, conf) {
|
|
|
|
let data = [];
|
|
|
|
for (let item of json) {
|
|
|
|
switch (item.type) {
|
|
|
|
case 'slider':
|
|
|
|
data.push(GUIHelper.createSliders(item, conf));
|
|
|
|
break;
|
|
|
|
case 'color':
|
|
|
|
data.push(GUIHelper.createColorPicker(item, conf));
|
|
|
|
break;
|
|
|
|
case 'checkbox':
|
|
|
|
data.push(GUIHelper.createCheckbox(item, conf));
|
|
|
|
break;
|
|
|
|
case 'input':
|
|
|
|
data.push(GUIHelper.createInputField(item, conf));
|
|
|
|
break;
|
|
|
|
case 'select':
|
|
|
|
data.push(GUIHelper.createSelect(item, conf));
|
|
|
|
break;
|
|
|
|
case 'button':
|
|
|
|
data.push(GUIHelper.createButton(item, conf));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
console.error(`Unknown Type: ${item.type}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return data.join(" ");
|
|
|
|
}
|
|
|
|
|
|
|
|
static createSliders(data, conf) {
|
|
|
|
let content = "";
|
|
|
|
if (typeof data.name === "object") {
|
|
|
|
for (let i = 0; i < data.name.length; i++) {
|
|
|
|
let newData = {};
|
|
|
|
Object.assign(newData, data);
|
|
|
|
newData.showName = data.name[i];
|
|
|
|
newData.name = GUIHelper.richName(data, data.props[i]);
|
|
|
|
content += GUIHelper.createSlider(newData, conf);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
content = GUIHelper.createSlider(data, conf);
|
|
|
|
}
|
|
|
|
return content;
|
|
|
|
}
|
|
|
|
|
|
|
|
static createSlider(data, conf) {
|
|
|
|
let newData = {};
|
|
|
|
Object.assign(newData, data);
|
|
|
|
newData.value = conf.get(newData.name, newData.value);
|
|
|
|
return template.parseTemplate('inputs/slider', newData)
|
|
|
|
}
|
|
|
|
|
|
|
|
static createColorPicker(data, conf) {
|
|
|
|
let newData = {};
|
|
|
|
Object.assign(newData, data);
|
|
|
|
newData.value = conf.get(newData.name, newData.value);
|
|
|
|
return template.parseTemplate('inputs/color', newData)
|
|
|
|
}
|
|
|
|
|
|
|
|
static createCheckbox(data, conf) {
|
|
|
|
let newData = {};
|
|
|
|
Object.assign(newData, data);
|
|
|
|
newData.value = conf.get(newData.name, newData.value) ? 'checked' : '';
|
|
|
|
return template.parseTemplate('inputs/switch', newData)
|
|
|
|
}
|
|
|
|
|
|
|
|
static createInputField(data, conf) {
|
|
|
|
let newData = {};
|
|
|
|
Object.assign(newData, data);
|
|
|
|
newData.value = conf.get(newData.name, newData.value);
|
|
|
|
return template.parseTemplate('inputs/input', newData)
|
|
|
|
}
|
|
|
|
|
|
|
|
static createSelect(data, conf) {
|
|
|
|
let newData = {};
|
|
|
|
Object.assign(newData, data);
|
|
|
|
newData.value = conf.get(newData.name, newData.value);
|
|
|
|
let options = '';
|
|
|
|
for (let i = 0; i < newData.options.length; i++) {
|
|
|
|
options += template.parseTemplate('inputs/option', {
|
|
|
|
value: newData.options[i]
|
|
|
|
})
|
|
|
|
}
|
|
|
|
newData.options = options;
|
|
|
|
newData.event = 'visualConf';
|
|
|
|
newData.conf = conf.type;
|
|
|
|
return template.parseTemplate('inputs/select', newData)
|
|
|
|
}
|
|
|
|
|
|
|
|
static richName(data, name) {
|
|
|
|
if (data.group !== "") {
|
|
|
|
return data.group + "-" + name
|
|
|
|
}
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
static createButton(item, conf) {
|
|
|
|
return `<div class='button spaced' data-action="${item.action}">${item.name}</div>`
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-01 21:51:54 +02:00
|
|
|
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) {
|
2020-08-06 23:44:37 +02:00
|
|
|
$('#modal').removeClass('lightMode')
|
2020-08-01 21:51:54 +02:00
|
|
|
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) {
|
2020-08-06 23:44:37 +02:00
|
|
|
let con = $('modal-footer .inner', this.modal);
|
|
|
|
con.innerHTML = footer || "by VersusTuneZ";
|
2020-08-01 21:51:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|