webclient/js/GUI/Screen.js

50 lines
1.1 KiB
JavaScript
Raw Normal View History

import * as Dom from UnitJS.Dom;
import I18n;
var current = document.querySelector("body > div.on");
var errorBox = document.getElementById('error');
errorBox.addEventListener('click', function() {
errorBox.className = "";
});
return {
error: error,
dialog: dialog,
select: select
};
function select(name) {
current.className = "";
current = document.getElementById(name);
current.className = "on";
}
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";
}