From 1b60fb8a63fce278ddb93fd4328ef60730899afa Mon Sep 17 00:00:00 2001 From: Jens Kraemer Date: Wed, 26 Oct 2016 17:01:30 +0800 Subject: [PATCH] dynamically build the autocomplete url #294652 - use the selected project if any to scope the autocompletion accordingly --- app/views/timelog/_form.html.erb | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/app/views/timelog/_form.html.erb b/app/views/timelog/_form.html.erb index ec35e8c..c54f003 100644 --- a/app/views/timelog/_form.html.erb +++ b/app/views/timelog/_form.html.erb @@ -40,10 +40,37 @@ }); <% end %> - observeAutocompleteField('time_entry_issue_id', '<%= escape_javascript auto_complete_issues_path(:project_id => @project, :scope => (@project ? nil : 'all'))%>', { - select: function(event, ui) { - $('#time_entry_issue').text(ui.item.label); - $('#time_entry_issue_id').blur(); + observeAutocompleteField('time_entry_issue_id', + function(request, callback) { + var url = '<%= j auto_complete_issues_path %>'; + var data = { + term: request.term + }; + var project_id; + <% if @project %> + project_id = '<%= @project.id %>'; + <% else %> + project_id = $('#time_entry_project_id').val(); + <% end %> + if(project_id){ + data['project_id'] = project_id; + } else { + data['scope'] = 'all'; + } + + $.get(url, data, null, 'json') + .done(function(data){ + callback(data); + }) + .fail(function(jqXHR, status, error){ + callback([]); + }); + }, + { + select: function(event, ui) { + $('#time_entry_issue').text(ui.item.label); + $('#time_entry_issue_id').blur(); + } } - }); + ); <% end %> -- 2.1.4