2017-08-15 02:56:04 +02:00
|
|
|
class PushNotification extends this.OS.GUI.BaseService
|
2017-08-27 23:40:02 +02:00
|
|
|
constructor: (args) ->
|
|
|
|
super "PushNotification", args
|
2017-08-26 16:50:13 +02:00
|
|
|
@iconclass = "fa fa-bars"
|
2017-08-16 00:27:32 +02:00
|
|
|
@onmenuselect = (e) -> console.log e
|
|
|
|
@cb = undefined
|
2017-08-26 16:50:13 +02:00
|
|
|
@pending = []
|
2017-08-15 02:56:04 +02:00
|
|
|
init: ->
|
2017-08-16 00:27:32 +02:00
|
|
|
@view = false
|
2018-01-23 10:10:40 +01:00
|
|
|
path = path = "packages/CoreServices/notifications.html"
|
2017-08-16 00:27:32 +02:00
|
|
|
@render path
|
|
|
|
|
2017-08-26 16:50:13 +02:00
|
|
|
spin: (b) ->
|
|
|
|
if b and @iconclass is "fa fa-bars"
|
|
|
|
@iconclass = "fa fa-spinner fa-spin"
|
2017-08-27 23:40:02 +02:00
|
|
|
@color = "#f90e00"
|
2017-08-26 16:50:13 +02:00
|
|
|
@update()
|
|
|
|
else if not b and @iconclass is "fa fa-spinner fa-spin"
|
|
|
|
@iconclass = "fa fa-bars"
|
2017-08-27 23:40:02 +02:00
|
|
|
@color = "#414339"
|
2017-08-26 16:50:13 +02:00
|
|
|
@update()
|
|
|
|
|
2017-08-16 00:27:32 +02:00
|
|
|
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-26 16:50:13 +02:00
|
|
|
@fzone = @find "feedzone"
|
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-26 16:50:13 +02:00
|
|
|
|
|
|
|
@subscribe "loading", (o) ->
|
|
|
|
me.pending.push o.id
|
|
|
|
me.spin true
|
2017-08-16 00:27:32 +02:00
|
|
|
|
2017-08-26 16:50:13 +02:00
|
|
|
@subscribe "loaded", (o) ->
|
|
|
|
i = me.pending.indexOf o.id
|
|
|
|
me.pending.splice i, 1 if i >= 0
|
|
|
|
me.spin false if me.pending.length is 0
|
|
|
|
|
2017-08-17 00:42:05 +02:00
|
|
|
($ @nzone).css "right", 0
|
2017-08-16 00:27:32 +02:00
|
|
|
.css "top", "-3px"
|
|
|
|
.css "height", ""
|
|
|
|
.css "bottom", "0"
|
2017-08-26 16:50:13 +02:00
|
|
|
.css "z-index", 1000000
|
|
|
|
.hide()
|
|
|
|
($ @fzone)
|
|
|
|
#.css("z-index", 99999)
|
|
|
|
.css("bottom", "0")
|
|
|
|
.css("height", "")
|
2017-08-16 00:27:32 +02:00
|
|
|
.hide()
|
|
|
|
|
2017-08-24 01:53:13 +02:00
|
|
|
pushout: (s, o, mfeed) ->
|
|
|
|
d = {
|
2017-08-25 00:18:35 +02:00
|
|
|
text: "[#{s}] #{o.name} (#{o.id}): #{o.data.m}",
|
2017-08-24 01:53:13 +02:00
|
|
|
icon: o.data.icon,
|
|
|
|
iconclass: o.data.iconclass,
|
|
|
|
closable: true }
|
2017-08-26 16:50:13 +02:00
|
|
|
@mlist.unshift d, true
|
|
|
|
@notifeed d
|
2017-08-24 01:53:13 +02:00
|
|
|
|
|
|
|
notifeed: (d) ->
|
|
|
|
me = @
|
2017-08-26 16:50:13 +02:00
|
|
|
@mfeed.unshift d, true
|
|
|
|
($ @fzone).show()
|
2017-08-16 00:27:32 +02:00
|
|
|
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
|
2017-08-16 00:27:32 +02:00
|
|
|
, 3000
|
|
|
|
|
|
|
|
awake: (e) ->
|
2017-08-17 00:42:05 +02:00
|
|
|
if @view then ($ @nzone).hide() else ($ @nzone).show()
|
2017-08-16 00:27:32 +02:00
|
|
|
@view = not @view
|
|
|
|
me = @
|
|
|
|
if not @cb
|
|
|
|
@cb = (e) ->
|
2017-08-26 16:50:13 +02:00
|
|
|
return if e.originalEvent.item and e.originalEvent.item.i isnt undefined
|
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()
|
2017-08-16 00:27:32 +02:00
|
|
|
$(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
|