Class: Notification::MainController
- Inherits:
-
Volt::ModelController
- Object
- Volt::ModelController
- Notification::MainController
- Defined in:
- app/notification/controllers/main_controller.rb
Instance Method Summary collapse
- #auto_close_time ⇒ Object
- #default_icon ⇒ Object
- #direction ⇒ Object
- #index ⇒ Object
- #volt_notify(msg) ⇒ Object
Instance Method Details
#auto_close_time ⇒ Object
22 23 24 25 26 |
# File 'app/notification/controllers/main_controller.rb', line 22 def auto_close_time #puts attrs.auto_close_time attrs.auto_close_time ? attrs.auto_close_time.to_i : 0 end |
#default_icon ⇒ Object
28 29 30 |
# File 'app/notification/controllers/main_controller.rb', line 28 def default_icon attrs.default_icon ? attrs.default_icon : 'favicon.ico' end |
#direction ⇒ Object
32 33 34 |
# File 'app/notification/controllers/main_controller.rb', line 32 def direction attrs.direction ? attrs.direction : 'auto' end |
#index ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'app/notification/controllers/main_controller.rb', line 4 def index puts 'Hello from Notification Component Setup' page..on('added') do |pos| puts "message_added #{pos.to_s}" notification = page.[pos] volt_notify(notification) end Volt.current_user.then do |user | user..on('added') do |pos| puts "message_added #{pos.to_s}" notification = page.[pos] volt_notify(notification) end if user end end |
#volt_notify(msg) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'app/notification/controllers/main_controller.rb', line 36 def volt_notify(msg) #puts "volt_notify" if `'Notification' in window` #puts "has Notifican Object" ` if (!window.Notification.permission) { console.log('requesting permission') window.Notification.requestPermission(); }` if (`window.Notification.permission`) puts "has permission: #{msg.body}" ztitle = msg.title zbody = msg.body zdir = msg.direction ? msg.direction : direction zlang = msg.language zicon = msg.icon && msg.icon != '' ? msg.icon : default_icon ztag = msg.tag `notification = new window.Notification(ztitle, {dir: zdir, lang: zlang, icon: zicon, tag: ztag, body: zbody});` #puts notification end if (auto_close_time > 0) act = auto_close_time puts "autoclose" `setTimeout(function () { notification.close(); //closes the notification }, act);` end end end |