<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: zsy
    $Date: 2018/11/14
    $Revision: 1.0
    新手入门 微件
-->
<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[
            $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 template="default" package="leaf.ui.std">
        <style>
            html,body{
                width:220px;
                height:249px;
                margin: 0;
                padding: 0;
                color:#000;
            }
            .widget_new_guide{
                box-sizing:border-box;
                width:220px;
                height:249px;
                background-color:#fff;
                position:relative;
                border:1px solid #F0F0F3;
                user-select:none;
                cursor:default;
            }
            .widget_new_guide .widget_label{
                position:absolute;
                width:40px;
                height:4px;
                top:0;
                left:16px;
                background-color:#5A7FFF;
            }
            .widget_new_guide .widget_title{
                box-sizing:border-box;
                position:relative;
                height:20px;
                line-height:20px;
                margin:16px 0 10px 0;
                font-family: PingFangSC-Medium;
                font-size: 14px;
                padding:0 24px 0 16px;
                color: rgba(75,80,90,0.85);
                letter-spacing: 0;
            }
            .widget_new_guide .widget_content{
                box-sizing:border-box;
                width:100%;
                height:205px;
                border-top:1px solid #EDEDED;
                padding:4px 15px;
            }
            .widget_new_guide .widget_content .link{
                display: block;
                width:100%;
                height:20px;
                margin-top:12px;
                text-decoration:none;
            }
            .widget_new_guide .widget_content .link:visited,
            .widget_new_guide .widget_content .link:hover,
            .widget_new_guide .widget_content .link:active{
                text-decoration:none;
                color: rgba(75,80,90,0.85);
            }
            .widget_new_guide .widget_content .link .icon{
                width:20px;
                height:20px;
            }
            .widget_new_guide .widget_content .link .link_info{
                font-family: PingFangSC-Regular;
                font-size: 12px;
                color: rgba(75,80,90,0.85);
                line-height: 20px;
                vertical-align:top;
                padding-left:0.3em;
                max-width: 150px;
                white-space: nowrap;
                overflow: hidden;
                display: inline-block;
                text-overflow: ellipsis;
            }
        </style>
        <script><![CDATA[
        $L.onReady(function(){
            var ds = $("widget_new_guide_attachment_ds");
            ds.qpara={
                enable_flag:'Y'
            };
            ds.query();
        });
        function onLoad_widget_new_guide_attachment_ds(ds){
            var htmlStr = '';
            var records = ds.getAll();
            var wrapper = jQuery(".widget_new_guide .widget_content");
            var fileArr = [];
            var link = '${/request/@context_path}/atm_download.lsc?attachment_id=';
            for(var j=0;j<records.length;j++){
                if(!!records[j].get("file_name")){
                    var arr = records[j].get("file_name").split(';;');
                    for (var i = 0;i < arr.length;i++) {
                        var name = arr[i].split('--')[0];
                        var id = arr[i].split('--')[1];
                        if (!Leaf.isEmpty(name)) {
                            fileArr.push({
                                file_name : name,
                                file_id : id
                            });
                        }
                    }
                }
            }
            for(i=0;i<fileArr.length && i<5;i++){
                htmlStr += '<a class="link"';
                var file_name = fileArr[i].file_name;
                var file_id = fileArr[i].file_id;
                if (file_name.toUpperCase().indexOf('.PDF') >= 0) {
                    htmlStr += '<a class="link" href="javascript:view_pdf(\'' + file_id + '\')">'+
                        '<img class="icon" src="${/request/@context_path}/leafresource/images/widget/attachment.png"/>'+
                        '<span class="link_info" title="' +file_name + '" >' + file_name + '</span>';
                } else if (file_name.toUpperCase().indexOf('.GIF') >= 0 || file_name.indexOf('.JPG') >= 0 | file_name.indexOf('.JPEG') >= 0 || file_name.indexOf('.PNG') >= 0) {
                    htmlStr += '<a class="link" href="' + link + file_id + '">'+
                        '<img class="icon" src="${/request/@context_path}/leafresource/images/widget/attachment.png"/>'+
                        '<span class="link_info" title="' +file_name + '" ref="img">' + file_name + '</span>';
                } else {
                    htmlStr += '<a class="link" href="' + link + file_id + '">'+
                        '<img class="icon" src="${/request/@context_path}/leafresource/images/widget/attachment.png"/>'+
                        '<span class="link_info" title="' +file_name + '">' + file_name + '</span>';
                }
                htmlStr += '</a>';
            }
            wrapper.html(htmlStr);
        }

        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('regul_framwork_attachment'));
                    var tomcat_source = '${/parameter/@tomcat_source}';
                        var source_path = 'http://' + window.location.host + '/' + tomcat_source + '/' + path;
                    var oWin = window.open(source_path);

                },
                scope: this
            });
        }
        ]]></script>
        <a:dataSets>
            <a:dataSet id="widget_new_guide_attachment_ds" model="sys.SYS003.hls_new_start_attachment"
                       autoQuery="false" pageSize="5" fetchAll="false">
                <a:fields>
                    <a:field name="attachment_id"/>
                    <a:field name="attachment_name"/>
                    <a:field name="file_name"/>
                    <a:field name="enable_flag"/>
                </a:fields>
                <a:events>
                    <a:event name="load" handler="onLoad_widget_new_guide_attachment_ds"/>
                </a:events>
            </a:dataSet>
        </a:dataSets>
        <div class="widget_new_guide">
            <span class="widget_label"> </span>
            <div class="widget_title">新手入门</div>
            <div class="widget_content"> </div>
        </div>
    </a:view>
</a:screen>