mirror of
https://github.com/TracksApp/tracks.git
synced 2026-01-23 17:26:11 +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
|
|
@ -101,14 +101,6 @@ class RecurringTodo < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
def recurring_show_days_before=(days)
|
||||
self.show_from_delta=days
|
||||
end
|
||||
|
||||
def recurring_show_always=(value)
|
||||
self.show_always=value
|
||||
end
|
||||
|
||||
def daily_recurrence_pattern
|
||||
if only_work_days
|
||||
I18n.t("todos.recurrence.pattern.on_work_days")
|
||||
|
|
|
|||
|
|
@ -22,15 +22,10 @@ module RecurringTodos
|
|||
def build
|
||||
@recurring_todo = @pattern.build_recurring_todo(@mapped_attributes)
|
||||
|
||||
@recurring_todo.context = @filterred_attributes.get(:context)
|
||||
@recurring_todo.project = @filterred_attributes.get(:project)
|
||||
end
|
||||
|
||||
def update(recurring_todo)
|
||||
@recurring_todo = @pattern.update_recurring_todo(recurring_todo, @mapped_attributes)
|
||||
@recurring_todo.context = @filterred_attributes.get(:context)
|
||||
@recurring_todo.project = @filterred_attributes.get(:project)
|
||||
|
||||
@saved = @recurring_todo.save
|
||||
@recurring_todo.tag_with(@filterred_attributes.get(:tag_list)) if @saved && @filterred_attributes.get(:tag_list).present?
|
||||
@recurring_todo.reload
|
||||
|
|
@ -45,6 +40,22 @@ module RecurringTodos
|
|||
return @saved
|
||||
end
|
||||
|
||||
def save_collection(collection, collection_id)
|
||||
# save object (project or context) and add its id to @mapped_attributes and remove the object from the attributes
|
||||
object = @mapped_attributes.get(collection)
|
||||
object.save
|
||||
@mapped_attributes.set(collection_id, object.id)
|
||||
@mapped_attributes.except(collection)
|
||||
end
|
||||
|
||||
def save_project
|
||||
save_collection(:project, :project_id)
|
||||
end
|
||||
|
||||
def save_context
|
||||
save_collection(:context, :context_id)
|
||||
end
|
||||
|
||||
def saved_recurring_todo
|
||||
raise(Exception.new, @recurring_todo.valid? ? "Recurring todo was not saved yet" : "Recurring todos was not saved because of validation errors") unless @saved
|
||||
|
||||
|
|
|
|||
|
|
@ -33,11 +33,11 @@ module RecurringTodos
|
|||
end
|
||||
|
||||
def build_recurring_todo(attribute_handler)
|
||||
@recurring_todo = @user.recurring_todos.build(attribute_handler.attributes)
|
||||
@recurring_todo = @user.recurring_todos.build(attribute_handler.safe_attributes)
|
||||
end
|
||||
|
||||
def update_recurring_todo(recurring_todo, attribute_handler)
|
||||
recurring_todo.assign_attributes(attribute_handler.attributes)
|
||||
recurring_todo.assign_attributes(attribute_handler.safe_attributes)
|
||||
recurring_todo
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -14,10 +14,18 @@ module RecurringTodos
|
|||
get(:recurrence_selector) == 0
|
||||
end
|
||||
|
||||
def every_x_day
|
||||
get(:every_other1)
|
||||
end
|
||||
|
||||
def every_xth_day?
|
||||
get(:recurrence_selector) == 1
|
||||
end
|
||||
|
||||
def every_xth_day
|
||||
get :every_other2
|
||||
end
|
||||
|
||||
def every_x_month
|
||||
# in case monthly pattern is every day x, return every_other2 otherwise
|
||||
# return a default value
|
||||
|
|
|
|||
|
|
@ -32,8 +32,8 @@ module RecurringTodos
|
|||
end
|
||||
|
||||
def save
|
||||
@project.save if @new_project_created
|
||||
@context.save if @new_context_created
|
||||
@builder.save_project if @new_project_created
|
||||
@builder.save_context if @new_context_created
|
||||
|
||||
return @builder.save
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue