webclient/js/GUI/ConnectedForm.js

46 lines
843 B
JavaScript
Raw Normal View History

import Messaging;
var connectedForms = {};
Messaging.addEventListener('open', refreshForms);
Messaging.addEventListener('close', refreshForms);
return {
get: get
};
function ConnectedForm(root) {
var submits = root.querySelectorAll('[type=submit]');
var enabled = false
return {
enable: enable,
refresh: refresh,
root: root
}
function enable(setEnabled) {
enabled = setEnabled || undefined == setEnabled;
refresh();
}
function refresh() {
submits.forEach(function(button) {
button.disabled = !(Messaging.isOn() && enabled);
});
}
}
function get(formId) {
if(connectedForms[formId] == undefined) {
connectedForms[formId] = ConnectedForm(document.getElementById(formId));
}
return connectedForms[formId];
}
function refreshForms() {
for(var key in connectedForms) {
connectedForms[key].refresh();
}
}