mirror of
https://github.com/TracksApp/tracks.git
synced 2026-02-21 06:34:07 +01:00
fix updating of recurring todo and create a form helper for filling the recurring todo edit
form
This commit is contained in:
parent
59a29c664a
commit
b23338eaa2
9 changed files with 166 additions and 72 deletions
50
app/controllers/recurring_todos/form_helper.rb
Normal file
50
app/controllers/recurring_todos/form_helper.rb
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
module RecurringTodos
|
||||
|
||||
class FormHelper
|
||||
|
||||
def initialize(recurring_todo)
|
||||
@recurring_todo = recurring_todo
|
||||
end
|
||||
|
||||
def create_pattern(pattern_class)
|
||||
pattern = pattern_class.new(@recurring_todo.user)
|
||||
pattern.build_from_recurring_todo(@recurring_todo)
|
||||
pattern
|
||||
end
|
||||
|
||||
def daily_pattern
|
||||
@daily_pattern ||= create_pattern(DailyRepeatPattern)
|
||||
end
|
||||
|
||||
def weekly_pattern
|
||||
@weekly_pattern ||= create_pattern(WeeklyRepeatPattern)
|
||||
end
|
||||
|
||||
def monthly_pattern
|
||||
@monthly_pattern ||= create_pattern(MonthlyRepeatPattern)
|
||||
end
|
||||
|
||||
def yearly_pattern
|
||||
@yearly_pattern ||= create_pattern(YearlyRepeatPattern)
|
||||
end
|
||||
|
||||
def method_missing(method, *args)
|
||||
if method.to_s =~ /^daily_(.+)$/
|
||||
daily_pattern.send($1, *args)
|
||||
elsif method.to_s =~ /^weekly_(.+)$/
|
||||
weekly_pattern.send($1, *args)
|
||||
elsif method.to_s =~ /^monthly_(.+)$/
|
||||
monthly_pattern.send($1, *args)
|
||||
elsif method.to_s =~ /^yearly_(.+)$/
|
||||
yearly_pattern.send($1, *args)
|
||||
elsif method.to_s =~ /^on_(.+)$/ # on_monday, on_tuesday, etc.
|
||||
weekly_pattern.send(method, *args)
|
||||
else
|
||||
# no match, let @recurring_todo handle it, or fail
|
||||
@recurring_todo.send(method, *args)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -37,13 +37,15 @@ class RecurringTodosController < ApplicationController
|
|||
end
|
||||
|
||||
def edit
|
||||
@form_helper = RecurringTodos::FormHelper.new(@recurring_todo)
|
||||
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
updater = RecurringTodos::RecurringTodosBuilder.new(current_user, edit_recurring_todo_params)
|
||||
updater = RecurringTodos::RecurringTodosBuilder.new(current_user, update_recurring_todo_params)
|
||||
@saved = updater.update(@recurring_todo)
|
||||
|
||||
@recurring_todo.reload
|
||||
|
|
@ -162,23 +164,29 @@ class RecurringTodosController < ApplicationController
|
|||
|
||||
def all_recurring_todo_params
|
||||
# move context_name, project_name and tag_list into :recurring_todo hash for easier processing
|
||||
{ context_name: :context_name, project_name: :project_name, tag_list: :tag_list}.each do |target,source|
|
||||
{
|
||||
context_name: :context_name,
|
||||
project_name: :project_name,
|
||||
tag_list: :tag_list
|
||||
}.each do |target,source|
|
||||
move_into_recurring_todo_param(params, target, source)
|
||||
end
|
||||
recurring_todo_params
|
||||
end
|
||||
|
||||
def edit_recurring_todo_params
|
||||
def update_recurring_todo_params
|
||||
# we needed to rename the recurring_period selector in the edit form because
|
||||
# the form for a new recurring todo and the edit form are on the same page.
|
||||
# Same goes for start_from and end_date
|
||||
params['recurring_todo']['recurring_period'] = params['recurring_edit_todo']['recurring_period']
|
||||
|
||||
{ context_name: :context_name,
|
||||
{
|
||||
context_name: :context_name,
|
||||
project_name: :project_name,
|
||||
tag_list: :edit_recurring_todo_tag_list,
|
||||
end_date: :recurring_todo_edit_end_date,
|
||||
start_from: :recurring_todo_edit_start_from}.each do |target,source|
|
||||
start_from: :recurring_todo_edit_start_from
|
||||
}.each do |target,source|
|
||||
move_into_recurring_todo_param(params, target, source)
|
||||
end
|
||||
|
||||
|
|
@ -187,7 +195,8 @@ class RecurringTodosController < ApplicationController
|
|||
%w{monday tuesday wednesday thursday friday saturday sunday}.each do |day|
|
||||
params["recurring_todo"]["weekly_return_#{day}"]=' ' if params["recurring_todo"]["weekly_return_#{day}"].nil?
|
||||
end
|
||||
params['recurring_todo']
|
||||
|
||||
recurring_todo_params
|
||||
end
|
||||
|
||||
def move_into_recurring_todo_param(params, target, source)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue