diff --git a/src/core/tags/ListViewTag.coffee b/src/core/tags/ListViewTag.coffee index 5ab75f2..adfe9ed 100644 --- a/src/core/tags/ListViewTag.coffee +++ b/src/core/tags/ListViewTag.coffee @@ -12,7 +12,7 @@ class ListViewItemTag extends Ant.OS.GUI.BaseTag @setopt "closable", false @setopt "selected", false -class ListItemSimpleTag extends ListViewItemTag +class SimpleListItemTag extends ListViewItemTag constructor: (r, o) -> super r, o mount: () -> @@ -217,4 +217,5 @@ class ListViewTag extends Ant.OS.GUI.BaseTag ] Ant.OS.GUI.define "afx-list-view", ListViewTag -Ant.OS.GUI.define "afx-list-item", ListItemSimpleTag \ No newline at end of file +Ant.OS.GUI.define "afx-list-item-proto", ListViewItemTag +Ant.OS.GUI.define "afx-list-item", SimpleListItemTag \ No newline at end of file diff --git a/src/core/tags/MenuTag.coffee b/src/core/tags/MenuTag.coffee index bb4d9fd..d4fc439 100644 --- a/src/core/tags/MenuTag.coffee +++ b/src/core/tags/MenuTag.coffee @@ -1,5 +1,27 @@ class MenuEntryTag extends Ant.OS.GUI.BaseTag + constructor: (r, o) -> + super r, o + @setopt "data", {} + @setopt "onmenuselect", () -> + @setopt "children", undefined + @setopt "child", undefined + @setopt "parent", undefined + + on_data_changed: (data) -> + @set k, v for k, v of data + + on_child_changed: (v) -> + @set "children", v + + has_children: () -> + ch = @get "children" + return ch and ch.length > 0 + + is_root: () -> + return if @get "parent" then false else true + +class SimpleMenuEntryTag extends MenuEntryTag constructor: (r, o) -> super r, o @setopt "switch", false @@ -9,11 +31,7 @@ class MenuEntryTag extends Ant.OS.GUI.BaseTag @setopt "iconclass", undefined @setopt "text", "" @setopt "shortcut", undefined - @setopt "children", undefined - @setopt "data", {} - - on_data_changed: (data) -> - @set k, v for k, v of data + @setopt "checked", false on_switch_changed: (v) -> if @get("radio") or v @@ -27,6 +45,10 @@ class MenuEntryTag extends Ant.OS.GUI.BaseTag else $(@refs.switch).hide() + on_checked_changed: (v) -> + return unless @get("radio") or @get("switch") + @refs.switch.set "swon", v + on_color_changed: (v) -> return unless v @refs.label.set "color", v @@ -52,23 +74,61 @@ class MenuEntryTag extends Ant.OS.GUI.BaseTag $(@refs.shortcut).val v on_children_changed: (v) -> + me = @ $(@refs.container).removeClass("afx_submenu") return $(@refs.submenu).hide() unless v and v.length > 0 $(@refs.container).addClass("afx_submenu") $(@refs.submenu) .show() .attr("style", "") - @refs.submenu.set "root", false + @refs.submenu.set "parent", @ @refs.submenu.set "items", v + if @is_root() + $(@refs.container).mouseleave (e) -> + $(me.refs.submenu).attr("style", "") mount: () -> + me = @ @refs.switch.set "enable", false + $(@refs.entry).click (e) -> me.select e + + submenuoff: () -> + p = @get "parent" + return $(@refs.submenu).attr("style", "") unless p + p.submenuoff() + + reset_radio: () -> + return unless @has_children() + for v in @get "children" + return unless v.domel.get "radio" + v.domel.set "checked", false + + + select: (e) -> + me = @ + e.item = @root + evt = { id: @aid(), data: e } + e.preventDefault() + children = @get("children") + if @is_root() and @has_children() + $(@refs.submenu).show() + else + @submenuoff() + if @get "switch" + @set "checked", !@get "checked" + else if @get "radio" + p = @get "parent" + p.reset_radio() if p + @set "checked", !@get "checked" + + @get("onmenuselect") evt + @observable.trigger "menuselect", evt layout: () -> [{ el: "li", ref: "container", children: [ { - el: "a", children: [ + el: "a", ref: "entry", children: [ { el: "afx-switch", ref: "switch" }, { el: "afx-label", ref: "label" }, { el: "span", class: "shortcut", ref: "shortcut" } @@ -82,7 +142,7 @@ class MenuTag extends Ant.OS.GUI.BaseTag constructor: (r, o) -> super r, o @setopt "context", false - @setopt "root", true + @setopt "parent", undefined @setopt "contentag", "afx-menu-entry" @setopt "items", [] @@ -93,17 +153,20 @@ class MenuTag extends Ant.OS.GUI.BaseTag $(@refs.container).addClass("context") if v on_items_changed: (data) -> + me = @ $(@refs.container).empty() $("