%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /home1/dimen328/libertysa.com.br/admin/modules/dados/
Upload File :
Create Path :
Current File : //home1/dimen328/libertysa.com.br/admin/modules/dados/contatosFormJS.js

$(document).ready(function(){
	
	(function (id){
	
	$.ajax({
		url:"modules/dados/CTRL.php",
		type: 'POST',
		data:{ oper: "8", id: id},
		complete: function (e, xhr, result){
			if(e.readyState == 4 && e.status == 200){
				
				try{
					var Obj = eval ("("+ e.responseText + ")");
				
				}
				catch(err){}
				
				if(Obj != null){
					$(".txttipo").show();

					for(i = 0;i <Obj.length;i++ ){
						/*var tipo = "";
						switch(Obj[i].id_tipo_dados_empresa){
							case "1":tipo = "Telefone Residencial"; break;
							case "2":tipo = "Telefone Comercial"; break;
							case "3":tipo = "Celular"; break;
							case "4":tipo = "Email"; break;
							case "5":tipo = "Responsável Técnico"; break;
							case "6":tipo = "CROSP"; break;
							case "7":tipo = "CROCL"; break;
						}*/
						
						
						$(".descricaoadd").append(
							'<div class="remove">'+
								'<div class="form-group"'+
									'<label class="control-label esse">'+Obj[i].nome_tipo_dado+': </label>'+
									'<div class="input-group">'+
										'<input type="text" class="form-control input-sm txtdescricaoLi" id="txtdescricaoLi'+Obj[i].id+'" name="txtdescricaoLi" tipo="'+Obj[i].id_tipo_dados_empresa+'" value="'+Obj[i].descricao+'" />'+
										'<span class="input-group-btn">'+
											'<button class="btn btn-danger btn-sm" type="button" id="btn-remove" idDele="'+Obj[i].id+'" name="btn-remove"><i class="fa fa-remove"></i></button>'+ 
										'</span>'+
									'</div>'+
								'</div>'+
							'</div>'
						);						
					}

					$(".btn-danger").off();
					$(".btn-danger").on("click",function(){
					$(this).parents(".remove").remove();
						id=$(this).attr("iddele");
						deletar(id);
					});	
					
						$(".txtdescricaoLi").blur(function(){
							var valida = true;
							if($(this).val()){
								var tipo = $(this).attr("tipo");
								$(this).unmask();
								switch(tipo){
									case "1":
										$(this).mask("(99) 9999-9999");
									break;
									case "2":
										$(this).mask("(99) 9999-9999");
									break;
									case "3":
										$(this).mask("(99) 9999-99999");	
									break;
									case "4":
										$(this).change(function(){
											
											var regex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;

											if(!regex.test($(this).val())){
												$(".muda-label").show();
												$(".muda-label").html(" E-mail invalido");
												valida = false;
											}else{
												$(".muda-label").html("");
												$("#btn-add-descricao").removeAttr("disabled","disabled");
											}
										});
									break;
								}
							}else{
								valida = false;
							}	
							
							if(valida){
								id = $(this).attr("id");
								idLinha = id.replace("txtdescricaoLi","");
								descricao = $(this).val();							
								
								atualizar(idLinha,descricao);
								
							}else{
								console.log("erro");
							}
						
						});
				}	
			}
		
		}
	});
	

})($("#idDados").val());	
	
	comboMaker("#tipo","dados",6);
	
	function inserir(empresa,tipo,descricao,status){
		$.ajax({
			url: "modules/dados/CTRL.php",
			type: 'POST',
			data: { oper: "7",empresa: empresa, tipo: tipo, descricao:descricao, status: status },
			complete: function (e, xhr, result) {
				if (e.readyState == 4 && e.status == 200) {

					try { 
						var Obj = eval("(" + e.responseText + ")"); //Combo OS
					}
					catch (err) {
					}
					
					if(Obj != null){
									
						$("#collapseGalerias").append
						(
							'<div class="panel-footer">' +
							'</div>'
						);
						
						if(Obj.msg == '1'){
							
							$(".descricaoadd").append(
								'<div class="remove">'+
									'<label class="control-label esse">'+$("#tipo option:selected").text()+'</label>'+
									'<div class="input-group">'+
											'<input type="text" class="form-control input-sm txtdescricaoLi" id="txtdescricaoLi'+Obj.lastID+'" name="txtdescricaoLi" tipo="'+$("#tipo").val()+'" value ="'+$("#txtdescricao").val()+'"/>'+
											'<span class="input-group-btn">'+
												'<button class="btn btn-danger btn-sm" type="button" id="btn-remove" idDele="'+Obj.lastID+'" name="btn-remove"><i class="fa fa-remove"></i></button>'+ 
											'</span>'+
									'</div>'+
								'</div>'
							);
							 
							$("#txtdescricao").val("");
							$(".panel-footer").html("");
							
							$("#collapseGalerias").parent(".panel").addClass("panel-success");
							$("#collapseGalerias").parent(".panel").removeClass("panel-info");
							$(".panel-footer").html
							(
								'<div class="alert alert-success alert-dismissable">' +
									'<button type="button" class="close closeFooter" data-dismiss="alert" aria-hidden="true">x</button>' +
									'Dados alterados com sucesso.' +
								'</div>'
							);
							
							setTimeout(function(){
								$(".closeEdit").click();
							}, 1000);
							
							$(".btn-danger").off();
							$(".btn-danger").on("click",function(){
							$(this).parents(".remove").remove();
								id=$(this).attr("iddele");
								deletar(id);
							});	
							
						$(".txtdescricaoLi").blur(function(){
							var valida = true;
							if($(this).val()){
								var tipo = $(this).attr("tipo");
								$(this).unmask();
								switch(tipo){
									case "1":
										$(this).mask("(99) 9999-9999");
									break;
									case "2":
										$(this).mask("(99) 9999-9999");
									break;
									case "3":
										$(this).mask("(99) 9999-99999");	
									break;
									case "4":
										$(this).change(function(){
											
											var regex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;

											if(!regex.test($(this).val())){
												$(".muda-label").show();
												$(".muda-label").html(" E-mail invalido");
												valida = false;
											}else{
												$(".muda-label").html("");
												$("#btn-add-descricao").removeAttr("disabled","disabled");
											}
										});
									break;
								}
							}else{
								valida = false;
							}	
							
							if(valida){
								id = $(this).attr("id");
								idLinha = id.replace("txtdescricaoLi","");
								descricao = $(this).val();							
								
								atualizar(idLinha,descricao);
								
							}else{
								console.log("erro");
							}
						
						});
							
						} else {
							$("#collapseGalerias").parent(".panel").addClass("panel-danger");
							$("#collapseGalerias").parent(".panel").removeClass("panel-info");
							$(".panel-footer").html
							(
								'<div class="alert alert-danger alert-dismissable">' +
									'<button type="button" class="close closeFooter" data-dismiss="alert" aria-hidden="true">x</button>' +
									'Os Dados não foram alterados.' +
								'</div>'
							);
						}
						
						$(".closeFooter").click(function(){
							$(".panel-footer").hide(600);
							$(".panel-footer").remove();
							$("#collapseGalerias").parent(".panel").addClass("panel-info");
							($("#collapseGalerias").parent(".panel").hasClass("panel-danger")) ? $("#collapseGalerias").parent(".panel").removeClass("panel-danger") : $("#collapseGalerias").parent(".panel").removeClass("panel-success");
							$(".form-control-feedback").remove();
							$("#btninserir").removeAttr('disabled');
						});
						
						setTimeout(function(){
							$(".closeFooter").click();
							$("#btnSearch").click();	
						}, 1000);
						
					}
					
				}
			} 
		});
	} 
	
	function deletar(id){
		//definir url + oper 
		$.ajax({
				url: "modules/dados/CTRL.php",
				type: 'POST',
				data: { oper: "9",id:id },
				complete: function (e, xhr, result) {
					if (e.readyState == 4 && e.status == 200) {
		 
						try { 
							var Obj = eval("(" + e.responseText + ")"); //Combo OS
						}
						catch (err) {
						}
						
						if(Obj != null){
						
						}
					}
				}
			});
		
	}
	
	function atualizar(id,descricao){
		//definir url + oper 
		$.ajax({
			url: "modules/dados/CTRL.php",
			type: 'POST',
			data: { oper: "10",id:id, descricao:descricao },
			complete: function (e, xhr, result) {
				if (e.readyState == 4 && e.status == 200) {
	 
					try { 
						var Obj = eval("(" + e.responseText + ")"); //Combo OS
					}
					catch (err) {
					}
					
					if(Obj != null){
						window.alert('Editado com sucesso');
					}
					else{
						window.alert('Erro ao editar o dado');
					}
				}
			}
		});
	}

	$("#tipo").change(function(){
		
		$("#txtdescricao").unmask();
		$("#txtdescricao").unbind();
		$(".muda-label").html("");
		$("#btn-add-descricao").removeAttr("disabled","disabled");
		var tipo = $("#tipo").val();
		switch(tipo){
			case "1":
				$("#txtdescricao").mask("(99) 9999-9999");
			break;
			case "2":
				$("#txtdescricao").mask("(99) 9999-9999");
			break;
			case "3":
				$("#txtdescricao").mask("(99) 9999-99999");	
			break;
			case "4":
				$("#txtdescricao").change(function(){
					validarEmail($(this).val(), function(response){
						if(response == false){
							// campoError("valida");
							$(".muda-label").show();
							$(".muda-label").html(" E-mail invalido");
							$("#btn-add-descricao").attr("disabled","disabled");
							validar = false;
						}else{
							// campoSuccess("valida");
							$(".muda-label").html("");
							$("#btn-add-descricao").removeAttr("disabled","disabled");
						}	
					});
				});
			break;
		}
	});
		//valida botão add descricao
	$("#btn-add-descricao").off();
	$("#btn-add-descricao").on("click",function(){

		if( $("#txtdescricao").val() == ""){
			$("#btn-add-descricao").attr("disabled","disabled");
			
				$("#txtdescricao").addClass("panel-danger");
				$("#btn-add-descricao").removeClass("btn-success");
				$("#btn-add-descricao").addClass("btn-danger");
				$("#txtdescricao").attr("placeholder","Campo em Branco");
			flag = 0;
		}else if($("#tipo").val() == ""){
			$("#tipo").addClass("panel-danger");
			flag = 0;
		}else{
			$("#btn-add-descricao").removeAttr("disabled","disabled"); 
			$("#tipo").removeClass("panel-danger");
			flag = 1;
		}
		
		if (flag == 1){
			$(".txttipo").show();
			inserir($("#idDados").val(),$("#tipo").val(),$("#txtdescricao").val(),1);
		}else{
			setTimeout(function(){
				$("#txtdescricao").removeClass("panel-danger");
				$("#btn-add-descricao").addClass("btn-success");
				$("#btn-add-descricao").removeClass("btn-danger");
				$("#txtdescricao").removeAttr("placeholder");
			},1000);
			$("#btn-add-descricao").removeAttr("disabled","disabled"); 
		}
	});
	
	$("#btninserir").click(function(){
		
		$(".closePerm").click();
		
	});
	
});	
	

Zerion Mini Shell 1.0