From ed03c72e3b4134c722a5a06c7b8bf1b8f6858d74 Mon Sep 17 00:00:00 2001 From: lxsang Date: Mon, 2 Mar 2020 17:59:38 +0100 Subject: [PATCH] add tag --- Makefile | 2 + src/core/tags/ListViewTag.coffee | 22 ++++++----- src/core/tags/MenuTag.coffee | 44 ++++++++++++++++++++++ src/core/tags/NSpinnerTag.coffee | 45 +++++++++++++++++++++++ src/core/tags/SwitchTag.coffee | 30 +++++++++++++++ src/core/tags/tag.coffee | 8 +++- src/packages/ShowCase/coffees/main.coffee | 15 ++++++-- 7 files changed, 152 insertions(+), 14 deletions(-) create mode 100644 src/core/tags/MenuTag.coffee create mode 100644 src/core/tags/NSpinnerTag.coffee create mode 100644 src/core/tags/SwitchTag.coffee diff --git a/Makefile b/Makefile index 42dd07f..22dbbca 100644 --- a/Makefile +++ b/Makefile @@ -32,6 +32,8 @@ coffees= src/core/core.coffee \ src/core/tags/LabelTag.coffee \ src/core/tags/ButtonTag.coffee \ src/core/tags/ListViewTag.coffee \ + src/core/tags/SwitchTag.coffee \ + src/core/tags/NSpinnerTag.coffee \ src/antos.coffee diff --git a/src/core/tags/ListViewTag.coffee b/src/core/tags/ListViewTag.coffee index 3deca8f..14ed800 100644 --- a/src/core/tags/ListViewTag.coffee +++ b/src/core/tags/ListViewTag.coffee @@ -72,12 +72,12 @@ class ListViewTag extends Ant.OS.GUI.BaseTag @setopt "multiselect", false @setopt "selectedItem", undefined @setopt "selectedItems", [] - @items = [] $(@root) .css "display", "flex" .css "flex-direction", "column" multiselect: () -> + return false if @get "dropdown" @get "multiselect" @@ -89,12 +89,11 @@ class ListViewTag extends Ant.OS.GUI.BaseTag for item in data el = $("<#{@get "itemtag"}>").appendTo @refs.mlist el[0].uify @observable - console.log el me = @ el[0] .set "data", item .set "oncontextmenu", (e) -> - me.icontextmenu e + me.iclick e .set "ondbclick", (e) -> me.idbclick e .set "onclick", (e) -> @@ -108,15 +107,12 @@ class ListViewTag extends Ant.OS.GUI.BaseTag return if not e.item list = @get("selectedItems") if @multiselect() and list.includes(e.item) - list.splice(list.indexOf(e.item)) + list.splice(list.indexOf(e.item), 1) return e.item.set "selected", false - e.item.set "selected", true - icontextmenu: (e) -> - console.log "context menu", e idbclick: (e) -> - console.log "db click", e + @get("onlistdbclick")(e) iselect: (e) -> return unless e.item if @multiselect() @@ -128,10 +124,18 @@ class ListViewTag extends Ant.OS.GUI.BaseTag @get("selectedItem").set "selected", false if @get("selectedItem") @set "selectedItem", e.item @set "selectedItems", [e.item] + e.items = [e.item] + + if @get "dropdown" + @refs.drlabel.set "*", e.item.get "data" + $(@refs.mlist).hide() + @get("onlistselect")(e) + @observable.trigger "listselect", { id: @aid(), evt: e } iclose: (e) -> - console.log "close", e + return unless e.item + $(e.item).remove() on_dropdown_changed: (v) -> $(@refs.container).removeAttr "style" diff --git a/src/core/tags/MenuTag.coffee b/src/core/tags/MenuTag.coffee new file mode 100644 index 0000000..2a0c03f --- /dev/null +++ b/src/core/tags/MenuTag.coffee @@ -0,0 +1,44 @@ + +class MenuEntrySimpleContentTag extends Ant.OS.GUI.BaseTag + constructor: (r, o) -> + super r, o + @setopt "data", {} + + layout: () -> + [{ + el: "a", children: [ + { el: "afx-switch" }, + { el: "afx-label" }, + { el: "span", class: "shortcut" } + ] + }] + +class MenuEntryTag extends Ant.OS.GUI.BaseTag + constructor: (r, o) -> + super r, o + @setopt "data", {} + @setopt "contentag", "afx-menu-entry" + + on_data_changed: (v) -> + + + layout: () -> + [{ + el: "li", ref: "container" + }] + +class MenuTag extends Ant.OS.GUI.BaseTag + constructor: (r, o) -> + super r, o + @setopt "context", false + + layout: () -> + [{ + el: "ul", children: [ + { el: "li", ref: "start", class: "afx-corner-fix" }, + { el: "li", ref: "end", class: "afx-corner-fix" } + ] + }] + +Ant.OS.GUI.define "afx-menu", MenuTag +Ant.OS.GUI.define "afx-menu-entry", MenuEntrySimpleContentTag \ No newline at end of file diff --git a/src/core/tags/NSpinnerTag.coffee b/src/core/tags/NSpinnerTag.coffee new file mode 100644 index 0000000..8f75fab --- /dev/null +++ b/src/core/tags/NSpinnerTag.coffee @@ -0,0 +1,45 @@ + +class NSpinnerTag extends Ant.OS.GUI.BaseTag + constructor: (r, o) -> + super r, o + @setopt "value", 0 + @setopt "step", 1 + @setopt "onchange", (e) -> + + mount: () -> + me = @ + $(@refs.holder).attr "type", "text" + $(@refs.incr).click (e) -> + me.set "value", (me.get("value") + me.get("step") ) + e.nspin = me.get "value" + me.get("onchange")(e) + me.observable.trigger "nspin", { id: me.aid(), evt: e } + $(@refs.decr).click (e) -> + me.set "value", (me.get("value") - me.get("step") ) + e.nspin = me.get "value" + me.get("onchange")(e) + me.observable.trigger "nspin", { id: me.aid(), evt: e } + + on_value_changed: (v) -> + $(@refs.holder).val @get("value") + + + + layout: () -> + [ + { + el: "input", ref: "holder" + }, + { + el: "ul", ref: "spinner", children: [ + { el: "li", class: "incr", ref: "incr", children: [ + { el: "i" } + ] }, + { el: "li", class: "decr", ref: "decr", children: [ + { el: "i" } + ] } + ] + } + ] + +Ant.OS.GUI.define "afx-nspinner", NSpinnerTag \ No newline at end of file diff --git a/src/core/tags/SwitchTag.coffee b/src/core/tags/SwitchTag.coffee new file mode 100644 index 0000000..cc25636 --- /dev/null +++ b/src/core/tags/SwitchTag.coffee @@ -0,0 +1,30 @@ + +class SwitchTag extends Ant.OS.GUI.BaseTag + constructor: (r, o) -> + super r, o + @setopt "swon", false + @setopt "enable", true + @setopt "onchange", (e) -> + + mount: () -> + me = @ + $(@refs.switch).click (e) -> + me.onchange(e) + + onchange: (e) -> + return unless @get "enable" + @setopt "swon", !@get("swon") + e.swon = @get "swon" + @get("onchange")(e) + @observable.trigger "switch", { id: @aid(), evt: e } + + on_swon_changed: (v) -> + $(@refs.switch).removeClass() + $(@refs.switch).addClass "swon" if v + + layout: () -> + [{ + el: "span", ref: "switch" + }] + +Ant.OS.GUI.define "afx-switch", SwitchTag \ No newline at end of file diff --git a/src/core/tags/tag.coffee b/src/core/tags/tag.coffee index 7f3f7fb..e427a4a 100644 --- a/src/core/tags/tag.coffee +++ b/src/core/tags/tag.coffee @@ -36,8 +36,11 @@ class Ant.OS.GUI.BaseTag @set name, value set: (opt, value) -> - @opts[opt] = value - @["on_#{opt}_changed"](value) if @["on_#{opt}_changed"] + if opt is "*" + @set k, v for k, v of value + else + @opts[opt] = value + @["on_#{opt}_changed"](value) if @["on_#{opt}_changed"] @ aid: () -> @@ -45,6 +48,7 @@ class Ant.OS.GUI.BaseTag get: (opt) -> + return @opts if opt is "*" @opts[opt] uify: () -> diff --git a/src/packages/ShowCase/coffees/main.coffee b/src/packages/ShowCase/coffees/main.coffee index 648dd6a..5b39e22 100644 --- a/src/packages/ShowCase/coffees/main.coffee +++ b/src/packages/ShowCase/coffees/main.coffee @@ -43,14 +43,16 @@ class ShowCase extends this.OS.GUI.BaseApplication + + - +
box center 3
@@ -84,8 +86,8 @@ class ShowCase extends this.OS.GUI.BaseApplication list[0].set "data", [ { text: "some thing with avery long text" }, - { text: "some thing 1" }, - { text: "some thing 2" }, + { text: "some thing 1", closable: true }, + { text: "some thing 2", iconclass: "fa fa-camera-retro fa-lg" }, { text: "some thing 3" }, { text: "some thing 4" }, { text: "some thing 5" } @@ -93,6 +95,13 @@ class ShowCase extends this.OS.GUI.BaseApplication list[0].set "onlistselect", (e) -> console.log(e.items) + sw = $ "[data-id='switch']", scheme[0] + sw[0].set "onchange", (e) -> + console.log e.swon + + spin = $ "[data-id='spin']", scheme[0] + spin[0].set "onchange", (e) -> + console.log e.nspin ShowCase.singleton = true this.OS.register "ShowCase", ShowCase \ No newline at end of file