Sha256: be161aebbb4cde02ed2e476699660fcff585dffae50534f87b8261fe0431a125

Contents?: true

Size: 1.23 KB

Versions: 46

Compression:

Stored size: 1.23 KB

Contents

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

  def configure_notification
    if defined?(@notification)
      @notification.reverse_merge!(default_notification_configuration)
    else
      @notification = default_notification_configuration
    end
  end
  
  # 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")
  def set_notification(success, title, message)
    @notification[:success] = success
    @notification[:title] = title
    @notification[:message] = message
  end

  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

end

Version data entries

46 entries across 46 versions & 1 rubygems

Version Path
kuppayam-0.2.12.pre.materialize app/helpers/notification_helper.rb
kuppayam-0.2.11.pre.materialize app/helpers/notification_helper.rb
kuppayam-0.2.10.pre.materialize app/helpers/notification_helper.rb
kuppayam-0.2.9.pre.materialize app/helpers/notification_helper.rb
kuppayam-0.2.8.pre.materialize app/helpers/notification_helper.rb
kuppayam-0.2.7.pre.materialize app/helpers/notification_helper.rb
kuppayam-0.2.6.pre.materialize app/helpers/notification_helper.rb
kuppayam-0.2.5.pre.materialize app/helpers/notification_helper.rb
kuppayam-0.2.4.pre.materialize app/helpers/notification_helper.rb
kuppayam-0.2.3.pre.materialize app/helpers/notification_helper.rb
kuppayam-0.2.2.pre.materialize app/helpers/notification_helper.rb
kuppayam-0.2.1.pre.materialize app/helpers/notification_helper.rb
kuppayam-0.2.0.pre.materialize app/helpers/notification_helper.rb
kuppayam-0.1.39 app/helpers/notification_helper.rb
kuppayam-0.1.38 app/helpers/notification_helper.rb
kuppayam-0.1.37 app/helpers/notification_helper.rb
kuppayam-0.1.36 app/helpers/notification_helper.rb
kuppayam-0.1.35 app/helpers/notification_helper.rb
kuppayam-0.1.34 app/helpers/notification_helper.rb
kuppayam-0.1.33 app/helpers/notification_helper.rb