##// END OF EJS Templates
Add cancel button during edition of a wiki page (#4285)....
Jean-Philippe Lang -
r14352:a371c8d850a2
parent child
Show More
@@ -0,0 +1,45
1 # Redmine - project management software
2 # Copyright (C) 2006-2015 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
18 require File.expand_path('../../../test_helper', __FILE__)
19
20 class WikiHelperTest < ActionView::TestCase
21 include WikiHelper
22 include Rails.application.routes.url_helpers
23
24 fixtures :projects, :users,
25 :roles, :member_roles, :members,
26 :enabled_modules, :wikis, :wiki_pages
27
28 def test_wiki_page_edit_cancel_path_for_new_page_without_parent_should_be_wiki_index
29 wiki = Wiki.find(1)
30 page = WikiPage.new(:wiki => wiki)
31 assert_equal '/projects/ecookbook/wiki/index', wiki_page_edit_cancel_path(page)
32 end
33
34 def test_wiki_page_edit_cancel_path_for_new_page_with_parent_should_be_parent
35 wiki = Wiki.find(1)
36 page = WikiPage.new(:wiki => wiki, :parent => wiki.find_page('Another_page'))
37 assert_equal '/projects/ecookbook/wiki/Another_page', wiki_page_edit_cancel_path(page)
38 end
39
40 def test_wiki_page_edit_cancel_path_for_existing_page_should_be_the_page
41 wiki = Wiki.find(1)
42 page = wiki.find_page('Child_1')
43 assert_equal '/projects/ecookbook/wiki/Child_1', wiki_page_edit_cancel_path(page)
44 end
45 end
@@ -1,54 +1,67
1 1 # encoding: utf-8
2 2 #
3 3 # Redmine - project management software
4 4 # Copyright (C) 2006-2015 Jean-Philippe Lang
5 5 #
6 6 # This program is free software; you can redistribute it and/or
7 7 # modify it under the terms of the GNU General Public License
8 8 # as published by the Free Software Foundation; either version 2
9 9 # of the License, or (at your option) any later version.
10 10 #
11 11 # This program is distributed in the hope that it will be useful,
12 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 14 # GNU General Public License for more details.
15 15 #
16 16 # You should have received a copy of the GNU General Public License
17 17 # along with this program; if not, write to the Free Software
18 18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 19
20 20 module WikiHelper
21 21 include Redmine::Export::PDF::WikiPdfHelper
22 22
23 23 def wiki_page_options_for_select(pages, selected = nil, parent = nil, level = 0)
24 24 pages = pages.group_by(&:parent) unless pages.is_a?(Hash)
25 25 s = ''.html_safe
26 26 if pages.has_key?(parent)
27 27 pages[parent].each do |page|
28 28 attrs = "value='#{page.id}'"
29 29 attrs << " selected='selected'" if selected == page
30 30 indent = (level > 0) ? ('&nbsp;' * level * 2 + '&#187; ') : ''
31 31
32 32 s << content_tag('option', (indent + h(page.pretty_title)).html_safe, :value => page.id.to_s, :selected => selected == page) +
33 33 wiki_page_options_for_select(pages, selected, page, level + 1)
34 34 end
35 35 end
36 36 s
37 37 end
38 38
39 39 def wiki_page_wiki_options_for_select(page)
40 40 projects = Project.allowed_to(:rename_wiki_pages).joins(:wiki).preload(:wiki).to_a
41 41 projects << page.project unless projects.include?(page.project)
42 42
43 43 project_tree_options_for_select(projects, :selected => page.project) do |project|
44 44 wiki_id = project.wiki.try(:id)
45 45 {:value => wiki_id, :selected => wiki_id == page.wiki_id}
46 46 end
47 47 end
48 48
49 49 def wiki_page_breadcrumb(page)
50 50 breadcrumb(page.ancestors.reverse.collect {|parent|
51 51 link_to(h(parent.pretty_title), {:controller => 'wiki', :action => 'show', :id => parent.title, :project_id => parent.project, :version => nil})
52 52 })
53 53 end
54
55 # Returns the path for the Cancel link when editing a wiki page
56 def wiki_page_edit_cancel_path(page)
57 if page.new_record?
58 if parent = page.parent
59 project_wiki_page_path(parent.project, parent.title)
60 else
61 project_wiki_index_path(page.project)
62 end
63 else
64 project_wiki_page_path(page.project, page.title)
65 end
66 end
54 67 end
@@ -1,47 +1,50
1 1 <%= wiki_page_breadcrumb(@page) %>
2 2
3 3 <h2><%= @page.pretty_title %></h2>
4 4
5 5 <%= form_for @content, :as => :content,
6 6 :url => {:action => 'update', :id => @page.title},
7 7 :html => {:method => :put, :multipart => true, :id => 'wiki_form'} do |f| %>
8 8 <%= f.hidden_field :version %>
9 9 <% if @section %>
10 10 <%= hidden_field_tag 'section', @section %>
11 11 <%= hidden_field_tag 'section_hash', @section_hash %>
12 12 <% end %>
13 13 <%= error_messages_for 'content' %>
14 14
15 15 <div class="box tabular">
16 16 <%= text_area_tag 'content[text]', @text, :cols => 100, :rows => 25,
17 17 :class => 'wiki-edit', :accesskey => accesskey(:edit) %>
18 18
19 19 <% if @page.safe_attribute_names.include?('parent_id') && @wiki.pages.any? %>
20 20 <%= fields_for @page do |fp| %>
21 21 <p>
22 22 <label><%= l(:field_parent_title) %></label>
23 23 <%= fp.select :parent_id,
24 24 content_tag('option', '', :value => '') +
25 25 wiki_page_options_for_select(
26 26 @wiki.pages.includes(:parent).to_a -
27 27 @page.self_and_descendants, @page.parent) %>
28 28 </p>
29 29 <% end %>
30 30 <% end %>
31 31
32 32 <p><label><%= l(:field_comments) %></label><%= f.text_field :comments, :size => 120, :maxlength => 1024 %></p>
33 33 <p><label><%=l(:label_attachment_plural)%></label><%= render :partial => 'attachments/form' %></p>
34 34 </div>
35 35
36 <p><%= submit_tag l(:button_save) %>
37 <%= preview_link({:controller => 'wiki', :action => 'preview', :project_id => @project, :id => @page.title }, 'wiki_form') %></p>
36 <p>
37 <%= submit_tag l(:button_save) %>
38 <%= preview_link({:controller => 'wiki', :action => 'preview', :project_id => @project, :id => @page.title }, 'wiki_form') %>
39 | <%= link_to l(:button_cancel), wiki_page_edit_cancel_path(@page) %>
40 </p>
38 41 <%= wikitoolbar_for 'content_text' %>
39 42 <% end %>
40 43
41 44 <div id="preview" class="wiki"></div>
42 45
43 46 <% content_for :header_tags do %>
44 47 <%= robot_exclusion_tag %>
45 48 <% end %>
46 49
47 50 <% html_title @page.pretty_title %>
General Comments 0
You need to be logged in to leave comments. Login now