construct.js
2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/**
* Armado de formulario
*/
function removeField(b){
while(b.getAttribute("name") != "Field") b = b.parentElement;
if(b.nodeElement == "body") return;
b.parentElement.removeChild(b);
}
function addField(b){
let newfield = document.createElement("div");
newfield.setAttribute("name","Field");
newfield.innerHTML = document.getElementById("fieldTemplate").innerHTML;
let tab = b.parentElement;
// swap
tab.removeChild(b);
tab.appendChild(newfield);
tab.appendChild(b);
}
function removeTab(b){
while(b.getAttribute("name") != "Tab") b = b.parentElement;
if(b.nodeElement == "body") return;
b.parentElement.removeChild(b);
}
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));
}
function sortTabs(){
let tabs = document.getElementById("tabs");
Array.from(tabs.children).sort(
(a,b) => a.children[0].value < b.children[0].value ? -1 : a.children[0].value > b.children[0].value ? 1 : 0
).forEach(
c => tabs.appendChild(c)
)
}
function sortFields(tab){
Array.from(tab.children).sort(
(a,b) => a.children[0].value < b.children[0].value ? -1 : a.children[0].value > b.children[0].value ? 1 : 0
).forEach(
c => tabs.appendChild(c)
)
}