antos-frontend/src/services/PushNotification.coffee

75 lines
2.3 KiB
CoffeeScript
Raw Normal View History

2017-08-15 02:56:04 +02:00
class PushNotification extends this.OS.GUI.BaseService
constructor: () ->
super "PushNotification"
@iconclass = "fa fa-commenting"
@onmenuselect = (e) -> console.log e
@cb = undefined
2017-08-15 02:56:04 +02:00
init: ->
@view = false
path = "resources/schemes/notifications.html"
@render path
main: ->
me = @
2017-08-24 01:53:13 +02:00
@mlist = @find "notifylist"
@mfeed = @find "notifeed"
2017-08-17 00:42:05 +02:00
@nzone = @find "notifyzone"
2017-08-24 01:53:13 +02:00
(@find "btclear").set "onbtclick", (e) -> me.mlist.set "items", []
2017-08-17 00:42:05 +02:00
#mlist.set "onlistselect", (e) -> console.log e
2017-08-24 01:53:13 +02:00
@subscribe "notification", (o) -> me.pushout 'INFO', o
@subscribe "fail", (o) -> me.pushout 'FAIL', o
@subscribe "error", (o) -> me.pushout 'ERROR', o
2017-08-17 00:42:05 +02:00
($ @nzone).css "right", 0
.css "top", "-3px"
.css "height", ""
.css "bottom", "0"
.hide()
2017-08-24 01:53:13 +02:00
($ @mfeed).css "right", "5px"
.css "top", "0"
2017-08-24 01:53:13 +02:00
pushout: (s, o, mfeed) ->
d = {
text: "#{o.name} (#{o.id}) - #{s}: #{o.data.m}",
icon: o.data.icon,
iconclass: o.data.iconclass,
closable: true }
d1 = {
header: "#{o.name} (#{o.id})"
text: "#{s}: #{o.data.m}",
icon: o.data.icon,
iconclass: o.data.iconclass,
closable: true }
@mlist.push d, true
@notifeed d1
notifeed: (d) ->
me = @
@mfeed.push d, true
($ @mfeed).show()
timer = setTimeout () ->
2017-08-24 01:53:13 +02:00
me.mfeed.remove d, true
2017-08-17 00:42:05 +02:00
clearTimeout timer
, 3000
awake: (e) ->
2017-08-17 00:42:05 +02:00
if @view then ($ @nzone).hide() else ($ @nzone).show()
@view = not @view
me = @
if not @cb
@cb = (e) ->
return if e.originalEvent.item and e.originalEvent.item.closable
2017-08-17 00:42:05 +02:00
if not ($ e.target).closest($ me.nzone).length and not ($ e.target).closest($ me.holder.root).length
($ me.nzone).hide()
$(document).unbind "click", me.cb
me.view = not me.view
if @view
$(document).on "click", @cb
else
$(document).unbind "click", @cb
cleanup: (evt) ->
2017-08-15 02:56:04 +02:00
# do nothing
this.OS.register "PushNotification",PushNotification