summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2016-04-22 17:47:11 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2016-04-22 17:47:11 +0000
commitbda78a4679bc947dfd42ab92adfc043afd1d2f60 (patch)
tree39ad1356f3024f2dd9ee3a8710e8d9bd46334efc /app
parentb56f77322ac2f6a900ba011e767446e17401cf6f (diff)
downloadredmine-bda78a4679bc947dfd42ab92adfc043afd1d2f60.tar.gz
redmine-bda78a4679bc947dfd42ab92adfc043afd1d2f60.zip
Adds "New wiki page" link to create a new wiki page (#5536).
git-svn-id: http://svn.redmine.org/redmine/trunk@15346 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r--app/controllers/wiki_controller.rb17
-rw-r--r--app/helpers/application_helper.rb10
-rw-r--r--app/views/wiki/_new_modal.html.erb21
-rw-r--r--app/views/wiki/date_index.html.erb3
-rw-r--r--app/views/wiki/index.html.erb3
-rw-r--r--app/views/wiki/new.html.erb17
-rw-r--r--app/views/wiki/new.js.erb2
-rw-r--r--app/views/wiki/show.html.erb3
8 files changed, 74 insertions, 2 deletions
diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb
index 46dec485c..2f174877f 100644
--- a/app/controllers/wiki_controller.rb
+++ b/app/controllers/wiki_controller.rb
@@ -60,6 +60,23 @@ class WikiController < ApplicationController
@pages_by_date = @pages.group_by {|p| p.updated_on.to_date}
end
+ def new
+ @page = WikiPage.new(:wiki => @wiki, :title => params[:title])
+ unless User.current.allowed_to?(:edit_wiki_pages, @project) && editable?
+ render_403
+ end
+ if request.post?
+ @page.validate
+ if @page.errors[:title].blank?
+ path = project_wiki_page_path(@project, @page.title)
+ respond_to do |format|
+ format.html { redirect_to path }
+ format.js { render :js => "window.location = #{path.to_json}" }
+ end
+ end
+ end
+ end
+
# display a page (in editing mode if it doesn't exist)
def show
if params[:version] && !User.current.allowed_to?(:view_wiki_edits, @project)
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 7edfbd534..7cdf5061a 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -1057,11 +1057,17 @@ module ApplicationHelper
fields_for(*args, &proc)
end
+ # Render the error messages for the given objects
def error_messages_for(*objects)
- html = ""
objects = objects.map {|o| o.is_a?(String) ? instance_variable_get("@#{o}") : o}.compact
errors = objects.map {|o| o.errors.full_messages}.flatten
- if errors.any?
+ render_error_messages(errors)
+ end
+
+ # Renders a list of error messages
+ def render_error_messages(errors)
+ html = ""
+ if errors.present?
html << "<div id='errorExplanation'><ul>\n"
errors.each do |error|
html << "<li>#{h error}</li>\n"
diff --git a/app/views/wiki/_new_modal.html.erb b/app/views/wiki/_new_modal.html.erb
new file mode 100644
index 000000000..52a87b751
--- /dev/null
+++ b/app/views/wiki/_new_modal.html.erb
@@ -0,0 +1,21 @@
+<h3 class="title"><%=l(:label_wiki_page_new)%></h3>
+
+<%= labelled_form_for :page, @page,
+ :url => new_project_wiki_page_path(@project),
+ :method => 'post',
+ :remote => true do |f| %>
+
+ <%= render_error_messages @page.errors.full_messages_for(:title) %>
+
+ <div class="box tabular">
+ <p>
+ <%= f.text_field :title, :name => 'title', :size => 60, :required => true %>
+ <em class="info"><%= l(:text_unallowed_characters) %>: , . / ? ; : |</em>
+ </p>
+ </div>
+
+ <p class="buttons">
+ <%= submit_tag l(:label_next), :name => nil %>
+ <%= submit_tag l(:button_cancel), :name => nil, :onclick => "hideModal(this);", :type => 'button' %>
+ </p>
+<% end %>
diff --git a/app/views/wiki/date_index.html.erb b/app/views/wiki/date_index.html.erb
index 74a5f45fb..c382ed6e7 100644
--- a/app/views/wiki/date_index.html.erb
+++ b/app/views/wiki/date_index.html.erb
@@ -1,4 +1,7 @@
<div class="contextual">
+<% if User.current.allowed_to?(:edit_wiki_pages, @project) %>
+<%= link_to l(:label_wiki_page_new), new_project_wiki_page_path(@project), :remote => true, :class => 'icon icon-add' %>
+<% end %>
<%= watcher_link(@wiki, User.current) %>
</div>
diff --git a/app/views/wiki/index.html.erb b/app/views/wiki/index.html.erb
index 333cc8531..0d6955da1 100644
--- a/app/views/wiki/index.html.erb
+++ b/app/views/wiki/index.html.erb
@@ -1,4 +1,7 @@
<div class="contextual">
+<% if User.current.allowed_to?(:edit_wiki_pages, @project) %>
+<%= link_to l(:label_wiki_page_new), new_project_wiki_page_path(@project), :remote => true, :class => 'icon icon-add' %>
+<% end %>
<%= watcher_link(@wiki, User.current) %>
</div>
diff --git a/app/views/wiki/new.html.erb b/app/views/wiki/new.html.erb
new file mode 100644
index 000000000..d0674202d
--- /dev/null
+++ b/app/views/wiki/new.html.erb
@@ -0,0 +1,17 @@
+<%= title l(:label_wiki_page_new) %>
+
+<%= labelled_form_for :page, @page,
+ :url => new_project_wiki_page_path(@project) do |f| %>
+
+ <%= render_error_messages @page.errors.full_messages_for(:title) %>
+
+ <div class="box tabular">
+ <p>
+ <%= f.text_field :title, :name => 'title', :size => 60, :required => true %>
+ <em class="info"><%= l(:text_unallowed_characters) %>: , . / ? ; : |</em>
+ </p>
+ </div>
+
+ <%= submit_tag(l(:label_next)) %>
+
+<% end %>
diff --git a/app/views/wiki/new.js.erb b/app/views/wiki/new.js.erb
new file mode 100644
index 000000000..c12b35340
--- /dev/null
+++ b/app/views/wiki/new.js.erb
@@ -0,0 +1,2 @@
+$('#ajax-modal').html('<%= escape_javascript(render :partial => 'wiki/new_modal') %>');
+showModal('ajax-modal', '600px');
diff --git a/app/views/wiki/show.html.erb b/app/views/wiki/show.html.erb
index a9db7a0c4..41dd12d10 100644
--- a/app/views/wiki/show.html.erb
+++ b/app/views/wiki/show.html.erb
@@ -1,4 +1,7 @@
<div class="contextual">
+<% if User.current.allowed_to?(:edit_wiki_pages, @project) %>
+<%= link_to l(:label_wiki_page_new), new_project_wiki_page_path(@project), :remote => true, :class => 'icon icon-add' %>
+<% end %>
<% if @editable %>
<% if @content.current_version? %>
<%= link_to_if_authorized(l(:button_edit), {:action => 'edit', :id => @page.title}, :class => 'icon icon-edit', :accesskey => accesskey(:edit)) %>