From 9235ea321c0f559da622c3be6d5b74d27f89b6af Mon Sep 17 00:00:00 2001 From: Katsuya Hidaka Date: Mon, 16 Sep 2024 01:37:01 +0900 Subject: [PATCH 2/7] Implement and use JS function to handle quote reply --- app/assets/javascripts/application.js | 6 ++++++ app/helpers/journals_helper.rb | 12 +++++------- app/views/issues/show.html.erb | 2 +- app/views/messages/show.html.erb | 14 +++++--------- test/functional/journals_controller_test.rb | 10 +++++----- test/functional/messages_controller_test.rb | 6 +++--- 6 files changed, 25 insertions(+), 25 deletions(-) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 4560bff09..da0114dce 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -1262,6 +1262,12 @@ function inlineAutoComplete(element) { tribute.attach(element); } +function quoteReply(path) { + $.ajax({ + url: path, + type: 'post' + }); +} $(document).ready(setupAjaxIndicator); $(document).ready(hideOnLoad); diff --git a/app/helpers/journals_helper.rb b/app/helpers/journals_helper.rb index e51207e0e..f27799c7c 100644 --- a/app/helpers/journals_helper.rb +++ b/app/helpers/journals_helper.rb @@ -40,13 +40,11 @@ module JournalsHelper if journal.notes.present? if options[:reply_links] - links << link_to(icon_with_label('comment', l(:button_quote)), - quoted_issue_path(issue, :journal_id => journal, :journal_indice => indice), - :remote => true, - :method => 'post', - :title => l(:button_quote), - :class => 'icon-only icon-comment' - ) + links << link_to_function(icon_with_label('comment', l(:button_quote)), + "quoteReply('#{j quoted_issue_path(issue, :journal_id => journal, :journal_indice => indice)}')", + :title => l(:button_quote), + :class => 'icon-only icon-comment' + ) end if journal.editable_by?(User.current) links << link_to(icon_with_label('edit', l(:button_edit)), diff --git a/app/views/issues/show.html.erb b/app/views/issues/show.html.erb index 13c1bc632..a3efa28b9 100644 --- a/app/views/issues/show.html.erb +++ b/app/views/issues/show.html.erb @@ -84,7 +84,7 @@ end %>
- <%= link_to icon_with_label('comment', l(:button_quote)), quoted_issue_path(@issue), :remote => true, :method => 'post', :class => 'icon icon-comment ' if @issue.notes_addable? %> + <%= link_to_function icon_with_label('comment', l(:button_quote)), "quoteReply('#{j quoted_issue_path(@issue)}')",:class => 'icon icon-comment ' if @issue.notes_addable? %>

<%=l(:field_description)%>

diff --git a/app/views/messages/show.html.erb b/app/views/messages/show.html.erb index 64c69a0fe..6228a366b 100644 --- a/app/views/messages/show.html.erb +++ b/app/views/messages/show.html.erb @@ -2,12 +2,10 @@
<%= watcher_link(@topic, User.current) %> - <%= link_to( + <%= link_to_function( icon_with_label('comment', l(:button_quote)), - {:action => 'quote', :id => @topic}, - :method => 'get', - :class => 'icon icon-comment', - :remote => true) if !@topic.locked? && authorize_for('messages', 'reply') %> + "quoteReply('#{j url_for(:action => 'quote', :id => @topic, :format => 'js')}')", + :class => 'icon icon-comment') if !@topic.locked? && authorize_for('messages', 'reply') %> <%= link_to( icon_with_label('edit', l(:button_edit)), {:action => 'edit', :id => @topic}, @@ -42,11 +40,9 @@ <% @replies.each do |message| %>
">
- <%= link_to( + <%= link_to_function( icon_with_label('comment', l(:button_quote), icon_only: true), - {:action => 'quote', :id => message}, - :remote => true, - :method => 'get', + "quoteReply('#{j url_for(:action => 'quote', :id => message, :format => 'js')}')", :title => l(:button_quote), :class => 'icon icon-comment' ) if !@topic.locked? && authorize_for('messages', 'reply') %> diff --git a/test/functional/journals_controller_test.rb b/test/functional/journals_controller_test.rb index e02b29ca4..5fde7362b 100644 --- a/test/functional/journals_controller_test.rb +++ b/test/functional/journals_controller_test.rb @@ -168,7 +168,7 @@ class JournalsControllerTest < Redmine::ControllerTest def test_reply_to_issue @request.session[:user_id] = 2 - get(:new, :params => {:id => 6}, :xhr => true) + post(:new, :params => {:id => 6}, :xhr => true) assert_response :success assert_equal 'text/javascript', response.media_type @@ -177,13 +177,13 @@ class JournalsControllerTest < Redmine::ControllerTest def test_reply_to_issue_without_permission @request.session[:user_id] = 7 - get(:new, :params => {:id => 6}, :xhr => true) + post(:new, :params => {:id => 6}, :xhr => true) assert_response :forbidden end def test_reply_to_note @request.session[:user_id] = 2 - get( + post( :new, :params => { :id => 6, @@ -202,7 +202,7 @@ class JournalsControllerTest < Redmine::ControllerTest journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Privates notes', :private_notes => true) @request.session[:user_id] = 2 - get( + post( :new, :params => { :id => 2, @@ -215,7 +215,7 @@ class JournalsControllerTest < Redmine::ControllerTest assert_include '> Privates notes', response.body Role.find(1).remove_permission! :view_private_notes - get( + post( :new, :params => { :id => 2, diff --git a/test/functional/messages_controller_test.rb b/test/functional/messages_controller_test.rb index db91082ff..460651593 100644 --- a/test/functional/messages_controller_test.rb +++ b/test/functional/messages_controller_test.rb @@ -288,7 +288,7 @@ class MessagesControllerTest < Redmine::ControllerTest def test_quote_if_message_is_root @request.session[:user_id] = 2 - get( + post( :quote, :params => { :board_id => 1, @@ -306,7 +306,7 @@ class MessagesControllerTest < Redmine::ControllerTest def test_quote_if_message_is_not_root @request.session[:user_id] = 2 - get( + post( :quote, :params => { :board_id => 1, @@ -324,7 +324,7 @@ class MessagesControllerTest < Redmine::ControllerTest def test_quote_as_html_should_respond_with_404 @request.session[:user_id] = 2 - get( + post( :quote, :params => { :board_id => 1, -- 2.44.0