migrate adding to actions on all pages

This commit is contained in:
Reinier Balt 2010-12-17 16:01:22 +01:00
parent 25c6e2cc9c
commit e13e946295
24 changed files with 356 additions and 276 deletions

View file

@ -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

View file

@ -250,6 +250,7 @@ class ContextsController < ApplicationController
@count = @not_done_todos.size
end
end
end

View file

@ -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

View file

@ -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"

View file

@ -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>

View file

@ -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>

View 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>

View 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>

View 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 })) : "" %>";
}

View file

@ -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

View 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 -%>

View file

@ -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

View file

@ -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 -->

View file

@ -83,7 +83,7 @@ Feature: Edit a project
And I cancel adding a note to the project
Then the form for adding a note should not be visible
@selenium @wip
@selenium
Scenario: Long notes in a project are shown cut off
Given I have a project called "test"
When I visit the "test" project

View file

@ -133,4 +133,4 @@ Feature: Add new next action from every page
"""
Then I should see "You need to submit at least one next action"
Then I should see "You need to submit at least one next action"

View file

@ -8,7 +8,7 @@ var TracksForm = {
toggleLink.text(showLinkText).attr('title', showLinkTitle);
}
else {
toggleLink.text(hideLinkText).attr('title', hideLinkTitle);
toggleLidefault_ajax_optionsnk.text(hideLinkText).attr('title', hideLinkTitle);
$('#'+formId+' input:text:first').focus();
}
toggleLink.parent().toggleClass('hide_form');
@ -16,18 +16,30 @@ var TracksForm = {
set_project_name: function (name) {
$('input#todo_project_name').val(name);
},
set_context_name_and_default_context_name: function (name) {
set_project_name_for_multi_add: function (name) {
$('#multi_todo_project_name').val(name);
},
set_context_name: function (name) {
$('input#todo_context_name').val(name);
},
set_context_name_for_multi_add: function (name) {
$('#multi_todo_context_name').val(name);
},
set_context_name_and_default_context_name: function (name) {
TracksForm.set_context_name(name);
$('input[name=default_context_name]').val(name);
},
set_project_name_and_default_project_name: function (name) {
TracksForm.set_project_name('');
$('#default_project_name_id').val(name);
$('input#todo_project_name').val();
$('#project_name').html(name);
},
set_tag_list: function (name) {
$('input#tag_list').val(name);
},
set_tag_list_for_multi_add: function (name) {
$('#multi_tag_list').val(name);
},
setup_behavior: function() {
/* toggle new todo form for single todo */
$('#toggle_action_new').click(function(){
@ -94,6 +106,20 @@ var TracksForm = {
$.get(this.href, params, function(){
}, 'script');
});
/* submit todo form after entering new todo */
$("button#todo_new_action_submit").live('click', function (ev) {
if (TodoItems.askIfNewContextProvided('', this))
submit_with_ajax_and_block_element('form#todo-form-new-action', $(this));
return false;
});
/* submit multi-todo form after entering multiple new todos */
$("button#todo_multi_new_action_submit").live('click', function (ev) {
if (TodoItems.askIfNewContextProvided('multi_', this))
submit_with_ajax_and_block_element('form#todo-form-multi-new-action', $(this));
return false;
});
}
}
@ -106,8 +132,14 @@ var TracksPages = {
$('div#edit_error_status').html(html);
$('div#edit_error_status').show();
},
show_errors_for_multi_add: function(html) {
$('div#multiple_error_status').html(html);
$('div#multiple_error_status').show();
},
hide_errors: function() {
$('div#error_status').hide();
$('div#edit_error_status').hide();
$('div#multiple_error_status').hide();
},
update_sidebar: function(html) {
$('#sidebar').html(html);
@ -171,7 +203,7 @@ var TracksPages = {
$(".alert").fadeOut(8000);
/* for edit project form and edit todo form
* TODO: refactor to separate calls from project and todo */
* TODO: refactor to separate calls from project and todo */
$('.edit-form a.negative').live('click', function(){
$(this).parents('.edit-form').fadeOut(200, function () {
$(this).parents('.list').find('.project').fadeIn(500);
@ -261,24 +293,27 @@ var TodoItemsContainer = {
}
var TodoItems = {
askIfNewContextProvided: function(source) {
getContextsForAutocomplete: function (term, element_to_block) {
var allContexts = null;
params = default_ajax_options_for_scripts('GET', relative_to_root('contexts.autocomplete'), element_to_block);
params.data = "term="+term;
params.dataType = "json";
params.async = false;
params.success = function(result){
allContexts = result;
}
$.ajax(params);
return allContexts;
},
askIfNewContextProvided: function(source, element_to_block) {
var givenContextName = $('#'+source+'todo_context_name').val();
var contextNames = [];
var contextNamesRequest = $.ajax({
url: relative_to_root('contexts.autocomplete'),
async: false,
dataType: "text",
data: "q="+givenContextName,
success: function(result){
lines = result.split("\n");
for(var i = 0; i < lines.length; i++){
contextNames.push(lines[i].split("|")[0]);
}
}
});
if (givenContextName.length == 0) return true; // do nothing and depend on rails validation error
for (var i = 0; i < contextNames.length; ++i) {
if (contextNames[i] == givenContextName) return true;
contexts = TodoItems.getContextsForAutocomplete(givenContextName, element_to_block);
if (contexts) {
for (i=0; i<contexts.length; i++)
if (contexts[i].value == givenContextName) return true;
}
return confirm('New context "' + givenContextName + '" will be also created. Are you sure?');
},
@ -690,52 +725,47 @@ function generic_get_script_for_list(element, getter, param){
$(element).load(relative_to_root(getter+'?'+param));
}
function default_ajax_options(ajax_type, the_url, element_to_block) {
function default_ajax_options_for_submit(ajax_type, element_to_block) {
return {
url: the_url,
type: ajax_type,
async: true,
blocked_elem: element_to_block,
dataType: 'script',
context: element_to_block,
beforeSend: function() {
this.blocked_elem.block({
$(this).block({
message: null
});
},
complete:function() {
this.blocked_elem.unblock();
$(this).unblock();
enable_rich_interaction();
},
error: function(req, status) {
TracksPages.page_notify('error', 'There was an error retrieving from server: '+status, 8);
}
}
}
function default_ajax_options_for_scripts(ajax_type, the_url, element_to_block) {
options = default_ajax_options_for_submit(ajax_type, element_to_block);
options.url = the_url;
options.dataType = 'script';
return options;
}
function submit_with_ajax_and_block_element(form, element_to_block) {
$(form).ajaxSubmit({
type: 'POST',
async: true,
blocked_elem: element_to_block,
beforeSend: function() {
this.blocked_elem.block({
message: null
});
},
complete: function() {
this.blocked_elem.unblock();
enable_rich_interaction();
}
});
$(form).ajaxSubmit(default_ajax_options_for_submit('POST', element_to_block));
}
function get_with_ajax_and_block_element(the_url, element_to_block) {
$.ajax(default_ajax_options('GET', the_url, element_to_block));
$.ajax(default_ajax_options_for_scripts('GET', the_url, element_to_block));
}
function post_with_ajax_and_block_element(the_url, element_to_block) {
$.ajax(default_ajax_options('POST', the_url, element_to_block));
$.ajax(default_ajax_options_for_scripts('POST', the_url, element_to_block));
}
function put_with_ajax_and_block_element(the_url, element_to_block) {
options = default_ajax_options('POST', the_url, element_to_block);
options = default_ajax_options_for_scripts('POST', the_url, element_to_block);
options.data = '_method=put';
if(typeof(TAG_NAME) !== 'undefined')
options.data += "&_tag_name="+ encodeURIComponent (TAG_NAME);
@ -743,7 +773,7 @@ function put_with_ajax_and_block_element(the_url, element_to_block) {
}
function delete_with_ajax_and_block_element(the_url, element_to_block) {
$.ajax(default_ajax_options('DELETE', the_url, element_to_block));
$.ajax(default_ajax_options_for_scripts('DELETE', the_url, element_to_block));
}
$(document).ajaxSend(function(event, request, settings) {
@ -823,8 +853,8 @@ function enable_rich_interaction(){
/* called after completion of all AJAX calls */
/* fix for #1036 where closing a edit form before the autocomplete was filled
* resulted in a dropdown box that could not be removed. We remove all
* autocomplete boxes the hard way */
* resulted in a dropdown box that could not be removed. We remove all
* autocomplete boxes the hard way */
$('.ac_results').remove();
$('input.Date').datepicker({
@ -929,7 +959,7 @@ function enable_rich_interaction(){
field_touched = false;
/* shrink the notes on the project pages. This is not live(), so this needs
* to be run after ajax adding of a new note */
* to be run after ajax adding of a new note */
$('.note_wrapper').truncate({
max_length: 90,
more: '',