@@ -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 | 18 | class PreviewsController < ApplicationController |
|
2 | 19 | before_filter :find_project |
|
3 | 20 | |
|
4 | 21 | def issue |
|
5 | 22 | @issue = @project.issues.find_by_id(params[:id]) unless params[:id].blank? |
|
6 | 23 | if @issue |
|
7 | 24 | @attachements = @issue.attachments |
|
8 | 25 | @description = params[:issue] && params[:issue][:description] |
|
9 | 26 | if @description && @description.gsub(/(\r?\n|\n\r?)/, "\n") == @issue.description.to_s.gsub(/(\r?\n|\n\r?)/, "\n") |
|
10 | 27 | @description = nil |
|
11 | 28 | end |
|
12 | 29 | @notes = params[:notes] |
|
13 | 30 | else |
|
14 | 31 | @description = (params[:issue] ? params[:issue][:description] : nil) |
|
15 | 32 | end |
|
16 | 33 | render :layout => false |
|
17 | 34 | end |
|
18 | 35 | |
|
19 | 36 | def news |
|
20 | 37 | @text = (params[:news] ? params[:news][:description] : nil) |
|
21 | 38 | render :partial => 'common/preview' |
|
22 | 39 | end |
|
23 | 40 | |
|
24 | 41 | private |
|
25 | 42 | |
|
26 | 43 | def find_project |
|
27 | 44 | project_id = (params[:issue] && params[:issue][:project_id]) || params[:project_id] |
|
28 | 45 | @project = Project.find(project_id) |
|
29 | 46 | rescue ActiveRecord::RecordNotFound |
|
30 | 47 | render_404 |
|
31 | 48 | end |
|
32 | 49 | |
|
33 | 50 | end |
@@ -1,11 +1,21 | |||
|
1 | 1 | <% form_remote_tag(:url => {}, :html => { :id => "journal-#{@journal.id}-form" }) do %> |
|
2 | 2 | <%= text_area_tag :notes, @journal.notes, |
|
3 | 3 | :id => "journal_#{@journal.id}_notes", |
|
4 | 4 | :class => 'wiki-edit', |
|
5 | 5 | :rows => (@journal.notes.blank? ? 10 : [[10, @journal.notes.length / 50].max, 100].min) %> |
|
6 | 6 | <%= call_hook(:view_journals_notes_form_after_notes, { :journal => @journal}) %> |
|
7 | 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 | 16 | <%= link_to l(:button_cancel), '#', :onclick => "Element.remove('journal-#{@journal.id}-form'); " + |
|
9 | 17 | "Element.show('journal-#{@journal.id}-notes'); return false;" %></p> |
|
18 | ||
|
19 | <div id="journal_<%= @journal.id %>_preview" class="wiki"></div> | |
|
10 | 20 | <% end %> |
|
11 | 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 | 18 | require File.expand_path('../../test_helper', __FILE__) |
|
2 | 19 | |
|
3 | 20 | class PreviewsControllerTest < ActionController::TestCase |
|
4 | 21 | fixtures :all |
|
5 | 22 | |
|
6 | 23 | def test_preview_new_issue |
|
7 | 24 | @request.session[:user_id] = 2 |
|
8 | 25 | post :issue, :project_id => '1', :issue => {:description => 'Foo'} |
|
9 | 26 | assert_response :success |
|
10 | 27 | assert_template 'preview' |
|
11 | 28 | assert_not_nil assigns(:description) |
|
12 | 29 | end |
|
13 | 30 | |
|
14 | 31 | def test_preview_issue_notes |
|
15 | 32 | @request.session[:user_id] = 2 |
|
16 | 33 | post :issue, :project_id => '1', :id => 1, :issue => {:description => Issue.find(1).description}, :notes => 'Foo' |
|
17 | 34 | assert_response :success |
|
18 | 35 | assert_template 'preview' |
|
19 | 36 | assert_not_nil assigns(:notes) |
|
20 | 37 | end |
|
21 | 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 | |
|
47 | ||
|
22 | 48 | def test_news |
|
23 | 49 | get :news, :project_id => 1, |
|
24 | 50 | :news => {:title => '', |
|
25 | 51 | :description => 'News description', |
|
26 | 52 | :summary => ''} |
|
27 | 53 | assert_response :success |
|
28 | 54 | assert_template 'common/_preview' |
|
29 | 55 | assert_tag :tag => 'fieldset', :attributes => { :class => 'preview' }, |
|
30 | 56 | :content => /News description/ |
|
31 | 57 | end |
|
32 | 58 | end |
General Comments 0
You need to be logged in to leave comments.
Login now