Commit ab365492 authored by Marco Kellershoff's avatar Marco Kellershoff
Browse files

Way to go..

parent 74c5f159
......@@ -27,7 +27,7 @@
}
return el;
};
var getData = function(url, opts, cb) {
var getData = function(url, cb, opts) {
opts = opts || {};
var passToCallback = function(json) {
cb(json);
......@@ -47,21 +47,54 @@
};
fetch(url).then(processData);
};
var createTemplateEl = function(data) {
var node_name = 'input';
switch(data.type) {
case 'input':
break;
case 'checkbox':
break;
default:
break;
}
};
var loadTemplateFromJson = function(filename) {
var app_container = query('#app');
app_container.innerHTML = '';
var dataCallback = function(json) {
var elementsCallback = function(elData) {
console.log(elData);
};
json.data.forEach(elementsCallback);
};
getData('data/' + filename, dataCallback);
};
var renderPortalSelection = function() {
var portals = [];
var portals = [createEl('option', '', [['value', '']])];
var portalsCallback = function(portal) {
var el = createEl('option', portal.name, [
['value', portal.data]
]);
portals.push(el);
};
var selectChangeCallback = function(evt) {
var selectedIndex = this.selectedIndex,
selectedItem = this.children[selectedIndex],
selectedValue = selectedItem.value;
if (selectedValue === '') {
return;
}
else {
loadTemplateFromJson(selectedValue);
}
};
var cb = function(json) {
json.portals.forEach(portalsCallback);
var select = createEl('select', portals);
select.addEventListener('change', selectChangeCallback);
query('#app').appendChild(select);
console.log(portals);
};
getData('portals.json', null, cb);
getData('portals.json', cb);
};
var init = function() {
renderPortalSelection();
......
{
"success": true,
"data": [
{
"type": "input",
"label": "Vorname",
"value": "",
"placeholder": ""
},
{
"type": "input",
"label": "Nachname",
"value": "",
"placeholder": ""
},
{
"type": "input",
"label": "E-Mail",
"value": "",
"placeholder": ""
},
{
"type": "input",
"label": "Jobtitel",
"value": "",
"placeholder": ""
},
{
"type": "input",
"label": "Telefon",
"value": "+49 (0) 22 1 / 28 325-",
"placeholder": ""
},
{
"type": "input",
"label": "Dienstliche Handynummer",
"value": "",
"placeholder": "+49 175 1337 187"
},
{
"type": "input",
"label": "Fax",
"value": "+49 (0) 22 1 / 28 325-555",
"placeholder": ""
},
{
"type": "checkbox",
"label": "News GIF",
"value": "1"
},
{
"type": "checkbox",
"label": "BoxStories.de Banner",
"value": "1"
}
]
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment