diff options
-rw-r--r-- | app/helpers/application_helper.rb | 16 | ||||
-rw-r--r-- | app/helpers/custom_fields_helper.rb | 8 | ||||
-rw-r--r-- | app/views/documents/_form.html.erb | 3 | ||||
-rw-r--r-- | app/views/issues/_edit.html.erb | 3 | ||||
-rw-r--r-- | app/views/issues/_form.html.erb | 2 | ||||
-rw-r--r-- | app/views/issues/bulk_edit.html.erb | 3 | ||||
-rw-r--r-- | app/views/journals/_notes_form.html.erb | 3 | ||||
-rw-r--r-- | app/views/layouts/base.html.erb | 5 | ||||
-rw-r--r-- | app/views/messages/_form.html.erb | 3 | ||||
-rw-r--r-- | app/views/news/_form.html.erb | 3 | ||||
-rw-r--r-- | app/views/news/show.html.erb | 3 | ||||
-rw-r--r-- | app/views/search/index.html.erb | 3 | ||||
-rw-r--r-- | app/views/wiki/edit.html.erb | 3 | ||||
-rw-r--r-- | public/javascripts/application.js | 12 |
14 files changed, 39 insertions, 31 deletions
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 5a0868c2e..dd4a4f195 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1741,6 +1741,22 @@ module ApplicationHelper end end + def autocomplete_data_sources(project) + { + issues: auto_complete_issues_path(:project_id => project, :q => '') + } + end + + def heads_for_auto_complete(project) + data_sources = autocomplete_data_sources(project) + + javascript_tag( + "rm = window.rm || {};" + + "rm.AutoComplete = rm.AutoComplete || {};" + + "rm.AutoComplete.dataSources = '#{data_sources.to_json}';" + ) + end + private def wiki_helper diff --git a/app/helpers/custom_fields_helper.rb b/app/helpers/custom_fields_helper.rb index 1e0c1b07e..41b20c46a 100644 --- a/app/helpers/custom_fields_helper.rb +++ b/app/helpers/custom_fields_helper.rb @@ -84,9 +84,8 @@ module CustomFieldsHelper if custom_value.custom_field.full_text_formatting? css += ' wiki-edit' data = { - :auto_complete => true, - :issues_url => auto_complete_issues_path(:project_id => custom_value.customized.project, :q => '') - } if custom_value.customized&.try(:project) + :auto_complete => true + } end custom_value.custom_field.format.edit_tag( self, @@ -133,8 +132,7 @@ module CustomFieldsHelper if custom_field.full_text_formatting? css += ' wiki-edit' data = { - :auto_complete => true, - :issues_url => auto_complete_issues_path(:q => '') + :auto_complete => true } end custom_field.format.bulk_edit_tag( diff --git a/app/views/documents/_form.html.erb b/app/views/documents/_form.html.erb index b8b8c8404..45b63611f 100644 --- a/app/views/documents/_form.html.erb +++ b/app/views/documents/_form.html.erb @@ -5,8 +5,7 @@ <p><%= f.text_field :title, :required => true, :size => 60 %></p> <p><%= f.text_area :description, :cols => 60, :rows => 15, :class => 'wiki-edit', :data => { - :auto_complete => true, - :issues_url => auto_complete_issues_path(:project_id => @project, :q => '') + :auto_complete => true } %></p> diff --git a/app/views/issues/_edit.html.erb b/app/views/issues/_edit.html.erb index cc2f110b7..33f8352f5 100644 --- a/app/views/issues/_edit.html.erb +++ b/app/views/issues/_edit.html.erb @@ -31,8 +31,7 @@ <fieldset><legend><%= l(:field_notes) %></legend> <%= f.text_area :notes, :cols => 60, :rows => 10, :class => 'wiki-edit', :data => { - :auto_complete => true, - :issues_url => auto_complete_issues_path(:project_id => @issue.project, :q => '') + :auto_complete => true }, :no_label => true %> <%= wikitoolbar_for 'issue_notes', preview_issue_path(:project_id => @project, :issue_id => @issue) %> diff --git a/app/views/issues/_form.html.erb b/app/views/issues/_form.html.erb index 214502b0a..0d3ca5e22 100644 --- a/app/views/issues/_form.html.erb +++ b/app/views/issues/_form.html.erb @@ -38,7 +38,6 @@ :rows => [[10, @issue.description.to_s.length / 50].max, 20].min, :data => { :auto_complete => true, - :issues_url => auto_complete_issues_path(:project_id => @issue.project, :q => '') }, :no_label => true %> <% end %> @@ -54,6 +53,7 @@ <% end %> <% heads_for_wiki_formatter %> +<%= heads_for_auto_complete(@issue.project) %> <%= javascript_tag do %> $(document).ready(function(){ diff --git a/app/views/issues/bulk_edit.html.erb b/app/views/issues/bulk_edit.html.erb index 224ace22a..a49617aab 100644 --- a/app/views/issues/bulk_edit.html.erb +++ b/app/views/issues/bulk_edit.html.erb @@ -221,8 +221,7 @@ <legend><%= l(:field_notes) %></legend> <%= text_area_tag 'notes', @notes, :cols => 60, :rows => 10, :class => 'wiki-edit', :data => { - :auto_complete => true, - :issues_url => auto_complete_issues_path(:project_id => @project, :q => '') + :auto_complete => true } %> <%= wikitoolbar_for 'notes' %> diff --git a/app/views/journals/_notes_form.html.erb b/app/views/journals/_notes_form.html.erb index aeb4b6a93..13a6c7fdc 100644 --- a/app/views/journals/_notes_form.html.erb +++ b/app/views/journals/_notes_form.html.erb @@ -6,8 +6,7 @@ <%= text_area_tag 'journal[notes]', @journal.notes, :id => "journal_#{@journal.id}_notes", :class => 'wiki-edit', :rows => (@journal.notes.blank? ? 10 : [[10, @journal.notes.length / 50].max, 100].min), :data => { - :auto_complete => true, - :issues_url => auto_complete_issues_path(:project_id => @project, :q => '') + :auto_complete => true } %> <% if @journal.safe_attribute? 'private_notes' %> diff --git a/app/views/layouts/base.html.erb b/app/views/layouts/base.html.erb index d6c76c41c..50fe17b38 100644 --- a/app/views/layouts/base.html.erb +++ b/app/views/layouts/base.html.erb @@ -13,6 +13,7 @@ <%= stylesheet_link_tag 'rtl', :media => 'all' if l(:direction) == 'rtl' %> <%= javascript_heads %> <%= heads_for_theme %> +<%= heads_for_auto_complete(@project) %> <%= call_hook :view_layouts_base_html_head %> <!-- page specific tags --> <%= yield :header_tags -%> @@ -23,7 +24,6 @@ <div class="flyout-menu js-flyout-menu"> - <% if User.current.logged? || !Setting.login_required? %> <div class="flyout-menu__search"> <%= form_tag({:controller => 'search', :action => 'index', :id => @project}, :method => :get ) do %> @@ -82,8 +82,7 @@ </label> <%= text_field_tag 'q', @question, :size => 20, :class => 'small', :accesskey => accesskey(:quick_search), :data => { - :auto_complete => true, - :issues_url => auto_complete_issues_path(:q => '') + :auto_complete => true } %> <% end %> <%= render_project_jump_box %> diff --git a/app/views/messages/_form.html.erb b/app/views/messages/_form.html.erb index 7d3a9c59f..e030627a2 100644 --- a/app/views/messages/_form.html.erb +++ b/app/views/messages/_form.html.erb @@ -26,8 +26,7 @@ <%= f.text_area :content, :cols => 80, :rows => 15, :class => 'wiki-edit', :id => 'message_content', :accesskey => accesskey(:edit), :data => { - :auto_complete => true, - :issues_url => auto_complete_issues_path(:project_id => @project, :q => '') + :auto_complete => true } %></p> <%= wikitoolbar_for 'message_content', preview_board_message_path(:board_id => @board, :id => @message) %> diff --git a/app/views/news/_form.html.erb b/app/views/news/_form.html.erb index 58f68e1b2..a441b671d 100644 --- a/app/views/news/_form.html.erb +++ b/app/views/news/_form.html.erb @@ -5,8 +5,7 @@ <p><%= f.text_area :summary, :cols => 60, :rows => 2 %></p> <p><%= f.text_area :description, :required => true, :cols => 60, :rows => 15, :class => 'wiki-edit', :data => { - :auto_complete => true, - :issues_url => auto_complete_issues_path(:project_id => @project, :q => '') + :auto_complete => true } %></p> <p id="attachments_form"><label><%= l(:label_attachment_plural) %></label><%= render :partial => 'attachments/form', :locals => {:container => @news} %></p> diff --git a/app/views/news/show.html.erb b/app/views/news/show.html.erb index 04ea54a0a..95d6fe265 100644 --- a/app/views/news/show.html.erb +++ b/app/views/news/show.html.erb @@ -55,8 +55,7 @@ <div class="box"> <%= text_area 'comment', 'comments', :cols => 80, :rows => 15, :class => 'wiki-edit', :data => { - :auto_complete => true, - :issues_url => auto_complete_issues_path(:project_id => @project, :q => '') + :auto_complete => true } %> <%= wikitoolbar_for 'comment_comments', preview_news_path(:project_id => @project, :id => @news) %> diff --git a/app/views/search/index.html.erb b/app/views/search/index.html.erb index 5160f04fe..caaa3f35c 100644 --- a/app/views/search/index.html.erb +++ b/app/views/search/index.html.erb @@ -5,8 +5,7 @@ <%= label_tag "search-input", l(:description_search), :class => "hidden-for-sighted" %> <p><%= text_field_tag 'q', @question, :size => 60, :id => 'search-input', :data => { - :auto_complete => true, - :issues_url => auto_complete_issues_path(:q => '') + :auto_complete => true } %> <%= project_select_tag %> <%= hidden_field_tag 'all_words', '', :id => nil %> diff --git a/app/views/wiki/edit.html.erb b/app/views/wiki/edit.html.erb index 0e1c23cc4..c501d6e28 100644 --- a/app/views/wiki/edit.html.erb +++ b/app/views/wiki/edit.html.erb @@ -16,8 +16,7 @@ <%= text_area_tag 'content[text]', @text, :cols => 100, :rows => 25, :accesskey => accesskey(:edit), :class => 'wiki-edit', :data => { - :auto_complete => true, - :issues_url => auto_complete_issues_path(:project_id => @project, :q => '') + :auto_complete => true } %> diff --git a/public/javascripts/application.js b/public/javascripts/application.js index 825d96c88..90a5189fe 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -1045,11 +1045,15 @@ $(function () { function inlineAutoComplete(element) { 'use strict'; + // do not attach if Tribute is already initialized - if (element.dataset.tribute === 'true') {return;} + if (element.dataset.tribute === 'true') {return}; + + const getDataSource = function(entity) { + const dataSources = JSON.parse(rm.AutoComplete.dataSources); - const issuesUrl = element.dataset.issuesUrl; - const usersUrl = element.dataset.usersUrl; + return dataSources[entity]; + } const remoteSearch = function(url, cb) { const xhr = new XMLHttpRequest(); @@ -1074,7 +1078,7 @@ function inlineAutoComplete(element) { if (event.target.type === 'text' && $(element).attr('autocomplete') != 'off') { $(element).attr('autocomplete', 'off'); } - remoteSearch(issuesUrl + text, function (issues) { + remoteSearch(getDataSource('issues') + text, function (issues) { return cb(issues); }); }, |