antos-frontend/src/core/BaseModel.coffee

62 lines
1.4 KiB
CoffeeScript
Raw Normal View History

class BaseModel
constructor: (@name) ->
@observable = riot.observable()
@_api = self.OS.API
me = @
@on "exit", () -> me.quit()
2017-08-24 01:53:13 +02:00
@host = "#desktop"
@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 @
init: ->
#implement by sub class
onexit: (e) ->
#implement by subclass
on: (e, f) -> @observable.on e, f
trigger: (e, d) -> @observable.trigger e, d
2017-08-24 01:53:13 +02:00
subscribe: (e, f) -> _courrier.on e, f, @
openDialog: (d, f) ->
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-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
find: (id) -> ($ "[data-id='#{id}']", @scheme)[0] if @scheme
this.OS.GUI.BaseModel = BaseModel