<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: Feng  
    $Date: 2014-1-3 上午10:24:25  
    $Revision: 1.0  
    $Purpose: 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" trace="true">
    <a:init-procedure>
        <a:model-execute model="db.prj_cdd_item_pkg.prj_cdd_item_extra_save"/>
        <a:model-query model="cont.CON555.con555_get_info" rootPath="con555_get_info"/>
    </a:init-procedure>
    <a:view>
        <a:link id="con555_cdd_uploadFile_id" url="${/request/@context_path}/downloadFile.lview"/>
        <a:link id="con555_cdd_download_id" url="${/request/@context_path}/atm_download.lsc"/>
        <a:link id="con555_cdd_query_link" url="${/request/@context_path}/autocrud/csh.CSH530.con_content_query_detail/query"/>
        <a:link id="con_contract_file_link_id" model="db.con_contract_pkg.update_contract_file_date" modelaction="execute"/>
        <script type="text/javascript"><![CDATA[
        window['con555_cdd_editorFunction'] = function(record, name) {
                if (record.get('sys_flag') == 'N') {
                    return 'con555_cdd_tf_id';
                }
                return '';
            };
            
            function con555_cdd_selectFunc(record) {
                if (record.get('sys_flag') == 'Y') {
                    return false;
                }
                return true;
            }
            window['con555_cdd_attachment_render'] = function(value, record, name) {
                //
                var check_id = record.get('check_id');
                var file_name = record.get('file_name');
                var record_id = record.id;
                if (!record.isNew && check_id) {
                    return '<a href="javascript:window[\'con555_cdd_attachtment_upload\'](\'' + record.get('check_id') + '\',\'' + file_name + '\',\'' + record_id + '\')">${l:HLS.ATTACHMENT}</a>';
                }
            };
            
            window['con555_link_render'] = function(value, record, name) {
                // var file_name = record.get('file_name');
                // var url = $('con555_cdd_download_id').getUrl() + '?attachment_id=' + record.get('attachment_id');
                // if (file_name) {
                // return '<a href='+url+ '>' + value + '</a>';
                // }
                //
                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] + '>' + temp[0] + '</a>' + ',';
                        }
                    }
                    return url;
            
                }
            };
        
            window['con555_cdd_attachtment_upload'] = function(check_id, file_name, record_id) {
                //
                var url = $('con555_cdd_uploadFile_id').getUrl() + '?table_name=PRJ_CDD_ITEM_CHECK&header_id=' + check_id;
                var record = $('con555_detail_result_ds').getCurrentRecord();
                var oldvalue = file_name ? file_name : null;
                var contract_id = ${/parameter/@contract_id};
                paras = {
                    'contract_id': contract_id
                };
                var win = new Leaf.Window({
                    url: url,
                    title: '${l:HLS.SUPPORTING_DOCUMENT}',
                    id: 'con555_cdd_uploadFile_screen_id',
                    width: 850,
                    height: 400
                });
                win.on('close', function() {
                    //
                    Leaf.request({
                        url: $('con555_cdd_query_link').getUrl(),
                        para: paras,
                        success: function(data) {
                            $('con555_detail_result_ds').query();
            
                            var newvalue = $('con555_detail_result_ds').findById(record_id).get('file_name');
                            //con555_attach_update(oldvalue,newvalue);
                        },
                        sync: true
                    });
            
                });
            
            };
            window['con555_cdd_required_render'] = function(value, record, name) {
                var project_required_flag = record.get('project_required_flag');
                if (project_required_flag == 'Y') {
                    return '<pan style="color:red">' + value + '</pan>';
                } else {
                    return value;
                }
            };
            // window['con555_attach_add'] = function(ds) {
                // var record = $('con555_detail_result_ds').getAt(0);
                // var current_record = ds.getCurrentRecord();
                // current_record.data['document_table'] = 'PRJ_CDD_ITEM_CHECK';
                // current_record.data['cdd_list_id'] = record.get('cdd_list_id');
                // current_record.data['document_id'] = record.get('document_id');
                // current_record.data['note'] = record.get('note');
                // document_category = record.get('document_category');
                // if (document_category == 'CONTRACT') {
                    // current_record.data['contract_required_flag'] = 'N';
                    // current_record.data['contract_display_flag'] = 'Y';
                // } else if (document_category == 'PROJECT') {
                    // current_record.data['project_required_flag'] = 'N';
                    // current_record.data['project_display_flag'] = 'Y';
                // }
            // };
            // window['con555_attach_load'] = function(ds) {
                // var records = ds.getAll();
                // if (records.length) {
                    // for (var i = 0;i < records.length;i++) {
                        // var record = records[i];
                        // if (Ext.isEmpty(record.get('check_id'))) {
                            // record.dirty = true;
                        // }
                    // }
                // }
            // };
            
            // function con555_attach_update(ds, record, value, oldvalue, newvalue) {
                // alert('con555_attach_update');
            // }
            
            // function con555_attach_query(ds) {            
                // alert('con555_attach_refresh');
            // }
            
            function con555_con_contract_back() {
                //console.log($('con555_contract_query_ds').data[0].getMeta().getField('contract_status_desc'));
                $('con_contract_content_window').close();
            }
            
            function con555_con_contract_reset() {
                $('con555_detail_ds').reset();
            }
            
            function con555_con_contract_save() {
                var records = $('con555_detail_result_ds').getAll();
                var paras = {
                    'contract_id': '${/parameter/@contract_id}',
                    'file_date': $('con555_detail_ds').getCurrentRecord().get('creation_date')
                };
                // for (var i = 0;i < records.length;i++) {
                    // if (records[i].get('creation_date')?0:1) {
                        // Leaf.showMessage('提示', '有附件没有提交!', function() {}, 280, 100);
                        // return;
                    // }
            
                // }
            
                Leaf.request({
	                url: $('con_contract_file_link_id').getUrl(),
	                para : paras,
	                success: function(data) {          	                               	
	            
	                },
	                sync : true
                });
                $('con555_detail_result_ds').submit();
            }
            
            function con555_download()
             {
	             var root_ds = $('con555_detail_ds');
	             var record = root_ds.getAt(0);
	             var document_id = record.get('contract_id');
	             var document_table = 'CON_CONTRACT';
	             var document_number = record.get('contract_number');
	             var url='${/request/@context_path}/modules/cont/CON500/lease_atm_batch_dl.lsc?table_name='+document_table+'&table_pk_value='+document_id+'&doc_code='+document_number;
	             window.open(url);
             }
        ]]></script>
        <a:dataSets>
            <a:dataSet id="con555_detail_ds" autoCreate="true" fetchAll="true">
                <a:fields>
                    <a:field name="contract_id" defaultValue="${/model/con555_get_info/record/@contract_id}"/>
                    <a:field name="contract_number" defaultValue="${/model/con555_get_info/record/@contract_number}" readOnly="true"/>
                    <a:field name="bp_id_tenant_desc" defaultValue="${/model/con555_get_info/record/@bp_id_tenant_desc}" readOnly="true"/>
                    <a:field name="creation_date" defaultValue="${/model/con555_get_info/record/@contract_file_date}"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="con555_detail_result_ds" autoPageSize="true" autoQuery="true" fetchAll="true" model="csh.CSH530.con_content_query_detail" pageSize="13" queryDataSet="con555_detail_ds" queryUrl="${/request/@context_path}/autocrud/csh.CSH530.con_content_query_detail/query?contract_id=${/parameter/@contract_id}" selectFunction="con555_cdd_selectFunc">
                <a:fields>
                    <a:field name="paper_required" checkedValue="Y" defaultValue="N" uncheckedValue="N"/>
                    <a:field name="not_applicable" checkedValue="Y" defaultValue="N" uncheckedValue="N"/>
                    <a:field name="attachment_required" checkedValue="Y" defaultValue="N" uncheckedValue="N"/>
                    <a:field name="sys_flag" defaultValue="N"/>
                    <a:field name="document_id" defaultValue="${/parameter/@contract_id}"/>
                    <a:field name="cdd_list_id" defaultValue="${/parameter/@cdd_list_id}"/>
                    <a:field name="document_table" defaultValue="CON_CONTRACT"/>
                    <a:field name="creation_date"/>
                    <a:field name="note"/>
                </a:fields>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:gridButton click="con555_con_contract_back" text="HLS.BACK"/>
                <a:gridButton click="con555_download" text="打包下载"/>
            </a:screenTopToolbar>
            <!-- <a:form column="3" labelWidth="120" marginWidth="30" title="基础信息">
                <a:textField name="contract_number" bindTarget="con555_detail_ds" prompt="合同编号"/>
                <a:textField name="bp_id_tenant_desc" bindTarget="con555_detail_ds" prompt="承租人名称"/>
                <a:datePicker name="creation_date" bindTarget="con555_detail_ds" prompt="归档完成日期"/>
            </a:form> -->
            <a:grid bindTarget="con555_detail_result_ds" height="400" marginWidth="30" navBar="true">
                <!-- <a:toolBar>
                    <a:button type="add"/>
                    <a:button type="save"/>
                    <a:button type="delete"/>
                </a:toolBar> -->
                <a:columns>
                    <a:column name="description" prompt="HLS.DOCUMENT_NAME" renderer="con555_cdd_required_render" width="250"/>
                    <!--<a:column name="attachment_required" editor="con555_cdd_ck_id" prompt="HLS.DIGITAL_FILE" width="40"/>
                    <a:column name="paper_required" editor="con555_cdd_ck_id" prompt="已提交" width="40"/>-->
                    <a:column name="attachment" align="center" prompt="附件" renderer="con555_cdd_attachment_render" width="60"/>
                    <a:column name="file_name" align="center" prompt="附件名" renderer="con555_link_render" width="450"/>
                    <a:column name="note" prompt="HLS.COMMENT" width="450"/>
                    <!--<a:column name="creation_date" prompt="附件上传时期" renderer="Leaf.formatDate" width="150"/>-->
                </a:columns>
                <a:editors>
                    <a:checkBox id="con555_cdd_ck_id"/>
                    <a:textField id="con555_cdd_tf_id"/>
                </a:editors>
            </a:grid>
        </a:screenBody>
    </a:view>
</a:screen>