2017-08-16 00:27:32 +02:00
|
|
|
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
|
2017-08-16 00:27:32 +02:00
|
|
|
|
|
|
|
render: (p) ->
|
2017-08-24 01:53:13 +02:00
|
|
|
_GUI.loadScheme p, @, @host
|
2017-08-16 00:27:32 +02:00
|
|
|
|
|
|
|
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
|
2017-08-16 00:27:32 +02:00
|
|
|
_PM.kill @
|
|
|
|
|
|
|
|
init: ->
|
|
|
|
#implement by sub class
|
|
|
|
onexit: (e) ->
|
|
|
|
#implement by subclass
|
2017-08-26 16:50:13 +02:00
|
|
|
one: (e, f) -> @observable.one e, f
|
2017-08-16 00:27:32 +02:00
|
|
|
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-26 16:50:13 +02:00
|
|
|
@dialog.init()
|
2017-08-17 00:42:05 +02:00
|
|
|
|
2017-08-16 00:27:32 +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
|
|
|
|
2017-08-16 00:27:32 +02:00
|
|
|
notify: (m) ->
|
|
|
|
@publish "notification", m
|
2017-08-17 00:42:05 +02:00
|
|
|
|
2017-08-16 00:27:32 +02:00
|
|
|
warn: (m) ->
|
|
|
|
@publish "warning", m
|
2017-08-17 00:42:05 +02:00
|
|
|
|
2017-08-16 00:27:32 +02:00
|
|
|
error: (m) ->
|
|
|
|
@publish "error", m
|
2017-08-17 00:42:05 +02:00
|
|
|
|
2017-08-16 00:27:32 +02:00
|
|
|
fail: (m) ->
|
|
|
|
@publish "fail", m
|
|
|
|
|
|
|
|
|
|
|
|
find: (id) -> ($ "[data-id='#{id}']", @scheme)[0] if @scheme
|
|
|
|
|
|
|
|
this.OS.GUI.BaseModel = BaseModel
|