mirror of
https://github.com/lxsang/antos-frontend.git
synced 2024-11-08 14:08:22 +01:00
add tag
This commit is contained in:
parent
5d987f8fb6
commit
ed03c72e3b
2
Makefile
2
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
|
||||
|
||||
|
||||
|
@ -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"
|
||||
|
44
src/core/tags/MenuTag.coffee
Normal file
44
src/core/tags/MenuTag.coffee
Normal file
@ -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
|
45
src/core/tags/NSpinnerTag.coffee
Normal file
45
src/core/tags/NSpinnerTag.coffee
Normal file
@ -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
|
30
src/core/tags/SwitchTag.coffee
Normal file
30
src/core/tags/SwitchTag.coffee
Normal file
@ -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
|
@ -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: () ->
|
||||
|
@ -43,14 +43,16 @@ class ShowCase extends this.OS.GUI.BaseApplication
|
||||
<afx-resizer data-width="5" />
|
||||
<afx-vbox data-width="grow">
|
||||
<afx-hbox min-height="50">
|
||||
<afx-switch data-id="switch" />
|
||||
<afx-button text="__(This is the label)"
|
||||
data-id="bttest"
|
||||
iconclass="fa fa-camera-retro fa-lg"
|
||||
icon="os://packages/DummyApp/icon.png"/>
|
||||
<afx-nspinner data-id="spin" value="10" step="2" />
|
||||
</afx-hbox>
|
||||
<afx-resizer data-height="5" />
|
||||
<afx-hbox>
|
||||
<afx-list-view data-id="list" multiselect="true" />
|
||||
<afx-list-view data-id="list" dropdown="true" multiselect="false" />
|
||||
</afx-hbox>
|
||||
<afx-hbox data-height="150">
|
||||
<div>box center 3</div>
|
||||
@ -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
|
Loading…
Reference in New Issue
Block a user