Project

General

Profile

porting from redmine 1.3.2 to redmine 2.1.2 - problems with autocomplete

Added by Marco Nobler over 11 years ago

hello everibody, i have a problem with the autocomplete functionality in porting my plugin from redmine 1.3.2 to 2.1.2.

I followed the hints in the post [[http://www.redmine.org/boards/3/topics/31445]] and it helped me a lot to solve many porting issues, but with autocomplete i'm really blocked (maybe because i'm not very experienced in JQuery/JSON/Javascript etc....)

I try to explain: I have a partial ("redmine_tlcit/app/views/impacts/_form.html.erb") where i need to use autocomplete features to specify issues related systems:


<%= error_messages_for 'impact' %>
<%= l(:label_system) %>
<!-- PROVA -->
<%= f.select :system_id, System.find_by_sql(["SELECT * FROM systems WHERE id NOT IN (SELECT system_id FROM impacts WHERE issue_id=?)", @issue.id]).collect {|s| [ s.name, s.id ] }, :include_blank => false %>
<!-- %= f.text_field 'system_id'% -->
<!-- %= javascript_tag "observeAutocompleteField('impact_system_id', '#{escape_javascript auto_complete_system_name_path}')" % -->
<!-- FINE PROVA -->
<!-- %= text_field_with_auto_complete 'system', 'name', {}, :skip_style => false, :select =>'systemname' , :after_update_element => 'function(inputfield,li) { document.newimpactform.impact_system_id.value=li.getElementsByTagName("div")[1].innerHTML;}', :html => {:onkeypress => 'return event.keyCode!=13'} % -->
<!-- %= f.hidden_field :system_id % -->
<%= submit_tag l(:button_add) %>
<%= toggle_link l(:button_cancel), 'new-impact-form'%>

Originally (in redmine 1.3.2) it is using "text_field_with_auto_complete" and, in my "redmine_tlcit/lib/redmine_tlcit/patches/issues_controller_patch.rb" is define "auto_complete_for_system_name" as InstanceMethod like this for Issues controller:

def auto_complete_for_system_name()
system_name = params[:system][:name]
@systems = System.find(:all , :conditions=>"name like '%"+system_name.downcase+"%' AND project_id IS NOT NULL")
render :partial => 'systemname'
end

and all is working ok.

Now, in redmine 2.1.2, this chain doesn't works: when i type in texbox, nothing happens...

How can i port the autocomplete functionality?

As you can see i tried to use "observeAutocompleteField" but this is the result (production.log, "Cro" is what i type in text box):

Started GET "/redmine/issues/auto_complete_for_system_name?term=Cro" for 10.173.139.40 at Wed Nov 21 10:17:58 +0000 2012 Processing by IssuesController#show as JSON
Parameters: {"term"=>"Cro", "id"=>"auto_complete_for_system_name"} Current user: admin (id=1) Rendered common/error.html.erb (1.0ms) Filter chain halted as :find_issue rendered or redirected Completed 404 Not Found in 23ms (Views: 11.5ms | ActiveRecord: 1.6ms)

I have some question about this log snippet:

1.why is processing as JSON?
2.What does "Filter chain halted means" means? (The "find_issue" filter is define as private in my own ImpactsController and ReleasecompositionsController).
Could you provide me some hints?

P.S: this is my routes.rb:

@if Rails::VERSION::MAJOR >= 3
RedmineApp::Application.routes.draw do
match 'issues/:issue_id/releasecompositions/:id', :to => 'releasecompositions#new', :via => [:post]
match 'issues/:issue_id/releasecompositions/:id/destroy', :to => 'releasecompositions#destroy', :via => [:post]
match 'issues/:issue_id/impacts/:id', :to => 'impacts#new', :via => [:post]
match 'issues/:issue_id/impacts/:id/destroy', :to => 'impacts#destroy', :via => [:post]
#match 'issues/auto_complete_for_system_name', :to => 'issues#auto_complete_for_system_name', :via => [:post]
match 'issues/auto_complete_for_system_name', :to => 'issues#auto_complete_for_system_name', :as => 'auto_complete_system_name'
#match 'issues/auto_complete_for_impact_issue', :to => 'issues#auto_complete_for_impact_issue', :via => [:post]
match 'issues/auto_complete_for_impact_issue', :to => 'issues#auto_complete_for_impact_issue'
end
else
ActionController::Routing::Routes.draw do |map|
map.with_options :controller => 'releasecompositions', :conditions => {:method => :post} do |releasecompositions|
releasecompositions.connect 'issues/:issue_id/releasecompositions/:id', :action => 'new'
releasecompositions.connect 'issues/:issue_id/releasecompositions/:id/destroy', :action => 'destroy'
end

map.with_options  :controller => 'impacts', :conditions => {:method => :post} do |impacts|
impacts.connect 'issues/:issue_id/impacts/:id', :action => 'new'
impacts.connect 'issues/:issue_id/impacts/:id/destroy', :action => 'destroy'
end
end
end@

Thanks a lot in advance. Marco