tracks/app/views/todos/destroy.js.erb
2014-08-13 15:33:32 +02:00

103 lines
No EOL
3.8 KiB
Text

<%- unless @saved -%>
TracksPages.page_error("<%= t('todos.error_deleting_item', :description => @todo.description) %>");
<%- else -%>
TracksPages.page_inform('<%= escape_javascript(t('todos.deleted_success')) %>');
TracksPages.set_page_badge(<%=@down_count%>);
remove_todo_from_page();
show_new_todo_if_todo_was_recurring();
activate_pending_todos();
update_predecessors();
show_empty_messages();
<%- end -%>
function show_empty_messages() {
<% if @old_due_empty -%>
$('#empty_<%=@original_item_due_id%>').slideDown(1000);
<% end -%>
<% if todo_container_is_empty -%>
$('#<%=empty_container_msg_div_id%>').slideDown(1000);
<% if @down_count == 0 -%>
$('#no_todos_in_view').slideDown(1000);
<% end -%>
<% end -%>
<% if source_view_is(:deferred) && @down_count==0 -%>
$('#deferred_pending_container-empty-d').slideDown(100);
<% end -%>
}
function remove_todo_from_page() {
<% if (@remaining_in_context == 0) && update_needs_to_hide_container
# remove context with deleted todo
-%>
$('#<%=item_container_id(@todo)%>').fadeOut(400, function() {
$('#<%=dom_id(@todo)%>').remove();
});
<%= show_empty_message_in_source_container -%>
<% else
# remove only the todo
-%>
<%= show_empty_message_in_source_container %>
$('#<%=dom_id(@todo)%>').slideUp(400, function() {
$('#<%=dom_id(@todo)%>').remove();
<% if source_view_is :calendar
# in calendar view it is possible to have a todo twice on the page
-%>
$('#<%=dom_id(@todo)%>').remove();
<% end %>
});
<% end -%>
}
function show_new_todo_if_todo_was_recurring() {
<% if @todo.from_recurring_todo? -%>
<% unless @new_recurring_todo.nil? || @new_recurring_todo.deferred? -%>
TodoItemsContainer.ensureVisibleWithEffectAppear("<%=item_container_id(@new_recurring_todo)%>");
$('#<%=item_container_id(@new_recurring_todo)%>_items').append(html_for_new_recurring_todo());
$('#<%= dom_id(@new_recurring_todo, 'line')%>').effect('highlight', {}, 2000 );
TracksPages.page_inform("<%=t('todos.recurring_action_deleted')%>");
<% else -%>
<% if @todo.recurring_todo.todos.active.count(:all) == 0 && @new_recurring_todo.nil? -%>
TracksPages.page_inform("<%=t('todos.completed_recurrence_completed')%>");
<% end -%>
<% end -%>
<% end -%>
}
function activate_pending_todos() {
<% # Activate pending todos that are successors of the deleted
if @saved && @pending_to_activate
# do not render the js in case of an error or if no todos to activate
@pending_to_activate.each do |t|
html = js_render(t, { :parent_container_type => parent_container_type })
# only project and tag view have a deferred/blocked container
if source_view_is_one_of(:project,:tag) -%>
$('#<%= dom_id(t) %>').fadeOut(400, function() {
$('#<%= dom_id(t) %>').remove();
$('#<%= item_container_id(t) %>_items').append("<%= html %>");
<%= "$('#deferred_pending_container-empty-d').show();".html_safe if @remaining_deferred_or_pending_count==0 -%>
});
<% else -%>
$('#<%= item_container_id(t) %>_items').append("<%= html%>");
<% end -%>
TodoItems.highlight_todo('#<%= dom_id(t, 'line')%>');
<% end -%>
<% end -%>
}
function update_predecessors() {
<%
if @todo_was_destroyed_from_pending_state
@uncompleted_predecessors.each do |p| -%>
if ($('#<%=item_container_id(p)%>')) {
$('#<%=dom_id(p)%>').html('<%=js_render(p, { :parent_container_type => parent_container_type })%>');
}
<% end
end
%>
}
function html_for_new_recurring_todo() {
return "<%= @saved && @new_recurring_todo ? js_render(@new_recurring_todo, { :parent_container_type => parent_container_type }) : "" %>";
}