mirror of
https://github.com/lxsang/antos-frontend.git
synced 2024-12-27 01:38:21 +01:00
Enhance dialog api
This commit is contained in:
parent
9f184fc19b
commit
0c93ff7c9c
@ -54,18 +54,21 @@ class BaseDialog extends SubWindow
|
||||
this.OS.GUI.BaseDialog = BaseDialog
|
||||
|
||||
class BasicDialog extends BaseDialog
|
||||
constructor: ( name, target) ->
|
||||
constructor: ( name, @markup) ->
|
||||
super name
|
||||
if target
|
||||
if typeof target is "string"
|
||||
Ant.OS.GUI.htmlToScheme target, @, @host
|
||||
else # a file handle
|
||||
@render target.path
|
||||
else if Ant.OS.GUI.subwindows[name] and Ant.OS.GUI.subwindows[name].scheme
|
||||
scheme = Ant.OS.GUI.subwindows[name].scheme
|
||||
Ant.OS.GUI.htmlToScheme scheme, @, @host
|
||||
|
||||
|
||||
init: () ->
|
||||
if @markup
|
||||
if typeof @markup is "string"
|
||||
Ant.OS.GUI.htmlToScheme @markup, @, @host
|
||||
else # a file handle
|
||||
@render @markup.path
|
||||
else if Ant.OS.GUI.subwindows[@name] and Ant.OS.GUI.subwindows[@name].scheme
|
||||
scheme = Ant.OS.GUI.subwindows[@name].scheme
|
||||
Ant.OS.GUI.htmlToScheme scheme, @, @host
|
||||
|
||||
main: () ->
|
||||
@scheme.set "apptitle", @data.title if @data and @data.title
|
||||
@scheme.set "resizable", false
|
||||
@scheme.set "minimizable", false
|
||||
@ -76,8 +79,8 @@ class PromptDialog extends BasicDialog
|
||||
constructor: () ->
|
||||
super "PromptDialog"
|
||||
|
||||
init: () ->
|
||||
super.init()
|
||||
main: () ->
|
||||
super.main()
|
||||
$input = $(@find "txtInput")
|
||||
@find("lbl").set "text", @data.label if @data and @data.label
|
||||
$input.val @data.value if @data and @data.value
|
||||
@ -122,10 +125,10 @@ this.OS.register "PromptDialog", PromptDialog
|
||||
|
||||
class TextDialog extends this.OS.GUI.BasicDialog
|
||||
constructor: () ->
|
||||
super "TextDialog", TextDialog.scheme
|
||||
super "TextDialog"
|
||||
|
||||
init: () ->
|
||||
super.init()
|
||||
main: () ->
|
||||
super.main()
|
||||
$input = $(@find "txtInput")
|
||||
$input.val @data.value if @data and @data.value
|
||||
|
||||
@ -166,8 +169,8 @@ class CalendarDialog extends BasicDialog
|
||||
constructor: () ->
|
||||
super "CalendarDialog"
|
||||
|
||||
init: () ->
|
||||
super.init()
|
||||
main: () ->
|
||||
super.main()
|
||||
(@find "btnOk").set "onbtclick", (e) =>
|
||||
date = (@find "cal").get "selectedDate"
|
||||
return @notify __("Please select a day") unless date
|
||||
@ -205,8 +208,8 @@ class ColorPickerDialog extends BasicDialog
|
||||
constructor: () ->
|
||||
super "ColorPickerDialog"
|
||||
|
||||
init: () ->
|
||||
super.init()
|
||||
main: () ->
|
||||
super.main()
|
||||
(@find "btnOk").set "onbtclick", (e) =>
|
||||
color = (@find "cpicker").get "selectedColor"
|
||||
return @notify __("Please select color") unless color
|
||||
@ -244,8 +247,8 @@ class InfoDialog extends BasicDialog
|
||||
constructor: () ->
|
||||
super "InfoDialog"
|
||||
|
||||
init: () ->
|
||||
super.init()
|
||||
main: () ->
|
||||
super.main()
|
||||
rows = []
|
||||
delete @data.title if @data and @data.title
|
||||
rows.push [ { text: k }, { text: v } ] for k, v of @data
|
||||
@ -282,8 +285,8 @@ class YesNoDialog extends BasicDialog
|
||||
constructor: () ->
|
||||
super "YesNoDialog"
|
||||
|
||||
init: () ->
|
||||
super.init()
|
||||
main: () ->
|
||||
super.main()
|
||||
@find("lbl").set "*", @data if @data
|
||||
(@find "btnYes").set "onbtclick", (e) =>
|
||||
@handle(true) if @handle
|
||||
@ -318,8 +321,8 @@ class SelectionDialog extends BasicDialog
|
||||
constructor: () ->
|
||||
super "SelectionDialog"
|
||||
|
||||
init: () ->
|
||||
super.init()
|
||||
main: () ->
|
||||
super.main()
|
||||
(@find "list").set "data", @data.data if @data and @data.data
|
||||
fn = (e) =>
|
||||
data = (@find "list").get "selectedItem"
|
||||
@ -357,7 +360,8 @@ this.OS.register "SelectionDialog", SelectionDialog
|
||||
class AboutDialog extends BasicDialog
|
||||
constructor: () ->
|
||||
super "AboutDialog"
|
||||
init: () ->
|
||||
main: () ->
|
||||
super.main()
|
||||
mt = @meta()
|
||||
@scheme.set "apptitle", __("About: {0}", mt.name)
|
||||
(@find "mylabel").set "*", {
|
||||
@ -403,8 +407,8 @@ class FileDialog extends BasicDialog
|
||||
constructor: () ->
|
||||
super "FileDialog"
|
||||
|
||||
init: () ->
|
||||
super.init()
|
||||
main: () ->
|
||||
super.main()
|
||||
fileview = @find "fileview"
|
||||
location = @find "location"
|
||||
filename = @find "filename"
|
||||
|
@ -25,6 +25,7 @@ class BaseModel
|
||||
@on "exit", () => @quit()
|
||||
@host = @_gui.workspace
|
||||
@dialog = undefined
|
||||
|
||||
render: (p) ->
|
||||
Ant.OS.GUI.loadScheme p, @, @host
|
||||
|
||||
|
@ -362,8 +362,8 @@ Ant.OS.API =
|
||||
setting: (f) ->
|
||||
Ant.OS.API.handle.setting f
|
||||
|
||||
apigateway: (d, ws, c) ->
|
||||
return Ant.OS.API.handle.apigateway d, ws, c
|
||||
apigateway: (d, ws) ->
|
||||
return Ant.OS.API.handle.apigateway d, ws
|
||||
|
||||
search: (text) ->
|
||||
r = []
|
||||
|
@ -20,22 +20,41 @@ class DB
|
||||
constructor: (@table) ->
|
||||
|
||||
save: (d) ->
|
||||
Ant.OS.API.handle.dbquery "save", { table: @table, data: d }
|
||||
return new Promise (resolve, reject) =>
|
||||
Ant.OS.API.handle.dbquery "save", { table: @table, data: d }
|
||||
.then (r) ->
|
||||
return reject(Ant.OS.API.throwe(r.error)) if r.error
|
||||
resolve(r.result)
|
||||
.catch (e) -> reject __e e
|
||||
|
||||
delete: (c) ->
|
||||
rq = { table: @table }
|
||||
return new Promise (resolve, reject) ->
|
||||
return new Promise (resolve, reject) =>
|
||||
rq = { table: @table }
|
||||
reject(Ant.OS.API.throwe("OS.DB: unkown condition")) unless c and c isnt ""
|
||||
if isNaN c
|
||||
rq.cond = c
|
||||
else
|
||||
rq.id = c
|
||||
Ant.OS.API.handle.dbquery "delete", rq
|
||||
if isNaN c
|
||||
rq.cond = c
|
||||
else
|
||||
rq.id = c
|
||||
Ant.OS.API.handle.dbquery "delete", rq
|
||||
.then (r) ->
|
||||
return reject(Ant.OS.API.throwe(r.error)) if r.error
|
||||
resolve(r.result)
|
||||
.catch (e) -> reject __e e
|
||||
|
||||
get: (id) ->
|
||||
Ant.OS.API.handle.dbquery "get", { table: @table, id: id }
|
||||
new Promise (resolve, reject) =>
|
||||
Ant.OS.API.handle.dbquery "get", { table: @table, id: id }
|
||||
.then (r) ->
|
||||
return reject(Ant.OS.API.throwe(r.error)) if r.error
|
||||
resolve(r.result)
|
||||
.catch (e) -> reject __e e
|
||||
|
||||
find: (cond) ->
|
||||
Ant.OS.API.handle.dbquery "select", { table: @table, cond: cond }
|
||||
new Promise (resolve, reject) =>
|
||||
Ant.OS.API.handle.dbquery "select", { table: @table, cond: cond }
|
||||
.then (r) ->
|
||||
return reject(Ant.OS.API.throwe(r.error)) if r.error
|
||||
resolve(r.result)
|
||||
.catch (e) -> reject __e e
|
||||
|
||||
Ant.OS.API.DB = DB
|
@ -422,9 +422,6 @@ Ant.OS.GUI =
|
||||
|
||||
refreshDesktop: () ->
|
||||
($ Ant.OS.GUI.workspace)[0].fetch()
|
||||
|
||||
mkdialog: (conf) ->
|
||||
return new Ant.OS.GUI.BasicDialog conf.name, conf.layout
|
||||
|
||||
login: () ->
|
||||
scheme = $.parseHTML Ant.OS.GUI.schemes.login
|
||||
|
@ -210,13 +210,14 @@ class MenuTag extends Ant.OS.GUI.BaseTag
|
||||
push: (item, flag) ->
|
||||
tag = @get "contentag"
|
||||
tag = item.tag if item.tag
|
||||
items = @get "items"
|
||||
el = $("<#{tag}>")
|
||||
if flag
|
||||
$(@refs.container).prepend el[0]
|
||||
@get("items").unshift item
|
||||
@get("items").unshift item if not items.includes item
|
||||
else
|
||||
el.appendTo @refs.container
|
||||
@get("items").push item
|
||||
@get("items").push item if not items.includes item
|
||||
el[0].uify undefined
|
||||
el[0].set "parent", @get("parent")
|
||||
el[0].set "root", if @get("parent") then @get("parent").get("root") else @
|
||||
|
@ -104,6 +104,13 @@ class SystemPanelTag extends Ant.OS.GUI.BaseTag
|
||||
list = []
|
||||
list.push v for k, v of Ant.OS.setting.system.packages when (v and v.app)
|
||||
list.push v for k, v of Ant.OS.setting.system.menu
|
||||
list.sort (a, b) ->
|
||||
if a.text < b.text
|
||||
-1
|
||||
else if a.text > b.text
|
||||
1
|
||||
else
|
||||
0
|
||||
@refs.applist.set "data", list
|
||||
|
||||
toggle: (flag) ->
|
||||
|
@ -15,18 +15,31 @@ class TreeViewItemPrototype extends Ant.OS.GUI.BaseTag
|
||||
|
||||
update: (p) ->
|
||||
return unless p
|
||||
return unless p is @get("treepath")
|
||||
@set "open", true
|
||||
switch p
|
||||
when "expand"
|
||||
@set "open", true
|
||||
when "collapse"
|
||||
@set "open", false
|
||||
else
|
||||
return unless p is @get("treepath")
|
||||
@set "open", true
|
||||
|
||||
__data__: (v) ->
|
||||
return unless v
|
||||
@set "nodes", v.nodes if v.nodes
|
||||
@set "open", v.open
|
||||
@set "treepath", v.path if v.path
|
||||
@set "selected", v.selected
|
||||
|
||||
__selected__: (v) ->
|
||||
return unless @opts.data
|
||||
$(@refs.wrapper).removeClass()
|
||||
return $(@refs.wrapper).addClass("afx_tree_item_selected") if v
|
||||
@opts.data.selected = v
|
||||
if v
|
||||
@get("treeroot").unselect()
|
||||
# set selectedItem but not trigger the update
|
||||
@get("treeroot").set "selectedItem", @root, true
|
||||
return $(@refs.wrapper).addClass("afx_tree_item_selected")
|
||||
|
||||
__open__: (v) ->
|
||||
return unless @is_folder()
|
||||
@ -164,14 +177,28 @@ class TreeViewTag extends Ant.OS.GUI.BaseTag
|
||||
@setopt "fetch", undefined
|
||||
@setopt "dragndrop", false
|
||||
@setopt "treepath", @aid()
|
||||
@root.is_left = () => @is_left()
|
||||
@root.is_leaf = () => @is_leaf()
|
||||
@root.expandAll = () => @expandAll()
|
||||
@root.collapseAll = () => @collapseAll()
|
||||
@root.unselect = () => @unselect()
|
||||
@indexcounter = 0
|
||||
|
||||
|
||||
unselect: () ->
|
||||
@get("selectedItem").set "selected", false if @get("selectedItem")
|
||||
|
||||
__selectedItem: (v) ->
|
||||
return unless v
|
||||
@get("selectedItem").set "selected", false if @get("selectedItem")
|
||||
return if v is @get("selectedItem")
|
||||
v.set "selected", true
|
||||
|
||||
expandAll: () ->
|
||||
return if @is_leaf()
|
||||
@root.update "expand"
|
||||
|
||||
collapseAll: () ->
|
||||
return if @is_leaf()
|
||||
@root.update "collapse"
|
||||
|
||||
itemclick: (e, flag) ->
|
||||
return unless e and e.item
|
||||
@ -188,7 +215,7 @@ class TreeViewTag extends Ant.OS.GUI.BaseTag
|
||||
is_root: () ->
|
||||
return @get("treeroot") is undefined
|
||||
|
||||
is_left: () ->
|
||||
is_leaf: () ->
|
||||
data = @get "data"
|
||||
return true unless data
|
||||
return if data.nodes then false else true
|
||||
@ -232,7 +259,7 @@ class TreeViewTag extends Ant.OS.GUI.BaseTag
|
||||
el = $(e.target).closest("afx-tree-view")
|
||||
return if el.length is 0
|
||||
el = el[0]
|
||||
el = el.get("parent") if el.is_left()
|
||||
el = el.get("parent") if el.is_leaf()
|
||||
return if el is @dnd.from or el is @dnd.from.get("parent")
|
||||
@dnd.to = el
|
||||
@__("ondragndrop") { id: @aid(), data: @dnd }
|
||||
|
@ -47,13 +47,13 @@ class Ant.OS.GUI.BaseTag
|
||||
value = v
|
||||
@set name, value
|
||||
|
||||
set: (opt, value) ->
|
||||
set: (opt, value, flag) ->
|
||||
if opt is "*"
|
||||
@set k, v for k, v of value
|
||||
else
|
||||
@["__#{opt}"](value) if @["__#{opt}"]
|
||||
@["__#{opt}"](value) if @["__#{opt}"] and not flag
|
||||
@opts[opt] = value
|
||||
@["__#{opt}__"](value) if @["__#{opt}__"]
|
||||
@["__#{opt}__"](value) if @["__#{opt}__"] and not flag
|
||||
@
|
||||
|
||||
aid: () ->
|
||||
|
@ -2,7 +2,8 @@ class CommandPalette extends this.OS.GUI.BasicDialog
|
||||
constructor: () ->
|
||||
super "CommandPalete", CommandPalette.scheme
|
||||
|
||||
init: () ->
|
||||
main: () ->
|
||||
super.main()
|
||||
offset = $(".afx-window-content", @parent.scheme).offset()
|
||||
pw = @parent.scheme.get("width") / 5
|
||||
@scheme.set "width", 3 * pw
|
||||
|
@ -19,7 +19,9 @@
|
||||
class RepositoryDialog extends this.OS.GUI.subwindows.SelectionDialog
|
||||
constructor: () ->
|
||||
super()
|
||||
|
||||
main: () ->
|
||||
super.main()
|
||||
@list = @find "list"
|
||||
$((@find "btnOk")).hide()
|
||||
@list.set "buttons", [
|
||||
|
@ -20,7 +20,8 @@ class VFSSettingDialog extends this.OS.GUI.BasicDialog
|
||||
constructor: () ->
|
||||
super "VFSSettingDialog", VFSSettingDialog.scheme
|
||||
|
||||
init: () ->
|
||||
main: () ->
|
||||
super.main()
|
||||
$(@find("txtPath")).click (e) =>
|
||||
@openDialog("FileDialog", {
|
||||
title: "__(Select a directory)",
|
||||
|
Loading…
Reference in New Issue
Block a user