From 71b0e188c1d0b5c7d11f4d92bdb1ba09fcc7685e Mon Sep 17 00:00:00 2001 From: Eric Allen Date: Sun, 29 Nov 2009 20:14:05 -0500 Subject: [PATCH] Autocompletion for predecessors working --- app/controllers/todos_controller.rb | 4 ++-- app/helpers/todos_helper.rb | 7 +------ app/views/shared/_add_new_item_form.rhtml | 6 ------ public/javascripts/application.js | 2 ++ public/javascripts/jquery.autocomplete.js | 3 ++- 5 files changed, 7 insertions(+), 15 deletions(-) diff --git a/app/controllers/todos_controller.rb b/app/controllers/todos_controller.rb index affd101b..43c693f8 100644 --- a/app/controllers/todos_controller.rb +++ b/app/controllers/todos_controller.rb @@ -620,7 +620,7 @@ class TodosController < ApplicationController :conditions => [ '(todos.state = ? OR todos.state = ?) AND ' + 'NOT (id = ?) AND lower(description) LIKE ?', 'active', 'pending', - params[:id], '%' + params[:predecessor_list].downcase + '%' ], + params[:id], '%' + params[:q].downcase + '%' ], :order => 'description ASC', :limit => 10 ) @@ -631,7 +631,7 @@ class TodosController < ApplicationController :select => 'description, project_id, context_id, created_at', :conditions => [ '(todos.state = ? OR todos.state = ?) AND lower(description) LIKE ?', 'active', 'pending', - '%' + params[:predecessor_list].downcase + '%' ], + '%' + params[:q].downcase + '%' ], :order => 'description ASC', :limit => 10 ) diff --git a/app/helpers/todos_helper.rb b/app/helpers/todos_helper.rb index 8c886d50..9c023ce9 100644 --- a/app/helpers/todos_helper.rb +++ b/app/helpers/todos_helper.rb @@ -313,12 +313,7 @@ module TodosHelper end def auto_complete_result2(entries, phrase = nil) - return unless entries - items = entries.map do |entry| - item = entry.specification() - content_tag("li", phrase ? highlight(h(item), phrase) : h(item)) - end - content_tag("ul", items.uniq) + return entries.map{|e| e.specification()}.join("\n") rescue '' end end diff --git a/app/views/shared/_add_new_item_form.rhtml b/app/views/shared/_add_new_item_form.rhtml index 7b2f313f..e8226fb8 100644 --- a/app/views/shared/_add_new_item_form.rhtml +++ b/app/views/shared/_add_new_item_form.rhtml @@ -53,12 +53,6 @@ <%= text_field_tag "predecessor_list", nil, :size => 30, :tabindex => 8 %> - <%= content_tag("div", "", :id => "predecessor_list_auto_complete", :class => "auto_complete") %> - <%= auto_complete_field 'predecessor_list', { - :url => {:controller => 'todos', :action => 'auto_complete_for_predecessor', :id => nil}, - :tokens => [','] - } %> - <%= source_view_tag( @source_view ) %> <%= hidden_field_tag :_tag_name, @tag_name.underscore.gsub(/\s+/,'_') if source_view_is :tag %> diff --git a/public/javascripts/application.js b/public/javascripts/application.js index 0b090502..1fcc3f73 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -191,6 +191,8 @@ function enable_rich_interaction(){ $('input[name=project[default_context_name]]').autocomplete(contextNames, {matchContains: true}); $('input[name=project_name]').autocomplete(projectNames, {matchContains: true}); $('input[name=tag_list]').autocomplete(tagNames, {multiple: true,multipleSeparator:',',matchContains:true}); + $('input[name=predecessor_list]').autocomplete('/todos/auto_complete_for_predecessor', + {multiple: true,multipleSeparator:','}); /* have to bind on keypress because of limitataions of live() */ $('input[name=project_name]').live('keypress', function(){ diff --git a/public/javascripts/jquery.autocomplete.js b/public/javascripts/jquery.autocomplete.js index 9d12a29f..276736a3 100644 --- a/public/javascripts/jquery.autocomplete.js +++ b/public/javascripts/jquery.autocomplete.js @@ -364,6 +364,7 @@ $.Autocompleter = function(input, options) { // limit abortion to this input port: "autocomplete" + input.name, dataType: options.dataType, + type: 'POST', url: options.url, data: $.extend({ q: lastWord(term), @@ -805,4 +806,4 @@ $.fn.selection = function(start, end) { } }; -})(jQuery); \ No newline at end of file +})(jQuery);