mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-16 23:30:12 +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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -5,91 +5,91 @@
|
|||
<div id="recurring_todo_form_container">
|
||||
<div id="recurring_todo">
|
||||
<label for="recurring_todo_description"><%= Todo.human_attribute_name('description') %></label><%=
|
||||
text_field_tag( "recurring_todo[description]", @recurring_todo.description, "size" => 30, "maxlength" => 100, :id => "edit_recurring_todo_description") -%>
|
||||
text_field_tag( "recurring_todo[description]", @form_helper.description, "size" => 30, "maxlength" => 100, :id => "edit_recurring_todo_description") -%>
|
||||
|
||||
<label for="recurring_todo_notes"><%= Todo.human_attribute_name('notes') %></label><%=
|
||||
text_area_tag( "recurring_todo[notes]", @recurring_todo.notes, {:cols => 29, :rows => 6}) -%>
|
||||
text_area_tag( "recurring_todo[notes]", @form_helper.notes, {:cols => 29, :rows => 6}) -%>
|
||||
|
||||
<label for="edit_recurring_todo_project_name"><%= Todo.human_attribute_name('project') %></label>
|
||||
<input id="edit_recurring_todo_project_name" name="project_name" autocomplete="off" size="30" type="text" value="<%= @recurring_todo.project.nil? ? 'None' : @recurring_todo.project.name.gsub(/"/,""") %>" />
|
||||
<input id="edit_recurring_todo_project_name" name="project_name" autocomplete="off" size="30" type="text" value="<%= @form_helper.project.nil? ? 'None' : @form_helper.project.name.gsub(/"/,""") %>" />
|
||||
<div class="page_name_auto_complete" id="edit_project_list" style="display:none"></div>
|
||||
|
||||
<label for="edit_recurring_todo_context_name"><%= Todo.human_attribute_name('context') %></label>
|
||||
<input id="edit_recurring_todo_context_name" name="context_name" autocomplete="off" size="30" type="text" value="<%= @recurring_todo.context.name %>" />
|
||||
<input id="edit_recurring_todo_context_name" name="context_name" autocomplete="off" size="30" type="text" value="<%= @form_helper.context.name %>" />
|
||||
<div class="page_name_auto_complete" id="edit_context_list" style="display:none"></div>
|
||||
|
||||
<label for="edit_recurring_todo_tag_list"><%= "#{Todo.human_attribute_name('tags')} #{t('shared.separate_tags_with_commas')}"%></label>
|
||||
<%= text_field_tag "edit_recurring_todo_tag_list", @recurring_todo.tag_list, :size => 30 -%>
|
||||
<%= text_field_tag "edit_recurring_todo_tag_list", @form_helper.tag_list, :size => 30 -%>
|
||||
</div>
|
||||
</div>
|
||||
<div id="recurring_edit_period_id">
|
||||
<div id="recurring_edit_period">
|
||||
<label><%= t('todos.recurrence_period') %></label><br/>
|
||||
<%= radio_button_tag('recurring_edit_todo[recurring_period]', 'daily', @recurring_todo.recurring_period == 'daily')%> <%= t('todos.recurrence.daily') %><br/>
|
||||
<%= radio_button_tag('recurring_edit_todo[recurring_period]', 'weekly', @recurring_todo.recurring_period == 'weekly')%> <%= t('todos.recurrence.weekly') %><br/>
|
||||
<%= radio_button_tag('recurring_edit_todo[recurring_period]', 'monthly', @recurring_todo.recurring_period == 'monthly')%> <%= t('todos.recurrence.monthly') %><br/>
|
||||
<%= radio_button_tag('recurring_edit_todo[recurring_period]', 'yearly', @recurring_todo.recurring_period == 'yearly')%> <%= t('todos.recurrence.yearly') %><br/>
|
||||
<%= radio_button_tag('recurring_edit_todo[recurring_period]', 'daily', @form_helper.recurring_period == 'daily')%> <%= t('todos.recurrence.daily') %><br/>
|
||||
<%= radio_button_tag('recurring_edit_todo[recurring_period]', 'weekly', @form_helper.recurring_period == 'weekly')%> <%= t('todos.recurrence.weekly') %><br/>
|
||||
<%= radio_button_tag('recurring_edit_todo[recurring_period]', 'monthly', @form_helper.recurring_period == 'monthly')%> <%= t('todos.recurrence.monthly') %><br/>
|
||||
<%= radio_button_tag('recurring_edit_todo[recurring_period]', 'yearly', @form_helper.recurring_period == 'yearly')%> <%= t('todos.recurrence.yearly') %><br/>
|
||||
</div>
|
||||
<div id="recurring_timespan">
|
||||
<br/>
|
||||
<label for="recurring_todo[start_from]"><%= t('todos.recurrence.starts_on') %>: </label><%=
|
||||
text_field_tag("recurring_todo_edit_start_from", format_date(@recurring_todo.start_from), "size" => 12, "class" => "Date", "autocomplete" => "off") %><br/>
|
||||
text_field_tag("recurring_todo_edit_start_from", format_date(@form_helper.start_from), "size" => 12, "class" => "Date", "autocomplete" => "off") %><br/>
|
||||
<br/>
|
||||
<label for="recurring_todo[ends_on]"><%= t('todos.recurrence.ends_on') %>:</label><br/>
|
||||
<%= radio_button_tag('recurring_todo[ends_on]', 'no_end_date', @recurring_todo.ends_on == 'no_end_date')%> <%= t('todos.recurrence.no_end_date') %><br/>
|
||||
<%= radio_button_tag('recurring_todo[ends_on]', 'ends_on_number_of_times', @recurring_todo.ends_on == 'ends_on_number_of_times')%>
|
||||
<%= radio_button_tag('recurring_todo[ends_on]', 'no_end_date', @form_helper.ends_on == 'no_end_date')%> <%= t('todos.recurrence.no_end_date') %><br/>
|
||||
<%= radio_button_tag('recurring_todo[ends_on]', 'ends_on_number_of_times', @form_helper.ends_on == 'ends_on_number_of_times')%>
|
||||
<%= raw t('todos.recurrence.ends_on_number_times', :number => text_field( :recurring_todo, :number_of_occurences, "size" => 3)) %><br/>
|
||||
<%= radio_button_tag('recurring_todo[ends_on]', 'ends_on_end_date', @recurring_todo.ends_on == 'ends_on_end_date')%>
|
||||
<%= raw t('todos.recurrence.ends_on_date', :date => text_field_tag('recurring_todo_edit_end_date', format_date(@recurring_todo.end_date), "size" => 12, "class" => "Date", "autocomplete" => "off")) %><br/>
|
||||
<%= radio_button_tag('recurring_todo[ends_on]', 'ends_on_end_date', @form_helper.ends_on == 'ends_on_end_date')%>
|
||||
<%= raw t('todos.recurrence.ends_on_date', :date => text_field_tag('recurring_todo_edit_end_date', format_date(@form_helper.end_date), "size" => 12, "class" => "Date", "autocomplete" => "off")) %><br/>
|
||||
</div></div>
|
||||
<div id="recurring_edit_daily" style="display:<%= @recurring_todo.recurring_period == 'daily' ? 'block' : 'none' %> ">
|
||||
<div id="recurring_edit_daily" style="display:<%= @form_helper.recurring_period == 'daily' ? 'block' : 'none' %> ">
|
||||
<label><%= t('todos.recurrence.daily_options') %></label><br/>
|
||||
<%= radio_button_tag('recurring_todo[daily_selector]', 'daily_every_x_day', !@recurring_todo.only_work_days)%>
|
||||
<%= raw t('todos.recurrence.daily_every_number_day', :number=> text_field_tag( 'recurring_todo[daily_every_x_days]', @recurring_todo.daily_every_x_days, {"size" => 3})) %><br/>
|
||||
<%= radio_button_tag('recurring_todo[daily_selector]', 'daily_every_work_day', @recurring_todo.only_work_days)%> <%= t('todos.recurrence.every_work_day') %><br/>
|
||||
<%= radio_button_tag('recurring_todo[daily_selector]', 'daily_every_x_day', !@form_helper.only_work_days)%>
|
||||
<%= raw t('todos.recurrence.daily_every_number_day', :number=> text_field_tag( 'recurring_todo[daily_every_x_days]', @form_helper.daily_every_x_days, {"size" => 3})) %><br/>
|
||||
<%= radio_button_tag('recurring_todo[daily_selector]', 'daily_every_work_day', @form_helper.only_work_days)%> <%= t('todos.recurrence.every_work_day') %><br/>
|
||||
</div>
|
||||
<div id="recurring_edit_weekly" style="display:<%= @recurring_todo.recurring_period == 'weekly' ? 'block' : 'none' %>">
|
||||
<div id="recurring_edit_weekly" style="display:<%= @form_helper.recurring_period == 'weekly' ? 'block' : 'none' %>">
|
||||
<label><%= t('todos.recurrence.weekly_options') %></label><br/>
|
||||
<%= raw t('todos.recurrence.weekly_every_number_week', :number => text_field_tag('recurring_todo[weekly_every_x_week]', @recurring_todo.weekly_every_x_week, {"size" => 3})) %><br/>
|
||||
<%= check_box_tag('recurring_todo[weekly_return_monday]', 'm', @recurring_todo.on_monday ) %> <%= t('date.day_names')[1] %>
|
||||
<%= check_box_tag('recurring_todo[weekly_return_tuesday]', 't', @recurring_todo.on_tuesday) %> <%= t('date.day_names')[2] %>
|
||||
<%= check_box_tag('recurring_todo[weekly_return_wednesday]', 'w', @recurring_todo.on_wednesday) %> <%= t('date.day_names')[3] %>
|
||||
<%= check_box_tag('recurring_todo[weekly_return_thursday]', 't', @recurring_todo.on_thursday) %> <%= t('date.day_names')[4] %><br/>
|
||||
<%= check_box_tag('recurring_todo[weekly_return_friday]', 'f', @recurring_todo.on_friday) %> <%= t('date.day_names')[5] %>
|
||||
<%= check_box_tag('recurring_todo[weekly_return_saturday]', 's', @recurring_todo.on_saturday) %> <%= t('date.day_names')[6] %>
|
||||
<%= check_box_tag('recurring_todo[weekly_return_sunday]', 's', @recurring_todo.on_sunday) %> <%= t('date.day_names')[0] %><br/>
|
||||
<%= raw t('todos.recurrence.weekly_every_number_week', :number => text_field_tag('recurring_todo[weekly_every_x_week]', @form_helper.weekly_every_x_week, {"size" => 3})) %><br/>
|
||||
<%= check_box_tag('recurring_todo[weekly_return_monday]', 'm', @form_helper.on_monday ) %> <%= t('date.day_names')[1] %>
|
||||
<%= check_box_tag('recurring_todo[weekly_return_tuesday]', 't', @form_helper.on_tuesday) %> <%= t('date.day_names')[2] %>
|
||||
<%= check_box_tag('recurring_todo[weekly_return_wednesday]', 'w', @form_helper.on_wednesday) %> <%= t('date.day_names')[3] %>
|
||||
<%= check_box_tag('recurring_todo[weekly_return_thursday]', 't', @form_helper.on_thursday) %> <%= t('date.day_names')[4] %><br/>
|
||||
<%= check_box_tag('recurring_todo[weekly_return_friday]', 'f', @form_helper.on_friday) %> <%= t('date.day_names')[5] %>
|
||||
<%= check_box_tag('recurring_todo[weekly_return_saturday]', 's', @form_helper.on_saturday) %> <%= t('date.day_names')[6] %>
|
||||
<%= check_box_tag('recurring_todo[weekly_return_sunday]', 's', @form_helper.on_sunday) %> <%= t('date.day_names')[0] %><br/>
|
||||
</div>
|
||||
<div id="recurring_edit_monthly" style="display:<%= @recurring_todo.recurring_period == 'monthly' ? 'block' : 'none' %>">
|
||||
<div id="recurring_edit_monthly" style="display:<%= @form_helper.recurring_period == 'monthly' ? 'block' : 'none' %>">
|
||||
<label><%= t('todos.recurrence.monthly_options') %></label><br/>
|
||||
<%= radio_button_tag('recurring_todo[monthly_selector]', 'monthly_every_x_day', @recurring_todo.is_monthly_every_x_day || @recurring_todo.recurring_period == 'weekly')%>
|
||||
<%= radio_button_tag('recurring_todo[monthly_selector]', 'monthly_every_x_day', @form_helper.monthly_every_x_day? || @form_helper.recurring_period == 'weekly')%>
|
||||
<%= raw t('todos.recurrence.day_x_on_every_x_month',
|
||||
:day => text_field_tag('recurring_todo[monthly_every_x_day]', @recurring_todo.monthly_every_x_day, {"size" => 3}),
|
||||
:month => text_field_tag('recurring_todo[monthly_every_x_month]', @recurring_todo.monthly_every_x_month, {"size" => 3})) %><br/>
|
||||
<%= radio_button_tag('recurring_todo[monthly_selector]', 'monthly_every_xth_day', @recurring_todo.is_monthly_every_xth_day)%>
|
||||
:day => text_field_tag('recurring_todo[monthly_every_x_day]', @form_helper.monthly_every_x_day, {"size" => 3}),
|
||||
:month => text_field_tag('recurring_todo[monthly_every_x_month]', @form_helper.monthly_every_x_month, {"size" => 3})) %><br/>
|
||||
<%= radio_button_tag('recurring_todo[monthly_selector]', 'monthly_every_xth_day', @form_helper.monthly_every_xth_day?)%>
|
||||
<%= raw t('todos.recurrence.monthly_every_xth_day',
|
||||
:day => select_tag('recurring_todo[monthly_every_xth_day]', options_for_select(@xth_day, @xth_day[@recurring_todo.monthly_every_xth_day(1)-1][1])),
|
||||
:day_of_week => select_tag('recurring_todo[monthly_day_of_week]' , options_for_select(@days_of_week, @recurring_todo.monthly_day_of_week)),
|
||||
:month => text_field_tag('recurring_todo[monthly_every_x_month2]', @recurring_todo.monthly_every_x_month2, {"size" => 3})) %><br/>
|
||||
:day => select_tag('recurring_todo[monthly_every_xth_day]', options_for_select(@xth_day, @xth_day[@form_helper.monthly_every_xth_day(1)-1][1])),
|
||||
:day_of_week => select_tag('recurring_todo[monthly_day_of_week]' , options_for_select(@days_of_week, @form_helper.monthly_day_of_week)),
|
||||
:month => text_field_tag('recurring_todo[monthly_every_x_month2]', @form_helper.monthly_every_x_month2, {"size" => 3})) %><br/>
|
||||
</div>
|
||||
<div id="recurring_edit_yearly" style="display:<%= @recurring_todo.recurring_period == 'yearly' ? 'block' : 'none' %>">
|
||||
<div id="recurring_edit_yearly" style="display:<%= @form_helper.recurring_period == 'yearly' ? 'block' : 'none' %>">
|
||||
<label><%= t('todos.recurrence.yearly_options') %></label><br/>
|
||||
<%= radio_button_tag('recurring_todo[yearly_selector]', 'yearly_every_x_day', @recurring_todo.recurrence_selector == 0)%>
|
||||
<%= radio_button_tag('recurring_todo[yearly_selector]', 'yearly_every_x_day', @form_helper.recurrence_selector == 0)%>
|
||||
<%= raw t('todos.recurrence.yearly_every_x_day',
|
||||
:month => select_tag('recurring_todo[yearly_month_of_year]', options_for_select(@months_of_year, @recurring_todo.yearly_month_of_year)),
|
||||
:day => text_field_tag('recurring_todo[yearly_every_x_day]', @recurring_todo.yearly_every_x_day, "size" => 3)) %><br/>
|
||||
<%= radio_button_tag('recurring_todo[yearly_selector]', 'yearly_every_xth_day', @recurring_todo.recurrence_selector == 1)%>
|
||||
:month => select_tag('recurring_todo[yearly_month_of_year]', options_for_select(@months_of_year, @form_helper.yearly_month_of_year)),
|
||||
:day => text_field_tag('recurring_todo[yearly_every_x_day]', @form_helper.yearly_every_x_day, "size" => 3)) %><br/>
|
||||
<%= radio_button_tag('recurring_todo[yearly_selector]', 'yearly_every_xth_day', @form_helper.recurrence_selector == 1)%>
|
||||
<%= raw t('todos.recurrence.yearly_every_xth_day',
|
||||
:day => select_tag('recurring_todo[yearly_every_xth_day]', options_for_select(@xth_day, @recurring_todo.yearly_every_xth_day)),
|
||||
:day_of_week => select_tag('recurring_todo[yearly_day_of_week]', options_for_select(@days_of_week, @recurring_todo.yearly_day_of_week)),
|
||||
:month => select_tag('recurring_todo[yearly_month_of_year2]', options_for_select(@months_of_year, @recurring_todo.yearly_month_of_year2))) %><br/>
|
||||
:day => select_tag('recurring_todo[yearly_every_xth_day]', options_for_select(@xth_day, @form_helper.yearly_every_xth_day)),
|
||||
:day_of_week => select_tag('recurring_todo[yearly_day_of_week]', options_for_select(@days_of_week, @form_helper.yearly_day_of_week)),
|
||||
:month => select_tag('recurring_todo[yearly_month_of_year2]', options_for_select(@months_of_year, @form_helper.yearly_month_of_year2))) %><br/>
|
||||
</div>
|
||||
<div id="recurring_target">
|
||||
<label><%= t('todos.recurrence.recurrence_on.options') %></label><br/>
|
||||
<%= radio_button_tag('recurring_todo[recurring_target]', 'due_date', @recurring_todo.target == 'due_date')%> <%= t('todos.recurrence.recurrence_on.due_date') %>. <%= t('todos.recurrence.recurrence_on.show_options') %>:
|
||||
<%= radio_button_tag('recurring_todo[recurring_show_always]', '1', @recurring_todo.show_always?)%> <%= t('todos.recurrence.recurrence_on.show_always') %>
|
||||
<%= radio_button_tag('recurring_todo[recurring_show_always]', '0', !@recurring_todo.show_always?)%>
|
||||
<%= raw t('todos.recurrence.recurrence_on.show_days_before', :days => text_field_tag( 'recurring_todo[recurring_show_days_before]', @recurring_todo.show_from_delta, {"size" => 3})) %><br/>
|
||||
<%= radio_button_tag('recurring_todo[recurring_target]', 'show_from_date', @recurring_todo.target == 'show_from_date')%> <%= t('todos.recurrence.recurrence_on.from_tickler') %><br/>
|
||||
<%= radio_button_tag('recurring_todo[recurring_target]', 'due_date', @form_helper.target == 'due_date')%> <%= t('todos.recurrence.recurrence_on.due_date') %>. <%= t('todos.recurrence.recurrence_on.show_options') %>:
|
||||
<%= radio_button_tag('recurring_todo[recurring_show_always]', '1', @form_helper.show_always?)%> <%= t('todos.recurrence.recurrence_on.show_always') %>
|
||||
<%= radio_button_tag('recurring_todo[recurring_show_always]', '0', !@form_helper.show_always?)%>
|
||||
<%= raw t('todos.recurrence.recurrence_on.show_days_before', :days => text_field_tag( 'recurring_todo[recurring_show_days_before]', @form_helper.show_from_delta, {"size" => 3})) %><br/>
|
||||
<%= radio_button_tag('recurring_todo[recurring_target]', 'show_from_date', @form_helper.target == 'show_from_date')%> <%= t('todos.recurrence.recurrence_on.from_tickler') %><br/>
|
||||
<br/>
|
||||
</div>
|
||||
<% end %>
|
||||
|
|
|
|||
|
|
@ -42,8 +42,9 @@ module Tracks
|
|||
new_object_created = false
|
||||
|
||||
if specified_by_name?(object_type)
|
||||
# find or create context or project by given name
|
||||
object, new_object_created = find_or_create_by_name(relation, name)
|
||||
# put id of object in @attributes, i.e. set :project_id to project.id
|
||||
@attributes[object_type.to_s + "_id"] = object.id unless new_object_created
|
||||
else
|
||||
# find context or project by its id
|
||||
object = attribute_with_id_of(object_type).present? ? relation.find(attribute_with_id_of(object_type)) : nil
|
||||
|
|
@ -99,6 +100,29 @@ module Tracks
|
|||
Hash[attributes.map{|k,v| [k.to_sym,v]}]
|
||||
end
|
||||
|
||||
def safe_attributes
|
||||
ActionController::Parameters.new(attributes).permit(
|
||||
:context, :project,
|
||||
# model attributes
|
||||
:context_id, :project_id, :description, :notes, :state, :start_from,
|
||||
:ends_on, :end_date, :number_of_occurences, :occurences_count, :target,
|
||||
:show_from_delta, :recurring_period, :recurrence_selector, :every_other1,
|
||||
:every_other2, :every_other3, :every_day, :only_work_days, :every_count,
|
||||
:weekday, :show_always, :context_name, :project_name, :tag_list,
|
||||
# form attributes
|
||||
:recurring_period, :daily_selector, :monthly_selector, :yearly_selector,
|
||||
:recurring_target, :daily_every_x_days, :monthly_day_of_week,
|
||||
:monthly_every_x_day, :monthly_every_x_month2, :monthly_every_x_month,
|
||||
:monthly_every_xth_day, :recurring_show_days_before,
|
||||
:recurring_show_always, :weekly_every_x_week, :weekly_return_monday,
|
||||
:yearly_day_of_week, :yearly_every_x_day, :yearly_every_xth_day,
|
||||
:yearly_month_of_year2, :yearly_month_of_year,
|
||||
# derived attributes
|
||||
:weekly_return_monday, :weekly_return_tuesday, :weekly_return_wednesday,
|
||||
:weekly_return_thursday, :weekly_return_friday, :weekly_return_saturday, :weekly_return_sunday
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue