<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: gaoyang  
    $Date: 2013-9-10 下午01:51:25  
    $Revision: 1.0  
    $Purpose: 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" customizationEnabled="true" trace="true">
    <a:init-procedure/>
    <a:view>
        <a:link id="leg_print_detail_link" url="${/request/@context_path}/modules/leg/LEG400/leg_content_print_word.lview"/>
        <a:link id="leg_print_information_link" model="leg.LEG400.leg_content_print_info" modelaction="execute"/>
        <a:link id="leg400_batch_dl_link" url="${/request/@context_path}/modules/leg/LEG400/leg_atm_batch_dl.lsc"/>
        <a:link id="leg400_content_create_link" model="leg.LEG400.leg_content_create" modelaction="execute"/>
        <script type="text/javascript"><![CDATA[
            
            function lock_current_window() {
                Leaf.Masker.mask($('${/parameter/@winid}').wrap, '${l:HLS.EXECUTING}');
            }
            
            function unlock_current_window() {
                Leaf.Masker.unmask($('${/parameter/@winid}').wrap);
            }
            
            function on_result_load(ds) {
                var records = ds.getAll();
                for (var i = 0;i < records.length;i++) {
                    var record = records[i];
                }
            }
            
            function leg400_delete_print(){
                $('leg_content_print_detail_grid').remove();
            }
            
            function leg400_print_detail_print() {
                //
                if ($('leg_content_print_detail_ds').validate(true)) {
                    var records = $('leg_content_print_detail_ds').getSelected();
                    if (records.length == 0) {
                        Leaf.showMessage('${l:PROMPT}', '${l:HLS.SELECT_RECORD}');
                        return;
                    }
                    
                    lock_current_window();
                 
                    $('leg400_print_btn').disable();
                    for(i=0;i<records.length;i++){
	                    var record = records[i];
	                    var templt_name;
                        var clause_usage = record.get('clause_usage');
                        var ref_v01 = record.get('ref_v01');
                        var content_id = record.get('content_id');
                            
                        var file_path = 'E:\\u01\\lsh_leg\\';
	                    Leaf.request({
	                        url: $('leg_print_information_link').getUrl(),
	                        para: {
	                            content_id: record.get('content_id'),
	                            file_path:file_path,
	                            type:'doc',
	                            file_name:ref_v01
	                        },
	                        success: function() {
	                            if (clause_usage == 'DUNNING') {
	                                templt_name = 'leg_dunning.xml';
	                            } else if (clause_usage == 'SIGN') {
	                                templt_name = 'leg_sign.xml';
	                            } else if (clause_usage == 'KEEP_PAPER') {
	                                templt_name = 'leg_keep_paper.xml';
	                            } else if (clause_usage == 'REPURCHASE_CONFIRM') {
	                                templt_name = 'leg_repurchase_confirm.xml';
	                            } else if (clause_usage == 'REPURCHASE') {
	                                templt_name = 'leg_repurchase.xml';
	                            } else if (clause_usage == 'CANCEL_CONTRACT') {
	                                templt_name = 'leg_cancel_contract.xml';
	                            } else if(clause_usage == 'LAW'){
	                                templt_name = 'leg_law.xml';
	                            } else if(clause_usage == 'DELIVERY_AUTHO'){
	                                templt_name = 'leg_delivery_autho.xml';
	                            } else if (clause_usage == 'DELIVERY_CERTI') {
	                                templt_name = 'leg_delivery_certi.xml';
	                            } else if(clause_usage == 'RETURN_CONFIRM'){
	                                templt_name = 'leg_return_confirm.xml';
	                            } else if(clause_usage == 'ENTRUST'){
	                                templt_name = 'leg_entrust.xml';
	                            } else if(clause_usage == 'AUTHO_LETTER'){
	                                templt_name = 'leg_autho_letter.xml';
	                            } else if(clause_usage == 'DUNNING_NOTICE'){
	                                templt_name = 'leg_dunning_notice.xml';
	                            }
	                   
	                            var url = $('leg_print_detail_link').getUrl() + '?templt_name=' + templt_name + '&file_name=' + ref_v01 + '&file_path=' + file_path+'&contract_id=${/parameter/@contract_id}&legal_letter_id=${/parameter/@legal_letter_id}&law_id=${/parameter/@law_id}&clause_usage='+clause_usage+'&content_id='+content_id;
	                            var form = document.createElement("form");
	                            form.target = "word_export_window";
	                            form.method = "post";
	                            form.action = url;
	                            var iframe = Ext.get('word_export_window') || new Ext.Template('<iframe id ="word_export_window" name="word_export_window" style="position:absolute;left:-10000px;top:-10000px;width:1px;height:1px;display:none"></iframe>').insertFirst(document.body, {}, true);
	                            document.body.appendChild(form);
	                            form.submit();
	                            Ext.fly(form).remove();
	                            unlock_current_window();
	                            
			                    Leaf.SideBar.show({
			                        msg:'文件已生成',
			                        duration:2000
			                    });
	                        },
	                        failure: function() {
	                            alert('1');
	                            unlock_current_window();
	                        },
	                        error: function() {
	                            alert('2');
	                            unlock_current_window();
	                        },
	                        sync:true,
	                        scope: this
	                    });
                    }
                    $('leg_content_print_detail_ds').query();
                    $('leg400_print_btn').enable();
                }
            }
            
            function leg400_create_file(){
				Leaf.request({
				    url:$('leg400_content_create_link').getUrl(),
				    para:{contract_id: '${/parameter/@contract_id}',
				    	  clause_usage: '${/parameter/@clause_usage}'},
				    success:function(){
	                    Leaf.SideBar.show({
	                        msg:'文件已生成',
	                        duration:2000
	                    });
	                    $('leg_content_print_detail_ds').query();
				    },
				    scope:this
				});
            }
            
            function update_attachment_renderer(value, record, name) {
                var content_id = record.get('content_id');
                return '<a href="javascript:downloadfile_link(' + content_id + ')">下载</a>';
            }
            
            function downloadfile_link(content_id) {
                var url = $('leg400_batch_dl_link').getUrl() + '?content_id=' + content_id;
                window.open(url, '_self');
            }
           
            function leg400_download_zip(){
                var url = $('leg400_batch_dl_link').getUrl() + '?contract_id=' + '${/parameter/@contract_id}';
                window.open(url, '_self');
            }
        ]]></script>
        <a:dataSets>
            <a:dataSet id="leg_content_print_detail_header_ds" loadData="true" model="leg.LEG400.con_contract_v">
                <a:fields>
                    <a:field name="contract_number" readOnly="true"/>
                    <a:field name="contract_name" readOnly="true"/>
                    <a:field name="bp_name" readOnly="true"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="leg_content_print_detail_ds" autoQuery="true" model="leg.LEG400.leg_legal_content" queryUrl="${/request/@context_path}/autocrud/leg.LEG400.leg_legal_content/query?contract_id=${/parameter/@contract_id}&amp;function=${/parameter/@function}" selectable="true">
                <a:fields>
                    <a:field name="bp_name"/>
                    <a:field name="templet_name"/>
                    <a:field name="content_number"/>
                    <a:field name="print_date" datatype="java.util.DATE"/>
                </a:fields>
                <a:events>
                    <a:event name="load" handler="on_result_load"/>
                </a:events>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar style="width:848px">
                <a:gridButton click="leg400_create_file" text="生成法务文件"/>
                <a:gridButton id="leg400_print_btn" click="leg400_print_detail_print" text="PRJ702.GENERATE_THE_FILE"/>
                <a:gridButton click="leg400_download_zip" text="PRJ702.THE_FILE_DOWNLOAD"/>
                <a:gridButton click="leg400_delete_print" text="HLS.REMOVE"/>
            </a:screenTopToolbar>
            <a:form column="2" title="法务文本打印" width="852">
                <a:textField name="contract_number" bindTarget="leg_content_print_detail_header_ds" prompt="HLS.CONTRACT_NUMBER"/>
                <a:textField name="contract_name" bindTarget="leg_content_print_detail_header_ds" prompt="HLS.CONTRACT_NAME" width="330"/>
            </a:form>
            <a:grid id="leg_content_print_detail_grid" bindTarget="leg_content_print_detail_ds" height="300" navBar="true" width="850">
                <a:columns>
                    <a:column name="ref_v01" prompt="法务文件名" width="200"/>
                    <a:column name="print_date" prompt="PRJ702.FILE_GENERATED_DATE" renderer="Leaf.formatDate" width="80"/>
                    <a:column name="bp_name" prompt="承租人名称"/>
                    <a:column name="content_print_flag_name" prompt="CON505.CON_CONTENT_STATUS" width="80"/>
                    <a:column name="attachment" align="center" prompt="HLS.ATTACHMENT" renderer="update_attachment_renderer" width="50"/>
                </a:columns>
            </a:grid>
        </a:screenBody>
    </a:view>
</a:screen>