mirror of
https://github.com/redmine/redmine.git
synced 2025-11-11 15:56:03 +01:00
Store inline autocomplete data sources in a JS variable (#34122).
Patch by Marius BALTEANU. git-svn-id: http://svn.redmine.org/redmine/trunk@20191 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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>
|
||||
|
||||
|
||||
@@ -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) %>
|
||||
|
||||
@@ -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(){
|
||||
|
||||
@@ -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' %>
|
||||
|
||||
@@ -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' %>
|
||||
|
||||
@@ -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 %>
|
||||
|
||||
@@ -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) %>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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) %>
|
||||
|
||||
@@ -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 %>
|
||||
|
||||
@@ -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
|
||||
}
|
||||
%>
|
||||
|
||||
|
||||
@@ -1045,11 +1045,15 @@ $(function () {
|
||||
|
||||
function inlineAutoComplete(element) {
|
||||
'use strict';
|
||||
// do not attach if Tribute is already initialized
|
||||
if (element.dataset.tribute === 'true') {return;}
|
||||
|
||||
const issuesUrl = element.dataset.issuesUrl;
|
||||
const usersUrl = element.dataset.usersUrl;
|
||||
// do not attach if Tribute is already initialized
|
||||
if (element.dataset.tribute === 'true') {return};
|
||||
|
||||
const getDataSource = function(entity) {
|
||||
const dataSources = JSON.parse(rm.AutoComplete.dataSources);
|
||||
|
||||
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);
|
||||
});
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user