From ce83d6cc1905c233679ee7bd4e509c13bbf1e2bb Mon Sep 17 00:00:00 2001 From: sba16 <sba16@inf.ufpr.br> Date: Mon, 27 Mar 2017 11:59:49 -0300 Subject: [PATCH] Adicionar mais de um cardapio ao mesmo tempo --- main.js | 44 ++++++++++++++++++++++++++++++++++++++------ prototipo.html | 3 +++ 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/main.js b/main.js index 23f9c07..ca11cc4 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 1c64e8b..45982f0 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> -- GitLab