<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="utf-8" %>
<%@include file="/WEB-INF/ehr/commons/jsp/commonInclude.jsp" %>

<script type="text/javascript">

    /* *************************** 模块初始化 ***************************** */
    var editorProcessor = {
        //form
        index:1,
        actionUrl:"${contextRoot}/processor/addProcessor",
        $condition: null,
        init: function () {
            this.bindEvents();
            this.initForm();
        },
        initForm: function () {
            var me = this;
           var data;
            var modelString = "${model.id}";
            if(modelString!=undefined && modelString!=null && modelString.length>0)
            {
                data={
                    id: "${model.id}",
                    name: "${model.name}",
                    className: "${model.className}",
                    packageName: "${model.packageName}",
                };

                me.actionUrl = "${contextRoot}/processor/updateProcessor";
            }else{
                data={
                };
            }
            $("#div_info_form").ligerAutoForm({
                data:data,
                validate:{
                    name:"required",
                    className:"required",
                    packageName:"required"
                },
            });
        },
        bindEvents: function () {
            var me = this;
            $(".m-form-bottom").on("click","#btnSave",function () {
                $("#btnSave").css("pointer-events","none");
                $(".param").each(function(){$(this).removeClass("paramRequired")});
                var flag = false;
                $(".param").each(function(){
                    if($(this).val()=="") {
                        flag = true;
                        $(this).addClass("paramRequired");
                    }
                });

                if(!$("#div_info_form").ligerAutoForm("validate")){
                    return;
                }
                if (flag) {
                    return;
                }
                var data = $("#div_info_form").ligerAutoForm("getData");
                $.ajax({ //ajax处理
                    type: "POST",
                    url : me.actionUrl,
                    dataType : "json",
                    data:data,
                    cache:false,
                    success :function(data){
                        if(data.successFlg) {
                            parent.processor.dialogSuccess(data.message);
                        }
                        else{
                            $.ligerDialog.error(data.message);
                        }
                        $("#btnSave").css("pointer-events","");
                    },
                    error :function(data){
                        $.ligerDialog.error("Status:"+data.status +"(" +data.statusText+")");
                        $("#btnSave").css("pointer-events","");
                    }
                });
            });

            $(".m-form-bottom").on("click","#btnCancel",function () {
                parent.processor.dialog.close();
            });
        }
    };



    $(function () {
        editorProcessor.init();

    });
</script>