refactor application.rb further and migrate recurring todos

next: get tests for recurring todos
This commit is contained in:
Reinier Balt 2010-12-03 17:52:24 +01:00
parent 484356fe07
commit cafa774b4c
33 changed files with 688 additions and 571 deletions

View file

@ -1,72 +1,72 @@
class NotesController < ApplicationController
before_filter :set_source_view
def index
@all_notes = current_user.notes.all
@count = @all_notes.size
@page_title = "TRACKS::All notes"
@source_view = 'note_list'
respond_to do |format|
format.html
format.xml { render :xml => @all_notes.to_xml( :except => :user_id ) }
end
end
def show
@note = current_user.notes.find(params['id'])
@page_title = "TRACKS::Note " + @note.id.to_s
respond_to do |format|
format.html
format.m { render :action => 'note_mobile' }
end
end
def create
@note = current_user.notes.build
@note.attributes = params["note"]
@saved = @note.save
respond_to do |format|
format.js
format.xml do
if @saved
head :created, :location => note_url(@note), :text => "new note with id #{@note.id}"
else
render_failure @note.errors.full_messages.join(', ')
end
end
format.html do
render :text => 'unexpected request for html rendering'
end
end
end
def update
@note = current_user.notes.find(params['id'])
@note.attributes = params["note"]
@saved = @note.save
respond_to do |format|
format.html
format.js
end
end
def destroy
@note = current_user.notes.find(params['id'])
@note.destroy
respond_to do |format|
format.html
format.js { @down_count = current_user.notes.size }
end
end
protected
def set_source_view
@source_view = params['_source_view'] || 'note'
end
end
class NotesController < ApplicationController
before_filter :set_source_view
def index
@all_notes = current_user.notes.all
@count = @all_notes.size
@page_title = "TRACKS::All notes"
@source_view = 'note_list'
respond_to do |format|
format.html
format.xml { render :xml => @all_notes.to_xml( :except => :user_id ) }
end
end
def show
@note = current_user.notes.find(params['id'])
@page_title = "TRACKS::Note " + @note.id.to_s
respond_to do |format|
format.html
format.m { render :action => 'note_mobile' }
end
end
def create
@note = current_user.notes.build
@note.attributes = params["note"]
@saved = @note.save
respond_to do |format|
format.js
format.xml do
if @saved
head :created, :location => note_url(@note), :text => "new note with id #{@note.id}"
else
render_failure @note.errors.full_messages.join(', ')
end
end
format.html do
render :text => 'unexpected request for html rendering'
end
end
end
def update
@note = current_user.notes.find(params['id'])
@note.attributes = params["note"]
@saved = @note.save
respond_to do |format|
format.html
format.js
end
end
def destroy
@note = current_user.notes.find(params['id'])
@note.destroy
respond_to do |format|
format.html
format.js { @down_count = current_user.notes.size }
end
end
protected
def set_source_view
@source_view = params['_source_view'] || 'note'
end
end

View file

@ -6,15 +6,17 @@ class RecurringTodosController < ApplicationController
append_before_filter :get_recurring_todo_from_param, :only => [:destroy, :toggle_check, :toggle_star, :edit, :update]
def index
find_and_inactivate
@page_title = t('todos.recurring_actions_title')
find_and_inactivate
@recurring_todos = current_user.recurring_todos.active
@completed_recurring_todos = current_user.recurring_todos.completed
@no_recurring_todos = @recurring_todos.size == 0
@no_completed_recurring_todos = @completed_recurring_todos.size == 0
@count = @recurring_todos.size
@page_title = t('todos.recurring_actions_title')
@count = @recurring_todos.size
@new_recurring_todo = RecurringTodo.new
end
def new
@ -103,13 +105,13 @@ class RecurringTodosController < ApplicationController
@recurring_todo.context_id = context.id
end
@recurring_saved = @recurring_todo.save
unless (@recurring_saved == false) || p.tag_list.blank?
@saved = @recurring_todo.save
unless (@saved == false) || p.tag_list.blank?
@recurring_todo.tag_with(p.tag_list)
@recurring_todo.tags.reload
end
if @recurring_saved
if @saved
@message = "The recurring todo was saved"
@todo_saved = create_todo_from_recurring_todo(@recurring_todo).nil? == false
if @todo_saved
@ -117,7 +119,8 @@ class RecurringTodosController < ApplicationController
else
@message += " / did not create todo"
end
@count = current_user.recurring_todos.active.count
@down_count = current_user.recurring_todos.active.count
@new_recurring_todo = RecurringTodo.new
else
@message = "Error saving recurring todo"
end
@ -139,7 +142,10 @@ class RecurringTodosController < ApplicationController
# delete the recurring todo
@saved = @recurring_todo.destroy
@remaining = current_user.recurring_todos.count
# count remaining recurring todos
@active_remaining = current_user.recurring_todos.active.count
@completed_remaining = current_user.recurring_todos.completed.count
respond_to do |format|
@ -162,11 +168,12 @@ class RecurringTodosController < ApplicationController
def toggle_check
@saved = @recurring_todo.toggle_completion!
@count = current_user.recurring_todos.active.count
@remaining = @count
@down_count = current_user.recurring_todos.active.count
@active_remaining = @down_count
@completed_remaining = 0
if @recurring_todo.active?
@remaining = current_user.recurring_todos.completed.count
@completed_remaining = current_user.recurring_todos.completed.count
# from completed back to active -> check if there is an active todo
# current_user.todos.count(:all, {:conditions => ["state = ? AND recurring_todo_id = ?", 'active',params[:id]]})

