tracks/app/views/recurring_todos/toggle_check.js.erb
Reinier Balt 4cdbd9a451 move js genreated for ajax calls into their own object to prevent name clashes
I only modified the js that is most likely to be used in cocurrent calls. This because we
start the development of Tracks 3 that will change all js.
2014-08-13 15:33:32 +02:00

51 lines
No EOL
2 KiB
Text

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