2013-04-16 10:20:44 +02:00
|
|
|
<% unless @saved -%>
|
2011-03-28 11:38:33 +02:00
|
|
|
TracksPages.page_notify('error', "<%= t('todos.error_toggle_complete') %>", 5);
|
2011-01-06 23:01:17 +01:00
|
|
|
<% else -%>
|
2011-01-11 02:47:29 +01:00
|
|
|
<% if @wants_redirect_after_complete && @todo.completed? -%>
|
2011-01-06 23:01:17 +01:00
|
|
|
redirect_after_complete();
|
|
|
|
|
<% else
|
|
|
|
|
animation = []
|
2011-09-16 12:38:35 +02:00
|
|
|
unless source_view_is(:search)
|
|
|
|
|
animation << "remove_todo"
|
|
|
|
|
if @todo.completed?
|
|
|
|
|
animation << "add_to_completed_container" unless source_view_is_one_of(:calendar, :deferred)
|
|
|
|
|
animation << "add_new_recurring_todo"
|
|
|
|
|
animation << "activate_pending_todos"
|
|
|
|
|
else
|
2013-04-17 22:11:24 +02:00
|
|
|
animation << "add_todo_to_container" unless source_view_is(:done)
|
2011-09-16 12:38:35 +02:00
|
|
|
animation << "block_predecessors"
|
|
|
|
|
end
|
2013-06-11 15:36:27 +02:00
|
|
|
animation << "update_empty_container" if source_view_is_one_of(:tag, :todo, :deferred, :project, :context)
|
2011-09-16 12:38:35 +02:00
|
|
|
animation << "regenerate_predecessor_family"
|
2011-01-06 23:01:17 +01:00
|
|
|
else
|
2011-09-16 12:38:35 +02:00
|
|
|
animation << "replace_todo"
|
|
|
|
|
end -%>
|
2011-01-06 23:01:17 +01:00
|
|
|
<%= render_animation(animation) %>
|
|
|
|
|
TracksPages.set_page_badge(<%= @down_count %>);
|
|
|
|
|
<% end -%>
|
2008-08-05 11:00:04 +02:00
|
|
|
|
2011-01-06 23:01:17 +01:00
|
|
|
function redirect_after_complete() {
|
2011-03-10 16:50:19 +01:00
|
|
|
var path = "<%= @todo.project_id.nil? ? "/" : project_path(@todo.project) -%>";
|
|
|
|
|
redirect_to(path);
|
2011-01-06 23:01:17 +01:00
|
|
|
}
|
2009-04-14 21:36:57 +02:00
|
|
|
|
2011-01-06 23:01:17 +01:00
|
|
|
function remove_todo(next_steps) {
|
2013-04-11 10:53:35 +02:00
|
|
|
<% if (@remaining_in_context == 0) && update_needs_to_hide_container
|
2011-01-11 02:47:29 +01:00
|
|
|
# remove context with deleted todo
|
|
|
|
|
-%>
|
2013-04-17 22:11:24 +02:00
|
|
|
$('#<%= item_container_id(@original_item)%>').slideUp(400, function() {
|
2011-01-11 02:47:29 +01:00
|
|
|
$('#<%=dom_id(@todo)%>').remove();
|
|
|
|
|
next_steps.go();
|
|
|
|
|
});
|
2011-01-06 23:01:17 +01:00
|
|
|
<%= show_empty_message_in_source_container -%>
|
2011-01-11 02:47:29 +01:00
|
|
|
<% else
|
|
|
|
|
# remove only the todo
|
|
|
|
|
-%>
|
|
|
|
|
<%= show_empty_message_in_source_container %>
|
|
|
|
|
$('#<%=dom_id(@todo)%>').slideUp(400, function() {
|
|
|
|
|
$('#<%=dom_id(@todo)%>').remove();
|
|
|
|
|
next_steps.go();
|
2011-01-06 23:01:17 +01:00
|
|
|
});
|
2011-01-11 02:47:29 +01:00
|
|
|
<% end -%>
|
2011-01-06 23:01:17 +01:00
|
|
|
}
|
2009-04-14 21:36:57 +02:00
|
|
|
|
2011-01-06 23:01:17 +01:00
|
|
|
function add_to_completed_container(next_steps) {
|
|
|
|
|
<% unless current_user.prefs.hide_completed_actions? -%>
|
2013-04-17 22:11:24 +02:00
|
|
|
$('#<%= item_container_id(@todo) %>_items').prepend(html_for_todo());
|
2013-03-17 15:41:36 +01:00
|
|
|
$("#completed_container-empty-d").slideUp(100);
|
2011-01-06 23:01:17 +01:00
|
|
|
highlight_updated_todo(next_steps);
|
|
|
|
|
<% end -%>
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-16 12:38:35 +02:00
|
|
|
function replace_todo(next_steps) {
|
|
|
|
|
$('#<%= dom_id(@todo) %>').html(html_for_todo());
|
|
|
|
|
next_steps.go();
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-17 22:11:24 +02:00
|
|
|
function add_todo_to_container(next_steps) {
|
|
|
|
|
$('#<%= item_container_id(@todo) %>_items').append(html_for_todo());
|
2011-01-11 02:47:29 +01:00
|
|
|
<% if should_make_context_visible -%>
|
2013-04-17 22:11:24 +02:00
|
|
|
$('#<%= item_container_id(@todo) %>').slideDown(500, function() {
|
2013-06-11 15:36:27 +02:00
|
|
|
$("#<%= empty_container_msg_div_id %>").slideUp(100);
|
2011-01-11 02:47:29 +01:00
|
|
|
highlight_updated_todo(next_steps);
|
|
|
|
|
});
|
|
|
|
|
<% else -%>
|
2013-06-11 15:36:27 +02:00
|
|
|
$("#<%= empty_container_msg_div_id(@todo) %>").slideUp(100);
|
2011-01-06 23:01:17 +01:00
|
|
|
highlight_updated_todo(next_steps);
|
2011-01-11 02:47:29 +01:00
|
|
|
<% end -%>
|
2011-04-21 16:54:35 +02:00
|
|
|
<% if @completed_count == 0 -%>
|
2013-03-17 15:41:36 +01:00
|
|
|
$("#completed_container-empty-d").slideDown(100);
|
2011-04-21 16:54:35 +02:00
|
|
|
<% end -%>
|
2011-01-06 23:01:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function add_new_recurring_todo(next_steps) {
|
|
|
|
|
<% # show new todo if the completed todo was recurring
|
2008-08-05 11:00:04 +02:00
|
|
|
if @todo.from_recurring_todo?
|
2011-08-18 17:15:00 +02:00
|
|
|
unless @new_recurring_todo.nil? || (@new_recurring_todo.deferred? && !source_view_is(:deferred)) -%>
|
2013-04-17 22:11:24 +02:00
|
|
|
$('#<%= item_container_id(@new_recurring_todo) %>_items').append(html_for_recurring_todo());
|
|
|
|
|
$('#c<%= @new_recurring_todo.context_id %>').slideDown(500, function() {
|
2011-01-06 23:01:17 +01:00
|
|
|
highlight_updated_recurring_todo(next_steps);
|
|
|
|
|
});
|
|
|
|
|
<% else
|
2011-04-19 13:42:05 +02:00
|
|
|
if @todo.recurring_todo.todos.active.count(:all) == 0 && @new_recurring_todo.nil? -%>
|
2011-01-06 23:01:17 +01:00
|
|
|
TracksPages.page_notify('notice', "<%=t('todos.recurrence_completed')%>", 6);
|
2011-01-11 02:47:29 +01:00
|
|
|
<% end -%>
|
|
|
|
|
next_steps.go();
|
|
|
|
|
<% end
|
|
|
|
|
else -%>
|
|
|
|
|
next_steps.go();
|
|
|
|
|
<% end -%>
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-09 10:53:54 +01:00
|
|
|
function update_empty_container(next_steps) {
|
2011-01-11 02:47:29 +01:00
|
|
|
<% if @down_count==0 -%>
|
2011-03-09 10:53:54 +01:00
|
|
|
$('#no_todos_in_view').slideDown(400, function(){ next_steps.go(); });
|
2011-01-11 02:47:29 +01:00
|
|
|
<% else -%>
|
2013-04-17 22:11:24 +02:00
|
|
|
$('#no_todos_in_view').slideUp(400, function(){ next_steps.go(); });
|
2011-01-11 02:47:29 +01:00
|
|
|
<% end -%>
|
2011-01-06 23:01:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<% if @new_recurring_todo # hide js if @new_recurring_todo is not there-%>
|
|
|
|
|
function highlight_updated_recurring_todo(next_steps) {
|
2011-03-08 23:28:48 +01:00
|
|
|
TodoItems.highlight_todo('#<%= dom_id(@new_recurring_todo)%>');
|
2011-01-06 23:01:17 +01:00
|
|
|
next_steps.go();
|
|
|
|
|
}
|
|
|
|
|
<% end -%>
|
|
|
|
|
|
|
|
|
|
function highlight_updated_todo(next_steps) {
|
2011-03-08 23:28:48 +01:00
|
|
|
TodoItems.highlight_todo('#<%= dom_id(@todo)%>');
|
2011-01-06 23:01:17 +01:00
|
|
|
next_steps.go();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function activate_pending_todos(next_steps) {
|
|
|
|
|
<% # Activate pending todos that are successors of the completed
|
2013-06-11 15:36:27 +02:00
|
|
|
if @pending_to_activate
|
2011-01-06 23:01:17 +01:00
|
|
|
# do not render the js in case of an error or if no todos to activate
|
|
|
|
|
@pending_to_activate.each do |t|
|
2011-03-08 23:28:48 +01:00
|
|
|
html = escape_javascript(render(:partial => t, :locals => { :parent_container_type => parent_container_type }))
|
|
|
|
|
# only project and tag view have a deferred/blocked container
|
2011-01-11 02:47:29 +01:00
|
|
|
if source_view_is_one_of(:project,:tag) -%>
|
2013-04-17 22:11:24 +02:00
|
|
|
$('#<%= dom_id(t) %>').slideUp(400, function() {
|
2011-01-06 23:01:17 +01:00
|
|
|
$('#<%= dom_id(t) %>').remove();
|
2013-04-17 22:11:24 +02:00
|
|
|
$('#<%= item_container_id(t) %>_items').append("<%= html %>");
|
2013-03-17 15:41:36 +01:00
|
|
|
<%= "$('#deferred_pending_container-empty-d').show();".html_safe if @remaining_deferred_or_pending_count==0 -%>
|
2011-01-06 23:01:17 +01:00
|
|
|
});
|
2011-03-08 23:28:48 +01:00
|
|
|
<% else -%>
|
2013-04-17 22:11:24 +02:00
|
|
|
$('#<%= item_container_id(t) %>_items').append("<%= html%>");
|
2011-08-18 17:15:00 +02:00
|
|
|
<% end -%>
|
2011-03-08 23:28:48 +01:00
|
|
|
TodoItems.highlight_todo('#<%= dom_id(t)%>');
|
2011-01-06 23:01:17 +01:00
|
|
|
<% end -%>
|
|
|
|
|
<% end -%>
|
2011-01-11 02:47:29 +01:00
|
|
|
next_steps.go();
|
2011-01-06 23:01:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function block_predecessors(next_steps) {
|
2011-08-18 17:15:00 +02:00
|
|
|
<% # Block active todos that are successors of the uncompleted
|
2011-01-06 23:01:17 +01:00
|
|
|
if @saved && @active_to_block
|
|
|
|
|
# do not render the js in case of an error or if no todos to block
|
|
|
|
|
@active_to_block.each do |t| %>
|
2013-04-17 22:11:24 +02:00
|
|
|
$('#<%= dom_id(t) %>').slideUp(400, function() {
|
2011-01-06 23:01:17 +01:00
|
|
|
$('#<%= dom_id(t) %>').remove();
|
|
|
|
|
<% if source_view_is(:project) or source_view_is(:tag) # Insert it in deferred/pending block if existing -%>
|
2013-04-17 22:11:24 +02:00
|
|
|
$('#<%= item_container_id(t) %>_items').append("<%= escape_javascript(render(:partial => t, :locals => { :parent_container_type => parent_container_type }))%>");
|
2011-03-08 23:28:48 +01:00
|
|
|
TodoItems.highlight_todo('#<%= dom_id(t)%>');
|
2011-01-06 23:01:17 +01:00
|
|
|
<% end -%>
|
|
|
|
|
});
|
|
|
|
|
<% end -%>
|
|
|
|
|
<% end -%>
|
2011-01-11 02:47:29 +01:00
|
|
|
next_steps.go();
|
2011-01-06 23:01:17 +01:00
|
|
|
}
|
|
|
|
|
|
2011-08-18 17:15:00 +02:00
|
|
|
function regenerate_predecessor_family(next_steps) {
|
|
|
|
|
<%
|
|
|
|
|
if @predecessors
|
2014-04-12 21:21:40 +02:00
|
|
|
parents = @predecessors.to_a
|
2011-08-18 17:15:00 +02:00
|
|
|
until parents.empty?
|
|
|
|
|
parent = parents.pop
|
|
|
|
|
parents += parent.predecessors -%>
|
|
|
|
|
$('#<%= dom_id(parent) %>').html("<%= escape_javascript(render(:partial => parent, :locals => { :parent_container_type => parent_container_type })) %>");
|
|
|
|
|
<%end
|
|
|
|
|
end
|
|
|
|
|
-%>
|
|
|
|
|
next_steps.go();
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-24 20:47:07 +02:00
|
|
|
function html_for_recurring_todo() {
|
|
|
|
|
<%-
|
2013-06-11 15:36:27 +02:00
|
|
|
js = @new_recurring_todo ? escape_javascript(render(:partial => @new_recurring_todo, :locals => { :parent_container_type => parent_container_type })) : ""
|
2012-04-24 20:47:07 +02:00
|
|
|
-%>
|
|
|
|
|
return "<%= js %>";
|
2011-01-06 23:01:17 +01:00
|
|
|
}
|
|
|
|
|
|
2012-04-24 20:47:07 +02:00
|
|
|
function html_for_todo() {
|
|
|
|
|
<%-
|
|
|
|
|
js = ""
|
2013-06-11 15:36:27 +02:00
|
|
|
if !source_view_is(:done)
|
2012-04-24 20:47:07 +02:00
|
|
|
js = escape_javascript(render(
|
|
|
|
|
:partial => @todo,
|
|
|
|
|
:locals => {
|
|
|
|
|
:parent_container_type => parent_container_type,
|
|
|
|
|
:suppress_project => source_view_is(:project),
|
|
|
|
|
:suppress_context => source_view_is(:context)
|
|
|
|
|
}
|
|
|
|
|
))
|
|
|
|
|
end
|
|
|
|
|
-%>
|
|
|
|
|
return "<%= js %>";
|
2013-04-16 10:20:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<% end -%>
|