package cn.cerc.ui.parts;

import cn.cerc.core.Utils;
import cn.cerc.ui.core.HtmlWriter;
import cn.cerc.ui.core.UrlRecord;
import cn.cerc.ui.vcl.UIButton;
import cn.cerc.ui.vcl.UIImage;
import cn.cerc.ui.vcl.ext.UISpan;

import java.util.ArrayList;
import java.util.List;

public class UISheetMenu extends UISheet {
    private List<UrlRecord> menus = new ArrayList<>();
    private UIImage icon; // 显示icon
    private UISpan caption; // 标题
    private UIButton opera; // 操作

    public UISheetMenu(UIToolbar owner) {
        super(owner);
        this.setCssClass("menuList");
    }

    @Override
    public void output(HtmlWriter html) {
        if (menus.size() == 0) {
            return;
        }

        html.println("<section class='%s'>", this.cssClass);
        if (caption != null) {
            html.println("<div class='nowpage'>");
            icon.output(html);
            caption.output(html);
            if (opera != null) {
                opera.output(html);
            }
            html.println("</div>");
        }
        html.println("<div>");
        html.println("<ul>");
        for (UrlRecord url : menus) {
            html.println("<li>");
            if (url.isWindow()) {
                String href = "hrip:" + url.getUrl();
                html.print("<img src='%s' role='icon' onclick='window.open(\"%s\")'/>", url.getImgage(), href);
            } else {
                html.print("<img src='%s' role='icon'/>", url.getImgage());
            }

            html.print("<a href='%s' onclick=\"updateUserHit('%s')\"", url.getUrl(), url.getUrl());
            if (url.getId() != null) {
                html.print(" id='%s'", url.getId());
            }
            if (url.getTitle() != null) {
                html.print(" title='%s'", url.getTitle());
            }
            if (url.getHintMsg() != null) {
                html.print(" onClick='return confirm('%s');'", url.getHintMsg());
            }
            if (url.getTarget() != null) {
                html.print(" target='%s'", url.getTarget());
            }
            html.print(">%s</a>", url.getName());
            if (Utils.isNotEmpty(url.getArrow())) {
                html.println("<img src='%s' role='arrow' />", url.getArrow());
            }
            html.println("</li>");
        }
        html.println("</ul>");
        html.println("</div>");
        html.println("</section>");
    }

    public UrlRecord addMenu() {
        UrlRecord menu = new UrlRecord();
        menus.add(menu);
        return menu;
    }

    public UrlRecord addMenus(UrlRecord menu) {
        menus.add(menu);
        return menu;
    }

    public void setIconAndCaption(String logoUrl, String caption) {
        this.icon = new UIImage();
        this.icon.setSrc(logoUrl);
        this.caption = new UISpan();
        this.caption.setText(caption);
    }

    public void setIconAndCaption(String logoUrl, String caption, UIButton opera) {
        this.icon = new UIImage();
        this.icon.setSrc(logoUrl);
        this.caption = new UISpan();
        this.caption.setText(caption);
        this.opera = opera;
    }
}

@@ -1172,233 +1172,8 @@
 %22);%0A
-            if (url.isWindow()) %7B%0A                String href = %22hrip:%22 + url.getUrl();%0A                html.print(%22%3Cimg src='%25s' role='icon' onclick='window.open(%5C%22%25s%5C%22)'/%3E%22, url.getImgage(), href);%0A            %7D else %7B%0A    
     
@@ -1239,30 +1239,16 @@
 gage());
-%0A            %7D
 %0A%0A      
@@ -1866,24 +1866,310 @@
 getName());%0A
+            if (url.isWindow()) %7B%0A                String hrip = %22hrip:%22 + url.getUrl();%0A                html.print(%22 %3Ca href='%25s'/%3E%3Cimg src='%25s' role='icon'/%3E%3C/a%3E%22,hrip,%22images/menu/erp-blue.png%22);%0A                //html.print(%22%3Ca href='%25s' target='_blank'/%3E%E2%9A%A1%3C/a%3E%22,hrip);%0A            %7D%0A
             

Update UISheetMenu.java