]> source.dussan.org Git - redmine.git/commitdiff
Adds autocomplete to issue field on time logging form.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Thu, 9 Aug 2012 16:58:36 +0000 (16:58 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Thu, 9 Aug 2012 16:58:36 +0000 (16:58 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10182 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/auto_completes_controller.rb
app/views/timelog/_form.html.erb
test/functional/auto_completes_controller_test.rb

index 1bbcd33f822a98d0ed2ed0bb34b82a3beacc4bc8..f32adace435c31a2c43e92abc9b0f2ea5c2d9e17 100644 (file)
@@ -22,7 +22,7 @@ class AutoCompletesController < ApplicationController
     @issues = []
     q = (params[:q] || params[:term]).to_s.strip
     if q.present?
-      scope = (params[:scope] == "all" ? Issue : @project.issues).visible
+      scope = (params[:scope] == "all" || @project.nil? ? Issue : @project.issues).visible
       if q.match(/^\d+$/)
         @issues << scope.find_by_id(q.to_i)
       end
@@ -35,7 +35,9 @@ class AutoCompletesController < ApplicationController
   private
 
   def find_project
-    @project = Project.find(params[:project_id])
+    if params[:project_id].present?
+      @project = Project.find(params[:project_id])
+    end
   rescue ActiveRecord::RecordNotFound
     render_404
   end
index 258de205fa0ffcbb05c9fa3e38b211c612d05e44..8b1ed3a0ab2c28e9da0b7959c815c28715ea2481 100644 (file)
@@ -19,3 +19,5 @@
        <% end %>
        <%= call_hook(:view_timelog_edit_form_bottom, { :time_entry => @time_entry, :form => f }) %>
 </div>
+
+<%= javascript_tag "observeAutocompleteField('time_entry_issue_id', '#{escape_javascript auto_complete_issues_path(:project_id => @project, :scope => (@project ? nil : 'all'))}')" %>
index 554d52088b862a3308c9bac8c1a7481656ed0658..0be93b049e8c6cf6b98ff2bea55b4d7e21a45450 100644 (file)
@@ -40,6 +40,13 @@ class AutoCompletesControllerTest < ActionController::TestCase
     assert assigns(:issues).include?(Issue.find(13))
   end
 
+  def test_auto_complete_without_project_should_search_all_projects
+    get :issues, :q => '13'
+    assert_response :success
+    assert_not_nil assigns(:issues)
+    assert assigns(:issues).include?(Issue.find(13))
+  end
+
   def test_auto_complete_without_scope_all_should_not_search_other_projects
     get :issues, :project_id => 'ecookbook', :q => '13'
     assert_response :success