antos-frontend/src/core/BaseModel.coffee

78 lines
1.9 KiB
CoffeeScript
Raw Normal View History

class BaseModel
2017-08-27 23:40:02 +02:00
constructor: (@name, @args) ->
@observable = riot.observable()
@_api = self.OS.API
2018-01-26 18:57:28 +01:00
@_gui = self.OS.GUI
2018-01-28 02:01:21 +01:00
@systemsetting = self.OS.setting
me = @
@on "exit", () -> me.quit()
2018-01-27 03:16:06 +01:00
@host = "#desktop"
2017-08-24 01:53:13 +02:00
@dialog = undefined
render: (p) ->
2017-08-24 01:53:13 +02:00
_GUI.loadScheme p, @, @host
quit: () ->
evt = new _GUI.BaseEvent("exit")
@onexit(evt)
if not evt.prevent
delete @.observable
2017-08-24 01:53:13 +02:00
@dialog.quit() if @dialog
_PM.kill @
2018-02-16 18:38:14 +01:00
path: () ->
mt = @meta()
return mt.path if mt and mt.path
return null
init: ->
#implement by sub class
onexit: (e) ->
#implement by subclass
2018-01-24 15:03:33 +01:00
2017-08-26 16:50:13 +02:00
one: (e, f) -> @observable.one e, f
on: (e, f) -> @observable.on e, f
trigger: (e, d) -> @observable.trigger e, d
2018-01-22 19:59:08 +01:00
subscribe: (e, f) ->
_courrier.on e, f, @
2017-08-24 01:53:13 +02:00
2018-01-25 19:15:41 +01:00
openDialog: (d, f, title, data) ->
2017-08-24 01:53:13 +02:00
if @dialog
@dialog.show()
return
2018-02-01 19:36:09 +01:00
if not _GUI.subwindows[d]
2017-08-24 01:53:13 +02:00
@error "Dialog #{d} not found"
return
2018-02-01 19:36:09 +01:00
@dialog = new _GUI.subwindows[d]()
2017-08-24 01:53:13 +02:00
@dialog.parent = @
@dialog.handler = f
@dialog.pid = @pid
2017-08-27 23:40:02 +02:00
@dialog.data = data
2018-01-25 19:15:41 +01:00
@dialog.title = title
2017-08-26 16:50:13 +02:00
@dialog.init()
2017-08-17 00:42:05 +02:00
publish: (t, m) ->
mt = @meta()
2017-08-24 01:53:13 +02:00
_courrier.trigger t, { id: @pid, name: @name, data: { m: m, icon: mt.icon, iconclass: mt.iconclass } }
2017-08-17 00:42:05 +02:00
notify: (m) ->
@publish "notification", m
2017-08-17 00:42:05 +02:00
warn: (m) ->
@publish "warning", m
2017-08-17 00:42:05 +02:00
error: (m) ->
2018-01-24 15:03:33 +01:00
@publish "error", m + (@_api.throwe @name)
2017-08-17 00:42:05 +02:00
fail: (m) ->
@publish "fail", m
2018-01-24 01:03:14 +01:00
throwe: () ->
@_api.throwe @name
find: (id) -> ($ "[data-id='#{id}']", @scheme)[0] if @scheme
2018-02-05 19:05:41 +01:00
select: (sel) -> $ sel, @scheme if @scheme
this.OS.GUI.BaseModel = BaseModel