webclient/js/GUI/Screen.js

60 lines
1.3 KiB
JavaScript
Raw Normal View History

import * as Dom from UnitJS.Dom;
import I18n;
var sidebar = document.getElementById('sidebar');
var current = document.querySelector("body > div.on");
var errorBox = document.getElementById('error');
errorBox.addEventListener('click', function() {
errorBox.className = "";
});
return {
error: error,
dialog: dialog,
register: register,
select: select
};
function closeAndRun(dialog, action) {
return function() {
dialog.className = '';
Dom.clear(dialog);
action();
};
}
function dialog(config) {
var layer = document.getElementById('dialog');
var dialog = Dom.make('div', {});
dialog.appendChild(Dom.make('p', {textContent: config.text}));
var answers = Dom.make('p', {class: 'answers'});
for(var i in config.answers) {
answers.appendChild(Dom.make('button', {
textContent: I18n.get(config.answers[i].label),
onClick: closeAndRun(layer, config.answers[i].action)
}));
}
dialog.appendChild(answers);
layer.appendChild(dialog);
layer.className = "on";
}
function error(message) {
errorBox.textContent = message;
errorBox.className = "on";
}
function register(name) {
sidebar.appendChild(Dom.make('li', {
onClick: function() {select(name);},
textContent: name
}));
}
function select(name) {
sidebar.className = "";
current.className = "";
current = document.getElementById(name);
current.className = "on";
}