From e13e94629518771fd334afb64ea9c602eb8ff95b Mon Sep 17 00:00:00 2001 From: Reinier Balt Date: Fri, 17 Dec 2010 16:01:22 +0100 Subject: [PATCH] migrate adding to actions on all pages --- app/controllers/application_controller.rb | 3 +- app/controllers/contexts_controller.rb | 1 + app/controllers/todos_controller.rb | 22 ++-- app/helpers/todos_helper.rb | 12 +- app/views/shared/_add_new_item_form.rhtml | 100 +------------- app/views/sidebar/sidebar.html.erb | 12 +- app/views/todos/_new_multi_todo_form.rhtml | 35 +++++ app/views/todos/_new_todo_form.rhtml | 51 +++++++ ...decessor.js.rjs => add_predecessor.js.erb} | 0 ..._deferred.js.rjs => check_deferred.js.erb} | 0 app/views/todos/create.js.erb | 77 +++++++++++ app/views/todos/create.js.rjs | 41 ------ app/views/todos/create_multiple.js.erb | 83 ++++++++++++ app/views/todos/create_multiple.js.rjs | 50 ------- .../todos/{destroy.js.rjs => destroy.js.erb} | 0 app/views/todos/{edit.js.rjs => edit.js.erb} | 0 .../todos/{error.js.rjs => error.js.erb} | 0 app/views/todos/index.html.erb | 17 ++- ...essor.js.rjs => remove_predecessor.js.erb} | 0 ...oggle_check.js.rjs => toggle_check.js.erb} | 0 .../todos/{update.js.rjs => update.js.erb} | 0 features/project_edit.feature | 2 +- features/shared_add_new_todo.feature | 2 +- public/javascripts/application.js | 124 +++++++++++------- 24 files changed, 356 insertions(+), 276 deletions(-) create mode 100644 app/views/todos/_new_multi_todo_form.rhtml create mode 100644 app/views/todos/_new_todo_form.rhtml rename app/views/todos/{add_predecessor.js.rjs => add_predecessor.js.erb} (100%) rename app/views/todos/{check_deferred.js.rjs => check_deferred.js.erb} (100%) create mode 100644 app/views/todos/create.js.erb delete mode 100644 app/views/todos/create.js.rjs create mode 100644 app/views/todos/create_multiple.js.erb delete mode 100644 app/views/todos/create_multiple.js.rjs rename app/views/todos/{destroy.js.rjs => destroy.js.erb} (100%) rename app/views/todos/{edit.js.rjs => edit.js.erb} (100%) rename app/views/todos/{error.js.rjs => error.js.erb} (100%) rename app/views/todos/{remove_predecessor.js.rjs => remove_predecessor.js.erb} (100%) rename app/views/todos/{toggle_check.js.rjs => toggle_check.js.erb} (100%) rename app/views/todos/{update.js.rjs => update.js.erb} (100%) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d2bc46dc..f80dd4a1 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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 diff --git a/app/controllers/contexts_controller.rb b/app/controllers/contexts_controller.rb index 83a4c217..3dcf663a 100644 --- a/app/controllers/contexts_controller.rb +++ b/app/controllers/contexts_controller.rb @@ -250,6 +250,7 @@ class ContextsController < ApplicationController @count = @not_done_todos.size end + end end diff --git a/app/controllers/todos_controller.rb b/app/controllers/todos_controller.rb index d217abfe..8bc89e74 100644 --- a/app/controllers/todos_controller.rb +++ b/app/controllers/todos_controller.rb @@ -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 diff --git a/app/helpers/todos_helper.rb b/app/helpers/todos_helper.rb index d3c3cb0b..9fcd4a6d 100644 --- a/app/helpers/todos_helper.rb +++ b/app/helpers/todos_helper.rb @@ -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" diff --git a/app/views/shared/_add_new_item_form.rhtml b/app/views/shared/_add_new_item_form.rhtml index bc5843bf..041163c7 100644 --- a/app/views/shared/_add_new_item_form.rhtml +++ b/app/views/shared/_add_new_item_form.rhtml @@ -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 @@ <%= t('shared.toggle_multi') %> -
- <% 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 -%> - -
<%= error_messages_for("item", :object_name => 'action') %>
- - - <%= text_field( "todo", "description", "size" => 30, "tabindex" => 1, "maxlength" => 100, "autocomplete" => "off", :autofocus => 1) %> - - - <%= text_area( "todo", "notes", "cols" => 29, "rows" => 6, "tabindex" => 2) %> - - - - - - - - - - - - - - <%= text_field_tag "tag_list", @default_tags, :size => 30, :tabindex => 5 %> - <%= content_tag("div", "", :id => "tag_list_auto_complete", :class => "auto_complete") %> - -
- - <%= text_field("todo", "due", "size" => 12, "class" => "Date", "tabindex" => 6, "autocomplete" => "off") %> -
- -
- - <%= text_field("todo", "show_from", "size" => 12, "class" => "Date", "tabindex" => 7, "autocomplete" => "off") %> -
- - - <%= 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 %> - -
-
- -
-
- - <% end # form-remote-tag -%> -
- - + <%= render :partial => 'todos/new_todo_form', :object => Todo.new %> + <%= render :partial => 'todos/new_multi_todo_form', :object => Todo.new %> diff --git a/app/views/sidebar/sidebar.html.erb b/app/views/sidebar/sidebar.html.erb index f539587f..173aa882 100644 --- a/app/views/sidebar/sidebar.html.erb +++ b/app/views/sidebar/sidebar.html.erb @@ -1,13 +1,7 @@ \ No newline at end of file diff --git a/app/views/todos/_new_multi_todo_form.rhtml b/app/views/todos/_new_multi_todo_form.rhtml new file mode 100644 index 00000000..8a7f901c --- /dev/null +++ b/app/views/todos/_new_multi_todo_form.rhtml @@ -0,0 +1,35 @@ +<%- todo = new_multi_todo_form -%> + + diff --git a/app/views/todos/_new_todo_form.rhtml b/app/views/todos/_new_todo_form.rhtml new file mode 100644 index 00000000..1c1af12d --- /dev/null +++ b/app/views/todos/_new_todo_form.rhtml @@ -0,0 +1,51 @@ +<%- todo = new_todo_form -%> + +
+ <% form_for(todo, :html=> { :id=>'todo-form-new-action', :name=>'todo', :class => 'inline-form' }) do |t|%> + + + +
<%= error_messages_for("item", :object_name => 'action') %>
+ + + <%= t.text_field("description", "size" => 30, "tabindex" => 1, "maxlength" => 100, "autocomplete" => "off", :autofocus => 1) %> + + + <%= t.text_area("notes", "cols" => 29, "rows" => 6, "tabindex" => 2) %> + + + + + + + + + + <%= text_field_tag "tag_list", @default_tags, :size => 30, :tabindex => 5 %> + <%= content_tag("div", "", :id => "tag_list_auto_complete", :class => "auto_complete") %> + +
+ + <%= t.text_field("due", "size" => 12, "class" => "Date", "tabindex" => 6, "autocomplete" => "off") %> +
+ +
+ + <%= t.text_field("show_from", "size" => 12, "class" => "Date", "tabindex" => 7, "autocomplete" => "off") %> +
+ + + <%= 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 %> + +
+
+ +
+
+ + <% end # form_for -%> +
\ No newline at end of file diff --git a/app/views/todos/add_predecessor.js.rjs b/app/views/todos/add_predecessor.js.erb similarity index 100% rename from app/views/todos/add_predecessor.js.rjs rename to app/views/todos/add_predecessor.js.erb diff --git a/app/views/todos/check_deferred.js.rjs b/app/views/todos/check_deferred.js.erb similarity index 100% rename from app/views/todos/check_deferred.js.rjs rename to app/views/todos/check_deferred.js.erb diff --git a/app/views/todos/create.js.erb b/app/views/todos/create.js.erb new file mode 100644 index 00000000..29797d37 --- /dev/null +++ b/app/views/todos/create.js.erb @@ -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 })) : "" %>"; +} \ No newline at end of file diff --git a/app/views/todos/create.js.rjs b/app/views/todos/create.js.rjs deleted file mode 100644 index 2423105e..00000000 --- a/app/views/todos/create.js.rjs +++ /dev/null @@ -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 diff --git a/app/views/todos/create_multiple.js.erb b/app/views/todos/create_multiple.js.erb new file mode 100644 index 00000000..06f35340 --- /dev/null +++ b/app/views/todos/create_multiple.js.erb @@ -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 -%> \ No newline at end of file diff --git a/app/views/todos/create_multiple.js.rjs b/app/views/todos/create_multiple.js.rjs deleted file mode 100644 index 3e6c2fc3..00000000 --- a/app/views/todos/create_multiple.js.rjs +++ /dev/null @@ -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 \ No newline at end of file diff --git a/app/views/todos/destroy.js.rjs b/app/views/todos/destroy.js.erb similarity index 100% rename from app/views/todos/destroy.js.rjs rename to app/views/todos/destroy.js.erb diff --git a/app/views/todos/edit.js.rjs b/app/views/todos/edit.js.erb similarity index 100% rename from app/views/todos/edit.js.rjs rename to app/views/todos/edit.js.erb diff --git a/app/views/todos/error.js.rjs b/app/views/todos/error.js.erb similarity index 100% rename from app/views/todos/error.js.rjs rename to app/views/todos/error.js.erb diff --git a/app/views/todos/index.html.erb b/app/views/todos/index.html.erb index 92694508..2bca0603 100644 --- a/app/views/todos/index.html.erb +++ b/app/views/todos/index.html.erb @@ -1,16 +1,15 @@
- - <%= 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 -%>
-
<%= 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" %>
\ No newline at end of file diff --git a/app/views/todos/remove_predecessor.js.rjs b/app/views/todos/remove_predecessor.js.erb similarity index 100% rename from app/views/todos/remove_predecessor.js.rjs rename to app/views/todos/remove_predecessor.js.erb diff --git a/app/views/todos/toggle_check.js.rjs b/app/views/todos/toggle_check.js.erb similarity index 100% rename from app/views/todos/toggle_check.js.rjs rename to app/views/todos/toggle_check.js.erb diff --git a/app/views/todos/update.js.rjs b/app/views/todos/update.js.erb similarity index 100% rename from app/views/todos/update.js.rjs rename to app/views/todos/update.js.erb diff --git a/features/project_edit.feature b/features/project_edit.feature index 7380ddba..33fae5ed 100644 --- a/features/project_edit.feature +++ b/features/project_edit.feature @@ -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 diff --git a/features/shared_add_new_todo.feature b/features/shared_add_new_todo.feature index bb8e7f04..092ca0d8 100644 --- a/features/shared_add_new_todo.feature +++ b/features/shared_add_new_todo.feature @@ -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" \ No newline at end of file diff --git a/public/javascripts/application.js b/public/javascripts/application.js index 74b6d31e..db04829a 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -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