diff --git a/app/controllers/todos_controller.rb b/app/controllers/todos_controller.rb index 2de83892..b82a2a2f 100644 --- a/app/controllers/todos_controller.rb +++ b/app/controllers/todos_controller.rb @@ -4,8 +4,11 @@ class TodosController < ApplicationController skip_before_filter :login_required, :only => [:index, :calendar] prepend_before_filter :login_or_feed_token_required, :only => [:index, :calendar] - append_before_filter :init, :except => [ :destroy, :completed, :completed_archive, :check_deferred, :toggle_check, :toggle_star, :edit, :update, :create, :calendar ] + append_before_filter :init, :except => [ :destroy, :completed, + :completed_archive, :check_deferred, :toggle_check, :toggle_star, + :edit, :update, :create, :calendar, :auto_complete_for_tag] append_before_filter :get_todo_from_params, :only => [ :edit, :toggle_check, :toggle_star, :show, :update, :destroy ] + protect_from_forgery :except => [:auto_complete_for_tag] session :off, :only => :index, :if => Proc.new { |req| is_feed_request(req) } @@ -502,7 +505,16 @@ class TodosController < ApplicationController render :action => 'calendar', :layout => false, :content_type => Mime::ICS } end - end + end + + def auto_complete_for_tag + puts params.inspect + @items = Tag.find(:all, + :conditions => [ "name LIKE ?", '%' + params['tag_list'] + '%' ], + :order => "name ASC", + :limit => 10) + render :inline => "<%= auto_complete_result(@items, :name) %>" + end private diff --git a/app/views/shared/_add_new_item_form.rhtml b/app/views/shared/_add_new_item_form.rhtml index 973434a7..e9db5162 100644 --- a/app/views/shared/_add_new_item_form.rhtml +++ b/app/views/shared/_add_new_item_form.rhtml @@ -45,6 +45,11 @@ <%= text_field_tag "tag_list", nil, :size => 30, :tabindex => 5 %> + <%= content_tag("div", "", :id => "tag_list_auto_complete", :class => "auto_complete") %> + <%= auto_complete_field 'tag_list', { + :url => {:controller => 'todos', :action => 'auto_complete_for_tag'}, + :tokens => [','] + } %>
diff --git a/public/stylesheets/standard.css b/public/stylesheets/standard.css index fbc7ded0..18752ec0 100644 --- a/public/stylesheets/standard.css +++ b/public/stylesheets/standard.css @@ -1224,3 +1224,30 @@ body.integrations textarea { .defer-container a:hover { background-color: inherit; } + +div.auto_complete { + width: 350px; + background: #fff; + color: #000; +} +div.auto_complete ul { + border:1px solid #888; + margin:0; + padding:0; + width:100%; + list-style-type:none; +} +div.auto_complete ul li { + margin:0; + padding:3px; + list-style-type: none; +} +div.auto_complete ul li.selected { + background-color: #ffb; + font-weight:bold; +} +div.auto_complete ul strong.highlight { + color: #800; + margin:0; + padding:0; +} diff --git a/vendor/plugins/auto_complete/README b/vendor/plugins/auto_complete/README new file mode 100644 index 00000000..e08a8151 --- /dev/null +++ b/vendor/plugins/auto_complete/README @@ -0,0 +1,23 @@ +Example: + + # Controller + class BlogController < ApplicationController + auto_complete_for :post, :title + end + + # View + <%= text_field_with_auto_complete :post, title %> + +By default, auto_complete_for limits the results to 10 entries, +and sorts by the given field. + +auto_complete_for takes a third parameter, an options hash to +the find method used to search for the records: + + auto_complete_for :post, :title, :limit => 15, :order => 'created_at DESC' + +For more examples, see script.aculo.us: +* http://script.aculo.us/demos/ajax/autocompleter +* http://script.aculo.us/demos/ajax/autocompleter_customized + +Copyright (c) 2007 David Heinemeier Hansson, released under the MIT license diff --git a/vendor/plugins/auto_complete/Rakefile b/vendor/plugins/auto_complete/Rakefile new file mode 100644 index 00000000..5af4e826 --- /dev/null +++ b/vendor/plugins/auto_complete/Rakefile @@ -0,0 +1,22 @@ +require 'rake' +require 'rake/testtask' +require 'rake/rdoctask' + +desc 'Default: run unit tests.' +task :default => :test + +desc 'Test auto_complete plugin.' +Rake::TestTask.new(:test) do |t| + t.libs << 'lib' + t.pattern = 'test/**/*_test.rb' + t.verbose = true +end + +desc 'Generate documentation for auto_complete plugin.' +Rake::RDocTask.new(:rdoc) do |rdoc| + rdoc.rdoc_dir = 'rdoc' + rdoc.title = 'Auto Complete' + rdoc.options << '--line-numbers' << '--inline-source' + rdoc.rdoc_files.include('README') + rdoc.rdoc_files.include('lib/**/*.rb') +end diff --git a/vendor/plugins/auto_complete/init.rb b/vendor/plugins/auto_complete/init.rb new file mode 100644 index 00000000..87bf027d --- /dev/null +++ b/vendor/plugins/auto_complete/init.rb @@ -0,0 +1,2 @@ +ActionController::Base.send :include, AutoComplete +ActionController::Base.helper AutoCompleteMacrosHelper \ No newline at end of file diff --git a/vendor/plugins/auto_complete/lib/auto_complete.rb b/vendor/plugins/auto_complete/lib/auto_complete.rb new file mode 100644 index 00000000..4afc7c2e --- /dev/null +++ b/vendor/plugins/auto_complete/lib/auto_complete.rb @@ -0,0 +1,47 @@ +module AutoComplete + + def self.included(base) + base.extend(ClassMethods) + end + + # + # Example: + # + # # Controller + # class BlogController < ApplicationController + # auto_complete_for :post, :title + # end + # + # # View + # <%= text_field_with_auto_complete :post, title %> + # + # By default, auto_complete_for limits the results to 10 entries, + # and sorts by the given field. + # + # auto_complete_for takes a third parameter, an options hash to + # the find method used to search for the records: + # + # auto_complete_for :post, :title, :limit => 15, :order => 'created_at DESC' + # + # For help on defining text input fields with autocompletion, + # see ActionView::Helpers::JavaScriptHelper. + # + # For more examples, see script.aculo.us: + # * http://script.aculo.us/demos/ajax/autocompleter + # * http://script.aculo.us/demos/ajax/autocompleter_customized + module ClassMethods + def auto_complete_for(object, method, options = {}) + define_method("auto_complete_for_#{object}_#{method}") do + find_options = { + :conditions => [ "LOWER(#{method}) LIKE ?", '%' + params[object][method].downcase + '%' ], + :order => "#{method} ASC", + :limit => 10 }.merge!(options) + + @items = object.to_s.camelize.constantize.find(:all, find_options) + + render :inline => "<%= auto_complete_result @items, '#{method}' %>" + end + end + end + +end \ No newline at end of file diff --git a/vendor/plugins/auto_complete/lib/auto_complete_macros_helper.rb b/vendor/plugins/auto_complete/lib/auto_complete_macros_helper.rb new file mode 100644 index 00000000..1d25ee47 --- /dev/null +++ b/vendor/plugins/auto_complete/lib/auto_complete_macros_helper.rb @@ -0,0 +1,143 @@ +module AutoCompleteMacrosHelper + # Adds AJAX autocomplete functionality to the text input field with the + # DOM ID specified by +field_id+. + # + # This function expects that the called action returns an HTML