<?xml version="1.0" encoding="UTF-8"?>
<!--
  create by nyl  2014-12-3 
  for contract context create
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" customizationEnabled="true" dynamiccreateenabled="true" trace="true">
    <a:init-procedure/>
    <a:view>
        <!-- <a:link id="con560n_contract_modify_link_id" url="${/request/@context_path}/modules/cont/CON301/con_contract_query_n.lview"/> -->
        <a:link id="con560n_contract_modify_link_id" url="${/request/@context_path}/modules/prj/PRJ506/virtual_contract_query.lview"/>
        <a:link id="con560n_contract_get_layout_code_link_id" model="cont.CON500.con_contract_get_layout_code" modelaction="update"/>
        <a:link id="con_contract_terminate_link_id" model="cont.CON560.con_contract_terminate" modelaction="batch_update"/>
        <a:link id="${/parameter/@layout_code}_con560_uploadFile_id" url="${/request/@context_path}/uploadFile.lview"/>
        <a:link id="${/parameter/@layout_code}_con560_downloadFile_id" url="${/request/@context_path}/downloadFile.lview"/>
        <script type="text/javascript"><![CDATA[
            function open_contract_win(ds_id, record_id) {
                var record = $(ds_id).findById(record_id);

                var param = record.data;
                
                param['function_code'] = 'CON301R';
                param['function_usage'] = 'QUERY';
                param['maintain_type'] = 'READONLY';
                param['cond_para2'] = record.get('hn_industry_classification');
                param['url_title'] = '${l:CON301.CONTRACT_DETAIL}';
                var winid = 'con560n_contract_query_link_id';
                new Leaf.Window({
                    id: winid,
                    params: param,
                    url: $('con560n_contract_modify_link_id').getUrl(),
                    title: param['url_title'] + '(' + 'CONTRACT_QUERY' + ')',
                    fullScreen: true,
                    draggable: true
                });
            
                //  hls_doc_get_layout_code('con560n_contract_get_layout_code_link_id', param, 'con560n_contract_modify_link_id',ds_id);
            }
            
            function virtual_con_link(record_id, name){
                //
                var record = window['${/parameter/@layout_code}_hls_link_render_record'][record_id + '---' + name];
                var head_ds=  get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract');
                var param={};
                //var param = record.data;
                param['function_code'] = 'C0N301D_CON';
                param['document_id'] = record.get('project_id');
                param['function_usage'] = 'QUERY';
                param['maintain_type'] = 'READONLY';
                param['cond_para2'] = record.get('hn_industry_classification');
                 param['url_title'] = '合同明细';
                param['winid']='con301_virtual_contract_query_detail_link_id';
                hls_doc_get_layout_code('con560n_contract_get_layout_code_link_id', param, 'con560n_contract_modify_link_id',head_ds);
            }
            
            
            //提交
            window['${/parameter/@layout_code}_user_button1_layout_dynamic_click'] = function() {
            
                var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract');
                if (ds_id) {
                    var records = $(ds_id).getSelected();
                    if (!records.length) {
                        Leaf.showMessage('${l:PROMPT}', '请至少选择一条记录');
                        return;
                    }
                    var TerminateData = [];
                    for (var i = 0;i < records.length;i++) {
                        var data = {};
                        data['contract_id'] = records[i].get('contract_id');
                        data['_status'] = 'update';
                        TerminateData.push(data);
            
                    }
            
                    Leaf.showConfirm('${l:PROMPT}', '确认要结束?', function() {
            
                        Leaf.request({
                            url: $('con_contract_terminate_link_id').getUrl(),
                            para: TerminateData,
                            success: function() {
                                Leaf.SideBar.show({
                                    msg: '操作成功',
                                    duration: 2000
                                });
                                $(ds_id).query();
                            },
                            scope: this
                        });
                    }, function() {
                        return;
                    }, null, null);
                }
            };
            
            function upload_attachment(ds_id, record_id) {
            		return;
               }
            
            window['${/parameter/@layout_code}_con560_attachtment_upload'] = function(id, dsid, name, query_only) {
                var record = $(dsid).findById(id);
                if (record.get('contract_id')) {
                    var url;
                    if (query_only == 'Y') {
                        url = $('${/parameter/@layout_code}_con560_downloadFile_id').getUrl() + '?table_name=CON_CONTRACT&header_id=' + record.get('contract_id');
                    } else {
                        url = $('${/parameter/@layout_code}_con560_uploadFile_id').getUrl() + '?table_name=CON_CONTRACT&header_id=' + record.get('contract_id');
                    }
                    var win = new Leaf.Window({
                        url: url,
                        title: '${l:HLS.SUPPORTING_DOCUMENT}',
                        id: '${/parameter/@layout_code}_con560_uploadFile_screen_id',
                        width: 850,
                        height: 400
                    });
            
                    win.on('close', function() {
                        record.ds.query();
                    });
                }
            };
            
            
            window['${/parameter/@layout_code}_dynamic_link_renderer'] = function(value, record, name, config_record) {
            	var link_function = '';
                window['${/parameter/@layout_code}_hls_link_render_record'][record.id + '---' + name] = record;
                if(name==='contract_number'){
                    link_function = 'virtual_con_link';
                        return '<a href="javascript:window[\'' + link_function + '\'](\'' + record.id + '\',\'' + name + '\');">' + value + '</a>';
                    
                } 
                else if (name == 'attachment_upload') {  //add by zhangyu 2015-12-13 for guotou
                    link_function = '${/parameter/@layout_code}_con560_attachtment_upload';
                    return '<a href="javascript:window[\'' + link_function + '\'](\'' + record.id + '\',\'' + record.ds.id + '\',\'' + name + '\',\'' + config_record.get('query_only') + '\');">' + config_record.get('prompt') + '</a>';
                }
            
                return value;
            };
        ]]></script>
        <a:screen-include screen="modules/cont/CON500/con_contract_get_layout_code.lview"/>
    </a:view>
</a:screen>
