@@ -1,33 +1,50 | |||||
|
1 | # Redmine - project management software | |||
|
2 | # Copyright (C) 2006-2011 Jean-Philippe Lang | |||
|
3 | # | |||
|
4 | # This program is free software; you can redistribute it and/or | |||
|
5 | # modify it under the terms of the GNU General Public License | |||
|
6 | # as published by the Free Software Foundation; either version 2 | |||
|
7 | # of the License, or (at your option) any later version. | |||
|
8 | # | |||
|
9 | # This program is distributed in the hope that it will be useful, | |||
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
12 | # GNU General Public License for more details. | |||
|
13 | # | |||
|
14 | # You should have received a copy of the GNU General Public License | |||
|
15 | # along with this program; if not, write to the Free Software | |||
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
|
17 | ||||
1 | class PreviewsController < ApplicationController |
|
18 | class PreviewsController < ApplicationController | |
2 | before_filter :find_project |
|
19 | before_filter :find_project | |
3 |
|
20 | |||
4 | def issue |
|
21 | def issue | |
5 | @issue = @project.issues.find_by_id(params[:id]) unless params[:id].blank? |
|
22 | @issue = @project.issues.find_by_id(params[:id]) unless params[:id].blank? | |
6 | if @issue |
|
23 | if @issue | |
7 | @attachements = @issue.attachments |
|
24 | @attachements = @issue.attachments | |
8 | @description = params[:issue] && params[:issue][:description] |
|
25 | @description = params[:issue] && params[:issue][:description] | |
9 | if @description && @description.gsub(/(\r?\n|\n\r?)/, "\n") == @issue.description.to_s.gsub(/(\r?\n|\n\r?)/, "\n") |
|
26 | if @description && @description.gsub(/(\r?\n|\n\r?)/, "\n") == @issue.description.to_s.gsub(/(\r?\n|\n\r?)/, "\n") | |
10 | @description = nil |
|
27 | @description = nil | |
11 | end |
|
28 | end | |
12 | @notes = params[:notes] |
|
29 | @notes = params[:notes] | |
13 | else |
|
30 | else | |
14 | @description = (params[:issue] ? params[:issue][:description] : nil) |
|
31 | @description = (params[:issue] ? params[:issue][:description] : nil) | |
15 | end |
|
32 | end | |
16 | render :layout => false |
|
33 | render :layout => false | |
17 | end |
|
34 | end | |
18 |
|
35 | |||
19 | def news |
|
36 | def news | |
20 | @text = (params[:news] ? params[:news][:description] : nil) |
|
37 | @text = (params[:news] ? params[:news][:description] : nil) | |
21 | render :partial => 'common/preview' |
|
38 | render :partial => 'common/preview' | |
22 | end |
|
39 | end | |
23 |
|
40 | |||
24 | private |
|
41 | private | |
25 |
|
42 | |||
26 | def find_project |
|
43 | def find_project | |
27 | project_id = (params[:issue] && params[:issue][:project_id]) || params[:project_id] |
|
44 | project_id = (params[:issue] && params[:issue][:project_id]) || params[:project_id] | |
28 | @project = Project.find(project_id) |
|
45 | @project = Project.find(project_id) | |
29 | rescue ActiveRecord::RecordNotFound |
|
46 | rescue ActiveRecord::RecordNotFound | |
30 | render_404 |
|
47 | render_404 | |
31 | end |
|
48 | end | |
32 |
|
49 | |||
33 | end |
|
50 | end |
@@ -1,11 +1,21 | |||||
1 | <% form_remote_tag(:url => {}, :html => { :id => "journal-#{@journal.id}-form" }) do %> |
|
1 | <% form_remote_tag(:url => {}, :html => { :id => "journal-#{@journal.id}-form" }) do %> | |
2 | <%= text_area_tag :notes, @journal.notes, |
|
2 | <%= text_area_tag :notes, @journal.notes, | |
3 | :id => "journal_#{@journal.id}_notes", |
|
3 | :id => "journal_#{@journal.id}_notes", | |
4 | :class => 'wiki-edit', |
|
4 | :class => 'wiki-edit', | |
5 | :rows => (@journal.notes.blank? ? 10 : [[10, @journal.notes.length / 50].max, 100].min) %> |
|
5 | :rows => (@journal.notes.blank? ? 10 : [[10, @journal.notes.length / 50].max, 100].min) %> | |
6 | <%= call_hook(:view_journals_notes_form_after_notes, { :journal => @journal}) %> |
|
6 | <%= call_hook(:view_journals_notes_form_after_notes, { :journal => @journal}) %> | |
7 | <p><%= submit_tag l(:button_save) %> |
|
7 | <p><%= submit_tag l(:button_save) %> | |
|
8 | <%= link_to_remote l(:label_preview), | |||
|
9 | { :url => preview_issue_path(:project_id => @project, :id => @journal.issue), | |||
|
10 | :method => 'post', | |||
|
11 | :update => "journal_#{@journal.id}_preview", | |||
|
12 | :with => "Form.serialize('journal-#{@journal.id}-form')", | |||
|
13 | :complete => "Element.scrollTo('journal_#{@journal.id}_preview')" | |||
|
14 | }, :accesskey => accesskey(:preview) %> | |||
|
15 | | | |||
8 | <%= link_to l(:button_cancel), '#', :onclick => "Element.remove('journal-#{@journal.id}-form'); " + |
|
16 | <%= link_to l(:button_cancel), '#', :onclick => "Element.remove('journal-#{@journal.id}-form'); " + | |
9 | "Element.show('journal-#{@journal.id}-notes'); return false;" %></p> |
|
17 | "Element.show('journal-#{@journal.id}-notes'); return false;" %></p> | |
|
18 | ||||
|
19 | <div id="journal_<%= @journal.id %>_preview" class="wiki"></div> | |||
10 | <% end %> |
|
20 | <% end %> | |
11 | <%= wikitoolbar_for "journal_#{@journal.id}_notes" %> |
|
21 | <%= wikitoolbar_for "journal_#{@journal.id}_notes" %> |
@@ -1,32 +1,58 | |||||
|
1 | # Redmine - project management software | |||
|
2 | # Copyright (C) 2006-2011 Jean-Philippe Lang | |||
|
3 | # | |||
|
4 | # This program is free software; you can redistribute it and/or | |||
|
5 | # modify it under the terms of the GNU General Public License | |||
|
6 | # as published by the Free Software Foundation; either version 2 | |||
|
7 | # of the License, or (at your option) any later version. | |||
|
8 | # | |||
|
9 | # This program is distributed in the hope that it will be useful, | |||
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
12 | # GNU General Public License for more details. | |||
|
13 | # | |||
|
14 | # You should have received a copy of the GNU General Public License | |||
|
15 | # along with this program; if not, write to the Free Software | |||
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
|
17 | ||||
1 | require File.expand_path('../../test_helper', __FILE__) |
|
18 | require File.expand_path('../../test_helper', __FILE__) | |
2 |
|
19 | |||
3 | class PreviewsControllerTest < ActionController::TestCase |
|
20 | class PreviewsControllerTest < ActionController::TestCase | |
4 | fixtures :all |
|
21 | fixtures :all | |
5 |
|
22 | |||
6 | def test_preview_new_issue |
|
23 | def test_preview_new_issue | |
7 | @request.session[:user_id] = 2 |
|
24 | @request.session[:user_id] = 2 | |
8 | post :issue, :project_id => '1', :issue => {:description => 'Foo'} |
|
25 | post :issue, :project_id => '1', :issue => {:description => 'Foo'} | |
9 | assert_response :success |
|
26 | assert_response :success | |
10 | assert_template 'preview' |
|
27 | assert_template 'preview' | |
11 | assert_not_nil assigns(:description) |
|
28 | assert_not_nil assigns(:description) | |
12 | end |
|
29 | end | |
13 |
|
30 | |||
14 | def test_preview_issue_notes |
|
31 | def test_preview_issue_notes | |
15 | @request.session[:user_id] = 2 |
|
32 | @request.session[:user_id] = 2 | |
16 | post :issue, :project_id => '1', :id => 1, :issue => {:description => Issue.find(1).description}, :notes => 'Foo' |
|
33 | post :issue, :project_id => '1', :id => 1, :issue => {:description => Issue.find(1).description}, :notes => 'Foo' | |
17 | assert_response :success |
|
34 | assert_response :success | |
18 | assert_template 'preview' |
|
35 | assert_template 'preview' | |
19 | assert_not_nil assigns(:notes) |
|
36 | assert_not_nil assigns(:notes) | |
20 | end |
|
37 | end | |
|
38 | ||||
|
39 | def test_preview_journal_notes_for_update | |||
|
40 | @request.session[:user_id] = 2 | |||
|
41 | post :issue, :project_id => '1', :id => 1, :notes => 'Foo' | |||
|
42 | assert_response :success | |||
|
43 | assert_template 'preview' | |||
|
44 | assert_not_nil assigns(:notes) | |||
|
45 | assert_tag :p, :content => 'Foo' | |||
|
46 | end | |||
21 |
|
47 | |||
22 | def test_news |
|
48 | def test_news | |
23 | get :news, :project_id => 1, |
|
49 | get :news, :project_id => 1, | |
24 | :news => {:title => '', |
|
50 | :news => {:title => '', | |
25 | :description => 'News description', |
|
51 | :description => 'News description', | |
26 | :summary => ''} |
|
52 | :summary => ''} | |
27 | assert_response :success |
|
53 | assert_response :success | |
28 | assert_template 'common/_preview' |
|
54 | assert_template 'common/_preview' | |
29 | assert_tag :tag => 'fieldset', :attributes => { :class => 'preview' }, |
|
55 | assert_tag :tag => 'fieldset', :attributes => { :class => 'preview' }, | |
30 | :content => /News description/ |
|
56 | :content => /News description/ | |
31 | end |
|
57 | end | |
32 | end |
|
58 | end |
General Comments 0
You need to be logged in to leave comments.
Login now