From ff81353e8cfd099f83f70008d4a04aa3a4079ad6 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Fri, 16 Dec 2016 08:42:45 +0000 Subject: [PATCH] Time entry form - limit issue autocomplete to already selected project (#24189). Patch by Jens Kraemer. git-svn-id: http://svn.redmine.org/redmine/trunk@16082 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- 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 f5bc15100..712c7bde7 100644 --- a/app/views/timelog/_form.html.erb +++ b/app/views/timelog/_form.html.erb @@ -38,10 +38,37 @@ }); }); - 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(''); - $('#time_entry_issue_id').val(ui.item.value).change(); + 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(''); + $('#time_entry_issue_id').val(ui.item.value).change(); + } } - }); + ); <% end %> -- 2.39.5