From 5259dec0611a00c84b4ae7f460202c761abec5f9 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sat, 6 Oct 2007 08:54:05 +0000 Subject: [PATCH] Added preview on add/edit issue form. git-svn-id: http://redmine.rubyforge.org/svn/trunk@812 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/issues_controller.rb | 9 ++++++++- app/controllers/wiki_controller.rb | 2 +- app/views/{wiki => common}/_preview.rhtml | 0 app/views/issues/_form.rhtml | 6 +++++- app/views/issues/edit.rhtml | 14 +++++++++++++- app/views/projects/add_issue.rhtml | 14 +++++++++++++- public/stylesheets/application.css | 2 ++ 7 files changed, 42 insertions(+), 5 deletions(-) rename app/views/{wiki => common}/_preview.rhtml (100%) diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index d8fd95b6..1f983419 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -17,7 +17,7 @@ class IssuesController < ApplicationController layout 'base', :except => :export_pdf - before_filter :find_project, :authorize, :except => :index + before_filter :find_project, :authorize, :except => [:index, :preview] accept_key_auth :index cache_sweeper :issue_sweeper, :only => [ :edit, :change_status, :destroy ] @@ -167,6 +167,13 @@ class IssuesController < ApplicationController redirect_to :action => 'show', :id => @issue end + def preview + issue = Issue.find_by_id(params[:id]) + @attachements = issue.attachments if issue + @text = params[:issue][:description] + render :partial => 'common/preview' + end + private def find_project @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category]) diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb index e3c9ed20..fe53e63f 100644 --- a/app/controllers/wiki_controller.rb +++ b/app/controllers/wiki_controller.rb @@ -144,7 +144,7 @@ class WikiController < ApplicationController page = @wiki.find_page(params[:page]) @attachements = page.attachments if page @text = params[:content][:text] - render :partial => 'preview' + render :partial => 'common/preview' end def add_attachment diff --git a/app/views/wiki/_preview.rhtml b/app/views/common/_preview.rhtml similarity index 100% rename from app/views/wiki/_preview.rhtml rename to app/views/common/_preview.rhtml diff --git a/app/views/issues/_form.rhtml b/app/views/issues/_form.rhtml index 28d2b97e..203d1cca 100644 --- a/app/views/issues/_form.rhtml +++ b/app/views/issues/_form.rhtml @@ -25,7 +25,11 @@

<%= f.text_field :subject, :size => 80, :required => true %>

-

<%= f.text_area :description, :required => true, :cols => 60, :rows => (@issue.description.blank? ? 10 : [[10, @issue.description.length / 50].max, 100].min), :class => 'wiki-edit' %>

+

<%= f.text_area :description, :required => true, + :cols => 60, + :rows => (@issue.description.blank? ? 10 : [[10, @issue.description.length / 50].max, 100].min), + :accesskey => accesskey(:edit), + :class => 'wiki-edit' %>

<%= f.select :fixed_version_id, (@project.versions.sort.collect {|v| [v.name, v.id]}), { :include_blank => true } %>

<% for @custom_value in @custom_values %>

<%= custom_field_tag_with_label @custom_value %>

diff --git a/app/views/issues/edit.rhtml b/app/views/issues/edit.rhtml index 9efaeb2e..1577216e 100644 --- a/app/views/issues/edit.rhtml +++ b/app/views/issues/edit.rhtml @@ -1,7 +1,19 @@

<%=h "#{@issue.tracker.name} ##{@issue.id}" %>

-<% labelled_tabular_form_for :issue, @issue, :url => {:action => 'edit'} do |f| %> +<% labelled_tabular_form_for :issue, @issue, + :url => {:action => 'edit'}, + :html => {:id => 'issue-form'} do |f| %> <%= render :partial => 'form', :locals => {:f => f} %> <%= f.hidden_field :lock_version %> <%= submit_tag l(:button_save) %> + <%= link_to_remote l(:label_preview), + { :url => { :controller => 'issues', :action => 'preview', :id => @issue }, + :method => 'post', + :update => 'preview', + :with => "Form.serialize('issue-form')", + :complete => "location.href='#preview-top'" + }, :accesskey => accesskey(:preview) %> <% end %> + + +
diff --git a/app/views/projects/add_issue.rhtml b/app/views/projects/add_issue.rhtml index f0dbead9..8382d6c9 100644 --- a/app/views/projects/add_issue.rhtml +++ b/app/views/projects/add_issue.rhtml @@ -1,7 +1,19 @@

<%=l(:label_issue_new)%>: <%= @tracker.name %>

-<% labelled_tabular_form_for :issue, @issue, :url => {:action => 'add_issue'}, :html => {:multipart => true} do |f| %> +<% labelled_tabular_form_for :issue, @issue, + :url => {:action => 'add_issue'}, + :html => {:multipart => true, :id => 'issue-form'} do |f| %> <%= hidden_field_tag 'tracker_id', @tracker.id %> <%= render :partial => 'issues/form', :locals => {:f => f} %> <%= submit_tag l(:button_create) %> + <%= link_to_remote l(:label_preview), + { :url => { :controller => 'issues', :action => 'preview', :id => @issue }, + :method => 'post', + :update => 'preview', + :with => "Form.serialize('issue-form')", + :complete => "location.href='#preview-top'" + }, :accesskey => accesskey(:preview) %> <% end %> + + +
diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index 8f0064a2..fdeec2bb 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -139,6 +139,8 @@ text-align: left; width: 200px; } +#preview fieldset {margin-top: 1em; background: url(../images/draft.png)} + #settings .tabular p{ padding-left: 300px; } #settings .tabular label{ margin-left: -300px; width: 295px; } -- 2.11.0