mirror of
https://github.com/TracksApp/tracks.git
synced 2026-01-06 01:08:50 +01:00
attempt to fix creation of new recurring todo where selector attributes are posted later than other attributes
also fixes some issues when editing an existing rec todo wich handling nil values
This commit is contained in:
parent
47fe6afd14
commit
6b0a235275
3 changed files with 29 additions and 13 deletions
|
|
@ -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?
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -102,11 +102,11 @@
|
|||
</div>
|
||||
<div id="recurring_edit_monthly" style="display:<%= @recurring_todo.recurring_period == 'monthly' ? 'block' : 'none' %>">
|
||||
<label>Recurrence</label><br/>
|
||||
<%= radio_button_tag('recurring_todo[monthly_selector]', 'monthly_every_x_day', @recurring_todo.recurrence_selector == 0)%> Day <%=
|
||||
<%= radio_button_tag('recurring_todo[monthly_selector]', 'monthly_every_x_day', @recurring_todo.is_monthly_every_x_day || @recurring_todo.recurring_period == 'weekly')%> Day <%=
|
||||
text_field_tag('recurring_todo[monthly_every_x_day]', @recurring_todo.monthly_every_x_day, {"size" => 3, "tabindex" => 9}) %> on every <%=
|
||||
text_field_tag('recurring_todo[monthly_every_x_month]', @recurring_todo.monthly_every_x_month, {"size" => 3, "tabindex" => 10}) %> month<br/>
|
||||
<%= radio_button_tag('recurring_todo[monthly_selector]', 'monthly_every_xth_day', @recurring_todo.recurrence_selector == 1)%> The <%=
|
||||
select_tag('recurring_todo[monthly_every_xth_day]', options_for_select(@xth_day, @xth_day[@recurring_todo.monthly_every_xth_day-1][1])) %> <%=
|
||||
<%= radio_button_tag('recurring_todo[monthly_selector]', 'monthly_every_xth_day', @recurring_todo.is_monthly_every_xth_day)%> The <%=
|
||||
select_tag('recurring_todo[monthly_every_xth_day]', options_for_select(@xth_day, @xth_day[@recurring_todo.monthly_every_xth_day(1)-1][1])) %> <%=
|
||||
select_tag('recurring_todo[monthly_day_of_week]' , options_for_select(@days_of_week, @recurring_todo.monthly_day_of_week), {}) %> of every <%=
|
||||
text_field_tag('recurring_todo[monthly_every_x_month2]', @recurring_todo.monthly_every_x_month2, {"size" => 3, "tabindex" => 11}) %> month<br/>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue