let autocomplete fail gracefully when param is not set

This commit is contained in:
Reinier Balt 2011-01-10 22:47:19 +01:00
parent 05ba6060fc
commit 1a821a228f
3 changed files with 13 additions and 10 deletions

View file

@ -128,9 +128,13 @@ class ApplicationController < ActionController::Base
end
def for_autocomplete(coll, substr)
filtered = coll.find_all{|item| item.name.downcase.include? substr.downcase}
json_elems = "[{" + filtered.map {|item| "\"value\" : \"#{item.name}\", \"id\" : \"#{item.id}\""}.join("},{") + "}]"
return json_elems == "[{}]" ? "" : json_elems
if substr # protect agains empty request
filtered = coll.find_all{|item| item.name.downcase.include? substr.downcase}
json_elems = "[{" + filtered.map {|item| "\"value\" : \"#{item.name}\", \"id\" : \"#{item.id}\""}.join("},{") + "}]"
return json_elems == "[{}]" ? "" : json_elems
else
return ""
end
end
# Uses RedCloth to transform text using either Textile or Markdown Need to

View file

@ -9,7 +9,6 @@ class ProjectsController < ApplicationController
def index
@source_view = params['_source_view'] || 'project_list'
@projects = current_user.projects.all
@new_project = current_user.projects.build
if params[:projects_and_actions]
projects_and_actions
@ -18,6 +17,8 @@ class ProjectsController < ApplicationController
init_not_done_counts(['project'])
if params[:only_active_with_no_next_actions]
@projects = current_user.projects.active.select { |p| count_undone_todos(p) == 0 }
else
@projects = current_user.projects.all
end
init_project_hidden_todo_counts(['project'])
respond_to do |format|
@ -27,9 +28,7 @@ class ProjectsController < ApplicationController
format.rss &render_rss_feed
format.atom &render_atom_feed
format.text &render_text_feed
format.autocomplete {
uncompleted_projects = current_user.projects.uncompleted(true)
render :text => for_autocomplete(uncompleted_projects, params[:term]) }
format.autocomplete { render :text => for_autocomplete(current_user.projects.uncompleted, params[:term]) }
end
end
end
@ -139,7 +138,7 @@ class ProjectsController < ApplicationController
render :template => 'projects/update.js.erb'
return
# TODO: are these params ever set? or is this dead code?
# TODO: are these params ever set? or is this dead code?
elsif boolean_param('update_status')
render :template => 'projects/update_status.js.rjs'

View file

@ -15,10 +15,10 @@ Feature: Edit a next action from every page
Scenario: I can delete a todo
Given this is a pending scenario
Scenario: Deleting the last todo in context will hide context
Scenario: Removing the last todo in context will hide context # delete, edit
Given this is a pending scenario
Scenario: Deleting the last todo in container will show empty message
Scenario: Deleting the last todo in container will show empty message # only project, context, tag, not todo
Given this is a pending scenario
Scenario: I can mark a todo complete