From 4776d4e6057a8b674892b47bf9419d16f53014be Mon Sep 17 00:00:00 2001
From: mc16 <mc16>
Date: Thu, 23 Mar 2017 09:51:41 -0300
Subject: [PATCH] =?UTF-8?q?Op=C3=A7=C3=A3o=20de=20adicionar=20mais=20de=20?=
 =?UTF-8?q?um=20cardapio?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 prototipo.html | 163 ++++++++++++++++++++++++++++++-------------------
 1 file changed, 101 insertions(+), 62 deletions(-)

diff --git a/prototipo.html b/prototipo.html
index 801b760..10e39f4 100644
--- a/prototipo.html
+++ b/prototipo.html
@@ -19,7 +19,7 @@
 
 <script language="JavaScript">
 
-tiposDePreparo = ["Salada1","Salada2","Prato principal","Acompanhamento","Bebida","Sobremesa"];
+tiposDePreparo = ["Salada1","Salada2","Prato Principal","Acompanhamento","Bebida","Sobremesa"];
 
 tabelas = ["PNAE","PAT","DRIs"];
 
@@ -87,38 +87,42 @@ class TipoCardapio{
   getConjunto(){return this._conjunto;}
   setConjunto(_conjunto){this._conjunto=_conjunto;}
 
+  getNome(){return this._nome;}
+  setNome(_nome){this._nome=_nome;}
+
   getPrecoRef(){return this._precoRef}
   setPrecoRef(_precoRef){this._precoRef = _precoRef;}
 
   getPrecoTotal(){return this._precoTotal}
   setPrecoTotal(_precoTotal){this._precoTotal = _precoTotal;}
 
-  constructor(conjunto, precoRef, precoTotal)
+  constructor(conjunto, precoRef, precoTotal, nome)
   {
     this.setConjunto(conjunto);
     this.setPrecoRef(precoRef);
     this.setPrecoTotal(precoTotal);
+    this.setNome(nome);
   }
 
 }
 
 class Empresa{
 
-	getDados(){ return this._dados}
-	setDados(_cnpj) {this._dados = _cnpj;}
+		getDados(){ return this._dados}
+		setDados(_cnpj) {this._dados = _cnpj;}
 
-	getMediaRef(){ return this._mediaRef}
-	setMediaRef(_mediaRef) {this._mediaRef = _mediaRef;}
+		getMediaRef(){ return this._mediaRef}
+		setMediaRef(_mediaRef) {this._mediaRef = _mediaRef;}
 
-	getNecessidadesNutr(){ return this._necessidadesNutr}
-	setNecessidadesNutr(_necessidadesNutr) {this._necessidadesNutr = _necessidadesNutr;}
+		getNecessidadesNutr(){ return this._necessidadesNutr}
+		setNecessidadesNutr(_necessidadesNutr) {this._necessidadesNutr = _necessidadesNutr;}
 
-  getTiposCardapios(){return this._tiposCardapios;}
-  setTiposCardapios(_tiposCardapios){this._tiposCardapios = _tiposCardapios;}
+		  getTiposCardapios(){return this._tiposCardapios;}
+		  setTiposCardapios(_tiposCardapios){this._tiposCardapios = _tiposCardapios;}
 
-  constructor(nome,cnpj,telefone,responsavel){
-    this.setDados(new DadosEmpresa(nome,cnpj,telefone,responsavel))
-  }
+		  constructor(nome,cnpj,telefone,responsavel){
+		    this.setDados(new DadosEmpresa(nome,cnpj,telefone,responsavel))
+		  }
 }
 
 ListaEmpresas = []
