/**
 * 添加字典类型
 */
$(document).ready(function() {
	$("#close").click(function(){
        parent.layer.closeAll();
         });
	$("#insertAddDicType").click(function(){
		var dicTypeName=$("#dicTypeName").val();
		dicTypeName=dicTypeName.replace(/(^\s*)|(\s*$)/g, '');
		dicTypeName=filterXSS(dicTypeName);
		var re = chinesez;//只能输入汉字
		if (!re.test(dicTypeName)) {
			layer.tips('通用字典名非法', '#dicTypeName', {
				  tips: [1, 'red'] //还可配置颜色
				});
			$("#dicTypeName").val("");
			$("#dicTypeName").prop("placeholder","通用字典名由中文组成");
		  } else {
			  var dicTypeDescription=$("#dicTypeDescription").val();
			  dicTypeDescription=dicTypeDescription.replace(/(^\s*)|(\s*$)/g, '');
			  dicTypeDescription=filterXSS(dicTypeDescription);
			  $.ajax({
				  url:'/pqs9900/type/saveType',
				  type:'POST',
				  dataType:"text",
				  data:{
					  dicTypeName:dicTypeName,
					  dicTypeDescription:dicTypeDescription
					},
				 success:function(data){
					//没有权限的请求
						if(data==300){
							location.href='/pqs9900/auth/unauthorized';
						//没有登陆的请求
						}else if(data==301){
							location.href='/pqs9900';
						}else{
							var info = $.parseJSON(data);
							if(info.code!=200){
								layer.msg(info.message, {icon: 5});
							}else{
								layer.msg(info.message, {
									  icon:6,
									  time: 1000 
									}, function(){
										parent.getTree();
										parent.layer.closeAll();
									}); 
							}
						}	
				 }  
			  });
		  }
	});
})