Commit a7db7f62 by Luciano Barletta

generation complete

1 parent f873b0cc
......@@ -13,13 +13,12 @@ var getAncestorByAttribute = (elem,attr,val) => {
}
var getDescendantByAttribute = (elem,attr,val) => {
if (elem.getAttribute(attr) == val) return elem;
Array.from(elem.children).reduce( (a,b) => {
if (elem == null || elem.getAttribute(attr) == val) return elem;
return Array.from(elem.children).reduce( (a,b) => {
let x = getDescendantByAttribute(a,attr,val);
let y = getDescendantByAttribute(b,attr,val);
return x == null ? x : y;
});
return null;
return x == null ? y : x;
}, null);
}
/**
......@@ -61,28 +60,34 @@ function addTab(t,n){
* Lectura de información y formateado
*/
function processField(field){
let data = field.children[0];
return {
'Title' : field.children[0],
'Input' : field.children[1].selectedOptions[0].value,
'Required' : field.children[2].checked,
'Title' : data.children[1].value,
'Input' : data.children[2].selectedOptions[0].value,
'Required' : data.children[3].checked,
};
}
function processTab(tab){
let dict = {};
for(let i = 0; i < tab.children.length; i++){
if (tab.children[i].getAttribute("name") == "Field"){
dict[i] = processField(tab.children[i]);
let dict = [];
let container = getDescendantByAttribute(tab,"name","Field").parentElement;
for(let i = 0; i < container.children.length; i++){
if (container.children[i].getAttribute("name") == "Field") {
dict.push(processField(container.children[i]));
}
}
return dict;
}
function generate(tabs){
let dict = {};
for(let i = 0; i < tabs.children.length; i++){
if (tabs.children[i].getAttribute("name") == "Tab"){
dict[i] = processTab(tabs.children[i]);
let dict = [];
for (let i = 0; i < tabs.children.length; i++) {
let c = tabs.children[i];
if (c.getAttribute("name") == "Tab") {
dict.push({
"Title" : getDescendantByAttribute(c,"class","TabTitle").value,
"Fields" : processTab(c),
});
}
}
console.log(JSON.stringify(dict));
......@@ -104,6 +109,6 @@ function maxChild(container,number){
if (container.childElementCount == 0) return 0;
let max = Array.from(container.children).reduce(
(a,b) => fixinput(a) > fixinput(b) ? a : b
)
);
return fixinput(max);
}
\ No newline at end of file
......@@ -24,7 +24,7 @@
</button>
</div>
<h3 id="ContinuarText">Cuando se encuentre conforme con el formulario presione Continuar</h3>
<button id="ContinuarButton"> Continuar </button>
<button id="ContinuarButton" onclick="generate(document.getElementById('tabs'))"> Continuar </button>
</body>
<!-- templates -->
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!