construct.js 1.58 KB
/**
 * Armado de formulario 
 */
function removeField(b){
    let div = b.parentElement;
    let tab = div.parentElement;
    tab.removeChild(div);
}

function addField(b){
    let newfield = document.createElement("div");
    newfield.setAttribute("name","Field");
    newfield.innerHTML = document.getElementById("fieldTemplate").innerHTML;
    b.parentElement.appendChild(newfield);
}

function removeTab(b){
    let div = b.parentElement;
    let tab = div.parentElement;
    tab.removeChild(div);
}

function addTab(t){
    document.getElementById("ContinuarText").style.display = 'block';
    document.getElementById("ContinuarButton").style.display = 'block';
    let newtab = document.createElement("div");
    newtab.setAttribute("name","Tab");
    newtab.innerHTML = document.getElementById("tabTemplate").innerHTML;
    t.appendChild(newtab);
}

/**
 * Lectura de información y formateado
 */

function processField(field){
    return {
        'Title' : field.children[0],
        'Input' : field.children[1].selectedOptions[0].value,
        'Required' : field.children[2].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]);
        }
    }
    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]);
        }
    }
    console.log(JSON.stringify(dict));
}