<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: ericyin  
    $Date: 2013-4-11 下午13:15:36  
    $Revision: 1.0  
    $Purpose: 商业伙伴关系类别定义
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application">
    <a:init-procedure/>
    <a:view template="default">
        <a:link id="sys_service_welcome_link" url="${/request/@context_path}/welcome.lview"/>
        <script type="text/javascript"><![CDATA[



            var header = $jq('meta[name=_csrf_header]').attr('content');
            var token = $jq('meta[name=_csrf]').attr('content');
            $jq(document).ajaxSend(function (e, xhr, options) {
                xhr.setRequestHeader(header, token);
            });

            function queryFunction() {
                //alert("Search");
                $('hls_approve_template_ds').query();


            }
            
            function hls_112_back() {

                history.go(-1);
            }
            
            function hls_112_next() {
                history.go(1);
            }
            
            function hls_012_quit() {
                //alert("Q");
                location.href = $('sys_service_welcome_link').getUrl();
                parent.shMenu('show');
            }
            

            
            function hls_112_grid_clear() {
                $('hls_approve_template_grid').clear();
            }
            
            function hls_112_grid_submit() {
                $('hls_approve_template_ds').submit();
            }
            

            function hls_012_submitsuccess(){
                //alert("9");
                $('hls_approve_template_ds').query();
            }


            function tplNo_render(val,data,col_name){
                return "<a href=\"javascript:open_contract_win('"+ data.id +"','"+ val +"')\">"+ val +"</a>";
            }


            function setDetailParam(param, data){
                var tmp1;
                var tmpDiv, tmpNo, tmpDispAppDiv, tmpAppDiv;
                        var tmpDispAppVal = "";
                        for(var i=0; i < data.length; i++){
                            tmpDiv = data[i].DTL_DIV;
                            tmpAppDiv = (data[i].APPROVE_DIV == undefined ? "": data[i].APPROVE_DIV);
                            tmpNo = data[i].DTL_NO;

                            if(tmpDiv == "A"){        tmp1 = "appr";    }
                            else if(tmpDiv == "R"){  tmp1 = "reci";     }
                            else if(tmpDiv == "C"){  tmp1 = "cc";       }

                            if(tmpDiv =="A"){
                                if(tmpAppDiv == "N"){        tmpDispAppDiv = "Not Used";    }
                                else if(tmpAppDiv == "D"){  tmpDispAppDiv = "Dept Leader";     }
                                else if(tmpAppDiv == "U"){  tmpDispAppDiv = "User ID";       }
                                else if(tmpAppDiv == "P"){  tmpDispAppDiv = "Parents";       }
                                else if(tmpAppDiv == "Q"){  tmpDispAppDiv = "Grandparents";       }
                                else {  tmpDispAppDiv = "";       }
                            }else{
                                if(tmpAppDiv == "N"){        tmpDispAppDiv = "Not Used";    }
                                else if(tmpAppDiv == "D"){  tmpDispAppDiv = "Dept";     }
                                else if(tmpAppDiv == "U"){  tmpDispAppDiv = "User";       }
                                else {  tmpDispAppDiv = "";       }
                            }


                            param['inp_'+tmp1+'_div'+tmpNo] = data[i].APPROVE_DIV;
                            param['inp_combo_'+tmp1+'_div'+tmpNo] = tmpDispAppDiv;
                            param['inp_'+tmp1+'_tp'+tmpNo] = data[i].APPROVE_TP;
                            param['inp_combo_'+tmp1+'_tp'+tmpNo] = data[i].APPROVE_TP;


                            if(tmpAppDiv == "U"){
                                param['inp_'+tmp1+'_user_id'+tmpNo] = data[i].APPROVE_VAL;
                                param['inp_'+tmp1+'_user_name'+tmpNo] = data[i].USER_NAME;

                            }else if(tmpAppDiv == "D"){
                                param['inp_'+tmp1+'_dept_id'+tmpNo] = data[i].APPROVE_VAL;
                                param['inp_'+tmp1+'_dept_name'+tmpNo] = data[i].DEPT_NAME;
                            }

                }


            }

            function open_contract_win(record_id, tplNo){

                var data = $("hls_approve_template_ds").findById(record_id);

                //设置header token
                var header = $jq('meta[name=_csrf_header]').attr('content');
                var token = $jq('meta[name=_csrf]').attr('content');
                $jq(document).ajaxSend(function (e, xhr, options) {
                    xhr.setRequestHeader(header, token);
                });
                Leaf.Masker.mask(Ext.getBody(), '${l:HLS.EXECUTING}');

                var schData = {};
                schData ={'tplNo' : data.data.tpl_no};

                $jq.ajax({
                    url: '${/request/@context_path}/hls/template/detail/list',
                    method: 'post',
                    dataType: "json",
                    contentType: 'application/json;charset=UTF-8',
                    data: JSON.stringify(schData),
                    success: function (args) {

                        Leaf.Masker.unmask(Ext.getBody(), '${l:HLS.EXECUTING}');
                        if (args.success) {


                            var maintain_type = 'QUERY';
                            var param = {};
                            param['from_master_flag'] = "Y";
                            param['tpl_code'] = tplNo;
                            param['function_code'] = 'PRJ502D';
                            param['function_usage'] = 'QUERY';
                            param['maintain_type'] = maintain_type;
                            param['url_title'] = data.data.tpl_title;
                            param['winid'] = "hls_doc_get_layout_code_winid";

                            setDetailParam(param, args.rows);

                            var win = new Leaf.Window({
                                id: 'hls_doc_get_layout_code_winid',
                                /*params: {
                                    from_master_flag:'Y',
                                    tpl_code: param['tpl_code'],
                                    function_code: param['function_code'],
                                    function_usage: param['function_usage'],
                                    maintain_type: param['maintain_type'],
                                    //inp_combo_appr_div1: param['inp_combo_appr_div1'],
                                    //inp_combo_appr_div: param['inp_combo_appr_div'],
                                    winid: 'hls_doc_get_layout_code_winid'
                                },*/
                                params : param,
                                url: "${/request/@context_path}/modules/hls/HLS112/hls_approve_template_user_modify.lview?_csrf=${/session/@_csrf.token}",
                                title: param['url_title'] ,
                                fullScreen: true,
                                draggable: true
                            });
                            win.on('close', function() {
                                //if (list_ds) {
                                //   $(list_ds).query();
                                //}
                            });


                        } else {
                            Leaf.showMessage('提示', args.message);
                            return;
                        }
                    },
                    failure: function (args) {
                        //$('acr515_invoiceVatDs').query();
                        Leaf.Masker.unmask(Ext.getBody(), '${l:HLS.EXECUTING}');
                        Leaf.SideBar.show({
                            msg: 'failure',
                            duration: 2000
                        });
                    },
                    error: function (args) {
                        //alert(args);
                        console.log(args);
                        //$('acr515_invoiceVatDs').query();
                        Leaf.Masker.unmask(Ext.getBody(), '${l:HLS.EXECUTING}');
                        Leaf.SideBar.show({
                            msg: 'error',
                            duration: 2000
                        });
                    },
                });


            }

        ]]></script>
        <a:dataSets>
            <a:dataSet id="hls_approve_template_ds" autoQuery="true" model="hls.HLS112.hls_approve_template" selectable="true">
                <a:fields>
                    <a:field name="tpl_no" required="true" />
                    <a:field name="tpl_title" required="true"/>
                    <a:field name="last_update_dt" />
                </a:fields>
            </a:dataSet>
            <a:events>
                <a:event name="submitsuccess" handler="hls_012_submitsuccess"/>
            </a:events>
        </a:dataSets>
        <a:screenBody>

            <a:screenTopToolbar>
                <a:screenTitle/>
                <a:gridButton click="hls_112_back" text="HLS.BACK"/>
                <a:gridButton click="hls_112_next" text="HLS.FORWARD"/>
                <a:gridButton click="hls_112_grid_clear" text="HLS.CLEAR"/>
                <a:gridButton click="hls_112_grid_submit" text="HLS.SAVE"/>
                <a:gridButton click="queryFunction" text="HLS.QUERY"/>
            </a:screenTopToolbar>
            <a:grid id="hls_approve_template_grid" bindTarget="hls_approve_template_ds" marginHeight="80" marginWidth="30" navBar="true">
                <a:columns>
                    <a:column name="tpl_no" renderer="tplNo_render" width="100" />
                    <a:column name="tpl_title" editor="templateDs_title" width="500" />
                    <a:column name="last_update_dt" width="200" />
                </a:columns>
                <a:editors>
                    <a:textField id="templateDs_title"/>
                </a:editors>
            </a:grid>
        </a:screenBody>
    </a:view>
</a:screen>
