<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: gaoyang  
    $Date: 2013-11-9 上午08:58:08  
    $Revision: 1.0  
    $Purpose: 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application">
    <a:init-procedure>
        <a:model-query fetchAll="true" model="basic.hls_sys_time_default_value" rootPath="default_value_path"/>
    </a:init-procedure>
    <a:view>
        <script type="text/javascript"><![CDATA[
            function aut_authority_flag_check(ds, qpara) {
                if ('${/model/default_value_path/record/@authority_flag}' == 'Y') {
                    qpara['authority_flag'] = 'Y';
                }
            }
            
            function aut_authority_list_validate_query(ds, qpara) {
           
                var document_category = '${/parameter/@document_category}',
                    function_code = '${/parameter/@function_code}',
                    master_type = '${/parameter/@master_type}';
                if (document_category == 'CHANCE') {
                    aut_authority_flag_check(ds, qpara);
                    qpara['trx_category'] = document_category;
                    qpara['trx_id'] = 't1.chance_id';
                } else if (document_category == 'CONTRACT') {
                    if (function_code == 'CON210') {
                        qpara['contract_ref_content_flag'] = 'Y';
                    } else {
                        aut_authority_flag_check(ds, qpara);
                    }
                    qpara['trx_category'] = document_category;
                    qpara['trx_id'] = 't1.contract_id';
                } else if (document_category == 'PROJECT') {
                    aut_authority_flag_check(ds, qpara);
                    qpara['trx_category'] = document_category;
                    if (function_code == 'TRE510') {
                        qpara['trx_id'] = 'p.project_id';
                    } else {
                        qpara['trx_id'] = 't1.project_id';
                    }
                    if (function_code == 'PRJ501') {
                        qpara['prj_update_status_flag'] = 'Y';
                    }
                } else if (document_category == 'CHANGE_REQUEST') {
                    aut_authority_flag_check(ds, qpara);
                    qpara['trx_category'] = document_category;
                    qpara['trx_id'] = 't1.change_req_id';
                } else if (document_category == 'CONTRACT_ET') {
                    aut_authority_flag_check(ds, qpara);
                    qpara['trx_category'] = document_category;
                    qpara['trx_id'] = 't1.et_agreement_id';
                } else if (document_category == 'PAYMENT_REQ') {
                    aut_authority_flag_check(ds, qpara);
                    qpara['trx_category'] = document_category;
                    qpara['trx_id'] = 't1.payment_req_id';
                } else if (document_category == 'VISIT_REPORT') {
                    aut_authority_flag_check(ds, qpara);
                    qpara['trx_category'] = document_category;
                    qpara['trx_id'] = 't1.visit_report_id';
                } else if (document_category == 'CONFIG_REPORT') {
                    aut_authority_flag_check(ds, qpara);
                    qpara['trx_category'] = document_category;
                    qpara['trx_id'] = 't1.report_header_id';
                } else if (document_category == 'CONFIG_REPORT_RESULT') {
                    aut_authority_flag_check(ds, qpara);
                    qpara['trx_category'] = document_category;
                    qpara['trx_id'] = 't1.report_id';
                }
                else if (document_category == 'LEASE_ITEM') {
                    aut_authority_flag_check(ds, qpara);
                    qpara['trx_category'] = document_category;
                    qpara['trx_id'] = 't1.lease_item_id';
                }
                else if (document_category == 'MORTGAGE') {
                    aut_authority_flag_check(ds, qpara);
                    qpara['trx_category'] = document_category;
                    //qpara['master_type'] = master_type;
                    qpara['trx_id'] = 't1.mortgage_id';
                }
                else if (document_category == 'BP') {
                    aut_authority_flag_check(ds, qpara);
                    qpara['trx_category'] = document_category;
                    //qpara['master_type'] = master_type;
                    qpara['trx_id'] = 't1.bp_id';
                }
                if (master_type == 'BP') {
                    aut_authority_flag_check(ds, qpara);
                    qpara['trx_category'] = master_type;
                    qpara['master_type'] = master_type;
                    qpara['trx_id'] = 't1.bp_id';
                } else if (master_type == 'LEASE_ITEM') {
                    aut_authority_flag_check(ds, qpara);
                    qpara['trx_category'] = master_type;
                    qpara['master_type'] = master_type;
                    qpara['trx_id'] = 't1.lease_item_id';
                } else if (master_type == 'MORTGAGE') {
                    aut_authority_flag_check(ds, qpara);
                    qpara['trx_category'] = master_type;
                    qpara['master_type'] = master_type;
                    qpara['trx_id'] = 't1.mortgage_id';
                }
            }
            
            var std_type = '';
            var std_field_name = '';
            
            function set_std_type_and_field(field_std_type, std_field) {
                if (field_std_type) {
                    std_type = field_std_type;
                    if (std_field) {
                        std_field_name = std_field;
                    } else {
                        if (field_std_type == 'CHANCE') {
                            std_field_name = 't1.chance_id';
                        } else if (field_std_type == 'CONTRACT') {
                            std_field_name = 't1.contract_id';
                        } else if (field_std_type == 'PROJECT') {
                            std_field_name = 't1.project_id';
                        } else if (field_std_type == 'CHANGE_REQUEST') {
                            std_field_name = 't1.change_req_id';
                        } else if (field_std_type == 'CONTRACT_ET') {
                            std_field_name = 't1.et_agreement_id';
                        } else if (field_std_type == 'PAYMENT_REQ') {
                            std_field_name = 't1.payment_req_id';
                        } else if (field_std_type == 'BP') {
                            std_field_name = 't1.bp_id';
                        } else if (field_std_type == 'LEASE_ITEM') {
                            std_field_name = 't1.lease_item_id';
                        } else if (field_std_type == 'MORTGAGE') {
                            std_field_name = 't1.mortgage_id';
                        } else if (field_std_type == 'VISIT_REPORT') {
                            std_field_name = 't1.visit_report';
                        }
                    }
                }
            }
            
            function on_std_focus(object, field_std_type, std_field) {
                var display_name = object.binder.name,
                    record = object.record || object.binder.ds.create();
                var validate_record, lov_std_type, master_type = '${/parameter/@master_type}',
                    document_category = '${/parameter/@document_category}';
                if (field_std_type) {
                    lov_std_type = field_std_type;
                } else {
                    if (master_type) {
                        lov_std_type = master_type;
                    } else {
                        lov_std_type = document_category;
                    }
                }
                if (lov_std_type) {
                    validate_record = $('${/parameter/@custom_code}_con_contract_authority_list_validate_ds').find('authority_usage', lov_std_type);
                }
                if (validate_record) {
                    var object_field = record.getField(display_name);
                    set_std_type_and_field(lov_std_type, std_field);
                    object_field.setLovPara('master_type', std_type);
                    object_field.setLovPara('trx_category', std_type);
                    object_field.setLovPara('authority_flag', 'Y');
                    object_field.setLovPara('trx_id', std_field_name);
                }
            }
        ]]></script>
        <a:dataSets>
            <a:dataSet id="${/parameter/@custom_code}_con_contract_authority_list_validate_ds" loadData="true" model="cont.CON500.con_contract_authority_list_validate"/>
        </a:dataSets>
    </a:view>
</a:screen>
