mirror of
https://github.com/TracksApp/tracks.git
synced 2026-02-20 14:14:09 +01:00
migrate adding to actions on all pages
This commit is contained in:
parent
25c6e2cc9c
commit
e13e946295
24 changed files with 356 additions and 276 deletions
|
|
@ -136,7 +136,8 @@ class ApplicationController < ActionController::Base
|
|||
|
||||
def for_autocomplete(coll, substr)
|
||||
filtered = coll.find_all{|item| item.name.downcase.include? substr.downcase}
|
||||
return "[{" + filtered.map {|item| "\"value\"=\"#{item.name}\", \"id\"=\"#{item.id}\""}.join("},{") + "}]"
|
||||
json_elems = "[{" + filtered.map {|item| "\"value\" : \"#{item.name}\", \"id\" : \"#{item.id}\""}.join("},{") + "}]"
|
||||
return json_elems == "[{}]" ? "" : json_elems
|
||||
end
|
||||
|
||||
# Uses RedCloth to transform text using either Textile or Markdown Need to
|
||||
|
|
|
|||
|
|
@ -250,6 +250,7 @@ class ContextsController < ApplicationController
|
|||
|
||||
@count = @not_done_todos.size
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -48,6 +48,8 @@ class TodosController < ApplicationController
|
|||
|
||||
def create
|
||||
@source_view = params['_source_view'] || 'todo'
|
||||
@default_context = current_user.contexts.find_by_name(params['default_context_name'])
|
||||
|
||||
@tag_name = params['_tag_name']
|
||||
|
||||
is_multiple = params[:todo] && params[:todo][:multiple_todos] && !params[:todo][:multiple_todos].nil?
|
||||
|
|
@ -862,12 +864,11 @@ class TodosController < ApplicationController
|
|||
# current_users.todos.find but that broke with_scope for :limit
|
||||
|
||||
# Exclude hidden projects from count on home page
|
||||
@todos = Todo.find(:all, :conditions => ['todos.user_id = ?', current_user.id], :include => [ :project, :context, :tags ])
|
||||
@todos = current_user.todos.find(:all, :include => [ :project, :context, :tags ])
|
||||
|
||||
# Exclude hidden projects from the home page
|
||||
@not_done_todos = Todo.find(:all,
|
||||
:conditions => ['todos.user_id = ? AND contexts.hide = ? AND (projects.state = ? OR todos.project_id IS NULL)',
|
||||
current_user.id, false, 'active'],
|
||||
@not_done_todos = current_user.todos.find(:all,
|
||||
:conditions => ['contexts.hide = ? AND (projects.state = ? OR todos.project_id IS NULL)', false, 'active'],
|
||||
:order => "todos.due IS NULL, todos.due ASC, todos.created_at ASC",
|
||||
:include => [ :project, :context, :tags ])
|
||||
end
|
||||
|
|
@ -882,9 +883,8 @@ class TodosController < ApplicationController
|
|||
# but that broke with_scope for :limit
|
||||
|
||||
# Exclude hidden projects from the home page
|
||||
@not_done_todos = Todo.find(:all,
|
||||
:conditions => ['todos.user_id = ? AND todos.state = ? AND contexts.hide = ? AND (projects.state = ? OR todos.project_id IS NULL)',
|
||||
current_user.id, 'active', false, 'active'],
|
||||
@not_done_todos = current_user.todos.find(:all,
|
||||
:conditions => ['todos.state = ? AND contexts.hide = ? AND (projects.state = ? OR todos.project_id IS NULL)', 'active', false, 'active'],
|
||||
:order => "todos.due IS NULL, todos.due ASC, todos.created_at ASC",
|
||||
:include => [ :project, :context, :tags ])
|
||||
end
|
||||
|
|
@ -892,14 +892,10 @@ class TodosController < ApplicationController
|
|||
def determine_down_count
|
||||
source_view do |from|
|
||||
from.todo do
|
||||
@down_count = Todo.count(
|
||||
@down_count = current_user.todos.count(
|
||||
:all,
|
||||
:conditions => ['todos.user_id = ? and todos.state = ? and contexts.hide = ? AND (projects.state = ? OR todos.project_id IS NULL)', current_user.id, 'active', false, 'active'],
|
||||
:conditions => ['todos.state = ? and contexts.hide = ? AND (projects.state = ? OR todos.project_id IS NULL)', 'active', false, 'active'],
|
||||
:include => [ :project, :context ])
|
||||
# #@down_count = Todo.count_by_sql(['SELECT COUNT(*) FROM todos,
|
||||
# contexts WHERE todos.context_id = contexts.id and todos.user_id = ?
|
||||
# and todos.state = ? and contexts.hide = ?', current_user.id, 'active',
|
||||
# false])
|
||||
end
|
||||
from.context do
|
||||
@down_count = current_user.contexts.find(@todo.context_id).not_done_todo_count
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ module TodosHelper
|
|||
|
||||
def remote_toggle_checkbox
|
||||
check_box_tag('item_id', toggle_check_todo_path(@todo), @todo.completed?, :class => 'item-checkbox',
|
||||
:title => @todo.pending? ? t('todos.blocked_by', :predecessors => @todo.uncompleted_predecessors.map(&:description).join(', ')) : "", :readonly => @todo.pending?)
|
||||
:title => @todo.pending? ? t('todos.blocked_by', :predecessors => @todo.uncompleted_predecessors.map(&:description).join(', ')) : "", :readonly => @todo.pending?)
|
||||
end
|
||||
|
||||
def date_span
|
||||
|
|
@ -226,11 +226,9 @@ module TodosHelper
|
|||
end
|
||||
|
||||
def item_container_id (todo)
|
||||
if todo.deferred? or todo.pending?
|
||||
return "tickleritems"
|
||||
elsif source_view_is :project
|
||||
return "p#{todo.project_id}items"
|
||||
end
|
||||
return "c#{todo.context_id}items" if source_view_is :tickler
|
||||
return "tickleritems" if todo.deferred? or todo.pending?
|
||||
return "p#{todo.project_id}items" if source_view_is :project
|
||||
return "c#{todo.context_id}items"
|
||||
end
|
||||
|
||||
|
|
@ -244,6 +242,7 @@ module TodosHelper
|
|||
end
|
||||
|
||||
return false if (source_view_is(:tag) && !@todo.tags.include?(@tag_name))
|
||||
return false if (source_view_is(:context) && !(@todo.context_id==@default_context.id) )
|
||||
|
||||
return true if source_view_is(:deferred) && @todo.deferred?
|
||||
return true if source_view_is(:project) && @todo.project.hidden? && @todo.project_hidden?
|
||||
|
|
@ -264,6 +263,7 @@ module TodosHelper
|
|||
|
||||
def empty_container_msg_div_id
|
||||
todo = @todo || @successor
|
||||
return "" unless todo # empty id if no todo or successor given
|
||||
return "tickler-empty-nd" if source_view_is_one_of(:project, :tag) && todo.deferred?
|
||||
return "p#{todo.project_id}empty-nd" if source_view_is :project
|
||||
return "c#{todo.context_id}empty-nd"
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
<%
|
||||
@todo = nil
|
||||
@initial_context_name = @context.name unless @context.nil?
|
||||
@initial_context_name ||= @project.default_context.name unless @project.nil? || @project.default_context.nil?
|
||||
@initial_context_name ||= current_user.contexts.first.name unless current_user.contexts.first.nil?
|
||||
|
|
@ -12,102 +11,7 @@
|
|||
<a title="<%= t('shared.toggle_multi_title') %>" accesskey="m" href="#" id="toggle_multi"><%= t('shared.toggle_multi') %></a>
|
||||
</div>
|
||||
|
||||
<div id="todo_new_action" style="display:block">
|
||||
<% form_remote_tag(
|
||||
:url => todos_path, :method => :post,
|
||||
: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 => "TodoItems.askIfNewContextProvided('')") do -%>
|
||||
|
||||
<div id="status"><%= error_messages_for("item", :object_name => 'action') %></div>
|
||||
|
||||
<label for="todo_description"><%= Todo.human_attribute_name('description') %></label>
|
||||
<%= text_field( "todo", "description", "size" => 30, "tabindex" => 1, "maxlength" => 100, "autocomplete" => "off", :autofocus => 1) %>
|
||||
|
||||
<label for="todo_notes"><%= Todo.human_attribute_name('notes') %></label>
|
||||
<%= text_area( "todo", "notes", "cols" => 29, "rows" => 6, "tabindex" => 2) %>
|
||||
|
||||
<input id="default_project_name_id" name="default_project_name" type="hidden" value="<%=@initial_project_name-%>" />
|
||||
|
||||
<label for="todo_project_name"><%= Todo.human_attribute_name('project') %></label>
|
||||
<input id="todo_project_name" name="project_name" autocomplete="off" tabindex="3" size="30" type="text" value="<%= @initial_project_name %>" />
|
||||
<div class="page_name_auto_complete" id="project_list" style="display:none"></div>
|
||||
|
||||
<input id="default_context_name_id" name="default_context_name" type="hidden" value="<%=@initial_context_name-%>" />
|
||||
|
||||
<label for="todo_context_name"><%= Todo.human_attribute_name('context') %></label>
|
||||
<input id="todo_context_name" name="context_name" autocomplete="off" tabindex="4" size="30" type="text" value="<%= @initial_context_name %>" />
|
||||
|
||||
<label for="tag_list"><%= Todo.human_attribute_name('tags') + ' (' + t('shared.separate_tags_with_commas') + ')' %></label>
|
||||
<%= text_field_tag "tag_list", @default_tags, :size => 30, :tabindex => 5 %>
|
||||
<%= content_tag("div", "", :id => "tag_list_auto_complete", :class => "auto_complete") %>
|
||||
|
||||
<div class="due_input">
|
||||
<label for="todo_due"><%= Todo.human_attribute_name('due') %></label>
|
||||
<%= text_field("todo", "due", "size" => 12, "class" => "Date", "tabindex" => 6, "autocomplete" => "off") %>
|
||||
</div>
|
||||
|
||||
<div class="show_from_input">
|
||||
<label for="todo_show_from"><%= Todo.human_attribute_name('show_from') %></label>
|
||||
<%= text_field("todo", "show_from", "size" => 12, "class" => "Date", "tabindex" => 7, "autocomplete" => "off") %>
|
||||
</div>
|
||||
|
||||
<label for="predecessor_list"><%= Todo.human_attribute_name('predecessors')%></label>
|
||||
<%= text_field_tag "predecessor_list", nil, :size => 30, :tabindex => 8 %>
|
||||
<%= source_view_tag( @source_view ) %>
|
||||
<%= hidden_field_tag :_tag_name, @tag_name.underscore.gsub(/\s+/,'_') if source_view_is :tag %>
|
||||
|
||||
<div class="submit_box">
|
||||
<div class="widgets">
|
||||
<button type="submit" class="positive" id="todo_new_action_submit" tabindex="8">
|
||||
<%= image_tag("accept.png", :alt => "") + t('shared.add_action') %>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<% end # form-remote-tag -%>
|
||||
</div>
|
||||
|
||||
<div id="todo_multi_add" style="display:none">
|
||||
<% form_remote_tag(
|
||||
:url => todos_path, :method => :post,
|
||||
: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 => "TodoItems.askIfNewContextProvided('multi_')") do -%>
|
||||
|
||||
<div id="multiple_status"><%= error_messages_for("item", :object_name => 'action') %></div>
|
||||
|
||||
<label for="todo_notes"><%= t('shared.multiple_next_actions') %></label>
|
||||
<%= text_area( "todo", "multiple_todos", "cols" => 29, "rows" => 6, "tabindex" => 2) %>
|
||||
|
||||
<input id="default_project_name_id" name="default_project_name" type="hidden" value="<%=@initial_project_name-%>" />
|
||||
|
||||
<label for="todo_project_name"><%= t('shared.project_for_all_actions') %></label>
|
||||
<input id="multi_todo_project_name" name="project_name" autocomplete="off" tabindex="3" size="30" type="text" value="<%= @initial_project_name %>" />
|
||||
<div class="page_name_auto_complete" id="project_list" style="display:none"></div>
|
||||
|
||||
<input id="default_context_name_id" name="default_context_name" type="hidden" value="<%=@initial_context_name-%>" />
|
||||
|
||||
<label for="todo_context_name"><%= t('shared.context_for_all_actions') %></label>
|
||||
<input id="multi_todo_context_name" name="context_name" autocomplete="off" tabindex="4" size="30" type="text" value="<%= @initial_context_name %>" />
|
||||
<div class="page_name_auto_complete" id="context_list" style="display:none"></div>
|
||||
|
||||
<label for="tag_list"><%= t('shared.tags_for_all_actions') + ' (' + t('shared.separate_tags_with_commas') +')' %></label>
|
||||
<%= text_field_tag "multi_tag_list", @default_tags, :name=>:tag_list, :size => 30, :tabindex => 5 %>
|
||||
<%= content_tag("div", "", :id => "tag_list_auto_complete", :class => "auto_complete") %>
|
||||
|
||||
<div class="submit_box">
|
||||
<div class="widgets">
|
||||
<button type="submit" class="positive" id="todo_multi_new_action_submit" tabindex="8">
|
||||
<%= image_tag("accept.png", :alt => "") %><%= t('shared.add_actions') %>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<% end -%>
|
||||
|
||||
</div>
|
||||
<%= render :partial => 'todos/new_todo_form', :object => Todo.new %>
|
||||
<%= render :partial => 'todos/new_multi_todo_form', :object => Todo.new %>
|
||||
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,13 +1,7 @@
|
|||
<div id="sidebar">
|
||||
<%= sidebar_html_for_titled_list(@active_projects, t('sidebar.list_name_active_projects'))%>
|
||||
<%= sidebar_html_for_titled_list(@active_contexts, t('sidebar.list_name_active_contexts'))%>
|
||||
<% if prefs.show_hidden_projects_in_sidebar -%>
|
||||
<%= sidebar_html_for_titled_list(@hidden_projects, t('sidebar.list_name_hidden_projects'))%>
|
||||
<% end -%>
|
||||
<% if prefs.show_completed_projects_in_sidebar -%>
|
||||
<%= sidebar_html_for_titled_list(@completed_projects, t('sidebar.list_name_completed_projects'))%>
|
||||
<% end -%>
|
||||
<% if prefs.show_hidden_contexts_in_sidebar -%>
|
||||
<%= sidebar_html_for_titled_list(@hidden_contexts, t('sidebar.list_name_hidden_contexts'))%>
|
||||
<% end -%>
|
||||
<%= sidebar_html_for_titled_list(@hidden_projects, t('sidebar.list_name_hidden_projects')) if prefs.show_hidden_projects_in_sidebar %>
|
||||
<%= sidebar_html_for_titled_list(@completed_projects, t('sidebar.list_name_completed_projects')) if prefs.show_completed_projects_in_sidebar %>
|
||||
<%= sidebar_html_for_titled_list(@hidden_contexts, t('sidebar.list_name_hidden_contexts')) if prefs.show_hidden_contexts_in_sidebar %>
|
||||
</div>
|
||||
35
app/views/todos/_new_multi_todo_form.rhtml
Normal file
35
app/views/todos/_new_multi_todo_form.rhtml
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
<%- todo = new_multi_todo_form -%>
|
||||
|
||||
<div id="todo_multi_add" style="display:none">
|
||||
<% form_for(todo, :html=> { :id=>'todo-form-multi-new-action', :name=>'todo', :class => 'inline-form' }) do |t| %>
|
||||
<input id="default_project_name_id" name="default_project_name" type="hidden" value="<%=@initial_project_name-%>" />
|
||||
<input id="default_context_name_id" name="default_context_name" type="hidden" value="<%=@initial_context_name-%>" />
|
||||
|
||||
<div id="multiple_error_status"><%= error_messages_for("item", :object_name => 'action') %></div>
|
||||
|
||||
<label for="todo_notes"><%= t('shared.multiple_next_actions') %></label>
|
||||
<%= text_area_tag( "todo[multiple_todos]", "", :cols => 29, :rows => 6, :tabindex => 2) %>
|
||||
|
||||
<label for="todo_project_name"><%= t('shared.project_for_all_actions') %></label>
|
||||
<input id="multi_todo_project_name" name="project_name" autocomplete="off" tabindex="3" size="30" type="text" value="<%= @initial_project_name %>" />
|
||||
<div class="page_name_auto_complete" id="project_list" style="display:none"></div>
|
||||
|
||||
<label for="todo_context_name"><%= t('shared.context_for_all_actions') %></label>
|
||||
<input id="multi_todo_context_name" name="context_name" autocomplete="off" tabindex="4" size="30" type="text" value="<%= @initial_context_name %>" />
|
||||
<div class="page_name_auto_complete" id="context_list" style="display:none"></div>
|
||||
|
||||
<label for="tag_list"><%= t('shared.tags_for_all_actions') + ' (' + t('shared.separate_tags_with_commas') +')' %></label>
|
||||
<%= text_field_tag "multi_tag_list", @default_tags, :name=>:tag_list, :size => 30, :tabindex => 5 %>
|
||||
<%= content_tag("div", "", :id => "tag_list_auto_complete", :class => "auto_complete") %>
|
||||
|
||||
<div class="submit_box">
|
||||
<div class="widgets">
|
||||
<button type="submit" class="positive" id="todo_multi_new_action_submit" tabindex="8">
|
||||
<%= image_tag("accept.png", :alt => "") %><%= t('shared.add_actions') %>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<% end -%>
|
||||
|
||||
</div>
|
||||
51
app/views/todos/_new_todo_form.rhtml
Normal file
51
app/views/todos/_new_todo_form.rhtml
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
<%- todo = new_todo_form -%>
|
||||
|
||||
<div id="todo_new_action">
|
||||
<% form_for(todo, :html=> { :id=>'todo-form-new-action', :name=>'todo', :class => 'inline-form' }) do |t|%>
|
||||
<input id="default_project_name_id" name="default_project_name" type="hidden" value="<%=@initial_project_name-%>" />
|
||||
<input id="default_context_name_id" name="default_context_name" type="hidden" value="<%=@initial_context_name-%>" />
|
||||
|
||||
<div id="error_status"><%= error_messages_for("item", :object_name => 'action') %></div>
|
||||
|
||||
<label for="todo_description"><%= Todo.human_attribute_name('description') %></label>
|
||||
<%= t.text_field("description", "size" => 30, "tabindex" => 1, "maxlength" => 100, "autocomplete" => "off", :autofocus => 1) %>
|
||||
|
||||
<label for="todo_notes"><%= Todo.human_attribute_name('notes') %></label>
|
||||
<%= t.text_area("notes", "cols" => 29, "rows" => 6, "tabindex" => 2) %>
|
||||
|
||||
<label for="todo_project_name"><%= Todo.human_attribute_name('project') %></label>
|
||||
<input id="todo_project_name" name="project_name" autocomplete="off" tabindex="3" size="30" type="text" value="<%= @initial_project_name %>" />
|
||||
<div class="page_name_auto_complete" id="project_list" style="display:none"></div>
|
||||
|
||||
<label for="todo_context_name"><%= Todo.human_attribute_name('context') %></label>
|
||||
<input id="todo_context_name" name="context_name" autocomplete="off" tabindex="4" size="30" type="text" value="<%= @initial_context_name %>" />
|
||||
|
||||
<label for="tag_list"><%= Todo.human_attribute_name('tags') + ' (' + t('shared.separate_tags_with_commas') + ')' %></label>
|
||||
<%= text_field_tag "tag_list", @default_tags, :size => 30, :tabindex => 5 %>
|
||||
<%= content_tag("div", "", :id => "tag_list_auto_complete", :class => "auto_complete") %>
|
||||
|
||||
<div class="due_input">
|
||||
<label for="todo_due"><%= Todo.human_attribute_name('due') %></label>
|
||||
<%= t.text_field("due", "size" => 12, "class" => "Date", "tabindex" => 6, "autocomplete" => "off") %>
|
||||
</div>
|
||||
|
||||
<div class="show_from_input">
|
||||
<label for="todo_show_from"><%= Todo.human_attribute_name('show_from') %></label>
|
||||
<%= t.text_field("show_from", "size" => 12, "class" => "Date", "tabindex" => 7, "autocomplete" => "off") %>
|
||||
</div>
|
||||
|
||||
<label for="predecessor_list"><%= Todo.human_attribute_name('predecessors')%></label>
|
||||
<%= text_field_tag "predecessor_list", nil, :size => 30, :tabindex => 8 %>
|
||||
<%= source_view_tag( @source_view ) %>
|
||||
<%= hidden_field_tag :_tag_name, @tag_name.underscore.gsub(/\s+/,'_') if source_view_is :tag %>
|
||||
|
||||
<div class="submit_box">
|
||||
<div class="widgets">
|
||||
<button type="submit" class="positive" id="todo_new_action_submit" tabindex="8">
|
||||
<%= image_tag("accept.png", :alt => "") + t('shared.add_action') %>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<% end # form_for -%>
|
||||
</div>
|
||||
77
app/views/todos/create.js.erb
Normal file
77
app/views/todos/create.js.erb
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
<% if @saved -%>
|
||||
set_notification();
|
||||
hide_empty_message();
|
||||
TracksPages.hide_errors();
|
||||
TracksPages.set_page_badge(<%= @down_count %>);
|
||||
<% if should_show_new_item -%>
|
||||
<% if @new_context_created -%>
|
||||
insert_new_context_with_new_todo();
|
||||
<% else -%>
|
||||
add_todo_to_existing_context();
|
||||
<% end -%>
|
||||
<% end -%>
|
||||
update_predecessors();
|
||||
clear_form();
|
||||
<% else -%>
|
||||
TracksPages.show_errors(html_for_error_messages());
|
||||
<% end -%>
|
||||
|
||||
function set_notification() {
|
||||
<%-
|
||||
status_message = 'Added new next action'
|
||||
status_message += ' to tickler' if @todo.deferred?
|
||||
status_message += ' in pending state' if @todo.pending?
|
||||
status_message = 'Added new project / ' + status_message if @new_project_created
|
||||
status_message = 'Added new context / ' + status_message if @new_context_created
|
||||
-%>
|
||||
TracksPages.page_notify('notice', "<%=status_message%>", 5);
|
||||
}
|
||||
|
||||
function hide_empty_message() {
|
||||
<% if @todo %>
|
||||
$('#<%=empty_container_msg_div_id%>').hide();
|
||||
<% if (source_view_is :project and @todo.pending?) or (source_view_is :deferred) -%>
|
||||
$('#tickler-empty-nd').hide();
|
||||
<% end -%>
|
||||
<% end -%>
|
||||
}
|
||||
|
||||
function clear_form() {
|
||||
$('#todo-form-new-action').clearForm();
|
||||
TracksForm.set_context_name('<%=@initial_context_name%>');
|
||||
TracksForm.set_project_name('<%=@initial_project_name%>');
|
||||
TracksForm.set_tag_list('<%=@default_tags%>');
|
||||
$('#todo-form-new-action input:text:first').focus();
|
||||
}
|
||||
|
||||
function insert_new_context_with_new_todo() {
|
||||
$('#display_box').prepend(html_for_new_context());
|
||||
}
|
||||
|
||||
function add_todo_to_existing_context() {
|
||||
<% if source_view_is_one_of(:todo, :deferred, :tag) -%>
|
||||
TodoItemsContainer.ensureVisibleWithEffectAppear("c<%=@todo.context_id%>");
|
||||
<% end -%>
|
||||
$('#<%=item_container_id(@todo)%>').append(html_for_new_todo());
|
||||
$('#<%= dom_id(@todo)%>').effect('highlight', {}, 2000 );
|
||||
}
|
||||
|
||||
function update_predecessors() {
|
||||
<% @todo.uncompleted_predecessors.each do |p| -%>
|
||||
if ($('<%=item_container_id(p)%>')) {
|
||||
$('#<%=dom_id(p)%>').html('<%= escape_javascript(render(:partial => 'todos/todo', :locals => { :todo => p, :parent_container_type => parent_container_type, :source_view => @source_view }))%>');
|
||||
}
|
||||
<% end -%>
|
||||
}
|
||||
|
||||
function html_for_error_messages() {
|
||||
return "<%= escape_javascript(error_messages_for('todo', :object_name => 'action')) %>";
|
||||
}
|
||||
|
||||
function html_for_new_context() {
|
||||
return "<%= @saved && @new_context_created ? escape_javascript(render(:partial => 'contexts/context', :locals => { :context => @todo.context, :collapsible => true })) : "" %>";
|
||||
}
|
||||
|
||||
function html_for_new_todo() {
|
||||
return "<%= @saved ? escape_javascript(render(:partial => 'todos/todo', :locals => { :todo => @todo, :parent_container_type => parent_container_type, :source_view => @source_view })) : "" %>";
|
||||
}
|
||||
|
|
@ -1,41 +0,0 @@
|
|||
if @saved
|
||||
page.hide 'status'
|
||||
status_message = t('todos.added_new_next_action')
|
||||
status_message += t('todos.to_tickler') if @todo.deferred?
|
||||
status_message += t('todos.in_pending_state') if @todo.pending?
|
||||
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
|
||||
page['badge_count'].replace_html @down_count
|
||||
page.send :record, "$('#todo-form-new-action').clearForm();$('#todo-form-new-action input:text:first').focus();"
|
||||
page['todo_context_name'].value = @initial_context_name
|
||||
page['todo_project_name'].value = @initial_project_name
|
||||
page['tag_list'].value = @default_tags
|
||||
#page << "updateContextNamesForAutoComplete(#{context_names_for_autocomplete})" if @new_context_created
|
||||
#page << "projectAutoCompleter.options.array = #{project_names_for_autocomplete}" if @new_project_created
|
||||
if should_show_new_item()
|
||||
if @new_context_created
|
||||
page.insert_html :top, 'display_box', :partial => 'contexts/context', :locals => { :context => @todo.context, :collapsible => true }
|
||||
else
|
||||
page.call "todoItems.ensureVisibleWithEffectAppear", "c#{@todo.context_id}" if source_view_is_one_of(:todo, :deferred, :tag)
|
||||
page.insert_html :bottom, item_container_id(@todo), :partial => 'todos/todo', :locals => { :todo => @todo, :parent_container_type => parent_container_type, :source_view => @source_view }
|
||||
page.visual_effect :highlight, dom_id(@todo), :duration => 3
|
||||
page[empty_container_msg_div_id].hide unless empty_container_msg_div_id.nil?
|
||||
end
|
||||
if (source_view_is :project and @todo.pending?) or (source_view_is :deferred)
|
||||
page['tickler-empty-nd'].hide # For some reason this does not work: page['tickler-empty-nd'].hide if (@todo.pending? or (source_view_is :deferred))
|
||||
end
|
||||
end
|
||||
# Update predecessors (if they exist and are visible)
|
||||
@todo.uncompleted_predecessors.each do |p|
|
||||
page << "if ($(\'#{item_container_id(p)}\')) {"
|
||||
page[p].replace_html :partial => 'todos/todo',
|
||||
:locals => { :todo => p, :parent_container_type => parent_container_type }
|
||||
page << "}"
|
||||
end
|
||||
# make sure the behavior of the new/updated todo is enabled
|
||||
page << "enable_rich_interaction();"
|
||||
else
|
||||
page.show 'status'
|
||||
page.replace_html 'status', "#{error_messages_for('todo', :object_name => 'action')}"
|
||||
end
|
||||
83
app/views/todos/create_multiple.js.erb
Normal file
83
app/views/todos/create_multiple.js.erb
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
<% if @saved -%>
|
||||
set_notification();
|
||||
hide_empty_message();
|
||||
TracksPages.hide_errors();
|
||||
TracksPages.set_page_badge(<%= @down_count %>);
|
||||
<% if should_show_new_item -%>
|
||||
<% if @new_context_created -%>
|
||||
insert_new_context_with_new_todo();
|
||||
<% else -%>
|
||||
add_todo_to_existing_context();
|
||||
<% end -%>
|
||||
<% end -%>
|
||||
clear_form();
|
||||
<% else -%>
|
||||
TracksPages.show_errors_for_multi_add(html_for_error_messages());
|
||||
<% end -%>
|
||||
|
||||
<% if @saved
|
||||
# the following functions assume a todo is saved or not nil, so leave them out in case of an error
|
||||
-%>
|
||||
|
||||
function set_notification() {
|
||||
<%-
|
||||
status_message = 'Added new next action'
|
||||
status_message += 's' if @todos.size > 1
|
||||
status_message = 'Added new project / ' + status_message if @new_project_created
|
||||
status_message = 'Added new context / ' + status_message if @new_context_created
|
||||
-%>
|
||||
TracksPages.page_notify('notice', "<%=status_message%>", 5);
|
||||
}
|
||||
|
||||
function clear_form() {
|
||||
$('#todo-form-multi-new-action').clearForm();
|
||||
TracksForm.set_context_name_for_multi_add('<%=@initial_context_name%>');
|
||||
TracksForm.set_project_name_for_multi_add('<%=@initial_project_name%>');
|
||||
TracksForm.set_tag_list_for_multi_add('<%=@default_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) -%>
|
||||
$('#tickler-empty-nd').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 => 'todos/todo', :locals => { :todo => todo, :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 => 'contexts/context', :locals => { :context => @todo.context, :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|
|
||||
@todo_i = todo
|
||||
error_messages += error_messages_for('todo_i', :object_name => 'action')
|
||||
end
|
||||
-%>
|
||||
return "<%= escape_javascript(error_messages)%>";
|
||||
}
|
||||
|
||||
<% end # if @saved -%>
|
||||
|
|
@ -1,50 +0,0 @@
|
|||
if @saved
|
||||
page.hide 'multiple_status'
|
||||
|
||||
status_message = t('todos.added_new_next_action')
|
||||
status_message += 's' if @todos.size > 1
|
||||
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
|
||||
|
||||
page['badge_count'].replace_html @down_count
|
||||
|
||||
# reset form and set focus to first field
|
||||
page.send :record, "$('#todo-form-multi-new-action').clearForm();$('#todo-form-multi-new-action input:text:first').focus();"
|
||||
|
||||
# set defaults of form
|
||||
page.send :record, "$('#multi_todo_context_name').val('#{@initial_context_name}');"
|
||||
page.send :record, "$('#multi_todo_project_name').val('#{@initial_project_name}');"
|
||||
page.send :record, "$('#multi_tag_list').val('#{@default_tags}');"
|
||||
|
||||
if should_show_new_item()
|
||||
if @new_context_created
|
||||
page.insert_html :top, 'display_box', :partial => 'contexts/context', :locals => { :context => @todo.context, :collapsible => true }
|
||||
else
|
||||
page.call "todoItems.ensureVisibleWithEffectAppear", "c#{@todo.context_id}" if source_view_is_one_of(:todo, :deferred, :tag)
|
||||
|
||||
@todos.each do |todo|
|
||||
page.insert_html :bottom, item_container_id(todo), :partial => 'todos/todo', :locals => { :todo => todo, :parent_container_type => parent_container_type, :source_view => @source_view }
|
||||
page.visual_effect :highlight, dom_id(todo), :duration => 3
|
||||
end
|
||||
|
||||
page[empty_container_msg_div_id].hide unless empty_container_msg_div_id.nil?
|
||||
end
|
||||
if (source_view_is :project and @todo.pending?) or (source_view_is :deferred)
|
||||
page['tickler-empty-nd'].hide # For some reason this does not work: page['tickler-empty-nd'].hide if (@todo.pending? or (source_view_is :deferred))
|
||||
end
|
||||
end
|
||||
# make sure the behavior of the new/updated todo is enabled
|
||||
page << "enable_rich_interaction();"
|
||||
else
|
||||
page.show 'multiple_status'
|
||||
# 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|
|
||||
@todo_i = todo
|
||||
error_messages += error_messages_for('todo_i', :object_name => 'action')
|
||||
end
|
||||
page.replace_html 'multiple_status', error_messages
|
||||
end
|
||||
|
|
@ -1,16 +1,15 @@
|
|||
<div id="display_box">
|
||||
|
||||
<%= render :partial => "contexts/context", :collection => @contexts_to_show,
|
||||
:locals => { :collapsible => true } %>
|
||||
<%= render(
|
||||
:partial => "contexts/context",
|
||||
:collection => @contexts_to_show,
|
||||
:locals => { :collapsible => true }) -%>
|
||||
<% unless @done.nil? -%>
|
||||
<%= render :partial => "todos/completed",
|
||||
:locals => { :done => @done, :collapsible => true, :append_descriptor => nil } %>
|
||||
<%= render(
|
||||
:partial => "todos/completed",
|
||||
:locals => { :done => @done, :collapsible => true, :append_descriptor => nil }) -%>
|
||||
<% end -%>
|
||||
</div><!-- End of display_box -->
|
||||
|
||||
<div id="input_box">
|
||||
<%= render :partial => "shared/add_new_item_form" %>
|
||||
<%- # TODO: this used to be render :template, but somehow it was not
|
||||
#rendered after the rails2.2.2 upgrade -%>
|
||||
<%= render :file => "sidebar/sidebar.html.erb" %>
|
||||
<%= render :template => "sidebar/sidebar.html.erb" %>
|
||||
</div><!-- End of input box -->
|
||||
Loading…
Add table
Add a link
Reference in a new issue