diff --git a/app/views/hooks/redmine_mentions_suggestions/_edit_mentionable.html.erb b/app/views/hooks/redmine_mentions_suggestions/_edit_mentionable.html.erb index a1e7345..f3d63a4 100644 --- a/app/views/hooks/redmine_mentions_suggestions/_edit_mentionable.html.erb +++ b/app/views/hooks/redmine_mentions_suggestions/_edit_mentionable.html.erb @@ -13,6 +13,7 @@ var usersMapping = <%= self.map_users_to_states(users, @issue) %>; var statuses = <%= self.status_listing %>; + var suggestMentions = <%= User.current.pref.suggest_mentions? %> window.setInterval(function(){ var text = $('#issue_notes').val(); @@ -43,7 +44,9 @@ $suggestions.html(''); $suggestions.append('
'); $('#issue_private_notes').before($suggestions); - $('input[name="issue_suggest_assignee"]').prop('checked', true); + if (suggestMentions) { + $('input[name="issue_suggest_assignee"]').prop('checked', true); + } if (usersMapping[id]) { for (var index = 0; index < usersMapping[id].length; index++) { diff --git a/app/views/hooks/redmine_mentions_suggestions/_mentions_suggestions_preference.html.erb b/app/views/hooks/redmine_mentions_suggestions/_mentions_suggestions_preference.html.erb new file mode 100644 index 0000000..8e9c731 --- /dev/null +++ b/app/views/hooks/redmine_mentions_suggestions/_mentions_suggestions_preference.html.erb @@ -0,0 +1,3 @@ +<%= labelled_fields_for :pref, @user.pref do |pref_fields| %> +

<%= pref_fields.check_box :suggest_mentions %>

+<% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 642b07f..f4eca4d 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1,3 +1,4 @@ # English strings go here for Rails i18n en: # my_label: "My label" + field_suggest_mentions: 'Enable mentions suggestions by default' diff --git a/lib/redmine_mentions_suggestions.rb b/lib/redmine_mentions_suggestions.rb index b2dff5c..2c30a1e 100644 --- a/lib/redmine_mentions_suggestions.rb +++ b/lib/redmine_mentions_suggestions.rb @@ -3,3 +3,10 @@ IssuesController.send :helper, IssuesControllerHelper require_dependency 'redmine_mentions_suggestions/hooks' end + +require_dependency 'redmine_mentions_suggestions/patches/user_preference_patch' +ActiveSupport::Reloader.to_prepare do + unless UserPreference.included_modules.include?(RedmineMentionsSuggestions::Patches::UserPreferencePatch) + UserPreference.send :prepend, RedmineMentionsSuggestions::Patches::UserPreferencePatch + end +end diff --git a/lib/redmine_mentions_suggestions/hooks.rb b/lib/redmine_mentions_suggestions/hooks.rb index 6992446..d085631 100644 --- a/lib/redmine_mentions_suggestions/hooks.rb +++ b/lib/redmine_mentions_suggestions/hooks.rb @@ -7,6 +7,8 @@ class Hooks < Redmine::Hook::ViewListener # Additional context fields # :issue => the issue this is edited # :f => the form object to create additional fields + render_on :view_my_account_preferences, + partial: 'hooks/redmine_mentions_suggestions/mentions_suggestions_preference' render_on :view_issues_edit_notes_bottom, :partial => 'hooks/redmine_mentions_suggestions/edit_mentionable' render_on :view_issues_form_details_bottom, diff --git a/lib/redmine_mentions_suggestions/patches/user_preference_patch.rb b/lib/redmine_mentions_suggestions/patches/user_preference_patch.rb new file mode 100644 index 0000000..1d18b29 --- /dev/null +++ b/lib/redmine_mentions_suggestions/patches/user_preference_patch.rb @@ -0,0 +1,29 @@ +require_dependency 'user_preference' + +module RedmineMentionsSuggestions + module Patches + module UserPreferencePatch + + def self.prepended(base) + base.class_eval do + if defined? safe_attributes + safe_attributes :suggest_mentions + end + end + end + + def suggest_mentions + self[:suggest_mentions] + end + + def suggest_mentions=(val) + self[:suggest_mentions] = val + end + + def suggest_mentions? + self[:suggest_mentions] + end + + end + end +end