diff --git a/app/controllers/recurring_todos_controller.rb b/app/controllers/recurring_todos_controller.rb index 3b0101f9..7717dc83 100644 --- a/app/controllers/recurring_todos_controller.rb +++ b/app/controllers/recurring_todos_controller.rb @@ -82,7 +82,8 @@ class RecurringTodosController < ApplicationController def create p = RecurringTodoCreateParamsHelper.new(params) - @recurring_todo = current_user.recurring_todos.build(p.attributes) + @recurring_todo = current_user.recurring_todos.build(p.selector_attributes) + @recurring_todo.update_attributes(p.attributes) if p.project_specified_by_name? project = current_user.projects.find_or_create_by_name(p.project_name) @@ -185,22 +186,26 @@ class RecurringTodosController < ApplicationController def initialize(params) @params = params['request'] || params - attr = params['request'] && params['request']['recurring_todo'] || params['recurring_todo'] + @attributes = params['request'] && params['request']['recurring_todo'] || params['recurring_todo'] # make sure all selectors (recurring_period, recurrence_selector, # daily_selector, monthly_selector and yearly_selector) are first in hash # so that they are processed first by the model - @attributes = { - 'recurring_period' => attr['recurring_period'], - 'daily_selector' => attr['daily_selector'], - 'monthly_selector' => attr['monthly_selector'], - 'yearly_selector' => attr['yearly_selector'] - }.merge(attr) + @selector_attributes = { + 'recurring_period' => @attributes['recurring_period'], + 'daily_selector' => @attributes['daily_selector'], + 'monthly_selector' => @attributes['monthly_selector'], + 'yearly_selector' => @attributes['yearly_selector'] + } end def attributes @attributes end + + def selector_attributes + return @selector_attributes + end def project_name @params['project_name'].strip unless @params['project_name'].nil? diff --git a/app/models/recurring_todo.rb b/app/models/recurring_todo.rb index d40b4d42..66012735 100644 --- a/app/models/recurring_todo.rb +++ b/app/models/recurring_todo.rb @@ -170,6 +170,16 @@ class RecurringTodo < ActiveRecord::Base return self.every_other1 end + def is_monthly_every_x_day + return self.recurrence_selector == 0 if recurring_period == 'monthly' + return false + end + + def is_monthly_every_xth_day + return self.recurrence_selector == 1 if recurring_period == 'monthly' + return false + end + def monthly_every_x_month=(x) self.every_other2 = x if recurring_period=='monthly' && recurrence_selector == 0 end @@ -202,8 +212,9 @@ class RecurringTodo < ActiveRecord::Base self.every_other3 = x if recurring_period=='monthly' end - def monthly_every_xth_day - return self.every_other3 + def monthly_every_xth_day(default=nil) + return self.every_other3 unless self.every_other3.nil? + return default end def monthly_day_of_week=(dow) diff --git a/app/views/recurring_todos/_edit_form.html.erb b/app/views/recurring_todos/_edit_form.html.erb index 11f8ec5c..a134a627 100644 --- a/app/views/recurring_todos/_edit_form.html.erb +++ b/app/views/recurring_todos/_edit_form.html.erb @@ -102,11 +102,11 @@