<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: gaoyang  
    $Date: 2013-8-30 上午10:24:11  
    $Revision: 1.0  
    $Purpose: 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" customizationEnabled="true" trace="true">
    <a:view>
        <script type="text/javascript"><![CDATA[
        function hls_doc_get_layout_code(bm_url_link, param, win_url_link, list_ds, pre_layout_code) {

            Leaf.Masker.mask(Ext.getBody(), '${l:HLS.EXECUTING}');
            var t1 = $(bm_url_link).getUrl();
            Leaf.request({
                url: $(bm_url_link).getUrl(),
                para: param,
                sync: true,
                success: function (res) {
                    Leaf.Masker.unmask(Ext.getBody());
                    if (!res.result.layout_code) {
                        Leaf.showMessage('${l:PROMPT}', '${l:HLS.LAYOUT_CODE_IS_NULL}');
                        return;
                    }
                    param['layout_code'] = res.result.layout_code;
                    param['usage_type'] = res.result.usage_type;
                    var winid = '';
                    if (!param['winid']) {
                        if (pre_layout_code) {
                            param['pre_layout_code'] = pre_layout_code;
                            winid = pre_layout_code + 'hls_doc_get_layout_code_winid';
                        } else {
                            winid = 'hls_doc_get_layout_code_winid';
                        }
                    } else {
                        winid = param['winid'];
                    }

                    param['winid'] = winid;
                    param['calc_type'] = res.result.cond_para1;

                    if (param['window_open_flag'] == 'Y') {
                        var window_open_url = $(win_url_link).getUrl() + '?';
                        var temp_num = 0;
                        for (var key in param) {
                            temp_num = temp_num + 1;
                            if (param[key] && param[key].toString().indexOf('%') == -1 && key != 'winid') {
                                if (temp_num == 1) {
                                    window_open_url = window_open_url + key + '=' + param[key];
                                } else {
                                    window_open_url = window_open_url + '&' + key + '=' + param[key];
                                }
                            }
                        }
                        var jsid = Leaf.getCookie('JSID');
                        window._mainwin = window.open(window_open_url, '_blank');
                    } else {
                        if (param['screen_width'] || param['screen_height']) {
                            win = new Leaf.Window({
                                id: winid,
                                params: param,
                                url: $(win_url_link).getUrl(),
                                title: param['url_title'] + '(' + res.result.layout_code + ')',
                                width: param['screen_width'],
                                height: param['screen_height'],
                                draggable: true
                            });
                        } else {
                            var win = new Leaf.Window({
                                id: winid,
                                params: param,
                                url: $(win_url_link).getUrl(),
                                title: param['url_title'] + '(' + res.result.layout_code + ')',
                                fullScreen: true,
                                draggable: true
                            });
                        }
                        win.on('close', function () {

                            if(list_ds=='acp522_acp_invoice_import_detail_ds'){
                                location.reload();
                            }else if((param['function_code']=='HLS214B'||param['function_code']=='HLS214F')&&param['change_req_id']&&param['delete_flag']=='Y'){
                                check_hls_bp_master(param['function_code'],param['change_req_id']);
                                if (list_ds) {
                                    $(list_ds).query();
                                }
                            }
                            else{
                            if (list_ds) {
                                $(list_ds).query();
                            }}
                        });
                    }
                },
                failure: function () {
                    Leaf.Masker.unmask(Ext.getBody());
                },
                error: function () {
                    Leaf.Masker.unmask(Ext.getBody());
                },
                scope: this
            });
        }

        //通过基表名获取ds_id

        function get_dsid_by_basetable(layoutDataSetList, base_table) {
            if (base_table) {
                var base_table_temp = base_table.toLowerCase() + '_ds';
                for (var i = 0; i < layoutDataSetList.length; i++) {
                    var dsId = layoutDataSetList[i];
                    if (dsId.substring(dsId.length - base_table_temp.length, dsId.length) == base_table_temp) {
                        return dsId;
                    }
                }
            }
            return '';
        }

        function get_dsid_by_tabcode_basetable(layoutDataSetList, tab_code, base_table) {
            if (base_table && tab_code) {
                var base_table_temp = tab_code + '_' + base_table.toLowerCase() + '_ds';
                for (var i = 0; i < layoutDataSetList.length; i++) {
                    var dsId = layoutDataSetList[i];
                    if (dsId.substring(dsId.length - base_table_temp.length, dsId.length) == base_table_temp) {
                        return dsId;
                    }
                }
            }
            return '';
        }
        // 获取组件ID 参数prompt若传入则传'prompt'
        function get_id_by_basetable(layoutDataSetList, base_table, name, prompt) {
            var base_table_temp = '_' + base_table.toLowerCase() + '_ds';
            for (var i = 0; i < layoutDataSetList.length; i++) {
                var dsId = layoutDataSetList[i];
                if (dsId.substring(dsId.length - base_table_temp.length, dsId.length).toLowerCase() == base_table_temp) {
                    if(name){
                        if(name.toUpperCase() != 'F' && name.toUpperCase() != 'G'){
                            // 针对form下字段
                            if(prompt){
                                return dsId.substring(0, dsId.length - base_table_temp.length) + '_' + (base_table||'NULL').toUpperCase() + '_' +  name.toUpperCase() + '_' + prompt;
                            }else{
                                return dsId.substring(0, dsId.length - base_table_temp.length) + '_' + (base_table||'NULL').toUpperCase() + '_' +  name.toUpperCase();
                            }
                        }else if(name.toUpperCase() == 'F'){
                            // 针对form
                            return dsId.substring(0, dsId.length - base_table_temp.length) + '_component_id';
                        }else if(name.toUpperCase() == 'G'){
                            // 针对grid
                            // return dsId.substring(0, dsId.length - base_table_temp.length) + '_' + (base_table||'').toLowerCase() + '_layout_grid_id';
                            return dsId.replace('ds', 'layout_grid_id');
                        }
                    }
                }
            }
            return '';
        }

        // 获取组件ID 参数prompt若传入则传'prompt'
        function get_id_by_tabcode_basetable(layoutDataSetList, tab_code, base_table, name, prompt) {
            if (tab_code) {
                var base_table_temp = tab_code + '_' + base_table.toLowerCase() + '_ds';
                for (var i = 0; i < layoutDataSetList.length; i++) {
                    var dsId = layoutDataSetList[i];
                    if (dsId.substring(dsId.length - base_table_temp.length, dsId.length).toLowerCase() == base_table_temp.toLowerCase()) {
                        if(name){
                            if(name.toUpperCase() != 'F' && name.toUpperCase() != 'G'){
                                // 针对form下字段
                                if(prompt){
                                    return dsId.substring(0, dsId.length - base_table_temp.length) + tab_code.toUpperCase() + '_' + (base_table||'NULL').toUpperCase() + '_' + name.toUpperCase() + '_' + prompt;
                                }else{
                                    return dsId.substring(0, dsId.length - base_table_temp.length) + tab_code.toUpperCase() + '_' + (base_table||'NULL').toUpperCase() + '_' + name.toUpperCase();                                }
                            }else if(name.toUpperCase() == 'F'){
                                // 针对form
                                return dsId.substring(0, dsId.length - base_table_temp.length) + tab_code.toUpperCase() + '_component_id';
                            }else if(name.toUpperCase() == 'G'){
                                // 针对grid
                                // return dsId.substring(0, dsId.length - base_table_temp.length) + tab_code.toUpperCase()  + '_' + (base_table||'').toLowerCase() + '_layout_grid_id';
                                return dsId.replace('ds', 'layout_grid_id');
                            }
                        }
                    }
                }
            }
            return '';
        }
       function  check_hls_bp_master(function_code,change_req_id){
            debugger;
            var url = '${/request/@context_path}/autocrud/hls.HLS214N.hls_bp_master_req_submit/update';
            Leaf.request({
                url: url,
                para: {
                    function_code:function_code,
                    change_req_id: change_req_id
                },
                success: function (res) {
                    Leaf.Masker.unmask(Ext.getBody());
                },
                failure: function () {
                    Leaf.Masker.unmask(Ext.getBody());
                },
                error: function () {
                    Leaf.Masker.unmask(Ext.getBody());
                },
                scope: this
            });
        }
        ]]></script>
    </a:view>
</a:screen>