View file

@ -1,3 +1,3 @@
module SearchHelper
end
module SearchHelper
end

View file

@ -1,7 +1,7 @@
<% if @saved -%>
hide_empty_message();
TracksPages.hide_errors();
set_page_badge(<%= @down_count %>);
TracksPages.set_page_badge(<%= @down_count %>);
add_context("<%=@context.hidden? ? 'hidden' : 'active'%>");
clear_form();
<% else -%>

View file

@ -3,13 +3,12 @@ remove_deleted_context();
ContextListPage.update_all_states_count(<%=@active_contexts_count%>, <%=@hidden_contexts_count%>)
ContextListPage.show_or_hide_all_state_containers(<%= @show_active_contexts %>, <%= @show_hidden_contexts %>);
set_page_badge(<%=@down_count%>);
page_notify('notice', "<%= t('contexts.context_deleted', :name=>@context.name)%>", 5);
TracksPages.set_page_badge(<%=@down_count%>);
TracksPages.page_notify('notice', "<%= t('contexts.context_deleted', :name=>@context.name)%>", 5);
/* TODO: refactor and move function to application.js */
function remove_deleted_context() {
$('div#<%=dom_id(@context, "container")%>').slideUp(1000,
function() {
$('div#<%=dom_id(@context, "container")%>').slideUp(1000, function() {
$('div#<%=dom_id(@context, "container")%>').remove();
});
});
}

View file

@ -1,6 +1,6 @@
<% if @saved -%>
page_notify('notice', '<%= t('contexts.save_status_message') %>', 5);
TracksPages.page_notify('notice', '<%= t('contexts.save_status_message') %>', 5);
<% if @state_changed -%>
remove_and_re_add_context();
@ -9,7 +9,7 @@
<% end -%>
<% else -%>
show_errors();
TracksPages.show_edit_errors(html_for_error_messages());
<% end -%>
function remove_and_re_add_context() {
@ -33,11 +33,6 @@ function replace_context_form_with_updated_context() {
});
}
function show_errors() {
$('div#edit_error_status').html(html_for_error_messages());
$('div#edit_error_status').show();
}
function html_for_error_messages() {
return "<%= escape_javascript(error_messages_for('context')) %>";
}

View file

@ -1,9 +1,7 @@
<% if @session_expired
theHtml = escape_javascript(content_tag(
:div,
t('login.session_time_out', :link => link_to(t('login.log_in_again'), :controller => "login", :action => "login")),
:"class" => "warning"))
logger.debug("theHtml='#{theHtml}'")
theLink = link_to(t('login.log_in_again'), :controller => "login", :action => "login")
message = I18n.t('login.session_time_out', :link => theLink)
theHtml = escape_javascript(content_tag(:div, message, :"class" => "warning"))
-%>
$('div#navcontainer').hide();
$('div#content').html('<%=theHtml%>');

View file

