Commit 1394b79f62a87fb433d425b2b661f6122b7363d8

Authored by damau
1 parent 210ce8ac
Exists in master and in 1 other branch production

added interval array for notifications

Showing 1 changed file with 16 additions and 0 deletions   Show diff stats
app/controllers/apps_controller.rb
1 1 class AppsController < InheritedResources::Base
2 2 before_filter :require_admin!, :except => [:index, :show]
3 3 before_filter :parse_email_at_notices_or_set_default, :only => [:create, :update]
  4 + before_filter :parse_notice_at_notices_or_set_default, :only => [:create, :update]
4 5 respond_to :html
5 6  
6 7 def show
... ... @@ -105,5 +106,20 @@ class AppsController &lt; InheritedResources::Base
105 106 end
106 107 end
107 108 end
  109 +
  110 + def parse_notice_at_notices_or_set_default
  111 + if params[:app][:notification_service_attributes] && val = params[:app][:notification_service_attributes][:notify_at_notices]
  112 + # Sanitize negative values, split on comma,
  113 + # strip, parse as integer, remove all '0's.
  114 + # If empty, set as default and show an error message.
  115 + notify_at_notices = val.gsub(/-\d+/,"").split(",").map{|v| v.strip.to_i }
  116 + if notify_at_notices.any?
  117 + params[:app][:notification_service_attributes][:notify_at_notices] = notify_at_notices
  118 + else
  119 + default_array = params[:app][:notification_service_attributes][:notify_at_notices] = Errbit::Config.notify_at_notices
  120 + flash[:error] = "Couldn't parse your notification frequency. Value was reset to default (#{default_array.join(', ')})."
  121 + end
  122 + end
  123 + end
108 124 end
109 125  
... ...