Module: NotificationHelper

Included in:
Kuppayam::BaseController
Defined in:
app/helpers/notification_helper.rb

Instance Method Summary collapse

Instance Method Details

#configure_notificationObject



11
12
13
14
15
16
17
# File 'app/helpers/notification_helper.rb', line 11

def configure_notification
  if defined?(@notification)
    @notification.reverse_merge!(default_notification_configuration)
  else
    @notification = default_notification_configuration
  end
end

#default_notification_configurationObject



3
4
5
6
7
8
9
# File 'app/helpers/notification_helper.rb', line 3

def default_notification_configuration
  {
    success: false,
    title: "<NOT SET>",
    message: "<NO MESSAGE SET>"
  }
end

#set_notification(success, title, message) ⇒ Object

This function will set a notification message depending up on the request type (ajax - xml http or direct http) Example

set_notification("Success", "The message has been sent successfully")
set_notification("Success", "Permission denied")


23
24
25
26
27
# File 'app/helpers/notification_helper.rb', line 23

def set_notification(success, title, message)
  @notification[:success] = success
  @notification[:title] = title
  @notification[:message] = message
end

#set_resource_notification(obj) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
# File 'app/helpers/notification_helper.rb', line 29

def set_resource_notification(obj)
  if obj.errors.any?
    @notification[:success] = false
    @notification[:title] = I18n.translate("status.error")
    @notification[:message] = obj.errors.full_messages.join("<br>")
  else
    @notification[:success] = true
    @notification[:title] = I18n.translate("status.success")
    @notification[:message] = I18n.translate("success.saved", item: default_item_name.titleize)
  end
end