<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: LR  
    $Date: 2013-8-13 上午10:30:25  
    $Revision: 1.0  
    $Purpose: 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" customizationEnabled="true" dynamiccreateenabled="true" trace="true">
    <a:init-procedure><![CDATA[

    ]]></a:init-procedure>
    <a:view>
        <a:link id="submit_finish_link" model="cont.CON650.contract_workflow_start" modelaction="batch_update"/>
        <a:link id="car_modify_special_link" url="${/request/@context_path}/modules/prj/PRJ500N/prj_project_create_special.lview"/>
        <a:link id="con_contract_modify_link" url="${/request/@context_path}/modules/cont/CON505/con_contract_modify.lview"/>
        <a:link id="con_contract_get_layout_code_link_id" model="cont.CON500.con_contract_get_layout_code" modelaction="update"/>
        <script type="text/javascript"><![CDATA[
			window['${/parameter/@layout_code}_user_button1_layout_dynamic_click'] = function() {

                var records = $('CONTRACT_ANTI_INCEPT_G_CONTRACT_RESULT_con_contract_ds').getSelected();
                if (records.length != 1) {
                    Leaf.showMessage('${l:HLS.PROMPT}', '只能选择一条合同进行终止操作！');
                    return;
                }
                var cancel_status = records[0].get('cancel_status');
                if(cancel_status=='APPROVING'){
                    Leaf.showMessage('提示','已提交申请的合同不能重复提交');
                    return;
                }
                var prams = [];
                var data = {};
                var records_reason = $('CONTRACT_ANTI_INCEPT_CANCEL_REASON__ds').getAt(0);
                if (Leaf.isEmpty(records_reason.get('cancel_reason'))) {
                    Leaf.showMessage('提示', '请维护合同终止原因！');
                    return;
                } else if (Leaf.isEmpty(records_reason.get('closed_date'))) {
                    Leaf.showMessage('提示', '请维护合同终止日期！');
                    return;
                }
                data['contract_id'] = records[0].get('contract_id');
                data['cancel_reason'] = records_reason.get('cancel_reason');
                data['closed_date'] = records_reason.get('closed_date');
                data['_status'] = 'update';
                prams[0] = data;
                var detail_mask;
                detail_mask = Ext.getBody();
                Leaf.Masker.mask(detail_mask, '${l:HLS.EXECUTING}');
                Leaf.request({
                    url: $('submit_finish_link').getUrl(),
                    para: prams,
                    success: function() {
                        $('CONTRACT_ANTI_INCEPT_G_CONTRACT_RESULT_con_contract_ds').query();
                        Leaf.Masker.unmask(detail_mask);
                        Leaf.SideBar.show({
                            msg: '操作成功',
                            duration: 2000
                        });
                        var record1 = $('CONTRACT_ANTI_INCEPT_CANCEL_REASON__ds').getAt(0);
                        record1.set('closed_date','');
                        record1.set('cancel_reason','');
                    },
                    failure: function() {
            			Leaf.Masker.unmask(detail_mask);
                       },
                    error: function() {
            			Leaf.Masker.unmask(detail_mask);
                       },
                    scope: this
                });
            };   
            
            function open_contract_win(ds_id, record_id) {
                var record = $(ds_id).findById(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', null);
            }
            
            function open_project_Window(record_id, ds_id) {
                var record = $(ds_id).findById(record_id);
                var param = {};
                param['company_id'] = record.get('company_id');
                param['project_id'] = record.get('project_id');
                param['function_code'] = 'PRJ502D';
                param['function_usage'] = 'QUERY';
                param['bp_class'] = record.get('bp_class');
                param['maintain_type'] = 'QUERY';
               /*  param['window_open_flag'] = 'Y';
                param['show_history_flag'] = 'Y'; */
                param['url_title'] = '${l:HLS.PROJECT_MAITAIN}';
                hls_doc_get_layout_code('con_contract_get_layout_code_link_id', param, 'car_modify_special_link', ds_id, '${/parameter/@layout_code}');
            }
            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>';
                }
                if (name == 'project_id_c' && value) {
                    return '<a href="javascript:open_project_Window(\'' + 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>
