antos-frontend/src/core/BaseModel.coffee

78 lines
2.0 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
me = @
@on "exit", () -> me.quit()
2017-08-24 01:53:13 +02:00
@host = "#desktop"
2017-08-27 23:40:02 +02:00
_OS.setting.applications[@name] = {} if not _OS.setting.applications[@name]
@setting = _OS.setting.applications[@name]
2017-08-24 01:53:13 +02:00
@dialog = undefined
2018-01-22 19:59:08 +01:00
@subscribe "appregistry"
2018-01-24 01:03:14 +01:00
, ( m ) ->
2018-01-22 19:59:08 +01:00
me.applySetting m.data.m if (m.name is me.name)
2018-01-24 01:03:14 +01:00
registry: (k, v) ->
2018-01-22 19:59:08 +01:00
@setting[k] = v
2018-01-24 01:03:14 +01:00
@publish "appregistry", k
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 @
init: ->
#implement by sub class
onexit: (e) ->
#implement by subclass
2018-01-22 19:59:08 +01:00
applySetting: (k) ->
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
2017-08-27 23:40:02 +02:00
openDialog: (d, f, data) ->
2017-08-24 01:53:13 +02:00
if @dialog
@dialog.show()
return
if not _GUI.dialog[d]
@error "Dialog #{d} not found"
return
@dialog = new _GUI.dialog[d]()
@dialog.parent = @
@dialog.handler = f
@dialog.pid = @pid
2017-08-27 23:40:02 +02:00
@dialog.data = data
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) ->
@publish "error", m
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
this.OS.GUI.BaseModel = BaseModel