<?php include $this->admin_tpl('meta');?>
<title>添加配置 - YzmCMS内容管理系统</title>
</head>
<body>
<article class="page-container">
<div class="formdoby_normal"> 
	<form method="post" onsubmit="return dosub(this)">
		<ul>
			 <li><label><span class="c-red">*</span>配置名称：</label>
			 	<input type="text" class="input" placeholder="必须为英文拼音或数字,如：qq" name="name" value="">
			 </li>	
			 <li><label><span class="c-red">*</span>配置类型</label>
			 <span class="span_input" >
				<select name="fieldtype" class="select" style="width:244px" onchange="javascript:field_setting(this.value);">		
					<option value="textarea" selected>文本类型</option>					
					<option value="image">图片上传</option>
					<option value="attachment">附件上传</option>
					<option value="radio">radio选项卡</option>
					<option value="select">option下拉框</option>
				</select>
			 </span>
			 </li>	
			 <li><label><span class="c-red">*</span>配置值：</label>
				<span class="span_input" id="config_show"><textarea name="value" class="textarea w_420"  placeholder="例如：214243830"></textarea></span> 
			 </li>	
			 <li><label>简洁说明：</label>
			 	<textarea name="title" class="textarea w_420" placeholder="例如：这个是站点QQ"></textarea>
			 </li>
			 <li><label>状态</label>
			 <span class="span_input">
			 	<label class="label_radio"><input name="status" type="radio" value="1" checked> 启用</label>
			 	<label class="label_radio"><input name="status" type="radio" value="0"> 禁用</label>
			 </span>
			 </li>				 
		</ul>
		<div class="footer_btn">
			<input type="hidden" name="dosubmit" value="1">
			<input class="btn btn-primary radius" type="submit" value="提 交">
			<input class="btn btn-default radius" type="button" value="取 消" onclick="yzmcms_close()">	
		</div>
	</form>
</div>
</article>
<?php include $this->admin_tpl('footer');?>

<script type="text/javascript">

	function field_setting(fieldtype) {
	    $.ajax({
            type: 'POST',
            url: '<?php echo U('public_gethtml');?>', 
            data: 'fieldtype='+fieldtype,
		    dataType: "html", 
            success: function (msg) {		
				$('#config_show').html(msg);
            }
        })		
	}


	function dosub(obj){
		var reg = /^[a-zA-Z]{1}([a-zA-Z0-9]|[_]){0,29}$/;	
		if(obj.name.value.length<1 || obj.name.value.length>30){
			layer.msg('配置名称长度必须为1-30位！', {icon:2});
			return false;
		}
		if(!reg.test(obj.name.value)){
			layer.msg('配置名称必须为英文、数字或下划线！', {icon:2});
			return false;
		}
		if(obj.value.value==''){
			layer.msg('配置值不能为空！', {icon:2});
			return false;
		}

        $.ajax({
            type: 'POST',
            url: '<?php echo U('user_config_add');?>', 
            data: $(obj).serialize(),
		    dataType: "json", 
            success: function (msg) {		
				if(msg.status == 1){
					layer.msg(msg.message, {icon:1,time:1500}, function(){
						parent.location.reload();     
					});
			    }else{
					layer.msg(msg.message, {icon:2});
				}
            }
        })		 
		return false;			 
	}
</script> 

</body>
</html>