var isSubmit = true;
$(document).ready(function(){
	
	if ($('#activityForm').length>0){
		$('#activityForm').validate({
			
			rules : {
				"name" : {
					required : true					
				},
				"addr" : {
					required : true
				},
				"day" : {
					required : true
				},
				"max" : {
					required : true,
					isInteger: true
				},
				"crowd" : {
					required : true
				},
				"contacts" : {
					required : true
				},
				"tel": {
					required : true
				},
				"content" : {
					required : true
				}
				
				
				
			},
			messages:{
				"name" : {
					required : "不能为空"					
				},
				"addr" : {
					required : "不能为空"
				},
				"day" : {
					required : "不能为空"
				},
				"max" : {
					required : "不能为空"
				},
				"crowd" : {
					required : "不能为空"
				},
				"contacts" : {
					required : "不能为空"
				},
				"tel": {
					required : "不能为空"
				},
				"content" : {
					required : "不能为空"
				}

			},

	        
	        
	        submitHandler: function(form){  
	        	activity.save(form);
	        }
	        
	        
	        
		});
		
	}
	

	
	laydate.render({
	  elem: '#day'
	  ,type: 'datetime'
	});
	
	
	
})

var activity = {
	
	save : function(form){
		if (isSubmit){
			isSubmit = false;
			$.ajax({
				  type: 'POST',
				  url: '/api/activity/save',
				  dataType:'json',
				  data: {
					  id:$('#id').val(),
					  name:$('#name').val(),
					  type:$('#type').val(),
					  addr:$('#addr').val(),
					  content:$('#content').html(),
					  day:$('#day').val(),
					  max:$('#max').val(),
					  crowd:$('#crowd').val(),
					  available:$('#available').val(),
					  contacts:$('#contacts').val(),
					  tel:$('#tel').val()
				  },
				  success: function(data){
					  var status=data.status;
					  
					  if(status==1){//注册成功
							bootbox.dialog({
								message:"新增活动成功",
									buttons:{
										"cancel":{
											"label":"返回",
											"className":"btn-sm btn-primary",
											"callback": function () {
												window.location.href = webPath + '/activity/list';
					                        }
										},
										"success":{
											"label":"继续添加",
											"className":"btn-sm btn-primary",
											"callback": function () {
												window.location.href = webPath + '/activity/add';
					                        }
										}
							
									}
								});
							
						} else if (status == 2){
							isSubmit = true;
							bootbox.dialog({
								message:"修改活动成功",
									buttons:{
										"success":{
											"label":"确定",
											"className":"btn-sm btn-primary",
											"callback": function () {
					                        }
										}
							
									}
								});
							
							
						}
					  
					  
				  }
			});
		}
			

		
	}
	
}


















