diff --git a/main.js b/main.js index 164f656315320bb9c579e45f21eadddafb8ddd62..23f9c07319c115aff3258b56dcaab1dd8c0f1ba2 100644 --- a/main.js +++ b/main.js @@ -71,7 +71,6 @@ function alertPublicoEmpresa(e){ if(dados.getNecessidadesNutr()) { tabs = dados.getNecessidadesNutr().getTabelas() - for(var element in tabelas) { for (var e in tabs) @@ -92,28 +91,31 @@ function alertPublicoEmpresa(e){ } igual =0; } + + colunas=""; + vetor=[] + vetor = dados.getNecessidadesNutr().getIdades() + console.log(vetor) + for(var object in vetor) + { + faixaIdade= vetor[object] + console.log(faixaIdade[0], faixaIdade[1]) + colunas += "<tr><td><input type = text id=idadeMinima"+object+"></input></td>" + colunas +="<td><input type=text id=idadeMaxima"+object+"></input></td></tr>" + } + document.getElementById("tidades").innerHTML += colunas; + } + else { for (var element in tabelas) { htmlCheckBoxes+="<li> <input id="+tabelas[element]+" type=checkbox>"+tabelas[element]+" </li><br>" } - } + } $("#checkBoxes").html(htmlCheckBoxes+"</ul>"); - if(dados.getNecessidadesNutr()){ - colunas=""; - vetor=[] - vetor = dados.getNecessidadesNutr().getIdades() - console.log(vetor) - for(var object in vetor) - { - console.log(object) - colunas += "<tr><td><input type = text></input></td></tr>" - } - document.getElementById("tidades").innerHTML += colunas; -} } function alertCardapioEmpresa(e){ @@ -198,9 +200,29 @@ $("#adicionaCardapioEmpresa").click(function(){ }); $("#adicionaIdadesEmpresa").click(function(){ - var colunas = "<tr><td> <input type=text id = idadeCardapio></td><td style=\"width:auto;\">"; - colunas += "</td></tr>" + numFaixas = $("#tidades").children().length; + backupValues = []; + + numFaixas = $("#tidades").children().length; + + for (var i = 0; i < numFaixas; i++){ + valor = []; + valor.push(document.getElementById("idadeMinima"+i).value); + valor.push(document.getElementById("idadeMaxima"+i).value); + backupValues.push(valor); + } + + + var colunas = "<tr><td> <input type=text id = idadeMinima"+numFaixas+"></td><td><input type= text id = idadeMaxima"+numFaixas+">"; + colunas += "</td></tr>"; + console.log(colunas) document.getElementById("tidades").innerHTML += colunas; + + for (var i = 0; i < numFaixas; i++){ + document.getElementById("idadeMinima"+i).value = backupValues[i][0]; + document.getElementById("idadeMaxima"+i).value = backupValues[i][1]; + } + }); $("#editaDadosEmpresa").click( function(){ @@ -250,19 +272,18 @@ $("#editaPublicoEmpresa").click( function(){ tabelasDados.push(tabelas[element]); } } - idades = [] - if(dados.getNecessidadesNutr()) - { - idades = dados.getNecessidadesNutr().getIdades() - } - idades.push($("#idadeCardapio").val()); - console.log($("#idadeCardapio").val()) - console.log(idades); - dados.setNecessidadesNutr( new NecessidadesNutr(tabelasDados,idades) ); - atualizaEmpresas(); - $(".ui-button").click(); + idades = [] + numFaixas = $("#tidades").children().length; + console.log(numFaixas); + for (var i = 0; i < numFaixas; i++){ + console.log(document.getElementById("idadeMinima"+i).value); + console.log(document.getElementById("idadeMaxima"+i).value); + } + //dados.setNecessidadesNutr( new NecessidadesNutr(tabelasDados,idades) ); + atualizaEmpresas(); + $(".ui-button").click(); }); $("#editaCardapioEmpresa").click( function(){ diff --git a/prototipo.html b/prototipo.html index aefbc93b62c43cc8602bc4b95f39f1c3cbda3c68..1c64e8b3a8b43b4c885917265203cad0d300c13b 100644 --- a/prototipo.html +++ b/prototipo.html @@ -59,8 +59,8 @@ <thead> <tr> - <td> Faixa de idade </td> - <td> Ações </td> + <td> Idade minima </td> + <td> Idade máxima </td> </tr> </thead> <tbody id ="tidades">