@@ -190,7 +194,8 @@ function atualizaEmpresas(){
     <input type=hidden id="cardapioEmpresa_id">
     <tr><td>Preço refeição: </td><td><input type=text id="cardapioEmpresa_precoInd"></td></tr>
     <tr><td>Preço total: </td><td><input type=text id="cardapioEmpresa_precoTotal"></td></tr>
-    <tr><td id="checkBoxesCardapios"></td></tr>
+    <tr><td colspan=2><center><button id="adicionaCardapioEmpresa">Adicionar Cardápio</button> </center></td> </tr>
+    <tr><td colspan=2 id="checkBoxesCardapios"></td></tr>
     <tr><td colspan=2><center><button id="editaCardapioEmpresa">Salvar</button> <button class="cancelaEditaEmpresa">Cancelar</button></center></td> </tr>
   </table>
 </div>
@@ -231,7 +236,6 @@ $(".cancelaEditaEmpresa").click( function(){
 function alertDadosEmpresa(e){
   dados = ListaEmpresas[e].getDados();
     //alert(dados.getNome()+"\n"+dados.getCNPJ()+"\n"+dados.getResponsavel()+"\n"+dados.getTelefone())
-
    $("#dadosEmpresa").dialog();
    $("#dadosEmpresa_id").val(e);
    $("#dadosEmpresa_nome").val(dados.getNome());
@@ -259,25 +263,44 @@ function alertPublicoEmpresa(e){
    }
 
    htmlCheckBoxes = "<ul>";
-   tabs = [];
+   igual =0;
    if(dados.getNecessidadesNutr())
    {
      tabs = dados.getNecessidadesNutr().getTabelas()
+
+     for(var element in tabelas)
+  	 {
+  	  	for (var e in tabs)
+  	  	{
+          if(tabs[e] == tabelas[element])
+          {
+            igual = 1;
+          }
+
+  	  	}
+        if(igual)
+        {
+          htmlCheckBoxes+="<li> <input checked id = "+tabelas[element]+ " type=checkbox>"+tabelas[element]+" </li><br>"
+        }
+        else
+        {
+            htmlCheckBoxes+="<li> <input id = "+tabelas[element]+ " type=checkbox>"+tabelas[element]+" </li><br>"
+        }
+        igual =0;
+  	 }
    }
-   for (var element in tabelas){
-     if(tabs[element])
-     {
-       htmlCheckBoxes+="<li> <input checked name=item type=checkbox>"+tabs[element]+" </li><br>"
-     }
-     else
-     {
-       htmlCheckBoxes+="<li> <input name=item type=checkbox>"+tabelas[element]+" </li><br>"
-     }
-   }
+   else
+   {
+  		for (var element in tabelas)
+  		{
+  			htmlCheckBoxes+="<li> <input id="+tabelas[element]+" type=checkbox>"+tabelas[element]+" </li><br>"
+  		}
+	 }
    $("#checkBoxes").html(htmlCheckBoxes+"</ul>");
 }
 
 function alertCardapioEmpresa(e){
+  numero =0;
   dados = ListaEmpresas[e];
   $("#cardapioEmpresa").dialog();
   $("#cardapioEmpresa_id").val(e);
@@ -286,25 +309,35 @@ function alertCardapioEmpresa(e){
     $("#cardapioEmpresa_precoInd").val(dados.getTiposCardapios().getPrecoRef());
     $("#cardapioEmpresa_precoTotal").val(dados.getTiposCardapios().getPrecoTotal());
   }
-  htmlCheckBoxes = "<ul>";
-  conjuntos = [];
+  htmlCheckBoxes = "<tr><td>";
   if(dados.getTiposCardapios())
+   {
+       tabs = dados.getTiposCardapios().getConjunto()
+       for(var e in tabs)
+    	 {
+         aux = tabs[e]
+         for(var element in aux)
+         {
+           	htmlCheckBoxes+="<input id = \""+aux[element]+ "\" checked type=checkbox>"+aux[element]+" </li>"
+         }
+          htmlCheckBoxes+= "<tr><td>"
+
+    	 }
+  	  }
+
+  $("#checkBoxesCardapios").html(htmlCheckBoxes);
+}
+$("#adicionaCardapioEmpresa").click(function(){
+  numero+=1;
+  htmlCheckBoxes+= "<tr><td>"
+  for(var element in tiposDePreparo)
   {
-    conjuntos = dados.getTiposCardapios().getConjunto()
-  }
-  for (var element in tiposDePreparo){
-    if(conjuntos[element])
-    {
-      htmlCheckBoxes+="<li> <input checked name=preparacao type=checkbox>"+conjuntos[element]+" </li><br>"
-    }
-    else
-    {
-      htmlCheckBoxes+="<li> <input name=preparacao type=checkbox>"+tiposDePreparo[element]+" </li><br>"
-    }
+    	htmlCheckBoxes+="<input id = \""+tiposDePreparo[element]+numero+ "\"type=checkbox>"+tiposDePreparo[element]+""
   }
+  htmlCheckBoxes+= "<tr><td>"
   $("#checkBoxesCardapios").html(htmlCheckBoxes+"</ul>");
-}
 
+});
 $("#editaDadosEmpresa").click( function(){
 	dados = ListaEmpresas[ $("#dadosEmpresa_id").val() ].getDados();
 	dados.setNome($("#dadosEmpresa_nome").val());
@@ -323,36 +356,42 @@ $("#editaPublicoEmpresa").click( function(){
 									$("#publicoEmpresa_janta").val()
 							));
   tabelasDados=[]
-  checkBox = document.getElementsByName( "item" );
-  for (var i=0;i<checkBox.length;i++){
-      if(checkBox[i].checked )
-      {
-        tabelasDados.push(tabelas[i]); //ou tabelas[element]
-      }
-      else {
-        tabelasDados.push(0);
-      }
+  for(var element in tabelas)
+  {
+  	checkBox = document.getElementById( tabelas[element] );
+  	if(checkBox.checked)
+  	{
+  		tabelasDados.push(tabelas[element]);
+  	}
   }
-
 	dados.setNecessidadesNutr( new NecessidadesNutr(tabelasDados,$("#publicoEmpresa_idades").val()) );
-  atualizaEmpresas();
+  	atualizaEmpresas();
 	$(".ui-button").click();
 });
 
 $("#editaCardapioEmpresa").click( function(){
-	dados = ListaEmpresas[ $("#cardapioEmpresa_id").val() ];
+  dados = ListaEmpresas[ $("#cardapioEmpresa_id").val() ];
   tabelaPreparacao=[]
-  checkBox = document.getElementsByName( "preparacao" );
-  for (var i=0;i<checkBox.length;i++){
-      if(checkBox[i].checked )
-      {
-        tabelaPreparacao.push(tiposDePreparo[i]); //ou tabelas[element]
-      }
-      else {
-        tabelaPreparacao.push(0);
-      }
+  for(var element in tiposDePreparo)
+  {
+  	checkBox = document.getElementById( tiposDePreparo[element]+numero);
+  	if(checkBox.checked)
+  	{
+  		tabelaPreparacao.push(tiposDePreparo[element]);
+  	}
   }
-	dados.setTiposCardapios(new TipoCardapio(tabelaPreparacao, $("#cardapioEmpresa_precoInd").val(), $("#cardapioEmpresa_precoTotal").val()) );
+  tabela = []
+  if(dados.getTiposCardapios())
+  {
+    tabela = dados.getTiposCardapios().getConjunto()
+    tabela.push(tabelaPreparacao);
+    dados.setTiposCardapios(new TipoCardapio(tabela, $("#cardapioEmpresa_precoInd").val(), $("#cardapioEmpresa_precoTotal").val()) );
+  }
+  else {
+      tabela.push(tabelaPreparacao)
+      dados.setTiposCardapios(new TipoCardapio(tabela, $("#cardapioEmpresa_precoInd").val(), $("#cardapioEmpresa_precoTotal").val()) );
+  }
+
   atualizaEmpresas();
 	$(".ui-button").click();
 });
-- 
GitLab