Removes RJS from JournalsController.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10054 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2012-07-19 19:10:18 +00:00
parent e8469e2c5b
commit 3eaa998c28
7 changed files with 43 additions and 39 deletions

View File

@ -67,16 +67,8 @@ class JournalsController < ApplicationController
end end
# Replaces pre blocks with [...] # Replaces pre blocks with [...]
text = text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]') text = text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]')
content = "#{ll(Setting.default_language, :text_user_wrote, user)}\n> " @content = "#{ll(Setting.default_language, :text_user_wrote, user)}\n> "
content << text.gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n" @content << text.gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n"
render(:update) { |page|
page.<< "$('notes').value = \"#{escape_javascript content}\";"
page.show 'update'
page << "Form.Element.focus('notes');"
page << "Element.scrollTo('update');"
page << "$('notes').scrollTop = $('notes').scrollHeight - $('notes').clientHeight;"
}
end end
def edit def edit

View File

@ -0,0 +1,2 @@
Element.hide("journal-<%= @journal.id %>-notes");
Element.insert("journal-<%= @journal.id %>-notes", {'after': '<%= escape_javascript(render :partial => 'notes_form') %>'});

View File

@ -1,3 +0,0 @@
page.hide "journal-#{@journal.id}-notes"
page.insert_html :after, "journal-#{@journal.id}-notes",
:partial => 'notes_form'

View File

@ -0,0 +1,5 @@
$('notes').value = "<%= raw escape_javascript(@content) %>";
Element.show('update');
Form.Element.focus('notes');
Element.scrollTo('update');
$('notes').scrollTop = $('notes').scrollHeight - $('notes').clientHeight;

View File

@ -0,0 +1,9 @@
<% if @journal.frozen? %>
Element.remove("change-<%= @journal.id %>");
<% else %>
Element.replace("journal-<%= @journal.id %>-notes", '<%= escape_javascript(render_notes(@journal.issue, @journal, :reply_links => authorize_for('issues', 'edit'))) %>');
Element.show("journal-<%= @journal.id %>-notes");
Element.remove("journal-<%= @journal.id %>-form");
<% end %>
<%= call_hook(:view_journals_update_js_bottom, { :journal => @journal }) %>

View File

@ -1,10 +0,0 @@
if @journal.frozen?
# journal was destroyed
page.remove "change-#{@journal.id}"
else
page.replace "journal-#{@journal.id}-notes", render_notes(@journal.issue, @journal, :reply_links => authorize_for('issues', 'edit'))
page.show "journal-#{@journal.id}-notes"
page.remove "journal-#{@journal.id}-form"
end
call_hook(:view_journals_update_rjs_bottom, { :page => page, :journal => @journal })

View File

@ -54,47 +54,56 @@ class JournalsControllerTest < ActionController::TestCase
def test_reply_to_issue def test_reply_to_issue
@request.session[:user_id] = 2 @request.session[:user_id] = 2
get :new, :id => 6 xhr :get, :new, :id => 6
assert_response :success assert_response :success
assert_select_rjs :show, "update" assert_template 'new'
assert_equal 'text/javascript', response.content_type
assert_include '> This is an issue', response.body
end end
def test_reply_to_issue_without_permission def test_reply_to_issue_without_permission
@request.session[:user_id] = 7 @request.session[:user_id] = 7
get :new, :id => 6 xhr :get, :new, :id => 6
assert_response 403 assert_response 403
end end
def test_reply_to_note def test_reply_to_note
@request.session[:user_id] = 2 @request.session[:user_id] = 2
get :new, :id => 6, :journal_id => 4 xhr :get, :new, :id => 6, :journal_id => 4
assert_response :success assert_response :success
assert_select_rjs :show, "update" assert_template 'new'
assert_equal 'text/javascript', response.content_type
assert_include '> A comment with a private version', response.body
end end
def test_get_edit def test_edit_xhr
@request.session[:user_id] = 1 @request.session[:user_id] = 1
xhr :get, :edit, :id => 2 xhr :get, :edit, :id => 2
assert_response :success assert_response :success
assert_select_rjs :insert, :after, 'journal-2-notes' do assert_template 'edit'
assert_select 'form[id=journal-2-form]' assert_equal 'text/javascript', response.content_type
assert_select 'textarea' assert_include 'textarea', response.body
end
end end
def test_post_edit def test_update_xhr
@request.session[:user_id] = 1 @request.session[:user_id] = 1
xhr :post, :edit, :id => 2, :notes => 'Updated notes' xhr :post, :edit, :id => 2, :notes => 'Updated notes'
assert_response :success assert_response :success
assert_select_rjs :replace, 'journal-2-notes' assert_template 'update'
assert_equal 'text/javascript', response.content_type
assert_equal 'Updated notes', Journal.find(2).notes assert_equal 'Updated notes', Journal.find(2).notes
assert_include 'journal-2-notes', response.body
end end
def test_post_edit_with_empty_notes def test_update_xhr_with_empty_notes_should_delete_the_journal
@request.session[:user_id] = 1 @request.session[:user_id] = 1
xhr :post, :edit, :id => 2, :notes => '' assert_difference 'Journal.count', -1 do
assert_response :success xhr :post, :edit, :id => 2, :notes => ''
assert_select_rjs :remove, 'change-2' assert_response :success
assert_template 'update'
assert_equal 'text/javascript', response.content_type
end
assert_nil Journal.find_by_id(2) assert_nil Journal.find_by_id(2)
assert_include 'change-2', response.body
end end
end end