<?xml version="1.0" encoding="UTF-8"?>
<a:screen xmlns:a="http://www.leaf-framework.org/application" customizationEnabled="true" dynamiccreateenabled="true" trace="true">
    <a:init-procedure/>
    <a:view>
        <a:link id="con_contract_get_layout_code_link_id" model="cont.CON500.con_contract_get_layout_code" modelaction="update"/>
        <a:link id="con_contract_modify_link" url="${/request/@context_path}/modules/cont/CON501N/con_contract_modify.lview"/>
        <a:link id="prj_project_modify_link" url="${/request/@context_path}/modules/prj/PRJ501N/prj_project_create_tree_n.lview"/>
        <a:link id="con544_detail_link" url="${/request/@context_path}/modules/cont/CON544/contract_sign_detail.lview"/>
        <script type="text/javascript"><![CDATA[
            
            function open_project_modify_win(record_id, ds_id) {
                var record = $(ds_id).findById(record_id);
                var maintain_type = 'UPDATE';
                var param = record.data;
                param['declare_flag'] = 'Y';
                param['document_id'] = record.get('project_id');
                param['function_code'] = 'PRJ502';
                param['function_usage'] = 'QUERY';
                param['maintain_type'] = maintain_type;
                param['url_title'] = '${l:HLS.PROJECT_MAITAIN}';
                hls_doc_get_layout_code('con_contract_get_layout_code_link_id', param, 'prj_project_modify_link');
            }
            
            function open_contract_win(ds_id, record_id) {
                var record = $(ds_id).find(record_id);
                var param = record.data;
                param['function_code'] = 'CON301';
                param['function_usage'] = 'QUERY';
                param['maintain_type'] = 'UPDATE';
                param['url_title'] = '${l:CON301.CONTRACT_DETAIL}';
                hls_doc_get_layout_code('con_contract_get_layout_code_link_id', param, 'con_contract_modify_link', ds_id);
            }
            
            window['${/parameter/@layout_code}_user_button1_layout_dynamic_click'] = function() {
                var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'prj_cdd_item_doc_ref');
                var prj_project_result_ds = $(ds_id);
                var records = prj_project_result_ds.getSelected();
                if (records.length != 1) {
                    Leaf.showMessage('${l:PROMPT}', '${l:HLS.SELECT_RECORD}');
                    return;
                }
                var record = records[0];
                var contract_id = record.get('contract_id');
                var project_id	= record.get('project_id');
                var cdd_list_id = record.get('cdd_list_id');
                var project_number= record.get('project_number');
                var contract_number = record.get('contract_number');
                var document_id,document_number,document_table;
                if (contract_id){
                    document_id = contract_id;
                    document_number = contract_number;
                    document_table = 'CON_CONTRACT';
                }else{
                    document_id = project_id;
                    document_number = project_number;
                    document_table = 'PRJ_PROJECT';
                }
                
                var win = new Leaf.Window({
                    id: 'con544_sign_detail_id',
                    url: $('con544_detail_link').getUrl(),
                    params: {
                        document_id: document_id,
                        document_number:document_number,
                        document_table:document_table,
                        winid	: 'con544_sign_detail_id',
                        cdd_list_id:cdd_list_id
                    },
                    title: '合同签约',
                    fullScreen: true
                });
            };
            
            window['${/parameter/@layout_code}_dynamic_link_renderer'] = function(value, record, name, config_record) {
                if (name == 'contract_number' && value) {
                    return '<a href="javascript:open_contract_win(\''+record.ds.id+'\',\''+record.id+'\')">'+value+'</a>';
                }else if(name=='project_number' &&value){
                    return '<a href="javascript:open_project_modify_win(\'' + record.id + '\',\'' + record.ds.id + '\')">' + value + '</a>';
                }
                return value;
            };
        ]]></script>
        <a:screen-include screen="modules/cont/CON500/con_contract_get_layout_code.lview"/>
    </a:view>
</a:screen>
