<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: gaoyang  
    $Date: 2013-9-10 下午01:51:25  
    $Revision: 1.0  
    $Purpose: 
-->
<a:screen xmlns:s="leaf.plugin.script" xmlns:a="http://www.leaf-framework.org/application" customizationEnabled="true" trace="true">
    <a:init-procedure>
        <s:server-script import="contract_print_path.js"><![CDATA[
            set_parameter_file_path();
        ]]></s:server-script>
        <a:model-query fetchAll="true" model="cont.CON500N.bgfl_get_contract_print_file_path" rootPath="contract_file_path"/>
    </a:init-procedure>
    <a:view>
    <a:link id="con_contract_content_asset_detail_link_id" url="${/request/@context_path}/modules/cont/CON505/con_contract_content_asset_detail.lview"/>
    <a:link id="con_contract_update_print_fin_link_id" url="${/request/@context_path}/modules/cont/CON500/con_contract_update_print_word.lview"/>
    <a:link id="con_contract_create_content_link_id" model="cont.CON505.con_contract_create_content" modelaction="update"/>
    <a:link id="con_contract_save_print_information_link_id" model="cont.CON505.con_contract_save_print_information" modelaction="update"/>
    <a:link id="get_mapping_xml_svc_link_id" model="cont.CON505.con_contract_save_print_information" modelaction="execute"/>
    <a:link id="con_contract_uploadfile" url="${/request/@context_path}/uploadFile.lview"/>
    <a:link id="con_contract_content_bp_link" model="cont.CON505.con_contract_content_bp_for_lov" modelaction="query"/>
    <a:link id="con543_con_batch_dl_link_id" url="${/request/@context_path}/modules/cont/CON505/con_atm_batch_dl.lsc"/>
    <a:link id="con_doc_batch_create_link_id" url="${/request/@context_path}/modules/cont/CON500/con_doc_batch_create.lsc"/>
        <script><![CDATA[
        function con_print_detail_print(){	 
            //lock_current_window();
            Leaf.Masker.mask($('${/parameter/@winid}').wrap, '正在生成并打印合同文本，请稍等。。。');
            var result_ds = $('con_contract_update_print_detail_line_ds');
            // var records = result_ds.getAll();
            // var total_count = 0;
            // if ($('con_contract_update_print_detail_line_ds').getAll().length <= 0) {
            //     Leaf.showMessage('提示', '请先生成合同文本！');
            //     unlock_current_window();
            //     return;
            // }
            // for (var m = 0;m < records.length;m++) {
            //     if (records[m].get('file_exists_flag') != 'Y') {
            //         total_count = total_count + 1;
            //     }
            // }
         //   alert('${/parameter/@file_path}');
            var file_path = $('contract_file_path_ds').getAt(0).get('contract_file_path');
            Leaf.request({
                url: $('con_doc_batch_create_link_id').getUrl(),
                para: {
                    contract_id: '${/parameter/@contract_id}',
                    file_path: '${/parameter/@file_path}',
                    batch_flag: 'Y'
                },
                success: function(res) {
                    result_ds.query(result_ds.currentPage);
                    unlock_current_window();
                },
                error: function() {
                    unlock_current_window();
                },
                failure: function() {
                    unlock_current_window();
                },
                scope: this
            });
        }

        function lock_current_window() {
            Leaf.Masker.mask($('${/parameter/@winid}').wrap, '${l:HLS.EXECUTING}');
        }

        function unlock_current_window() {
            Leaf.Masker.unmask($('${/parameter/@winid}').wrap);
        }

        function con_print_detail_create() {
            Leaf.Masker.mask($('${/parameter/@winid}').wrap, '${l:HLS.EXECUTING}');
            Leaf.request({
                url: $('con_contract_create_content_link_id').getUrl(),
                para: {
                    contract_id: '${/parameter/@contract_id}',
                    content_type: '${/parameter/@content_type}'
                  /*  templet_usage: 'CON_SALE'*/
                },
                success: function(res) {
                    var result_ds = $('con_contract_update_print_detail_line_ds');
                    result_ds.query(result_ds.currentPage);
                    unlock_current_window();
                },
                error: function() {
                    unlock_current_window();
                },
                failure: function() {
                    unlock_current_window();
                },
                scope: this
            });
        }

        function on_result_load(ds) {
            var records = ds.getAll();
            for (var i = 0;i < records.length;i++) {
                var record = records[i];
            }
        }

        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 = $('con543_con_batch_dl_link_id').getUrl() + '?content_id=' + content_id + '&contract_id=' + '${/parameter/@contract_id}' + '&content_type=' + '${/parameter/@content_type}';
                window.open(url, '_self');
        }

        function con_download_zip() {
            var url = $('con543_con_batch_dl_link_id').getUrl() + '?contract_id=' + '${/parameter/@contract_id}';
            window.open(url, '_self');
        }

        function con500_delete_print() {
            $('con_contract_update_print_detail_grid_1').remove();
        }

        function detail_upload_window(record_id) {

            var url = $('con_contract_uploadfile').getUrl() + '?table_name=CON_CONTRACT_CONTENT_V&header_id=' + record_id;
            var win = new Leaf.Window({
                url: url,
                title: '${l:HLS.SUPPORTING_DOCUMENT}',
                id: 'insurance_records_uploadFile_id',
                width: 850,
                height: 400
            });
            win.on('close', function() {
                $('con_contract_update_print_detail_line_ds').query();
            });
        }

        function attachment_upload(val, rec, name) {
            return '<a href=javascript:detail_upload_window(' + rec.get('content_id') + ')>附件上传</a>';
        }

        window['con500_link_render'] = function(value, record, name) {
            if (value != null) {
                var link = '${/request/@context_path}/atm_download.lsc?attachment_id=';
                var str = value.split(';;');
                var url = '';
                for (var i = 0;i < str.length;i++) {
                    var temp = str[i].split('--');
                    if (!Leaf.isEmpty(temp[0])) {
                        url = url + '<a href=' + link + temp[1] + ' ref="img">' + temp[0] + '</a>' + ',';
                    }
                }
                return url;
            }
        };
        ]]></script>
        <a:dataSets>
            <a:dataSet id="basic_clause_tmplet_usage_ds" lookupCode="CON_TMPLET_USAGE"/>
            <a:dataSet id="contract_file_path_ds">
                <a:datas dataSource="/model/contract_file_path"/>
            </a:dataSet>
            <a:dataSet id="con_contract_update_print_detail_header_ds" autoQuery="true" model="cont.CON500.con_contract" queryUrl="${/request/@context_path}/autocrud/cont.CON500.con_contract/query?contract_id=${/parameter/@contract_id}">
                <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="con_contract_update_print_detail_line_ds" autoQuery="true" queryUrl="${/request/@context_path}/autocrud/cont.CON500.con_contract_content_v/query?contract_id=${/parameter/@contract_id}&amp;content_type=${/parameter/@content_type}" selectable="true" submitUrl="${/request/@context_path}/modules/cont/CON505/con_contract_content_save.lsc">
                <a:fields>
                    <a:field name="content_type" defaultValue="${/parameter/@content_type}"/>
                    <a:field name="bp_name" lovGridHeight="350" lovHeight="500" lovLabelWidth="100" lovService="cont.CON505.con_contract_content_bp_for_lov?contract_id=${/parameter/@contract_id}" lovWidth="550" required="true" title="HLS.BP_TITLE">
                        <a:mapping>
                            <a:map from="record_id" to="con_contract_bp_id"/>
                            <a:map from="bp_name" to="bp_name"/>
                            <a:map from="bp_category" to="bp_category"/>
                            <a:map from="bp_category_desc" to="bp_category_desc"/>
                            <a:map from="bp_class" to="bp_class"/>
                            <a:map from="bp_class_desc" to="bp_class_desc"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="clause_usage_name" displayField="code_value_name" options="basic_clause_tmplet_usage_ds" required="true" returnField="clause_usage" valueField="code_value"/>
                    <a:field name="clause_usage"/>
                    <a:field name="templet_name" lovGridHeight="350" lovHeight="500" lovService="basic.con_clause_templet_for_lov" lovWidth="500" title="CON505.CON_CONTENT_TEMPLET_NAME">
                        <a:mapping>
                            <a:map from="templet_id" to="templet_id"/>
                            <a:map from="description" to="templet_name"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="content_number"/>
                    <a:field name="available_flag" checkedValue="Y" defaultValue="Y" uncheckedValue="N"/>
                    <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="con_print_detail_create" text="CON505.CON_CONTENT_CREATE"/>-->
                <a:gridButton id="con500_print_btn" click="con_print_detail_print" text="生成文本"/>
                <!-- <a:gridButton click="con_download_zip" text="PRJ702.THE_FILE_DOWNLOAD"/> -->
                <a:gridButton click="con500_delete_print" text="HLS.REMOVE"/>
            </a:screenTopToolbar>
            <a:form column="2" title="CON505.CON_CONTENT_PRINT" width="900">
                <a:textField name="contract_number" bindTarget="con_contract_update_print_detail_header_ds" prompt="HLS.CONTRACT_NUMBER"/>
                <a:textField name="contract_name" bindTarget="con_contract_update_print_detail_header_ds" prompt="HLS.CONTRACT_NAME" width="330"/>
            </a:form>
            <a:grid id="con_contract_update_print_detail_grid_1" bindTarget="con_contract_update_print_detail_line_ds" height="300"  width="930" navBar="true">
                <a:columns>
                    <a:column name="content_number" prompt="CON505.CON_CONTENT_NUMBER" width="160"/>
                    <!-- <a:column name="clause_usage_name" prompt="HLS.CONTRACT_USAGE"/> -->
                    <a:column name="ref_n05" align="right" prompt="打印份数" width="70"/>
                    <a:column name="print_date" prompt="生成日期" renderer="Leaf.formatDate" width="80"/>
                    <!-- <a:column name="bp_class_desc" prompt="HLS.BP_CLASS"/> -->
                    <!-- <a:column name="asset_detail" align="center" prompt="CON505.CON_CONTENT_ASSET_DETAIL" renderer="see_asset_detail_renderer"/> -->
                    <!-- <a:column name="templet_name" editor="print_detail_grid_lov_id" prompt="CON505.CON_CONTENT_TEMPLET_NAME"/> -->
                    <a:column name="bp_name" prompt="HLS.BP_NAME"/>
                    <a:column name="bp_category_desc" prompt="HLS.BP_CATEGORY"/>
                    <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:column align="center" prompt="附件上传" renderer="attachment_upload" width="80"/>
                    <a:column name="file_name" align="left" prompt="附件名" renderer="con500_link_render" width="220"/>-->
                </a:columns>
            </a:grid>
        </a:screenBody>
    </a:view>
</a:screen>