function __processArg(e,i){var t=null;return e&&(t=e[i]||null,delete e[i]),t}function Controller(){function e(e){if(Ti.API.info(e.itemIndex),1==e.itemIndex||2==e.itemIndex||3==e.itemIndex||4==e.itemIndex)if(Ti.App.Properties.getList(SELECTED_CLIENTS)){for(var i=Ti.App.Properties.getList(SELECTED_CLIENTS),t=0;t<i.length;t++);0==t?alert("É necessário a seleção de um cliente ou mais para seguir em diante!"):menuSelection(e.itemIndex)}else alert("É necessário a seleção de um cliente ou mais para seguir em diante!");else menuSelection(e.itemIndex)}function i(){for(var e=consultaEmail(w),i=[];e.isValidRow();){var t=e.fieldByName("em_id"),o=e.fieldByName("em_email");i.push({em_id:t,label_email:{text:o}}),e.next()}a.listaemails.sections[0].setItems(i)}function t(){for(var e=dbLoad(),t=a.email_valor.value,o="INSERT INTO tb_email (em_representante, ep_id, em_email) VALUES("+w+", "+T+", '"+t+"');",l="SELECT * FROM tb_email;",r=e.execute(l),_=0;r.isValidRow();)r.fieldByName("em_email")==t&&_++,r.next();0!=_?Ti.UI.createAlertDialog({message:"Email ja esta casdastrado!\n"+_+" registros foram encontrados com esse e-mail!",ok:"Okay",title:"Erro, Email!"}).show():(e.execute(o),i(),_=0)}function o(e){var t=dbLoad(),o=a.listaemails.sections[e.sectionIndex],l=o.getItemAt(e.itemIndex),r=l.em_id,_="DELETE FROM tb_email WHERE em_id = "+r;t.execute(_),i()}require("alloy/controllers/BaseController").apply(this,Array.prototype.slice.call(arguments)),this.__controllerPath="email",this.args=arguments[0]||{},arguments[0]&&(__processArg(arguments[0],"__parentSymbol"),__processArg(arguments[0],"$model"),__processArg(arguments[0],"__itemTemplate"));var a=this,l={},r={};a.__views.email=Ti.UI.createWindow({backgroundColor:"white",id:"email"}),a.__views.email&&a.addTopLevelView(a.__views.email);var d={},s=[],n={type:"Ti.UI.View",childTemplates:function(){var e=[],i={type:"Ti.UI.Label",bindId:"btnmenu",properties:{touchEnabled:"false",width:"98%",color:"white",textAlign:Ti.UI.TEXT_ALIGNMENT_CENTER,bindId:"btnmenu"}};return e.push(i),e}(),properties:{backgroundColor:"#3f3a35",borderColor:"#9ccccb",borderWidth:"4",color:"#ffffff",width:"90%",height:"80%"},events:{click:e}};s.push(n);var c={properties:{height:"112dp",name:"menuTemplate"},childTemplates:s};d.menuTemplate=c;var f=[];a.__views.__alloyId528={btnmenu:{text:"CNPJ/\n RAZÃO SOCIAL/\n ENDEREÇO LOJA"},properties:{id:"__alloyId528"}},f.push(a.__views.__alloyId528),a.__views.__alloyId529={btnmenu:{text:"ANÁLISE DE \n CRÉDITO"},properties:{id:"__alloyId529"}},f.push(a.__views.__alloyId529),a.__views.__alloyId530={btnmenu:{text:"IR AO\n CATÁLOGO"},properties:{id:"__alloyId530"}},f.push(a.__views.__alloyId530),a.__views.__alloyId531={btnmenu:{text:"PEDIDOS"},properties:{id:"__alloyId531"}},f.push(a.__views.__alloyId531),a.__views.__alloyId532={btnmenu:{text:"TRANSPORTADORA"},properties:{id:"__alloyId532"}},f.push(a.__views.__alloyId532),a.__views.__alloyId533={btnmenu:{text:"NOVO CLIENTE"},properties:{id:"__alloyId533"}},f.push(a.__views.__alloyId533),a.__views.__alloyId534={btnmenu:{text:"FUNÇÕES"},properties:{id:"__alloyId534"}},f.push(a.__views.__alloyId534),a.__views.__alloyId535={btnmenu:{text:"VOLTAR PARA TELA INICIAL"},properties:{id:"__alloyId535"}},f.push(a.__views.__alloyId535),a.__views.__alloyId536={btnmenu:{text:"SAIR"},properties:{id:"__alloyId536"}},f.push(a.__views.__alloyId536),a.__views.__alloyId525=Ti.UI.createListSection({id:"__alloyId525"}),a.__views.__alloyId525.items=f;var p=[];p.push(a.__views.__alloyId525),a.__views.__alloyId515=Ti.UI.createListView({backgroundColor:"#ebf7f6",height:"100%",left:"0",width:"15%",sections:p,templates:d,defaultItemTemplate:"menuTemplate",id:"__alloyId515"}),a.__views.email.add(a.__views.__alloyId515),a.__views.__alloyId538=Ti.UI.createView({height:"100%",right:"0",width:"85%",id:"__alloyId538"}),a.__views.email.add(a.__views.__alloyId538),a.__views.__alloyId539=Ti.UI.createView({height:"90",top:"0",width:"98%",id:"__alloyId539"}),a.__views.__alloyId538.add(a.__views.__alloyId539),a.__views.__alloyId540=Ti.UI.createView({height:"90%",left:"0",width:"15%",id:"__alloyId540"}),a.__views.__alloyId539.add(a.__views.__alloyId540),a.__views.logoEmpresa=Ti.UI.createImageView({image:"/images/logo_rodape.jpg",id:"logoEmpresa"}),a.__views.__alloyId540.add(a.__views.logoEmpresa),a.__views.__alloyId541=Ti.UI.createButton({backgroundColor:"#FFFFFF",color:"#4e8789",height:"90",left:"15%",width:"70%",title:"EMAIL",id:"__alloyId541"}),a.__views.__alloyId539.add(a.__views.__alloyId541),a.__views.__alloyId542=Ti.UI.createView({height:"90",left:"85%",width:"15%",id:"__alloyId542"}),a.__views.__alloyId539.add(a.__views.__alloyId542),a.__views.__alloyId543=Ti.UI.createImageView({image:"/images/logo_rodape.jpg",id:"__alloyId543"}),a.__views.__alloyId542.add(a.__views.__alloyId543),a.__views.__alloyId544=Ti.UI.createView({borderColor:"#4e8789",borderWidth:"4",top:"90",width:"98%",id:"__alloyId544"}),a.__views.__alloyId538.add(a.__views.__alloyId544),a.__views.__alloyId545=Ti.UI.createView({borderColor:"#4e8789",borderWidth:"4",height:"70",top:"0",width:"100%",id:"__alloyId545"}),a.__views.__alloyId544.add(a.__views.__alloyId545),a.__views.__alloyId546=Ti.UI.createView({top:0,height:"70",left:"1%",width:"92%",id:"__alloyId546"}),a.__views.__alloyId545.add(a.__views.__alloyId546),a.__views.email_valor=Ti.UI.createTextField({borderColor:"#6EA9A0",borderRadius:"5",borderWidth:"4",color:"#000000",height:"50",left:"0",top:"10",textAlign:Ti.UI.TEXT_ALIGNMENT_CENTER,width:"80%",id:"email_valor",hintText:"Cadastrar novo email"}),a.__views.__alloyId546.add(a.__views.email_valor),a.__views.__alloyId547=Ti.UI.createView({height:"60",left:"92%",top:"0",width:"7%",id:"__alloyId547"}),a.__views.__alloyId545.add(a.__views.__alloyId547),a.__views.__alloyId548=Ti.UI.createButton({backgroundGradient:{type:"linear",colors:["#2c8f8e","#206764"]},borderRadius:"5",height:"80%",top:"10",width:"90%",color:"white",title:"Ir",id:"__alloyId548"}),a.__views.__alloyId547.add(a.__views.__alloyId548),t?a.__views.__alloyId548.addEventListener("click",t):r["$.__views.__alloyId548!click!novoEmail"]=!0;var h={},I=[],g={type:"Ti.UI.View",childTemplates:function(){var e=[],i={type:"Ti.UI.Label",bindId:"label_email",properties:{textAlign:Ti.UI.TEXT_ALIGNMENT_LEFT,color:"#000000",height:"100%",width:"90%",left:5,bindId:"label_email"}};e.push(i);var t={type:"Ti.UI.Label",bindId:"label_acoes",properties:{backgroundGradient:{type:"linear",colors:["#2c8f8e","#206764"]},borderRadius:"5",color:"#ffffff",top:"1%",bottom:"1%",height:"98%",width:"9%",textAlign:Ti.UI.TEXT_ALIGNMENT_CENTER,text:"Excluir",bindId:"label_acoes"},events:{click:o}};return e.push(t),e}(),properties:{width:"100%",layout:"horizontal"}};I.push(g);var y={properties:{height:"50",backgroundColor:"#cce9e5",name:"email_lista"},childTemplates:I};h.email_lista=y,a.__views.__alloyId560=Ti.UI.createListSection({id:"__alloyId560"});var u=[];u.push(a.__views.__alloyId560),a.__views.listaemails=Ti.UI.createListView({top:"80",height:"80%",width:"98%",sections:u,templates:h,id:"listaemails",defaultItemTemplate:"email_lista"}),a.__views.__alloyId544.add(a.__views.listaemails),l.destroy=function(){},_.extend(a,a.__views),arguments[0]||{},Ti.include("/api/config.js"),Ti.include("/database/aparencia.js"),Ti.include("/database/email.js"),Ti.include("/api/menu.js"),a.logoEmpresa.image=getImagesFolder()+selectLogoFile();var w=Ti.App.Properties.getString(CURRENT_USER_ID),T=Ti.App.Properties.getString(CURRENT_EMPRESA);i(),r["$.__views.__alloyId548!click!novoEmail"]&&a.__views.__alloyId548.addEventListener("click",t),_.extend(a,l)}var Alloy=require("alloy"),Backbone=Alloy.Backbone,_=Alloy._;module.exports=Controller;