Commit a7db7f62 by Luciano Barletta

generation complete

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