smtpset.js 8.1 KB
//SMTP设置
var reg = /^([a-zA-Z\.0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/;
var SMTP_LIST="";//SMTP信息集合
var SMTP_IsEdit=0;//是不是编辑
var SMTP_OldAccount="";//默认帐号
$(document).ready(function(){
	//查询SMTP信息
	findAllSmtp();
	//查询SMTP list信息
	fincSmtpList();

	//SMTP选择事件
	$("#smtp_list").live("change",function (){
		if($("#smtp_list").val()=="请选择SMTP服务器"){
			$("#smtp_host").val("");
		}else{
			$("#smtp_host").val($("#smtp_list").val());
		}
		
	});
	
	//是否启用SSL
	$("#smtp_isssl").live("click",function (){
		if($("#smtp_isssl").attr("checked")==true||$("#smtp_isssl").attr("checked")=="checked"){
			$("#smtp_portdiv").show();
		}else{
			$("#smtp_portdiv").hide();
		}
	});
	$("#smtp_isssl1").live("click",function (){
		$("#smtp_portdiv").hide();		
	});
	
	//SMTP服务器验证
	$("#smtp_host").live("blur",function (){
		hostYZ();					  
	});
	//SMTP帐号验证
	$("#smtp_account").live("blur",function (){
		accountYZ();			  
	});
	
	//SMTP密码验证
	$("#smtp_pass").live("blur",function (){
		passYZ();				  
	});
	
});


//查询所有SMTP信息
function findAllSmtp(){
	$.ajax({ 
		type:"POST",
		url: "smtp_findAllSmtp.action", 
		cache: false, 
		async: false,
		success: function(msg) { 
			SMTP_LIST=msg;
			var html="";
			if(msg==null||msg==""){
				$("#smtpset_list").html('<div class="re_mcon" style="color:#CCC; height:100px; font-size:36px" align="center">无数据</div>');				  			}else{
				$.each(msg,function(index,row){
					html+='<dl>';
					html+='<dd class="tdt5">'+(index+1)+'</dd>';
					html+='<dd class="tdt2">'+row.smtp_service_number+'</dd>';
					html+='<dd class="tdt2">'+row.smtp_service_account+'</dd>';
					html+='<dd class="tdt3">'+row.smtp_service_creatdate+'</dd>';
					html+='<dd class="tdt3"><a href=\'javascript:smtpedit('+row.smtp_service_id+')\'>编辑</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href=\'javascript:smtpdel('+row.smtp_service_id+')\'>删除</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href=\'javascript:smtpYZ('+row.smtp_service_id+')\'>验证</a></dd>';
					html+="</dl>";
				});
				
				
				$("#smtpset_list").html(html);
			}
			
		} 
	}); 
}

//查询SMTP list信息
function fincSmtpList(){
	$.ajax({ 
		type:"POST",
		url: "smtp_findSmtpList.action", 
		cache: false, 
		async: false,
		success: function(msg) {
			var html="";
			$.each(msg,function(index,row){
				html+='<option>'+row.smtpname+'</option>';
			});
			$("#smtp_list").append(html);
		}
	});
}

//SMTP服务器验证
function hostYZ(){
	//是否为空
	if($("#smtp_host").val()==""){
		$("#smtp_hostYZ").attr("style","color:#F00");
		$("#smtp_hostYZ").html("请选择或输入SMTP服务器");
		return false;
	}else{
		$("#smtp_hostYZ").attr("style","color:#096");
		$("#smtp_hostYZ").html("输入正确!");
		return true;
	}
	//是否存在
}

//SMTP邮箱帐号验证
function accountYZ(){	
	if($("#smtp_account").val()==""){//是否为空
		$("#smtp_accountYZ").attr("style","color:#F00");
		$("#smtp_accountYZ").html("请输入SMTP帐号");
		return false;
	}
	if(!reg.test($("#smtp_account").val())){//格式
		$("#smtp_accountYZ").attr("style","color:#F00");
		$("#smtp_accountYZ").html("SMTP帐号格式不正确!");
		return false;
	}
	if(!smtpaccountisexits()){//是否存在
		$("#smtp_accountYZ").attr("style","color:#F00");
		$("#smtp_accountYZ").html("SMTP帐号已存在!");
		return false;
	}
	
	$("#smtp_accountYZ").attr("style","color:#096");
	$("#smtp_accountYZ").html("输入正确!");
	return true;
	
}

//SMTP邮箱密码验证
function passYZ(){
	//是否为空
	if($("#smtp_pass").val()==""){
		$("#smtp_passYZ").attr("style","color:#F00");
		$("#smtp_passYZ").html("请输入SMTP密码");
		return false;
	}else{
		$("#smtp_passYZ").attr("style","color:#096");
		$("#smtp_passYZ").html("输入正确!");
		return true;
	}
}

//添加SMTP
function smtp_addcomit(){
	//验证格式正确性
	if(passYZ()&&accountYZ()&&hostYZ()){
		var option={
		   url: 'smtp_addSmtpInfo.action',
		   dataType:'json',
		   success: function(msg){
			 	if(msg==1){
					yxy_confirmTerm('smtpset_adddiv');
					findAllSmtp();
					alert("操作成功!");
				}else{
					alert("操作失败!");
				}
			}    				
		}
		$("#smtp_addForm").ajaxSubmit(option);
	}
}

//判断SMTP账号是否存在了
function smtpaccountisexits(){
	var isexits=true;
	if(SMTP_IsEdit==1&&SMTP_OldAccount==$("#smtp_account").val()){
		isexits=true;
	}else{
		$.ajax({ 
			type:"POST",
			url: "smtp_findBySmtp.action", 
			cache: false, 
			async: false,
			data:{
				account:$("#smtp_account").val(),
			},
			success: function(msg) {
				if(msg==1){
					isexits= true;
				}else{
					isexits= false;
				}
			}
		});
	}
	return isexits;
}

//SMTP服务器验证
function SmtpValidation(){
	
}
//SMTP添加
function smtpadd(){
	yxy_tipsWindown('添加SMTP','smtpset_adddiv',700)	;
	$("#smtp_savebutton").show();
	$("#smtp_editbutton").hide();
}

//SMTP编辑页面赋值
function smtpedit(id){
	SMTP_IsEdit=1;
	yxy_tipsWindown('编辑SMTP','smtpset_adddiv',700);
	$("#smtp_savebutton").hide();
	$("#smtp_editbutton").show();
	$.each(SMTP_LIST,function(index,row){
		if(id==row.smtp_service_id){
			$("#smtp_id").val(row.smtp_service_id);
			SMTP_OldAccount=row.smtp_service_account;
			$("#smtp_host").val(row.smtp_service_number);
			$("#smtp_account").val(row.smtp_service_account);
			$("#smtp_pass").val(row.smtp_service_password);
			if(row.smtp_is_ssl==1){
				$("#smtp_isssl").attr("checked","checked");
				$("#smtp_portdiv").show();
				$("#smtp_port").val(row.smtp_service_port);
			}else{
				$("#smtp_isssl1").attr("checked","checked");
				$("#smtp_portdiv").hide();
				$("#smtp_port").val("");
			}
			return;
		}
	});
}

//SMTP删除
function smtpdel(id){
	var a= confirm("确定删除该服务器信息?");
	if(a){
		$.ajax({ 
			type:"POST",
			url: "smtp_delSmtp.action", 
			cache: false, 
			async: false,
			data:{
				smtpid:id
			},
			success: function(msg) {
				if(msg==1){
					findAllSmtp();
					alert("删除成功!");
				}else{
					alert("删除失败!");
				}
			}
		});
	}else{
		return;
	}
	
}

//SMTP验证
function smtpYZ(id){
	$.each(SMTP_LIST,function(index,row){
		if(id==row.smtp_service_id){
			$("#smtp_id").val(row.smtp_service_id);
			SMTP_OldAccount=row.smtp_service_account;
			$("#smtp_host").val(row.smtp_service_number);
			$("#smtp_account").val(row.smtp_service_account);
			$("#smtp_pass").val(row.smtp_service_password);
			if(row.smtp_is_ssl==1){
				$("#smtp_isssl").attr("checked","checked");
				$("#smtp_portdiv").show();
				$("#smtp_port").val(row.smtp_service_port);
			}else{
				$("#smtp_isssl1").attr("checked","checked");
				$("#smtp_portdiv").hide();
				$("#smtp_port").val("");
			}
			return;
		}
	});
	var option={
		   url: 'smtp_connectionService.action',
		   dataType:'json',
		   success: function(msg){
			 	if(msg==1){
					alert("验证通过!");
				}else if(msg==2){
					alert("帐号或密码错误!");
				}else if(msg==3){
					alert("服务器登录失败!");
				}else if(msg==4){
					alert("服务器链接失败!");
				}else{
					alert("SMTP验证未通过!请确定SMTP的正确性!");
				}
			}    				
		}
	$("#smtp_addForm").ajaxSubmit(option);
}

//模糊查询SMTP
function smtp_findlike(){
	$.ajax({ 
			type:"POST",
			url: "smtp_findSmtpLike.action", 
			cache: false, 
			async: false,
			data:{
				account:$("#smtp_likevalue").val()
			},
			success: function(msg) {
			var html="";
			if(msg==null||msg==""){
				$("#smtpset_list").html('<div class="re_mcon" style="color:#CCC; height:100px; font-size:36px" align="center">无数据</div>');				  			}else{
				$.each(msg,function(index,row){
					html+='<dl>';
					html+='<dd class="tdt5">'+(index+1)+'</dd>';
					html+='<dd class="tdt2">'+row.smtp_service_number+'</dd>';
					html+='<dd class="tdt2">'+row.smtp_service_account+'</dd>';
					html+='<dd class="tdt3">'+row.smtp_service_creatdate+'</dd>';
					html+='<dd class="tdt3"><a href=\'javascript:smtpedit('+row.smtp_service_id+')\'>编辑</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href=\'javascript:smtpdel('+row.smtp_service_id+')\'>删除</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href=\'javascript:smtpYZ('+row.smtp_service_id+')\'>验证</a></dd>';
					html+="</dl>";
				});
				
				
				$("#smtpset_list").html(html);
			}
			
		
			}
		});
}