Module: Platformx::NotifyHelpers

Defined in:
lib/platformx/notify.rb

Overview

Notification helpers

Author:

  • Tim Mushen

Instance Method Summary collapse

Instance Method Details

#x_notify(flash: "", timer: 4000, align: "right", from: "top") ⇒ String

Notify view helper

Parameters:

  • flash (Object) (defaults to: "")

    flash object

  • timer (Integer) (defaults to: 4000)

    the length the notify should show

  • align (String) (defaults to: "right")

    the alignment of the notify (left or right)

  • from (String) (defaults to: "top")

    the location of the notify

Returns:

  • (String)

    rendered notify message (js script)



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/platformx/notify.rb', line 13

def x_notify(flash: "", timer: 4000, align: "right", from:"top")

color = "success"
message = ""

if !flash[:success].nil?
  message = flash[:success]
  color = "success"
end

if !flash[:notice].nil?
  message = flash[:notice]
  color = "warning"
end

if !flash[:error].nil?
  message = flash[:error]
  color = "danger"
end

unless message == ""
cb = <<EOS
<script>
    $().ready(function(){$.notify({message: "#{message}"},{type: "#{color}",timer: #{timer}, placement: {from: "#{from}",align: "#{align}"}});});
</script>
EOS
return cb
end
end