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