client/views: move form controls to HB helpers

This commit is contained in:
rr-
2016-04-10 10:23:27 +02:00
parent 7c1876dd5c
commit e268d679d3
10 changed files with 148 additions and 56 deletions

View File

@ -22,6 +22,29 @@ function _messageHandler(target, message, className) {
messagesHolder.appendChild(node);
}
function _serializeElement(name, attributes) {
return [name]
.concat(Object.keys(attributes).map(key => {
if (attributes[key] === true) {
return key;
} else if (attributes[key] === false ||
attributes[key] === undefined) {
return '';
}
return '{0}="{1}"'.format(key, attributes[key]);
}))
.join(' ');
}
function makeNonVoidElement(name, attributes, content) {
return '<{0}>{1}</{0}>'.format(
_serializeElement(name, attributes), content);
}
function makeVoidElement(name, attributes) {
return '<{0}/>'.format(_serializeElement(name, attributes));
}
function listenToMessages(target) {
events.unlisten(events.Success);
events.unlisten(events.Error);
@ -114,4 +137,6 @@ module.exports = {
listenToMessages: listenToMessages,
clearMessages: clearMessages,
decorateValidator: decorateValidator,
makeVoidElement: makeVoidElement,
makeNonVoidElement: makeNonVoidElement,
};