-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
175 lines (133 loc) · 5.69 KB
/
index.html
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<html>
<head>
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"/>
<title>Email Form Generator</title>
</head>
<body class="container-fluid">
<form method="POST" class="form container">
<div class="form-group col-sm-12">
<label>Nome da Empresa</label>
<input type="text" name="nome-empresa" class="form-control"/>
</div>
<div class="form-group col-sm-12">
<label>Endereço do Logo</label>
<input type="text" name="logo" class="form-control"/>
</div>
<div class="form-group col-sm-12">
<label>Cor</label>
<input type="text" name="color" class="form-control"/>
</div>
<div class="form-group col-sm-5">
<label>Nome da TAG</label>
<input type="text" class="form-control" name="tag-name" />
</div>
<div class="form-group col-sm-5">
<label>Nome da Legenda</label>
<input type="text" class="form-control" name="legenda-name" />
</div>
<div class="form-group col-sm-2">
<button class="btn btn-primary btn-block" type="button" id="adicionar">Adicionar</button>
</div>
<div class="form-group col-sm-12">
<table class="table" id="table-field">
<thead>
<th>Nome da TAG</th>
<th>Nome da Legenda</th>
<th>Ação</th>
</thead>
<tbody>
</tbody>
</table>
</div>
<div class="form-group col-sm-12">
<button type="button" class="btn btn-success" id="build" >Gerar Template</button>
</div>
<div class="form-group col-sm-12">
<label>Código do Template</label>
<textarea style="width: 100%; height: auto" id="template-code">
</textarea>
</div>
<div class="form-group col-sm-12">
<label>Preview</label>
<div id="area">
</div>
</div>
</form>
</body>
<script>
var btnAdd = document.querySelector("#adicionar");
var tagName = document.querySelector("input[name='tag-name']");
var fieldName = document.querySelector("input[name='legenda-name']");
var tableFields = document.querySelector("#table-field tbody");
var btBuild = document.querySelector("#build");
var arrFields = [];
var removeRow = function(){
var _span = this;
var _index = _span.attributes['data-index'].value;
console.log(arrFields, _index);
arrFields.splice(_index,1);
console.log(arrFields, _index);
_span.parentNode.parentNode.remove();
};
//Pega os dados e transforma em html
var buildHTML = function(){
var _image = document.querySelector("input[name='logo']").value;
var _nomeEmpresa= document.querySelector("input[name='nome-empresa']").value;
var _color = document.querySelector("input[name='color']").value;
var _arrayColors = [_color, "#fff"];
var _count = 0;
var _html = "";
_html += "<table style='width: 100%'>";
_html += "<tr style='background-color: "+ _arrayColors[1] +"'>";
_html += "<td colspan='2'>";
_html += "<img src='"+_image+"' alt='"+_nomeEmpresa+"' style='display:block; margin:15px auto; ' >";
_html += "</td>";
_html += "</tr>";
for (var i = 0; i < arrFields.length; i ++){
var field = arrFields[i];
console.log(field);
var _currentColor = _arrayColors[(_count%2)];
_html += "<tr style='background-color: "+_currentColor+"'>";
_html += "<td>";
_html += "<strong>"+field.fieldName + "</strong>";
_html += "</td>";
_html += "<td>";
_html += "["+field.tagName+"]";
_html += "</td>";
_html += "</tr>";
_count++;
}
_html += "</table>";
document.querySelector("#template-code").value = _html;
document.querySelector("#area").innerHTML = _html;
};
btBuild.addEventListener('click', buildHTML);
btnAdd.addEventListener('click',function(){
var index = arrFields.length;
var strHTML = "<tr>";
strHTML += "<td>";
strHTML += tagName.value;
strHTML += "</td>";
strHTML += "<td>";
strHTML += fieldName.value;
strHTML += "</td>";
strHTML += "<td>";
strHTML += "<span name='remove' data-index='"+index+"'>Remover</span>";
strHTML += "</td>";
strHTML += "</tr>";
arrFields.push({
fieldName : fieldName.value,
tagName : tagName.value
});
console.log(strHTML);
tableFields.innerHTML = tableFields.innerHTML + strHTML;
//Registra um event para esse elemento
var removeButton = document.querySelectorAll("#table-field tbody tr td span[name='remove']");
if(removeButton){
removeButton.forEach(function(s){
s.addEventListener('click',removeRow);
});
}
});
</script>
</html>