mirror of
https://github.com/TracksApp/tracks.git
synced 2026-01-30 12:45:18 +01:00
make adding of todos from sidebar work in context and project grouping
This commit is contained in:
parent
783d4dd774
commit
9c0445fcb7
17 changed files with 528 additions and 389 deletions
|
|
@ -10,6 +10,7 @@
|
|||
var SOURCE_VIEW = '<%=@source_view%>';
|
||||
var AUTH_TOKEN = '<%= raw(protect_against_forgery? ? form_authenticity_token.inspect : "") %>'
|
||||
var TAG_NAME = '<%= @tag_name ? @tag_name : "" %>'
|
||||
var GROUP_VIEW_BY = '<%= @group_view_by ? @group_view_by : "" %>'
|
||||
var defaultContexts = <%= default_contexts_for_autocomplete.html_safe rescue '{}' %>;
|
||||
var defaultTags = <%= default_tags_for_autocomplete.html_safe rescue '{}' %>;
|
||||
var dateFormat = '<%= date_format_for_date_picker %>';
|
||||
|
|
|
|||
|
|
@ -3,9 +3,10 @@
|
|||
# invalidate the cache every day because of staleness or
|
||||
# rendering of "due in x days" that change without touching updated at of the todo
|
||||
cache [project, @source_view, current_user.date.strftime("%Y%m%d")] do
|
||||
%>
|
||||
<%= render :partial => "project_settings_container", :locals => {:project => project} if source_view_is :project %>
|
||||
|
||||
-%>
|
||||
<% if source_view_is :project -%>
|
||||
<%= render :partial => "project_settings_container", :locals => {:project => project} %>
|
||||
<% end -%>
|
||||
<%=
|
||||
title = source_view_is(:project) ? t('projects.actions_in_project_title') : show_project_name(project)
|
||||
|
||||
|
|
@ -19,5 +20,4 @@ cache [project, @source_view, current_user.date.strftime("%Y%m%d")] do
|
|||
:show_empty_containers => settings[:show_empty_containers]
|
||||
}}
|
||||
%>
|
||||
|
||||
<% end %>
|
||||
<% end -%>
|
||||
|
|
@ -1,24 +1,32 @@
|
|||
<% unless @saved -%>
|
||||
|
||||
TracksPages.show_errors(html_for_error_messages());
|
||||
|
||||
function html_for_error_messages() {
|
||||
return "<%= escape_javascript(get_list_of_error_messages_for(@todo)) %>";
|
||||
}
|
||||
<% else -%>
|
||||
|
||||
<% else
|
||||
|
||||
animation = []
|
||||
if should_show_new_item
|
||||
if should_add_new_container
|
||||
animation << "insert_new_container_with_new_todo";
|
||||
else
|
||||
animation << "add_todo_to_existing_container";
|
||||
end
|
||||
end
|
||||
animation << "remove_empty_message_container";
|
||||
animation << "update_predecessors";
|
||||
animation << "clear_form";
|
||||
-%>
|
||||
|
||||
<%= render_animation(animation) %>
|
||||
TracksPages.page_notify('notice', "<%=escape_javascript @status_message%>", 8);
|
||||
TracksPages.hide_errors();
|
||||
TracksPages.set_page_badge(<%= @down_count %>);
|
||||
<% if should_show_new_item -%>
|
||||
<% if should_add_new_context -%>
|
||||
insert_new_context_with_new_todo();
|
||||
<% else -%>
|
||||
add_todo_to_existing_context();
|
||||
<% end -%>
|
||||
<% end -%>
|
||||
update_predecessors();
|
||||
clear_form();
|
||||
|
||||
function clear_form() {
|
||||
function clear_form(next_steps) {
|
||||
$('#todo-form-new-action').clearForm();
|
||||
$('#todo-form-new-action').clearDeps();
|
||||
TracksForm.set_context_name('<%=escape_javascript @initial_context_name%>');
|
||||
|
|
@ -27,43 +35,55 @@
|
|||
$('#todo-form-new-action input:text:first').focus();
|
||||
$('#new_todo_starred_link .todo_star').removeClass('starred');
|
||||
$('#new_todo_starred').val('false');
|
||||
next_steps.go();
|
||||
}
|
||||
|
||||
function insert_new_context_with_new_todo() {
|
||||
function insert_new_container_with_new_todo(next_steps) {
|
||||
<%-
|
||||
empty_id = '#no_todos_in_view'
|
||||
empty_id = '#deferred_pending_container-empty-d' if source_view_is :tickler
|
||||
-%>
|
||||
$('<%=empty_id%>').slideUp(100);
|
||||
$('#display_box').prepend(html_for_new_context());
|
||||
$('<%=empty_id%>').slideUp(100, function() {
|
||||
$('#display_box').prepend(html_for_new_container());
|
||||
next_steps.go();
|
||||
});
|
||||
}
|
||||
|
||||
function add_todo_to_existing_context() {
|
||||
<% if source_view_is_one_of(:todo, :deferred, :tag) -%>
|
||||
<% unless source_view_is_one_of(:todo, :tag) && (@todo.deferred?||@todo.hidden?) -%>
|
||||
$('#c<%= @todo.context_id %>').fadeIn(500, function() {});
|
||||
$('#no_todos_in_view').slideUp(100);
|
||||
<%= "$('#deferred_pending_container-empty-nd').slideUp(100);".html_safe if source_view_is(:deferred) && @todo.deferred? %>
|
||||
<% end -%>
|
||||
<% end -%>
|
||||
$('#<%=empty_container_msg_div_id%>').hide();
|
||||
$('#<%=item_container_id(@todo)%>').append(html_for_new_todo());
|
||||
$('#<%= dom_id(@todo)%>').effect('highlight', {}, 2000 );
|
||||
function add_todo_to_existing_container(next_steps) {
|
||||
$('#<%= empty_container_msg_div_id %>').hide();
|
||||
$('#<%= item_container_id(@todo) %>').append(html_for_new_todo());
|
||||
$('#<%= item_container_id(@todo) %>').slideDown(500, function() {
|
||||
$('#<%= dom_id(@todo) %>').effect('highlight', {}, 2000 );
|
||||
next_steps.go();
|
||||
});
|
||||
}
|
||||
|
||||
function update_predecessors() {
|
||||
function remove_empty_message_container(next_steps) {
|
||||
$('#no_todos_in_view').slideUp(100, function() { });
|
||||
<%# = "$('#deferred_pending_container-empty-nd').slideUp(100);".html_safe if source_view_is(:deferred) && @todo.deferred? %>
|
||||
next_steps.go();
|
||||
}
|
||||
|
||||
function update_predecessors(next_steps) {
|
||||
<% @todo.uncompleted_predecessors.each do |p| -%>
|
||||
if ($('<%=item_container_id(p)%>')) {
|
||||
$('#<%=dom_id(p)%>').html('<%= escape_javascript(render(:partial => p, :locals => { :parent_container_type => parent_container_type, :source_view => @source_view }))%>');
|
||||
}
|
||||
<% end -%>
|
||||
next_steps.go();
|
||||
}
|
||||
|
||||
function html_for_new_context() {
|
||||
return "<%= @saved && @new_context_created ? escape_javascript(render(:partial => @todo.context, :locals => { :settings => {:collapsible => true} })) : "" %>";
|
||||
function html_for_new_container() {
|
||||
<%
|
||||
want_render = @group_view_by == 'project' ? @new_project_created : @new_context_created
|
||||
container = @group_view_by == 'project' ? @todo.project : @todo.context
|
||||
js = want_render ? escape_javascript(render(:partial => container, :locals => { :settings => {:collapsible => true} })) : ""
|
||||
%>
|
||||
return "<%= js %>";
|
||||
}
|
||||
|
||||
function html_for_new_todo() {
|
||||
return "<%= @saved ? escape_javascript(render(:partial => @todo, :locals => { :parent_container_type => parent_container_type, :source_view => @source_view })) : "" %>";
|
||||
}
|
||||
<% end -%>
|
||||
|
||||
<% end -%>
|
||||
|
|
@ -1,5 +1,21 @@
|
|||
<% if @saved -%>
|
||||
set_notification();
|
||||
<% unless @saved -%>
|
||||
TracksPages.show_errors_for_multi_add(html_for_error_messages());
|
||||
|
||||
function html_for_error_messages() {
|
||||
<%
|
||||
# add error about missing todo description that is not available in @todos
|
||||
@multiple_error = content_tag(:div, content_tag(:p, @multiple_error), {:class => 'errorExplanation', :id => 'errorExplanation'}) unless @multiple_error.blank?
|
||||
error_messages = @multiple_error || ""
|
||||
# add errors of individual @todos
|
||||
@todos.each do |todo|
|
||||
error_messages += get_list_of_error_messages_for(todo)
|
||||
end
|
||||
-%>
|
||||
return "<%= escape_javascript(error_messages.html_safe)%>";
|
||||
}
|
||||
|
||||
<% else -%>
|
||||
TracksPages.page_notify('notice', "<%=@status_message%>", 5);
|
||||
hide_empty_message();
|
||||
TracksPages.hide_errors();
|
||||
TracksPages.set_page_badge(<%= @down_count %>);
|
||||
|
|
@ -11,67 +27,44 @@
|
|||
<% end -%>
|
||||
<% end -%>
|
||||
clear_form();
|
||||
<% else -%>
|
||||
TracksPages.show_errors_for_multi_add(html_for_error_messages());
|
||||
|
||||
function clear_form() {
|
||||
$('#todo-form-multi-new-action').clearForm();
|
||||
TracksForm.set_context_name_for_multi_add('<%=escape_javascript @initial_context_name%>');
|
||||
TracksForm.set_project_name_for_multi_add('<%=escape_javascript @initial_project_name%>');
|
||||
TracksForm.set_tag_list_for_multi_add('<%=escape_javascript @initial_tags%>');
|
||||
$('#todo-form-multi-new-action input:text:first').focus();
|
||||
}
|
||||
|
||||
function insert_new_context_with_new_todo() {
|
||||
$('#display_box').prepend(html_for_new_context());
|
||||
}
|
||||
|
||||
function hide_empty_message() {
|
||||
<% if (source_view_is :project and @todo.pending?) or (source_view_is :deferred) -%>
|
||||
$('#deferred_pending_container-empty-d').hide();
|
||||
<% else -%>
|
||||
$('#no_todos_in_view').hide();
|
||||
<% end -%>
|
||||
}
|
||||
|
||||
function add_todo_to_existing_context() {
|
||||
<%
|
||||
@todos.each do |todo|
|
||||
if should_show_new_item(todo)
|
||||
html = escape_javascript(render(:partial => todo, :locals => { :parent_container_type => parent_container_type, :source_view => @source_view }))
|
||||
-%>
|
||||
$('#<%= empty_container_msg_div_id(todo) %>').hide();
|
||||
$('#<%= item_container_id(todo) %>').append('<%= html %>');
|
||||
$('#<%= item_container_id(todo) %>').fadeIn(500, function() {
|
||||
$('#<%= dom_id(todo) %>').effect('highlight', {}, 2000 );
|
||||
});
|
||||
<% end %>
|
||||
<% end %>
|
||||
}
|
||||
|
||||
function html_for_new_context() {
|
||||
return "<%= @saved && @new_context_created ? escape_javascript(render(:partial => @todo.context, :locals => { :settings => {:collapsible => true} })) : "" %>";
|
||||
}
|
||||
|
||||
<% end -%>
|
||||
|
||||
<% if @saved
|
||||
# the following functions assume a todo is saved or at least not nil,
|
||||
# so leave them out in case of an error
|
||||
-%>
|
||||
|
||||
function set_notification() {
|
||||
TracksPages.page_notify('notice', "<%=@status_message%>", 5);
|
||||
}
|
||||
|
||||
function clear_form() {
|
||||
$('#todo-form-multi-new-action').clearForm();
|
||||
TracksForm.set_context_name_for_multi_add('<%=escape_javascript @initial_context_name%>');
|
||||
TracksForm.set_project_name_for_multi_add('<%=escape_javascript @initial_project_name%>');
|
||||
TracksForm.set_tag_list_for_multi_add('<%=escape_javascript @initial_tags%>');
|
||||
$('#todo-form-multi-new-action input:text:first').focus();
|
||||
}
|
||||
|
||||
function insert_new_context_with_new_todo() {
|
||||
$('#display_box').prepend(html_for_new_context());
|
||||
}
|
||||
|
||||
function hide_empty_message() {
|
||||
$('#<%=empty_container_msg_div_id%>').hide();
|
||||
<% if (source_view_is :project and @todo.pending?) or (source_view_is :deferred) -%>
|
||||
$('#deferred_pending_container-empty-d').hide();
|
||||
<% end -%>
|
||||
}
|
||||
|
||||
function add_todo_to_existing_context() {
|
||||
<% if source_view_is_one_of(:todo, :deferred, :tag) -%>
|
||||
TodoItemsContainer.ensureVisibleWithEffectAppear("c<%=@todo.context_id%>");
|
||||
<% end
|
||||
show = should_show_new_item # to hide html if not necessary
|
||||
@todos.each do |todo|
|
||||
html = show ? escape_javascript(render(:partial => todo, :locals => { :parent_container_type => parent_container_type, :source_view => @source_view })) : "" -%>
|
||||
$('#<%=item_container_id(todo)%>').append('<%= html %>');
|
||||
$('#<%= dom_id(todo)%>').effect('highlight', {}, 3000);
|
||||
<% end %>
|
||||
}
|
||||
|
||||
function html_for_new_context() {
|
||||
return "<%= @saved && @new_context_created ? escape_javascript(render(:partial => @todo.context, :locals => { :settings => {:collapsible => true} })) : "" %>";
|
||||
}
|
||||
|
||||
<% else # if @saved -%>
|
||||
|
||||
function html_for_error_messages() {
|
||||
<%
|
||||
# add error about missing todo description that is not available in @todos
|
||||
@multiple_error = content_tag(:div, content_tag(:p, @multiple_error), {:class => 'errorExplanation', :id => 'errorExplanation'}) unless @multiple_error.blank?
|
||||
error_messages = @multiple_error || ""
|
||||
# add errors of individual @todos
|
||||
@todos.each do |todo|
|
||||
error_messages += get_list_of_error_messages_for(todo)
|
||||
end
|
||||
-%>
|
||||
return "<%= escape_javascript(error_messages.html_safe)%>";
|
||||
}
|
||||
|
||||
<% end # if @saved -%>
|
||||
|
|
@ -1,4 +1,6 @@
|
|||
<%- if @saved -%>
|
||||
<%- unless @saved -%>
|
||||
TracksPages.page_notify('error', "<%= t('todos.error_deleting_item', :description => @todo.description) %>", 8);
|
||||
<%- else -%>
|
||||
TracksPages.page_notify('notice', '<%= escape_javascript(t('todos.deleted_success')) %>', 5);
|
||||
TracksPages.set_page_badge(<%=@down_count%>);
|
||||
remove_todo_from_page();
|
||||
|
|
@ -6,20 +8,14 @@
|
|||
activate_pending_todos();
|
||||
update_predecessors();
|
||||
show_empty_messages();
|
||||
<%- else -%>
|
||||
TracksPages.page_notify('error', "<%= t('todos.error_deleting_item', :description => @todo.description) %>", 8);
|
||||
<%- end -%>
|
||||
|
||||
<% if @saved
|
||||
# do not send the js in case of an error
|
||||
-%>
|
||||
|
||||
function show_empty_messages() {
|
||||
<% if @old_due_empty -%>
|
||||
$('#empty_<%=@original_item_due_id%>').slideDown(1000);
|
||||
<% end -%>
|
||||
|
||||
<% if empty_container_msg_div_id && todo_container_is_empty -%>
|
||||
<% if todo_container_is_empty -%>
|
||||
$('#<%=empty_container_msg_div_id%>').slideDown(1000);
|
||||
<% if @down_count == 0 -%>
|
||||
$('#no_todos_in_view').slideDown(1000);
|
||||
|
|
@ -32,10 +28,10 @@ function show_empty_messages() {
|
|||
}
|
||||
|
||||
function remove_todo_from_page() {
|
||||
<% if (@remaining_in_context == 0) && update_needs_to_hide_context
|
||||
<% if (@remaining_in_context == 0) && update_needs_to_hide_container
|
||||
# remove context with deleted todo
|
||||
-%>
|
||||
$('#c<%=@todo.context_id%>').fadeOut(400, function() {
|
||||
$('#<%=item_container_id(@todo)%>').fadeOut(400, function() {
|
||||
$('#<%=dom_id(@todo)%>').remove();
|
||||
});
|
||||
<%= show_empty_message_in_source_container -%>
|
||||
|
|
@ -104,8 +100,4 @@ function update_predecessors() {
|
|||
|
||||
function html_for_new_recurring_todo() {
|
||||
return "<%= @saved && @new_recurring_todo ? escape_javascript(render(:partial => @new_recurring_todo, :locals => { :parent_container_type => parent_container_type })) : "" %>";
|
||||
}
|
||||
|
||||
<% end
|
||||
# if @saved
|
||||
-%>
|
||||
}
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
<%= show_grouped_todos %>
|
||||
|
||||
<% if @group_view_by == 'project' -%>
|
||||
<%= show_todos_without_project(@todos_without_project) unless @todos_without_project.nil? -%>
|
||||
<%= show_todos_without_project(@todos_without_project) -%>
|
||||
<% end -%>
|
||||
|
||||
<%= show_done_todos(@done, {:parent_container_type => 'home', :collapsible => true}) unless @done.nil? %>
|
||||
|
|
|
|||
|
|
@ -13,6 +13,10 @@
|
|||
|
||||
<%= show_grouped_todos %>
|
||||
|
||||
<% if @group_view_by == 'project' -%>
|
||||
<%= show_todos_without_project(@todos_without_project) -%>
|
||||
<% end -%>
|
||||
|
||||
<%= show_deferred_pending_todos(@deferred_todos, @pending_todos, deferred_pending_options) %>
|
||||
|
||||
<%= show_hidden_todos(@hidden_todos, hidden_options) unless @hidden_todos.nil? %>
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ function redirect_after_complete() {
|
|||
}
|
||||
|
||||
function remove_todo(next_steps) {
|
||||
<% if (@remaining_in_context == 0) && update_needs_to_hide_context
|
||||
<% if (@remaining_in_context == 0) && update_needs_to_hide_container
|
||||
# remove context with deleted todo
|
||||
-%>
|
||||
$('#c<%=@todo.context_id%>').fadeOut(400, function() {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,10 @@
|
|||
<% if !@saved -%>
|
||||
<% unless @saved -%>
|
||||
TracksPages.show_edit_errors(html_for_error_messages());
|
||||
|
||||
function html_for_error_messages() {
|
||||
return "<%= escape_javascript(get_list_of_error_messages_for(@todo)) %>";
|
||||
}
|
||||
|
||||
<% else
|
||||
|
||||
# jquery animations are async, so first collect all animation steps that need
|
||||
|
|
@ -13,15 +18,14 @@
|
|||
elsif append_updated_todo
|
||||
animation << (@new_context_created ? "insert_new_context_with_updated_todo" : "add_to_existing_container")
|
||||
end
|
||||
animation << "hide_context" if update_needs_to_hide_context
|
||||
animation << "hide_container" if update_needs_to_hide_container
|
||||
animation << "highlight_updated_todo"
|
||||
animation << "update_empty_container" if source_view_is_one_of(:tag, :todo, :deferred)
|
||||
animation << "update_predecessors"
|
||||
%>
|
||||
|
||||
<%= render_animation(animation) %>
|
||||
TracksPages.page_notify('notice', '<%=escape_javascript @status_message%>', 5);
|
||||
TracksPages.set_page_badge(<%= @down_count %>);
|
||||
<%= render_animation(animation) %>
|
||||
<% end %>
|
||||
|
||||
function remove_todo(next_steps) {
|
||||
|
|
@ -46,7 +50,7 @@ function add_to_existing_container(next_steps) {
|
|||
<% end -%>
|
||||
<% else -%>
|
||||
<% unless (@todo_hidden_state_changed && @todo.hidden?) || @todo_was_deferred_from_active_state -%>
|
||||
$('#c<%= @todo.context_id %>').fadeIn(500, function() {
|
||||
$('#<%= item_container_id(@todo) %>').fadeIn(500, function() {
|
||||
next_steps.go();
|
||||
<% if @target_context_count==1 -%>
|
||||
$("#<%= empty_container_msg_div_id %>").slideUp(100);
|
||||
|
|
@ -69,9 +73,8 @@ function replace_todo(next_steps) {
|
|||
next_steps.go();
|
||||
}
|
||||
|
||||
function hide_context(next_steps) {
|
||||
<% context_id = @context_changed ? @original_item_context_id : @todo.context_id -%>
|
||||
$('#c<%= context_id %>').fadeOut(400, function(){ next_steps.go(); });
|
||||
function hide_container(next_steps) {
|
||||
$('#<%= item_container_id(@original_item) %>').fadeOut(400, function(){ next_steps.go(); });
|
||||
<%= "$('#deferred_pending_container_empty-nd').slideDown(400);".html_safe if source_view_is(:deferred) && @down_count == 0 %>
|
||||
}
|
||||
|
||||
|
|
@ -109,10 +112,6 @@ function html_for_new_context() {
|
|||
return "<%= @saved && @new_context_created ? escape_javascript(render(:partial => @new_context, :locals => { :settings => {:collapsible => true }})) : "" %>";
|
||||
}
|
||||
|
||||
function html_for_error_messages() {
|
||||
return "<%= escape_javascript(get_list_of_error_messages_for(@todo)) %>";
|
||||
}
|
||||
|
||||
function update_predecessors(next_steps) {
|
||||
regenerate_predecessor_family();
|
||||
<% if @removed_predecessors
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue