From 1394b79f62a87fb433d425b2b661f6122b7363d8 Mon Sep 17 00:00:00 2001 From: damau Date: Tue, 12 Feb 2013 13:48:22 +0000 Subject: [PATCH] added interval array for notifications --- app/controllers/apps_controller.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+), 0 deletions(-) diff --git a/app/controllers/apps_controller.rb b/app/controllers/apps_controller.rb index 6cdd8c5..ffbadbe 100644 --- a/app/controllers/apps_controller.rb +++ b/app/controllers/apps_controller.rb @@ -1,6 +1,7 @@ class AppsController < InheritedResources::Base before_filter :require_admin!, :except => [:index, :show] before_filter :parse_email_at_notices_or_set_default, :only => [:create, :update] + before_filter :parse_notice_at_notices_or_set_default, :only => [:create, :update] respond_to :html def show @@ -105,5 +106,20 @@ class AppsController < InheritedResources::Base end end end + + def parse_notice_at_notices_or_set_default + if params[:app][:notification_service_attributes] && val = params[:app][:notification_service_attributes][:notify_at_notices] + # Sanitize negative values, split on comma, + # strip, parse as integer, remove all '0's. + # If empty, set as default and show an error message. + notify_at_notices = val.gsub(/-\d+/,"").split(",").map{|v| v.strip.to_i } + if notify_at_notices.any? + params[:app][:notification_service_attributes][:notify_at_notices] = notify_at_notices + else + default_array = params[:app][:notification_service_attributes][:notify_at_notices] = Errbit::Config.notify_at_notices + flash[:error] = "Couldn't parse your notification frequency. Value was reset to default (#{default_array.join(', ')})." + end + end + end end -- libgit2 0.21.2