diff --git a/main.js b/main.js index 23f9c07319c115aff3258b56dcaab1dd8c0f1ba2..ca11cc473142f9242a0af210ab84747ed3ba01ee 100644 --- a/main.js +++ b/main.js @@ -147,6 +147,7 @@ function alertCardapioEmpresa(e){ } document.getElementById("tcardapio").innerHTML += colunas; + document.getElementById("tnovo").innerHTML = ""; } function alertConjuntoEmpresa(empresa, cardapio){ @@ -189,18 +190,44 @@ function alertConjuntoEmpresa(empresa, cardapio){ $("#adicionaCardapioEmpresa").click(function(){ - var colunas = "<tr><td> <input type=text id = nomeCardapio></td><td style=\"width:auto;\">"; + backupValues = []; + + numFaixas = $("#tnovo").children().length; + + for (var i = 0; i < numFaixas; i++){ + valor = []; + valor.push(document.getElementById("nomeCardapio"+i).value); + for(var element in tiposDePreparo) + { + valor.push(document.getElementById((tiposDePreparo[element].replace(" ",""))+i).checked); + } + + backupValues.push(valor); + } + + var colunas = "<tr><td> <input type=text id = nomeCardapio"+numFaixas+"></td><td style=\"width:auto;\">"; for(var element in tiposDePreparo) { - colunas+="<input id = \""+tiposDePreparo[element].replace(" ","")+"\"type=checkbox>"+tiposDePreparo[element]+"</br>" + colunas+="<input id = \""+tiposDePreparo[element].replace(" ","")+numFaixas+"\"type=checkbox>"+tiposDePreparo[element]+"</br>" } colunas += "</td></tr>" - document.getElementById("tcardapio").innerHTML += colunas; + for (var i = 0; i < numFaixas; i++){ + numero =0; + console.log(backupValues[i][numero]); + document.getElementById("nomeCardapio"+i).value = backupValues[i][numero]; + for(var element in tiposDePreparo) + { + numero++; + console.log(backupValues[i][numero]); + document.getElementById((tiposDePreparo[element].replace(" ",""))+i).checked = backupValues[i][numero]; + } + } + + document.getElementById("tnovo").innerHTML += colunas; }); $("#adicionaIdadesEmpresa").click(function(){ - numFaixas = $("#tidades").children().length; backupValues = []; numFaixas = $("#tidades").children().length; @@ -289,14 +316,19 @@ $("#editaPublicoEmpresa").click( function(){ $("#editaCardapioEmpresa").click( function(){ dados = ListaEmpresas[ $("#cardapioEmpresa_id").val() ]; tabelaPreparacao=[] + numFaixas = $("#tnovo").children().length; + for(var i=0; i< numFaixas; i++) + { for(var element in tiposDePreparo) { - checkBox = document.getElementById( tiposDePreparo[element].replace(" ","")); + console.log(tiposDePreparo[element].replace(" ","")+ i); + checkBox = document.getElementById( tiposDePreparo[element].replace(" ","")+ i); if(checkBox.checked) { - tabelaPreparacao.push(tiposDePreparo[element]); + tabelaPreparacao.push(tiposDePreparo[element]+i); } } + } tabelasConjunto =[] if(dados.getTiposCardapios()) { diff --git a/prototipo.html b/prototipo.html index 1c64e8b3a8b43b4c885917265203cad0d300c13b..45982f0209966a8f727d595df86fa918402f7135 100644 --- a/prototipo.html +++ b/prototipo.html @@ -98,6 +98,9 @@ </thead> <tbody id ="tcardapio"> + </tbody> + <tbody id ="tnovo"> + </tbody> </table> <tr><td colspan=2><center><button id="editaCardapioEmpresa">Salvar</button> <button class="cancelaEditaEmpresa">Cancelar</button></center></td> </tr>