1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
| {% import ( "fmt" "strings"
"{{{ .Package }}}/app/controller/cmenu" "{{{ .Package }}}/app/controller/cutil" "{{{ .Package }}}/app/lib/menu" "{{{ .Package }}}/app/util" "{{{ .Package }}}/views/components" ) %}
{% func Menu(ps *cutil.PageState) %}{% stripspace %} {% if len(ps.Menu.Visible()) > 0 %} <div class="menu-container"> {%= components.Indent(true, 2) %} <div class="menu"> {%= components.Indent(true, 3) %} <menu class="level-0"> {% for _, i := range ps.Menu %} {%= MenuItem(i, []string{}, ps.Breadcrumbs, 3, ps) %} {% endfor %} {%= components.Indent(true, 3) %} </menu> {%= components.Indent(true, 2) %} </div> {%= components.Indent(true, 1) %} </div> {% endif %} {% endstripspace %}{% endfunc %}
{% func MenuItem(i *menu.Item, path []string, breadcrumbs cmenu.Breadcrumbs, indent int, ps *cutil.PageState) %}{% stripspace %} {% code path = append(path, i.Key) active, final := breadcrumbs.Active(i, path) %} {% if i.Key == "" %} {%= components.Indent(true, indent + 1) %} <li class="separator"></li> {% elseif len(i.Children.Visible()) > 0 %} {% code itemID := util.StringJoin(path, "--")%} {%= components.Indent(true, indent + 1) %} {% if active %}<li class="active" data-menu-key="{%s i.Key %}">{% else %}<li data-menu-key="{%s i.Key %}">{% endif %} {%= components.Indent(true, indent + 2) %} <input id="{%s itemID %}-input" type="checkbox"{% if active %}{% space %}checked="checked"{% endif %}{% space %}hidden="hidden" /> {%= components.Indent(true, indent + 2) %} {% if final %}<label class="final" for="{%s itemID %}-input" title="{%s i.Desc() %}">{% else %}<label for="{%s itemID %}-input" title="{%s i.Desc() %}">{% endif %} {%= components.ExpandCollapse(indent + 3, ps) %} {%= menuBadge(i, indent + 3, ps) %} {%= components.Indent(true, indent + 3) %} {% if i.Icon != "" %} {% if i.Warning != "" %} <a class="link-confirm" data-message="{%s i.Warning %}" href="{%s i.Route %}">{%= components.SVGRef(i.Icon, 16, 16, "icon", ps) %}</a>{% space %} {% else %} <a href="{%s i.Route %}">{%= components.SVGRef(i.Icon, 16, 16, "icon", ps) %}</a>{% space %} {% endif %} {% endif %} {% if i.Route != "" %} {% if i.Warning != "" %} <a class="link-confirm" data-message="{%s i.Warning %}" href="{%s i.Route %}">{%s i.Title %}</a> {% else %} <a href="{%s i.Route %}">{%s i.Title %}</a> {% endif %} {% else %} {%s i.Title %} {% endif %} {%= components.Indent(true, indent + 2) %} {% if final %}</label>{% else %}</label>{% endif %} {%= components.Indent(true, indent + 2) %} <div class="menu-content level-{%d len(path) %}"> {%= components.Indent(true, indent + 3) %} <menu> {% for _, i := range i.Children.Visible() %} {%= MenuItem(i, path, breadcrumbs, indent + 3, ps) %} {% endfor %} {%= components.Indent(true, indent + 3) %} </menu> {%= components.Indent(true, indent + 2) %} </div> {%= components.Indent(true, indent + 1) %} </li> {% else %} {% code finalClass := "item" if active { finalClass += " active" } if final { finalClass += " final" } if i.Warning != "" { finalClass += " link-confirm" } %} {%= components.Indent(true, indent + 1) %} <li data-menu-key="{%s i.Key %}"> {% if i.Warning != "" %} <a class="{%s finalClass %}" data-message="{%s i.Warning %}" href="{%s i.Route %}" title="{%s i.Desc() %}"> {% else %} <a class="{%s finalClass %}" href="{%s i.Route %}" title="{%s i.Desc() %}"> {% endif %} {%= menuBadge(i, indent + 3, ps) %} {% if i.Icon != "" %} {%= components.SVGRef(i.Icon, 16, 16, "icon", ps) %}{% space %} {% endif %} <span>{%s i.Title %}</span> {% if i.Warning != "" %} </a> {% else %} </a> {% endif %} </li> {% endif %} {% endstripspace %}{% endfunc %}
{% func menuBadge(i *menu.Item, indent int, ps *cutil.PageState) %}{% stripspace %} {% if i.Badge != "" %} {%- code var badgeTitle string if idx := strings.Index(i.Badge, "**"); idx > -1 { badgeTitle = fmt.Sprintf(" title=%q", i.Badge[idx+2:]) i.Badge = i.Badge[:idx] } -%} {% if strings.HasPrefix(i.Badge, ":") %} {%= components.Indent(true, indent) %} <div class="badge"{%s= badgeTitle %}>{%= components.SVGSimple(i.Badge[1:], 18, ps) %}</div> {% else %} {%= components.Indent(true, indent) %} <div class="badge"{%s= badgeTitle %}>{%s i.Badge %}</div> {% endif %} {% endif %} {% endstripspace %}{% endfunc %}
|