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
|
||||||
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
|
private
|
||||||
|
|
||||||
def wiki_helper
|
def wiki_helper
|
||||||
|
|||||||
@@ -84,9 +84,8 @@ module CustomFieldsHelper
|
|||||||
if custom_value.custom_field.full_text_formatting?
|
if custom_value.custom_field.full_text_formatting?
|
||||||
css += ' wiki-edit'
|
css += ' wiki-edit'
|
||||||
data = {
|
data = {
|
||||||
:auto_complete => true,
|
:auto_complete => true
|
||||||
:issues_url => auto_complete_issues_path(:project_id => custom_value.customized.project, :q => '')
|
}
|
||||||
} if custom_value.customized&.try(:project)
|
|
||||||
end
|
end
|
||||||
custom_value.custom_field.format.edit_tag(
|
custom_value.custom_field.format.edit_tag(
|
||||||
self,
|
self,
|
||||||
@@ -133,8 +132,7 @@ module CustomFieldsHelper
|
|||||||
if custom_field.full_text_formatting?
|
if custom_field.full_text_formatting?
|
||||||
css += ' wiki-edit'
|
css += ' wiki-edit'
|
||||||
data = {
|
data = {
|
||||||
:auto_complete => true,
|
:auto_complete => true
|
||||||
:issues_url => auto_complete_issues_path(:q => '')
|
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
custom_field.format.bulk_edit_tag(
|
custom_field.format.bulk_edit_tag(
|
||||||
|
|||||||
@@ -5,8 +5,7 @@
|
|||||||
<p><%= f.text_field :title, :required => true, :size => 60 %></p>
|
<p><%= f.text_field :title, :required => true, :size => 60 %></p>
|
||||||
<p><%= f.text_area :description, :cols => 60, :rows => 15, :class => 'wiki-edit',
|
<p><%= f.text_area :description, :cols => 60, :rows => 15, :class => 'wiki-edit',
|
||||||
:data => {
|
:data => {
|
||||||
:auto_complete => true,
|
:auto_complete => true
|
||||||
:issues_url => auto_complete_issues_path(:project_id => @project, :q => '')
|
|
||||||
}
|
}
|
||||||
%></p>
|
%></p>
|
||||||
|
|
||||||
|
|||||||
@@ -31,8 +31,7 @@
|
|||||||
<fieldset><legend><%= l(:field_notes) %></legend>
|
<fieldset><legend><%= l(:field_notes) %></legend>
|
||||||
<%= f.text_area :notes, :cols => 60, :rows => 10, :class => 'wiki-edit',
|
<%= f.text_area :notes, :cols => 60, :rows => 10, :class => 'wiki-edit',
|
||||||
:data => {
|
:data => {
|
||||||
:auto_complete => true,
|
:auto_complete => true
|
||||||
:issues_url => auto_complete_issues_path(:project_id => @issue.project, :q => '')
|
|
||||||
},
|
},
|
||||||
:no_label => true %>
|
:no_label => true %>
|
||||||
<%= wikitoolbar_for 'issue_notes', preview_issue_path(:project_id => @project, :issue_id => @issue) %>
|
<%= 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,
|
:rows => [[10, @issue.description.to_s.length / 50].max, 20].min,
|
||||||
:data => {
|
:data => {
|
||||||
:auto_complete => true,
|
:auto_complete => true,
|
||||||
:issues_url => auto_complete_issues_path(:project_id => @issue.project, :q => '')
|
|
||||||
},
|
},
|
||||||
:no_label => true %>
|
:no_label => true %>
|
||||||
<% end %>
|
<% end %>
|
||||||
@@ -54,6 +53,7 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% heads_for_wiki_formatter %>
|
<% heads_for_wiki_formatter %>
|
||||||
|
<%= heads_for_auto_complete(@issue.project) %>
|
||||||
|
|
||||||
<%= javascript_tag do %>
|
<%= javascript_tag do %>
|
||||||
$(document).ready(function(){
|
$(document).ready(function(){
|
||||||
|
|||||||
@@ -221,8 +221,7 @@
|
|||||||
<legend><%= l(:field_notes) %></legend>
|
<legend><%= l(:field_notes) %></legend>
|
||||||
<%= text_area_tag 'notes', @notes, :cols => 60, :rows => 10, :class => 'wiki-edit',
|
<%= text_area_tag 'notes', @notes, :cols => 60, :rows => 10, :class => 'wiki-edit',
|
||||||
:data => {
|
:data => {
|
||||||
:auto_complete => true,
|
:auto_complete => true
|
||||||
:issues_url => auto_complete_issues_path(:project_id => @project, :q => '')
|
|
||||||
}
|
}
|
||||||
%>
|
%>
|
||||||
<%= wikitoolbar_for 'notes' %>
|
<%= wikitoolbar_for 'notes' %>
|
||||||
|
|||||||
@@ -6,8 +6,7 @@
|
|||||||
<%= text_area_tag 'journal[notes]', @journal.notes, :id => "journal_#{@journal.id}_notes", :class => 'wiki-edit',
|
<%= 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),
|
:rows => (@journal.notes.blank? ? 10 : [[10, @journal.notes.length / 50].max, 100].min),
|
||||||
:data => {
|
:data => {
|
||||||
:auto_complete => true,
|
:auto_complete => true
|
||||||
:issues_url => auto_complete_issues_path(:project_id => @project, :q => '')
|
|
||||||
}
|
}
|
||||||
%>
|
%>
|
||||||
<% if @journal.safe_attribute? 'private_notes' %>
|
<% if @journal.safe_attribute? 'private_notes' %>
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
<%= stylesheet_link_tag 'rtl', :media => 'all' if l(:direction) == 'rtl' %>
|
<%= stylesheet_link_tag 'rtl', :media => 'all' if l(:direction) == 'rtl' %>
|
||||||
<%= javascript_heads %>
|
<%= javascript_heads %>
|
||||||
<%= heads_for_theme %>
|
<%= heads_for_theme %>
|
||||||
|
<%= heads_for_auto_complete(@project) %>
|
||||||
<%= call_hook :view_layouts_base_html_head %>
|
<%= call_hook :view_layouts_base_html_head %>
|
||||||
<!-- page specific tags -->
|
<!-- page specific tags -->
|
||||||
<%= yield :header_tags -%>
|
<%= yield :header_tags -%>
|
||||||
@@ -23,7 +24,6 @@
|
|||||||
|
|
||||||
<div class="flyout-menu js-flyout-menu">
|
<div class="flyout-menu js-flyout-menu">
|
||||||
|
|
||||||
|
|
||||||
<% if User.current.logged? || !Setting.login_required? %>
|
<% if User.current.logged? || !Setting.login_required? %>
|
||||||
<div class="flyout-menu__search">
|
<div class="flyout-menu__search">
|
||||||
<%= form_tag({:controller => 'search', :action => 'index', :id => @project}, :method => :get ) do %>
|
<%= form_tag({:controller => 'search', :action => 'index', :id => @project}, :method => :get ) do %>
|
||||||
@@ -82,8 +82,7 @@
|
|||||||
</label>
|
</label>
|
||||||
<%= text_field_tag 'q', @question, :size => 20, :class => 'small', :accesskey => accesskey(:quick_search),
|
<%= text_field_tag 'q', @question, :size => 20, :class => 'small', :accesskey => accesskey(:quick_search),
|
||||||
:data => {
|
:data => {
|
||||||
:auto_complete => true,
|
:auto_complete => true
|
||||||
:issues_url => auto_complete_issues_path(:q => '')
|
|
||||||
} %>
|
} %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<%= render_project_jump_box %>
|
<%= render_project_jump_box %>
|
||||||
|
|||||||
@@ -26,8 +26,7 @@
|
|||||||
<%= f.text_area :content, :cols => 80, :rows => 15, :class => 'wiki-edit', :id => 'message_content',
|
<%= f.text_area :content, :cols => 80, :rows => 15, :class => 'wiki-edit', :id => 'message_content',
|
||||||
:accesskey => accesskey(:edit),
|
:accesskey => accesskey(:edit),
|
||||||
:data => {
|
:data => {
|
||||||
:auto_complete => true,
|
:auto_complete => true
|
||||||
:issues_url => auto_complete_issues_path(:project_id => @project, :q => '')
|
|
||||||
}
|
}
|
||||||
%></p>
|
%></p>
|
||||||
<%= wikitoolbar_for 'message_content', preview_board_message_path(:board_id => @board, :id => @message) %>
|
<%= 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 :summary, :cols => 60, :rows => 2 %></p>
|
||||||
<p><%= f.text_area :description, :required => true, :cols => 60, :rows => 15, :class => 'wiki-edit',
|
<p><%= f.text_area :description, :required => true, :cols => 60, :rows => 15, :class => 'wiki-edit',
|
||||||
:data => {
|
:data => {
|
||||||
:auto_complete => true,
|
:auto_complete => true
|
||||||
:issues_url => auto_complete_issues_path(:project_id => @project, :q => '')
|
|
||||||
}
|
}
|
||||||
%></p>
|
%></p>
|
||||||
<p id="attachments_form"><label><%= l(:label_attachment_plural) %></label><%= render :partial => 'attachments/form', :locals => {:container => @news} %></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">
|
<div class="box">
|
||||||
<%= text_area 'comment', 'comments', :cols => 80, :rows => 15, :class => 'wiki-edit',
|
<%= text_area 'comment', 'comments', :cols => 80, :rows => 15, :class => 'wiki-edit',
|
||||||
:data => {
|
:data => {
|
||||||
:auto_complete => true,
|
:auto_complete => true
|
||||||
:issues_url => auto_complete_issues_path(:project_id => @project, :q => '')
|
|
||||||
}
|
}
|
||||||
%>
|
%>
|
||||||
<%= wikitoolbar_for 'comment_comments', preview_news_path(:project_id => @project, :id => @news) %>
|
<%= 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" %>
|
<%= label_tag "search-input", l(:description_search), :class => "hidden-for-sighted" %>
|
||||||
<p><%= text_field_tag 'q', @question, :size => 60, :id => 'search-input',
|
<p><%= text_field_tag 'q', @question, :size => 60, :id => 'search-input',
|
||||||
:data => {
|
:data => {
|
||||||
:auto_complete => true,
|
:auto_complete => true
|
||||||
:issues_url => auto_complete_issues_path(:q => '')
|
|
||||||
} %>
|
} %>
|
||||||
<%= project_select_tag %>
|
<%= project_select_tag %>
|
||||||
<%= hidden_field_tag 'all_words', '', :id => nil %>
|
<%= hidden_field_tag 'all_words', '', :id => nil %>
|
||||||
|
|||||||
@@ -16,8 +16,7 @@
|
|||||||
<%= text_area_tag 'content[text]', @text, :cols => 100, :rows => 25, :accesskey => accesskey(:edit),
|
<%= text_area_tag 'content[text]', @text, :cols => 100, :rows => 25, :accesskey => accesskey(:edit),
|
||||||
:class => 'wiki-edit',
|
:class => 'wiki-edit',
|
||||||
:data => {
|
:data => {
|
||||||
:auto_complete => true,
|
:auto_complete => true
|
||||||
:issues_url => auto_complete_issues_path(:project_id => @project, :q => '')
|
|
||||||
}
|
}
|
||||||
%>
|
%>
|
||||||
|
|
||||||
|
|||||||
@@ -1045,11 +1045,15 @@ $(function () {
|
|||||||
|
|
||||||
function inlineAutoComplete(element) {
|
function inlineAutoComplete(element) {
|
||||||
'use strict';
|
'use strict';
|
||||||
// do not attach if Tribute is already initialized
|
|
||||||
if (element.dataset.tribute === 'true') {return;}
|
|
||||||
|
|
||||||
const issuesUrl = element.dataset.issuesUrl;
|
// do not attach if Tribute is already initialized
|
||||||
const usersUrl = element.dataset.usersUrl;
|
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 remoteSearch = function(url, cb) {
|
||||||
const xhr = new XMLHttpRequest();
|
const xhr = new XMLHttpRequest();
|
||||||
@@ -1074,7 +1078,7 @@ function inlineAutoComplete(element) {
|
|||||||
if (event.target.type === 'text' && $(element).attr('autocomplete') != 'off') {
|
if (event.target.type === 'text' && $(element).attr('autocomplete') != 'off') {
|
||||||
$(element).attr('autocomplete', 'off');
|
$(element).attr('autocomplete', 'off');
|
||||||
}
|
}
|
||||||
remoteSearch(issuesUrl + text, function (issues) {
|
remoteSearch(getDataSource('issues') + text, function (issues) {
|
||||||
return cb(issues);
|
return cb(issues);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user