Adds autocomplete to issue field on time logging form.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10182 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2012-08-09 16:58:36 +00:00
parent f82a7a35b0
commit f1650b8ff4
3 changed files with 13 additions and 2 deletions

View File

@ -22,7 +22,7 @@ class AutoCompletesController < ApplicationController
@issues = [] @issues = []
q = (params[:q] || params[:term]).to_s.strip q = (params[:q] || params[:term]).to_s.strip
if q.present? 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+$/) if q.match(/^\d+$/)
@issues << scope.find_by_id(q.to_i) @issues << scope.find_by_id(q.to_i)
end end
@ -35,7 +35,9 @@ class AutoCompletesController < ApplicationController
private private
def find_project def find_project
@project = Project.find(params[:project_id]) if params[:project_id].present?
@project = Project.find(params[:project_id])
end
rescue ActiveRecord::RecordNotFound rescue ActiveRecord::RecordNotFound
render_404 render_404
end end

View File

@ -19,3 +19,5 @@
<% end %> <% end %>
<%= call_hook(:view_timelog_edit_form_bottom, { :time_entry => @time_entry, :form => f }) %> <%= call_hook(:view_timelog_edit_form_bottom, { :time_entry => @time_entry, :form => f }) %>
</div> </div>
<%= javascript_tag "observeAutocompleteField('time_entry_issue_id', '#{escape_javascript auto_complete_issues_path(:project_id => @project, :scope => (@project ? nil : 'all'))}')" %>

View File

@ -40,6 +40,13 @@ class AutoCompletesControllerTest < ActionController::TestCase
assert assigns(:issues).include?(Issue.find(13)) assert assigns(:issues).include?(Issue.find(13))
end 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 def test_auto_complete_without_scope_all_should_not_search_other_projects
get :issues, :project_id => 'ecookbook', :q => '13' get :issues, :project_id => 'ecookbook', :q => '13'
assert_response :success assert_response :success