2017-08-16 00:27:32 +02:00
|
|
|
class BaseModel
|
2017-08-27 23:40:02 +02:00
|
|
|
constructor: (@name, @args) ->
|
2017-08-16 00:27:32 +02:00
|
|
|
@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
|
2018-01-24 15:03:33 +01:00
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
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
|
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
|
|
|
|
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) ->
|
2018-01-24 15:03:33 +01:00
|
|
|
@publish "error", m + (@_api.throwe @name)
|
2017-08-17 00:42:05 +02:00
|
|
|
|
2017-08-16 00:27:32 +02:00
|
|
|
fail: (m) ->
|
|
|
|
@publish "fail", m
|
|
|
|
|
2018-01-24 01:03:14 +01:00
|
|
|
throwe: () ->
|
|
|
|
@_api.throwe @name
|
2017-08-16 00:27:32 +02:00
|
|
|
|
|
|
|
find: (id) -> ($ "[data-id='#{id}']", @scheme)[0] if @scheme
|
|
|
|
|
|
|
|
this.OS.GUI.BaseModel = BaseModel
|