<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: zhuxianfei
    $Date: 2018-07-12 下午2:20:47
    $Revision: 1.0
    $Purpose:
-->
<a:screen xmlns:s="leaf.plugin.script" xmlns:a="http://www.leaf-framework.org/application"
          customizationEnabled="true" dynamiccreateenabled="true">
    <a:init-procedure>
        <s:server-script import="contract_print_path.js"><![CDATA[
            $ctx.parameter.file_path = con_print_path['con_print_path'];
            $ctx.parameter.tomcat_source = con_print_path['tomcat_source'];
            ]]>
        </s:server-script>
    </a:init-procedure>
    <a:view>
        <a:link id="${/parameter/layout_code}_layout_code_link_id" model="cont.CON500.con_contract_get_layout_code"
                modelaction="update"/>
        <a:link id="${/parameter/@layout_code}${/parameter/@pre_layout}prj500_cdd_uploadFile_id"
                url="${/request/@context_path}/uploadFile.lview"/>
        <a:link id="${/parameter/@layout_code}${/parameter/@pre_layout}prj500_cdd_downloadFile_id"
                url="${/request/@context_path}/downloadFile.lview"/>

        <script type="text/javascript"><![CDATA[
        function view_pdf(attachment_id) {
            Leaf.request({
                url: '${/request/@context_path}/autocrud/fnd.fnd_atm_attachment/query',
                para: {
                    attachment_id: attachment_id
                },
                success: function (res) {
                    var path = res.result.record.file_path;
                    path = path.substr(path.indexOf('hls_attachment'));
                    var tomcat_source = '${/parameter/@tomcat_source}';
                    var source_path = 'http://' + window.location.host + '/' + tomcat_source + '/' + path+'?type=pdf';
                    var oWin = window.open(source_path);
                },
                scope: this
            });
        }


        function upload_file(id, name, query_only) {
            var record = window['${/parameter/@layout_code}_hls_link_render_record'][id + '---' + name];
            if (record.get('check_id')) {
                var url;
                if (query_only == 'Y' || '${/parameter/@function_usage}' == 'QUERY') {
                    url = $('${/parameter/@layout_code}${/parameter/@pre_layout}prj500_cdd_downloadFile_id').getUrl() + '?table_name=PRJ_CDD_ITEM_CHECK&header_id=' + record.get('check_id');
                } else {
                    url = $('${/parameter/@layout_code}${/parameter/@pre_layout}prj500_cdd_uploadFile_id').getUrl() + '?table_name=PRJ_CDD_ITEM_CHECK&header_id=' + record.get('check_id');
                }
                var win = new Leaf.Window({
                    url: url,
                    title: '${l:HLS.SUPPORTING_DOCUMENT}',
                    id: 'prj500_cdd_uploadFile_screen_id',
                    width: 850,
                    height: 400
                });

                win.on('close', function () {
                    record.ds.query();
                });
            } else {
                Leaf.showMessage('${l:HLS.PROMPT}', '请先保存!');
            }
        }

        //超链接渲染
        window['${/parameter/@bp_seq}${/parameter/@layout_code}_dynamic_link_renderer'] = function (value, record, name, config_record, bp_seq) {
            var link_function = '';
            window['${/parameter/@bp_seq}${/parameter/@layout_code}_hls_link_render_record'][record.id + '---' + name] = record;
            if (name == 'attachment') {

                link_function = 'upload_file';
                return '<a href="javascript:window[\'' + link_function + '\'](\'' + record.id + '\',\'' + name + '\',\'' + config_record.get('query_only') + '\');">' + config_record.get('prompt') + '</a>';
            }
            else if (name == 'description') {
                if (record.get('important_flag') == 'Y') {
                    return '<font color="RED">' + value + '</font>';
                }
                return value;
            }
        };


        ]]></script>
        <a:screen-include screen="modules/cont/CON500/con_contract_get_layout_code.lview"/>
    </a:view>
</a:screen>