@ -1,6 +1,6 @@
remove_deleted_note();
set_page_badge(<%=@down_count%>);
page_notify('notice', "<%= t('notes.deleted_note', :id => @note.id)%>", 5);
TracksPages.set_page_badge(<%=@down_count%>);
TracksPages.page_notify('notice', "<%= t('notes.deleted_note', :id => @note.id)%>", 5);
function remove_deleted_note() {
$('div#note-<%=@note.id%>-wrapper').slideUp(1000,

View file

@ -1,7 +1,7 @@
<% if @saved -%>
TracksPages.hide_errors();
page_notify('notice', 'Note <%=@note.id %> saved', 5);
TracksPages.page_notify('notice', 'Note <%=@note.id %> saved', 5);
replace_note_form_with_updated_note();
<% else -%>

View file

@ -4,7 +4,7 @@
<% else -%>
TracksPages.hide_errors();
hide_empty_message();
set_page_badge(<%= @down_count %>);
TracksPages.set_page_badge(<%= @down_count %>);
update_active_projects_container();
add_project();
clear_form();
@ -13,19 +13,23 @@
TracksPages.show_errors(html_for_error_messages());
<% end -%>
/* TODO: make this generic for all pages with lists */
function hide_empty_message() {
$('projects-empty-nd').hide();
}
/* TODO: refactor and move this to application.js */
function add_project() {
$('#list-active-projects').append(html_for_project_listing());
}
/* TODO: refactor and move this to application.js */
function clear_form() {
$('#project_form').clearForm();
$('#project_form input:text:first').focus();
}
/* TODO: refactor and move this to application.js */
function update_active_projects_container() {
ProjectListPage.set_state_container_visibility('active', true);
ProjectListPage.update_state_count('active', <%=@active_projects_count%>);

View file

@ -1,9 +1,10 @@
remove_deleted_project();
ProjectListPage.update_all_states_count(<%=@active_projects_count%>, <%=@hidden_projects_count%>, <%=@completed_projects_count%>)
ProjectListPage.show_or_hide_all_state_containers(<%= @show_active_projects %>, <%= @show_hidden_projects %>, <%= @show_completed_projects %>);
page_notify('notice', "Deleted project '<%= @project.name%>'", 5);
set_page_badge(<%=@down_count%>);
TracksPages.page_notify('notice', "Deleted project '<%= @project.name%>'", 5);
TracksPages.set_page_badge(<%=@down_count%>);
/* TODO: refactor and move function to application.js */
function remove_deleted_project() {
$('div#<%=dom_id(@project, "container")%>').slideUp(1000,
function() {

View file

@ -1,6 +1,6 @@
<% if @saved -%>
page_notify('notice', '<%=t('projects.project_saved_status')%>', 5);
TracksPages.page_notify('notice', '<%=t('projects.project_saved_status')%>', 5);
<% if source_view_is :project_list -%>
@ -27,23 +27,16 @@
TracksForm.set_tag_list("<%= escape_javascript(@project.default_tags)%>");
<% end %>
update_sidebar();
TracksPages.update_sidebar(html_for_sidebar());
<% end %>
TracksForm.set_project_name_and_default_project_name("<%= escape_javascript(@project.name)%>");
<% else -%>
show_errors();
TracksPages.show_edit_errors(html_for_error_messages());
<% end %>
enable_rich_interaction();
function show_errors() {
$('div#edit_error_status').html(html_for_error_messages());
$('div#edit_error_status').show();
}
function remove_project_edit_form() {
$('#<%=dom_id(@project, 'edit')%>').hide(500, function() {$('#<%=dom_id(@project, 'edit')%>').remove();} );
}
@ -53,10 +46,6 @@ function update_and_show_project_settings() {
$('#<%=dom_id(@project)%>').show();
}
function update_sidebar() {
$('#sidebar').html(html_for_sidebar());
}
function replace_project_form_with_updated_project() {
$('#<%=dom_id(@project, 'container')%>').fadeOut(250, function() {
<%
@ -97,4 +86,4 @@ function html_for_project_settings() {
function html_for_error_messages() {
return "<%= escape_javascript(error_messages_for('project')) %>";
}
}

View file

@ -1,113 +1,113 @@
<label>Edit Recurring Todo</label><br/>
<div class="recurring_container">
<% form_remote_tag(
:url => recurring_todo_path(@recurring_todo), :method => :put,
:html=> { :id=>'recurring-todo-form-edit-action', :name=>'recurring_todo', :class => 'inline-form' },
:before => "$('#recurring_todo_edit_action_submit').block({message: null})",
:complete => "$('#recurring_todo_edit_action_submit').unblock();$('#recurring-todo-form-edit-action').clearForm();") do
-%>
<div id="edit_status"><%= error_messages_for("item", :object_name => 'action') %></div>
<div id="recurring_todo_form_container">
<div id="recurring_todo">
<label for="recurring_todo_description">Description</label><%=
text_field_tag( "recurring_todo[description]", @recurring_todo.description, "size" => 30, "tabindex" => 1, "maxlength" => 100) -%>
<label for="recurring_todo_notes">Notes</label><%=
text_area_tag( "recurring_todo[notes]", @recurring_todo.notes, {:cols => 29, :rows => 6, :tabindex => 2}) -%>
<label for="edit_recurring_todo_project_name">Project</label>
<input id="edit_recurring_todo_project_name" name="project_name" autocomplete="off" tabindex="3" size="30" type="text" value="<%= @recurring_todo.project.nil? ? 'None' : @recurring_todo.project.name.gsub(/"/,"&quot;") %>" />
<div class="page_name_auto_complete" id="edit_project_list" style="display:none"></div>
<% #form_remote_tag(
#url => recurring_todo_path(@recurring_todo), :method => :put,
#:html=> { :id=>'recurring-todo-form-edit-action', :name=>'recurring_todo', :class => 'inline-form' },
#:before => "$('#recurring_todo_edit_action_submit').block({message: null})",
#:complete => "$('#recurring_todo_edit_action_submit').unblock();$('#recurring-todo-form-edit-action').clearForm();") do
form_for(@recurring_todo, :html=> { :id=>'recurring-todo-form-edit-action', :name=>'recurring_todo', :class => 'inline-form' }) do |f|
-%>
<div id="edit_error_status"><%= error_messages_for("item", :object_name => 'action') %></div>
<label for="edit_recurring_todo_context_name">Context</label>
<input id="edit_recurring_todo_context_name" name="context_name" autocomplete="off" tabindex="4" size="30" type="text" value="<%= @recurring_todo.context.name %>" />
<div class="page_name_auto_complete" id="edit_context_list" style="display:none"></div>
<label for="edit_recurring_todo_tag_list">Tags (separate with commas)</label>
<%= text_field_tag "edit_recurring_todo_tag_list", @recurring_todo.tag_list, :size => 30, :tabindex => 5 -%>
</div>
<div id="recurring_todo_form_container">
<div id="recurring_todo">
<label for="recurring_todo_description">Description</label><%=
text_field_tag( "recurring_todo[description]", @recurring_todo.description, "size" => 30, "tabindex" => 1, "maxlength" => 100) -%>
<label for="recurring_todo_notes">Notes</label><%=
text_area_tag( "recurring_todo[notes]", @recurring_todo.notes, {:cols => 29, :rows => 6, :tabindex => 2}) -%>
<label for="edit_recurring_todo_project_name">Project</label>
<input id="edit_recurring_todo_project_name" name="project_name" autocomplete="off" tabindex="3" size="30" type="text" value="<%= @recurring_todo.project.nil? ? 'None' : @recurring_todo.project.name.gsub(/"/,"&quot;") %>" />
<div class="page_name_auto_complete" id="edit_project_list" style="display:none"></div>
<label for="edit_recurring_todo_context_name">Context</label>
<input id="edit_recurring_todo_context_name" name="context_name" autocomplete="off" tabindex="4" size="30" type="text" value="<%= @recurring_todo.context.name %>" />
<div class="page_name_auto_complete" id="edit_context_list" style="display:none"></div>
<label for="edit_recurring_todo_tag_list">Tags (separate with commas)</label>
<%= text_field_tag "edit_recurring_todo_tag_list", @recurring_todo.tag_list, :size => 30, :tabindex => 5 -%>
</div>
<div id="recurring_edit_period_id">
<div id="recurring_edit_period">
<label>Recurrence period</label><br/>
<%= radio_button_tag('recurring_edit_todo[recurring_period]', 'daily', @recurring_todo.recurring_period == 'daily')%> Daily<br/>
<%= radio_button_tag('recurring_edit_todo[recurring_period]', 'weekly', @recurring_todo.recurring_period == 'weekly')%> Weekly<br/>
<%= radio_button_tag('recurring_edit_todo[recurring_period]', 'monthly', @recurring_todo.recurring_period == 'monthly')%> Monthly<br/>
<%= radio_button_tag('recurring_edit_todo[recurring_period]', 'yearly', @recurring_todo.recurring_period == 'yearly')%> Yearly<br/>
<% #behaviour is set in index because behaviours in partials are not generated -%>
</div>
<div id="recurring_timespan">
<br/>
<label for="recurring_todo[start_from]">Starts on </label><%=
text_field_tag("recurring_todo_edit_start_from", format_date(@recurring_todo.start_from), "size" => 12, "class" => "Date", "tabindex" => 6, "autocomplete" => "off") %><br/>
<br/>
<label for="recurring_todo[ends_on]">Ends on:</label><br/>
<%= radio_button_tag('recurring_todo[ends_on]', 'no_end_date', @recurring_todo.ends_on == 'no_end_date')%> 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')%> Ends after <%= text_field_tag("recurring_todo[number_of_occurences]", @recurring_todo.number_of_occurences, "size" => 3, "tabindex" => 7) %> times<br/>
<%= radio_button_tag('recurring_todo[ends_on]', 'ends_on_end_date', @recurring_todo.ends_on == 'ends_on_end_date')%> Ends on <%=
text_field_tag('recurring_todo_edit_end_date', format_date(@recurring_todo.end_date), "size" => 12, "class" => "Date", "tabindex" => 8, "autocomplete" => "off") %><br/>
</div></div>
<div id="recurring_edit_daily" style="display:<%= @recurring_todo.recurring_period == 'daily' ? 'block' : 'none' %> ">
<label>Settings for daily recurring actions</label><br/>
<%= radio_button_tag('recurring_todo[daily_selector]', 'daily_every_x_day', !@recurring_todo.only_work_days)%> Every <%=
text_field_tag( 'recurring_todo[daily_every_x_days]', @recurring_todo.daily_every_x_days, {"size" => 3, "tabindex" => 9}) %> day(s)<br/>
<%= radio_button_tag('recurring_todo[daily_selector]', 'daily_every_work_day', @recurring_todo.only_work_days)%> Every work day<br/>
</div>
<div id="recurring_edit_period_id">
<div id="recurring_edit_period">
<label>Recurrence period</label><br/>
<%= radio_button_tag('recurring_edit_todo[recurring_period]', 'daily', @recurring_todo.recurring_period == 'daily')%> Daily<br/>
<%= radio_button_tag('recurring_edit_todo[recurring_period]', 'weekly', @recurring_todo.recurring_period == 'weekly')%> Weekly<br/>
<%= radio_button_tag('recurring_edit_todo[recurring_period]', 'monthly', @recurring_todo.recurring_period == 'monthly')%> Monthly<br/>
<%= radio_button_tag('recurring_edit_todo[recurring_period]', 'yearly', @recurring_todo.recurring_period == 'yearly')%> Yearly<br/>
<% #behaviour is set in index because behaviours in partials are not generated -%>
</div>
<div id="recurring_edit_weekly" style="display:<%= @recurring_todo.recurring_period == 'weekly' ? 'block' : 'none' %>">
<label>Settings for weekly recurring actions</label><br/>
Returns every <%= text_field_tag('recurring_todo[weekly_every_x_week]', @recurring_todo.weekly_every_x_week, {"size" => 3, "tabindex" => 9}) %> week on<br/>
<%= check_box_tag('recurring_todo[weekly_return_monday]', 'm', @recurring_todo.on_monday ) %> Monday
<%= check_box_tag('recurring_todo[weekly_return_tuesday]', 't', @recurring_todo.on_tuesday) %> Tuesday
<%= check_box_tag('recurring_todo[weekly_return_wednesday]', 'w', @recurring_todo.on_wednesday) %> Wednesday
<%= check_box_tag('recurring_todo[weekly_return_thursday]', 't', @recurring_todo.on_thursday) %> Thursday<br/>
<%= check_box_tag('recurring_todo[weekly_return_friday]', 'f', @recurring_todo.on_friday) %> Friday
<%= check_box_tag('recurring_todo[weekly_return_saturday]', 's', @recurring_todo.on_saturday) %> Saturday
<%= check_box_tag('recurring_todo[weekly_return_sunday]', 's', @recurring_todo.on_sunday) %> Sunday<br/>
</div>
<div id="recurring_edit_monthly" style="display:<%= @recurring_todo.recurring_period == 'monthly' ? 'block' : 'none' %>">
<label>Settings for monthly recurring actions</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')%> 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.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>
<div id="recurring_edit_yearly" style="display:<%= @recurring_todo.recurring_period == 'yearly' ? 'block' : 'none' %>">
<label>Settings for yearly recurring actions</label><br/>
<%= radio_button_tag('recurring_todo[yearly_selector]', 'yearly_every_x_day', @recurring_todo.recurrence_selector == 0)%> Every <%=
select_tag('recurring_todo[yearly_month_of_year]', options_for_select(@months_of_year, @recurring_todo.yearly_month_of_year), {}) %> <%=
text_field_tag('recurring_todo[yearly_every_x_day]', @recurring_todo.yearly_every_x_day, "size" => 3, "tabindex" => 9) %><br/>
<%= radio_button_tag('recurring_todo[yearly_selector]', 'yearly_every_xth_day', @recurring_todo.recurrence_selector == 1)%> The <%=
select_tag('recurring_todo[yearly_every_xth_day]', options_for_select(@xth_day, @recurring_todo.yearly_every_xth_day), {}) %> <%=
select_tag('recurring_todo[yearly_day_of_week]', options_for_select(@days_of_week, @recurring_todo.yearly_day_of_week), {}) %> of <%=
select_tag('recurring_todo[yearly_month_of_year2]', options_for_select(@months_of_year, @recurring_todo.yearly_month_of_year2), {}) %><br/>
</div>
<div id="recurring_target">
<label>Set recurrence on</label><br/>
<%= radio_button_tag('recurring_todo[recurring_target]', 'due_date', @recurring_todo.target == 'due_date')%> the date that the todo is due. Show the todo:
<%= radio_button_tag('recurring_todo[recurring_show_always]', '1', @recurring_todo.show_always?)%> always
<%= radio_button_tag('recurring_todo[recurring_show_always]', '0', !@recurring_todo.show_always?)%>
<%= text_field_tag( 'recurring_todo[recurring_show_days_before]', @recurring_todo.show_from_delta, {"size" => 3, "tabindex" => 12}) %>
days before the todo is due
<br/>
<%= radio_button_tag('recurring_todo[recurring_target]', 'show_from_date', @recurring_todo.target == 'show_from_date')%> the date todo comes from tickler (no due date set)<br/>
<div id="recurring_timespan">
<br/>
<label for="recurring_todo[start_from]">Starts on </label><%=
text_field_tag("recurring_todo_edit_start_from", format_date(@recurring_todo.start_from), "size" => 12, "class" => "Date", "tabindex" => 6, "autocomplete" => "off") %><br/>
<br/>
<label for="recurring_todo[ends_on]">Ends on:</label><br/>
<%= radio_button_tag('recurring_todo[ends_on]', 'no_end_date', @recurring_todo.ends_on == 'no_end_date')%> 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')%> Ends after <%= text_field_tag("recurring_todo[number_of_occurences]", @recurring_todo.number_of_occurences, "size" => 3, "tabindex" => 7) %> times<br/>
<%= radio_button_tag('recurring_todo[ends_on]', 'ends_on_end_date', @recurring_todo.ends_on == 'ends_on_end_date')%> Ends on <%=
text_field_tag('recurring_todo_edit_end_date', format_date(@recurring_todo.end_date), "size" => 12, "class" => "Date", "tabindex" => 8, "autocomplete" => "off") %><br/>
</div></div>
<div id="recurring_edit_daily" style="display:<%= @recurring_todo.recurring_period == 'daily' ? 'block' : 'none' %> ">
<label>Settings for daily recurring actions</label><br/>
<%= radio_button_tag('recurring_todo[daily_selector]', 'daily_every_x_day', !@recurring_todo.only_work_days)%> Every <%=
text_field_tag( 'recurring_todo[daily_every_x_days]', @recurring_todo.daily_every_x_days, {"size" => 3, "tabindex" => 9}) %> day(s)<br/>
<%= radio_button_tag('recurring_todo[daily_selector]', 'daily_every_work_day', @recurring_todo.only_work_days)%> Every work day<br/>
</div>
<div id="recurring_edit_weekly" style="display:<%= @recurring_todo.recurring_period == 'weekly' ? 'block' : 'none' %>">
<label>Settings for weekly recurring actions</label><br/>
Returns every <%= text_field_tag('recurring_todo[weekly_every_x_week]', @recurring_todo.weekly_every_x_week, {"size" => 3, "tabindex" => 9}) %> week on<br/>
<%= check_box_tag('recurring_todo[weekly_return_monday]', 'm', @recurring_todo.on_monday ) %> Monday
<%= check_box_tag('recurring_todo[weekly_return_tuesday]', 't', @recurring_todo.on_tuesday) %> Tuesday
<%= check_box_tag('recurring_todo[weekly_return_wednesday]', 'w', @recurring_todo.on_wednesday) %> Wednesday
<%= check_box_tag('recurring_todo[weekly_return_thursday]', 't', @recurring_todo.on_thursday) %> Thursday<br/>
<%= check_box_tag('recurring_todo[weekly_return_friday]', 'f', @recurring_todo.on_friday) %> Friday
<%= check_box_tag('recurring_todo[weekly_return_saturday]', 's', @recurring_todo.on_saturday) %> Saturday
<%= check_box_tag('recurring_todo[weekly_return_sunday]', 's', @recurring_todo.on_sunday) %> Sunday<br/>
</div>
<div id="recurring_edit_monthly" style="display:<%= @recurring_todo.recurring_period == 'monthly' ? 'block' : 'none' %>">
<label>Settings for monthly recurring actions</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')%> 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.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>
<div id="recurring_edit_yearly" style="display:<%= @recurring_todo.recurring_period == 'yearly' ? 'block' : 'none' %>">
<label>Settings for yearly recurring actions</label><br/>
<%= radio_button_tag('recurring_todo[yearly_selector]', 'yearly_every_x_day', @recurring_todo.recurrence_selector == 0)%> Every <%=
select_tag('recurring_todo[yearly_month_of_year]', options_for_select(@months_of_year, @recurring_todo.yearly_month_of_year), {}) %> <%=
text_field_tag('recurring_todo[yearly_every_x_day]', @recurring_todo.yearly_every_x_day, "size" => 3, "tabindex" => 9) %><br/>
<%= radio_button_tag('recurring_todo[yearly_selector]', 'yearly_every_xth_day', @recurring_todo.recurrence_selector == 1)%> The <%=
select_tag('recurring_todo[yearly_every_xth_day]', options_for_select(@xth_day, @recurring_todo.yearly_every_xth_day), {}) %> <%=
select_tag('recurring_todo[yearly_day_of_week]', options_for_select(@days_of_week, @recurring_todo.yearly_day_of_week), {}) %> of <%=
select_tag('recurring_todo[yearly_month_of_year2]', options_for_select(@months_of_year, @recurring_todo.yearly_month_of_year2), {}) %><br/>
</div>
<div id="recurring_target">
<label>Set recurrence on</label><br/>
<%= radio_button_tag('recurring_todo[recurring_target]', 'due_date', @recurring_todo.target == 'due_date')%> the date that the todo is due. Show the todo:
<%= radio_button_tag('recurring_todo[recurring_show_always]', '1', @recurring_todo.show_always?)%> always
<%= radio_button_tag('recurring_todo[recurring_show_always]', '0', !@recurring_todo.show_always?)%>
<%= text_field_tag( 'recurring_todo[recurring_show_days_before]', @recurring_todo.show_from_delta, {"size" => 3, "tabindex" => 12}) %>
days before the todo is due
<br/>
<%= radio_button_tag('recurring_todo[recurring_target]', 'show_from_date', @recurring_todo.target == 'show_from_date')%> the date todo comes from tickler (no due date set)<br/>
<br/>
</div>
<div class="recurring_submit_box">
<div class="widgets">
<button type="submit" class="positive" id="recurring_todo_edit_action_submit" tabindex="15">
<%=image_tag("accept.png", :alt => "") %>
Update
</button>
<button type="button" class="positive" id="recurring_todo_edit_action_cancel" tabindex="15">
<%=image_tag("cancel.png", :alt => "") %>
Cancel
</button>
</div>
<div class="recurring_submit_box">
<div class="widgets">
<button type="submit" class="positive" id="recurring_todo_edit_action_submit" tabindex="15">
<%=image_tag("accept.png", :alt => "") %>
Update
</button>
<button type="button" class="positive" id="recurring_todo_edit_action_cancel" tabindex="15">
<%=image_tag("cancel.png", :alt => "") %>
Cancel
</button>
</div>
</div>
<% end %>
</div>
<% end %>
</div>

View file

@ -3,7 +3,7 @@
<%= recurring_todo_remote_delete_icon %> <%= recurring_todo_remote_edit_icon -%>
<%= recurring_todo_remote_star_icon %> <%= recurring_todo_remote_toggle_checkbox -%>
<div class="description">
<div class="rec_description">
<span class="todo.descr"><%= sanitize(recurring_todo.description) %></span> <%= recurring_todo_tag_list %>
<span class='recurrence_pattern'>
[<%= recurrence_pattern_as_text(@recurring_todo) %>]

View file

@ -1,10 +1,12 @@
<div class="recurring_container">
<% form_remote_tag(
:url => recurring_todos_path, :method => :post,
:html=> { :id=>'recurring-todo-form-new-action', :name=>'recurring_todo', :class => 'inline-form' },
:before => "$('#recurring_todo_new_action_submit').block({message: null})") do
<%
form_for(@new_recurring_todo, :html=> { :id=>'recurring-todo-form-new-action', :name=>'recurring_todo', :class => 'inline-form' }) do
#form_remote_tag(
# :url => recurring_todos_path, :method => :post,
# :html=> { :id=>'recurring-todo-form-new-action', :name=>'recurring_todo', :class => 'inline-form' },
# :before => "$('#recurring_todo_new_action_submit').block({message: null})") do
-%>
<div id="new_status"><%= error_messages_for("item", :object_name => 'action') %></div>
<div id="error_status"><%= error_messages_for("item", :object_name => 'action') %></div>
<div id="recurring_todo_form_container">
<div id="recurring_todo">

View file

@ -0,0 +1,30 @@
<% if @saved -%>
RecurringTodosPage.toggle_overlay();
add_recurring_todo_to_active_container();
replace_form_with_empty_form();
TracksPages.set_page_badge(<%= @down_count %>);
<% else -%>
TracksPages.show_errors(html_for_error_messages());
<% end -%>
function replace_form_with_empty_form() {
$('div.recurring_container').html(html_for_empty_form());
}
function add_recurring_todo_to_active_container() {
$('#recurring_todos_container').append(html_for_recurring_todo());
$('#<%= dom_id(@recurring_todo)%>').effect('highlight', {}, 2000 );
$('#recurring-todos-empty-nd').hide();
}
function html_for_recurring_todo() {
return "<%= @saved ? escape_javascript(render(:partial => @recurring_todo)) : "" %>";
}
function html_for_empty_form() {
return "<%= @saved ? escape_javascript(render(:partial => 'recurring_todo_form')) : "" %>";
}
function html_for_error_messages() {
return "<%= escape_javascript(error_messages_for('recurring_todo')) %>";
}

View file

@ -1,18 +0,0 @@
page.show 'new_status'
page.replace_html 'new_status', "#{error_messages_for('recurring_todo')}"
page.notify :notice, @message, 5.0
if @recurring_saved
# reset form
page['new-recurring-todo'].replace_html :partial => 'recurring_todo_form'
# hide overlayed edit form
page << "TracksForm.toggle_overlay();"
# insert new recurring todo
page.hide 'recurring-todos-empty-nd'
page.insert_html :bottom,
'recurring_todos_container',
:partial => 'recurring_todos/recurring_todo', :locals => { :recurring_todo => @recurring_todo}
page.visual_effect :highlight, dom_id(@recurring_todo), :duration => 3
# update badge count
page['badge_count'].replace_html @count
end

View file

@ -0,0 +1,22 @@
<%- if @saved -%>
show_empty_messages();
TracksPages.page_notify('notice', '<%= escape_javascript(t('todos.recurring_deleted_success') + t(:todo_removed, :count => @number_of_todos)) %>', 5);
remove_recurring_todo_from_page();
<%- else -%>
TracksPages.page_notify('error', '<%= t('todos.error_deleting_recurring', :description => @recurring_todo.description) %>', 8);
<%- end -%>
function show_empty_messages() {
<%- if @active_remaining == 0 -%>
$('#recurring-todos-empty-nd').show();
<%- end -%>
<%- if @completed_remaining == 0 -%>
$('#completed-empty-nd').show();
<%- end -%>
}
function remove_recurring_todo_from_page() {
$('#<%=dom_id(@recurring_todo)%>').slideUp(1000, function() {
$('#<%=dom_id(@recurring_todo)%>').remove();
});
}

View file

@ -1,11 +0,0 @@
if @saved
if @remaining == 0
page.show 'recurring-todos-empty-nd'
end
page.notify :notice, t('todos.recurring_deleted_success') +
t(:todo_removed, :count => @number_of_todos), 5.0
page[@recurring_todo].remove
page.visual_effect :fade, dom_id(@recurring_todo), :duration => 0.4
else
page.notify :error, t('todos.error_deleting_recurring', :description => @recurring_todo.description), 8.0
end

View file

@ -0,0 +1,9 @@
$('#new-recurring-todo').hide();
$('#edit-recurring-todo').html(html_for_edit_form());
$('#edit-recurring-todo').show();
RecurringTodosPage.toggle_overlay();
enable_rich_interaction();
function html_for_edit_form() {
return "<%= escape_javascript(render(:partial => 'edit_form')) %>"
}

View file

@ -1,5 +0,0 @@
page << "TracksForm.toggle_overlay();"
page['new-recurring-todo'].hide
page['edit-recurring-todo'].replace_html :partial => 'recurring_todos/edit_form'
page['edit-recurring-todo'].show
page << "enable_rich_interaction();"

View file

@ -21,7 +21,7 @@
</div>
<div id="input_box">
<div id="recurring_new_container">
<a href='#' onclick="$('new-recurring-todo').show();$('edit-recurring-todo').hide();TracksForm.toggle_overlay()"><%= image_tag("add.png", {:alt => "[ADD]"})-%><%= t('todos.add_new_recurring') %></a>
<a href='#' id="add-new-recurring-todo"><%= image_tag("add.png", {:alt => "[ADD]"})-%><%= t('todos.add_new_recurring') %></a>
</div>
</div>

View file

@ -0,0 +1,51 @@
<%- if @saved -%>
TracksPages.set_page_badge(<%= @down_count %>);
remove_old_and_add_updated_recurring_todo();
inform_if_new_todo_created();
<%- else -%>
TracksPages.page_notify('error', '<%= t('todos.error_completing_todo', :description => @recurring_todo.description) %>', 8);
<%- end -%>
function inform_if_new_todo_created() {
<%- unless @new_recurring_todo.nil? -%>
TracksPages.page_notify('notice', '<%= t('todos.new_related_todo_created') %>', 5);
<%- end -%>
}
function remove_old_and_add_updated_recurring_todo() {
$('#<%=dom_id(@recurring_todo)%>').slideUp(1000, function() {
$('#<%=dom_id(@recurring_todo)%>').remove();
show_empty_messages();
<%- if @recurring_todo.completed? -%>
add_recurring_todo_to_completed_container();
<%- else -%>
add_recurring_todo_to_active_container();
<%- end -%>
});
}
function add_recurring_todo_to_completed_container() {
$('#completed_recurring_todos_container').append(html_for_recurring_todo());
$('#<%= dom_id(@recurring_todo)%>').effect('highlight', {}, 2000 );
$('#completed-empty-nd').hide();
}
function add_recurring_todo_to_active_container() {
$('#recurring_todos_container').append(html_for_recurring_todo());
$('#<%= dom_id(@recurring_todo)%>').effect('highlight', {}, 2000 );
$('#recurring-todos-empty-nd').hide();
}
function show_empty_messages() {
<%- if @active_remaining == 0 -%>
$('#recurring-todos-empty-nd').show();
<%- end -%>
<%- if @completed_remaining == 0 -%>
$('#completed-empty-nd').show();
<%- end -%>
}
function html_for_recurring_todo() {
return "<%= @saved ? escape_javascript(render(:partial => @recurring_todo)) : "" %>";
}

View file

@ -1,30 +0,0 @@
if @saved
page[@recurring_todo].remove
page['badge_count'].replace_html @count
if @recurring_todo.completed?
# show completed recurring todo
page.insert_html :top, "completed_recurring_todos_container", :partial => 'recurring_todos/recurring_todo', :locals => { :recurring_todo => @recurring_todo }
page.visual_effect :highlight, dom_id(@recurring_todo), :duration => 3
# set empty messages
page.show 'recurring-todos-empty-nd' if @remaining == 0
page.hide 'completed-empty-nd'
else
# recurring_todo is activated
# show completed recurring todo
page.insert_html :top, "recurring_todos_container", :partial => 'recurring_todos/recurring_todo', :locals => { :recurring_todo => @recurring_todo }
page.visual_effect :highlight, dom_id(@recurring_todo), :duration => 3
# inform user if a new todo has been created because of the activation
page.notify :notice, t('todos.new_related_todo_created'), 3.0 unless @new_recurring_todo.nil?
# set empty messages
page.show 'completed-empty-nd' if @remaining == 0
page.hide 'recurring-todos-empty-nd'
end
else
page.notify :error, t('todos.error_completing_todo', :description => @recurring_todo.description), 8.0
end

View file

@ -1,3 +1,5 @@
<% if @saved -%>
$('div#recurring_todo_<%= @recurring_todo.id %> a.star_item img').toggleClass('starred_todo').toggleClass('unstarred_todo');
<% end -%>
<%- else -%>
TracksPages.page_notify('error', '<%= t('todos.error_starring_recurring', :description => @recurring_todo.description) %>', 8);
<%- end -%>

View file

@ -0,0 +1,38 @@
<%- if @saved -%>
RecurringTodosPage.toggle_overlay();
TracksPages.page_notify('notice', text_for_status_message(), 5);
replace_old_recurring_todo_with_updated();
<%- else -%>
TracksPages.show_edit_errors(html_for_error_messages());
<%- end -%>
function replace_old_recurring_todo_with_updated() {
$('#<%=dom_id(@recurring_todo)%>').fadeOut(250, function() {
<%-
# first add the updated recurring todo after the old one, then remove old one
# using html() does not work, because it will replace the _content_ of
# the container instead of the container itself, i.e. you will get
# a container within a container which will break drag-and-drop sorting (when/if implemented)
-%>
$('#<%=dom_id(@recurring_todo)%>').after(html_for_updated_recurring_todo());
$('#<%=dom_id(@recurring_todo)%>').remove();
$('#<%=dom_id(@recurring_todo)%>').fadeIn(500);
});
}
function html_for_updated_recurring_todo() {
return "<%= escape_javascript(render(:partial => @recurring_todo))%>";
}
function text_for_status_message() {
<%-
status_message = t('todos.recurring_action_saved')
status_message = t('todos.added_new_project') + ' / ' + status_message if @new_project_created
status_message = t('todos.added_new_context') + ' / ' + status_message if @new_context_created
-%>
return "<%= status_message%>";
}
function html_for_error_messages() {
return "<%= escape_javascript(error_messages_for('recurring_todo')) %>";
}

View file

@ -1,18 +0,0 @@
if @saved
# hide overlayed edit form
page << "TracksForm.toggle_overlay();"
# show update message
status_message = t('todos.recurring_action_saved')
status_message = t('todos.added_new_project') + ' / ' + status_message if @new_project_created
status_message = t('todos.added_new_context') + ' / ' + status_message if @new_context_created
page.notify :notice, status_message, 5.0
# replace old recurring todo with updated todo
page.replace dom_id(@recurring_todo), :partial => 'recurring_todos/recurring_todo', :locals => { :recurring_todo => @recurring_todo }
page.visual_effect :highlight, dom_id(@recurring_todo), :duration => 3
else
page.show 'edit_status'
page.replace_html 'edit_status', "#{error_messages_for('recurring_todo')}"
end

View file

@ -18,7 +18,7 @@
:html=> { :id=>'todo-form-new-action', :name=>'todo', :class => 'inline-form' },
:before => "$('#todo_new_action_submit').block({message:null})",
:complete => "$('#todo_new_action_submit').unblock()",
:condition => "askIfNewContextProvided('')") do -%>
:condition => "TodoItems.askIfNewContextProvided('')") do -%>
<div id="status"><%= error_messages_for("item", :object_name => 'action') %></div>
@ -75,7 +75,7 @@
:html=> { :id=>'todo-form-multi-new-action', :name=>'todo', :class => 'inline-form' },
:before => "$('#todo_multi_new_action_submit').block({message:null})",
:complete => "$('#todo_multi_new_action_submit').unblock()",
:condition => "askIfNewContextProvided('multi_')") do -%>
:condition => "TodoItems.askIfNewContextProvided('multi_')") do -%>
<div id="multiple_status"><%= error_messages_for("item", :object_name => 'action') %></div>