/*
 * 功能：除修改外的模块操作，POST提交数据
 * 编写日期: 2014-03-05
 * 作者:     David.Dai@zkteco.com 
 */
var title = $("#title").val();
var model_data = $("#model_data").val();
var app_label = $("#app_label").val();
var data_model_url = $("#data_model_url").val();
var model_name = $("#model_name").val()
if (app_label == "/"){
	app_label = "/"+$("#id_sys_cur_app",parent.document).val();
}
if (model_data != ''){
	var $show_op= $("#id_edit_form #objs_for_op");
	$show_op.prepend($.validator.format(gettext("选择 {0}(s): "),title)+model_data);
	$show_op.addClass("objs_for_op");
	$show_op.parents("#pre_addition_fields").css("height",60);
}
 $("#OK").click(function(){
	 var operation_name = $("#operation_name").val();
     var pk =  $("#model_keys").val();
     var ret = ""
	 var t_pk = pk.split(",")
	 for(i=0;i<t_pk.length;i++){
			ret +='&K='+ t_pk[i]
	 }
	 $form= $("#id_edit_form");
	 if(typeof(before_submit)!= "undefined"){
		if(!before_submit()){
			return;
	    };
     }
     if ($form.valid()){ 
	     data=$("#id_edit_form").serialize();
	     $.ajax({
	        url:app_label+data_model_url+"/_op_"+operation_name+"/?"+ret,
	        data:data,
	        type:"POST",
	        dataType:'html',
	        success:function(callback){
	            if(callback.indexOf('{ Info:"OK" }') != -1){
	                window.location.assign(app_label+"/page"+app_label+model_name+"Report/?pure");
	            }
	            else{
	                var $error=$(callback).find("ul.errorlist");
	                if($error.length!=0){
	                    $("#id_info").html($error.eq(0)).hide().show(100); 
	                }else{
	                    $("#id_info").html(callback);
	                } 
	            }
	        },
	        error:function(callback){
	                alert(gettext("服务器出错!"));
	            }
	       });
	  }else{
        $form.find("input.error").eq(0).focus();
     }
});

$("#Cancel").click(function(){
	window.location.assign(app_label+"/page"+app_label+model_name+"Report/?pure");
});
