diff --git a/README b/README index 4edf0b1..b0fab74 100644 --- a/README +++ b/README @@ -1,3 +1,9 @@ +2012-12-06 +========== +Added compatibility with Redmine 2.x. +Compatibility with 1.x - not tested and may be corrupted + + 2011-06-01 ========== This is a fork of original ezfaq, a FAQ management plugin for Redmine by Zou Chaoqun. The goal is to fix bugs and merge existing patches for daily use. diff --git a/app/controllers/ezfaq_controller.rb b/app/controllers/ezfaq_controller.rb index eb07d46..3f0de86 100644 --- a/app/controllers/ezfaq_controller.rb +++ b/app/controllers/ezfaq_controller.rb @@ -15,6 +15,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + class EzfaqController < ApplicationController unloadable @@ -77,7 +78,7 @@ def new attachments = Attachment.attach_files(@faq, params[:attachments]) render_attachment_warning_if_needed(@faq) flash[:notice] = l(:notice_successful_create) - FaqMailer.deliver_faq_add(@project, @faq) + FaqMailer.faq_add(@project, @faq).deliver redirect_to :controller => 'ezfaq', :action => 'show', :id => @project, :faq_id => @faq return end @@ -93,14 +94,14 @@ def preview def edit @faq_categories = FaqCategory.find(:all, :conditions => "project_id = #{@project.id}", :order => "position") - if request.post? + if request.post? || request.put? @faq.attributes = params[:faq] @faq.updater_id = User.current.id if @faq.save attachments = Attachment.attach_files(@faq, params[:attachments]) render_attachment_warning_if_needed(@faq) flash[:notice] = l(:notice_successful_update) - FaqMailer.deliver_faq_update(@project, @faq) + FaqMailer.faq_update(@project, @faq).deliver redirect_to :controller => 'ezfaq', :action => 'show', :id => @project, :faq_id => @faq return end @@ -121,7 +122,7 @@ def copy end @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:new_project_id]} if params[:new_project_id] @target_project ||= @project - if request.post? + if request.post? || request.put? @faq.copy(@target_project) flash[:notice] = l(:notice_successful_update) redirect_to :controller => 'ezfaq', :action => 'index', :id => @project @@ -155,18 +156,15 @@ def show_history_version def add_faq_category @category = FaqCategory.new(params[:category]) @category.project_id = @project.id - if request.post? and @category.save + if (request.post? || request.put?) and @category.save respond_to do |format| - format.html do + format.html { flash[:notice] = l(:notice_successful_create) redirect_to :controller => 'faq_categories', :action => 'index', :id => @project - end - format.js do - faq_categories = FaqCategory.find(:all, :conditions => "project_id = #{@project.id}") - render(:update) {|page| page.replace "faq_category_id", - content_tag('select', '' + options_from_collection_for_select(faq_categories, 'id', 'name', @category.id), :id => 'faq_category_id', :name => 'faq[category_id]') - } - end + } + format.js { + render :partial => 'faq_category_modal_create' + } end end end @@ -175,7 +173,7 @@ def faq_setting @faq_setting = FaqSetting.find(:first, :conditions => "project_id = #{@project.id}") if !@faq_setting && request.get? @faq_setting = FaqSetting.new - elsif request.post? + elsif !request.get? if !@faq_setting @faq_setting = FaqSetting.new(params[:faq_setting]) else @@ -206,7 +204,7 @@ def find_faq def faq_to_pdf faq_setting = FaqSetting.find(:first, :conditions => "project_id = #{@project.id}") - pdf = IFPDF.new(current_language) + pdf = ITCPDF.new(current_language) pdf.SetTitle("#{l(:label_faq)}-#{@faq.question}") pdf.SetAuthor('ezFAQ for Redmine') pdf.AliasNbPages @@ -234,7 +232,7 @@ def faq_to_pdf end def faqs_to_pdf - pdf = IFPDF.new(current_language) + pdf = ITCPDF.new(current_language) pdf.SetTitle(@faq_setting.pdf_title) if (@faq_setting && @faq_setting.pdf_title) pdf.SetAuthor('ezFAQ for Redmine') pdf.AliasNbPages diff --git a/app/controllers/faq_categories_controller.rb b/app/controllers/faq_categories_controller.rb index ce27302..fe5ba88 100644 --- a/app/controllers/faq_categories_controller.rb +++ b/app/controllers/faq_categories_controller.rb @@ -22,8 +22,8 @@ class FaqCategoriesController < ApplicationController menu_item :ezfaq, :only => [:index, :edit, :destroy] before_filter :find_project, :authorize - verify :method => :post, :only => :destroy - verify :mothod => :post, :only => :change_order +# verify :method => :post, :only => :destroy +# verify :mothod => :post, :only => :change_order def index @categories = FaqCategory.find(:all, :conditions => "project_id = #{@project.id}", :order => "position") @@ -31,7 +31,7 @@ def index def edit @category = FaqCategory.find(:first, :conditions => "project_id = #{@project.id} and id = #{params[:category_id]}") - if request.post? and @category.update_attributes(params[:category]) + if (request.post? || request.put?) and @category.update_attributes(params[:category]) flash[:notice] = l(:notice_successful_update) redirect_to :controller => 'faq_categories', :action => 'index', :id => @project end @@ -40,7 +40,7 @@ def edit end def change_order - if request.post? + if request.post? || request.put? category = FaqCategory.find(:first, :conditions => "project_id = #{@project.id} and id = #{params[:category_id]}") case params[:position] when 'highest'; category.move_to_top diff --git a/app/helpers/ezfaq_helper.rb b/app/helpers/ezfaq_helper.rb deleted file mode 100644 index f721aa2..0000000 --- a/app/helpers/ezfaq_helper.rb +++ /dev/null @@ -1,26 +0,0 @@ -# ezFAQ plugin for redMine -# Copyright (C) 2008-2009 Zou Chaoqun -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -module EzfaqHelper - - def updated_by(updated, author) - time_tag = content_tag('acronym', distance_of_time_in_words(Time.now, updated), :title => format_time(updated)) - author_tag = (author.is_a?(User) && !author.is_a?(AnonymousUser)) ? link_to(h(author), :controller => 'account', :action => 'show', :id => author) : h(author || 'Anonymous') - l(:label_updated_time_by, :author => author_tag, :age => time_tag) - end - -end diff --git a/app/models/faq_mailer.rb b/app/models/faq_mailer.rb index 36009ca..0785d3c 100644 --- a/app/models/faq_mailer.rb +++ b/app/models/faq_mailer.rb @@ -24,25 +24,13 @@ def faq_add(project, faq) mail_addresses = [ faq.author.mail ] mail_addresses << faq.assigned_to.mail if faq.assigned_to - - recipients mail_addresses.compact.uniq - - subject "[#{faq.project.name} - #{l(:label_faq_new)} - #{l(:label_faq)}##{faq.id}] #{faq.question}" - body :faq => faq, - :faq_url => url_for(:controller => 'ezfaq', :action => 'show', :id => project, :faq_id => faq) - - content_type "multipart/alternative" - - part "text/plain" do |p| - p.body = render_message("faq_add.text.plain.rhtml", body) - end - - part "text/html" do |p| - p.body = render_message("faq_add.text.html.rhtml", body) - end + @faq = faq + @faq_url = url_for(:controller => 'ezfaq', :action => 'show', :id => project, :faq_id => faq) + mail :to => mail_addresses.compact.uniq, + :subject => "[#{faq.project.name} - #{l(:label_faq_new)} - #{l(:label_faq)}##{faq.id}] #{faq.question}" end - + def faq_update(project, faq) redmine_headers 'Project' => faq.project.identifier, 'Faq-Id' => faq.id, @@ -51,22 +39,10 @@ def faq_update(project, faq) mail_addresses = [ faq.author.mail, faq.updater.mail ] mail_addresses << faq.assigned_to.mail if faq.assigned_to - recipients mail_addresses.compact.uniq - - subject "[#{faq.project.name} - #{l(:label_faq_updated)} - #{l(:label_faq)}##{faq.id}] #{faq.question}" - body :faq => faq, - :faq_url => url_for(:controller => 'ezfaq', :action => 'show', :id => project, :faq_id => faq) - - content_type "multipart/alternative" - - part "text/plain" do |p| - p.body = render_message("faq_update.text.plain.rhtml", body) - end - - part "text/html" do |p| - p.body = render_message("faq_update.text.html.rhtml", body) - end - + @faq = faq + @faq_url = url_for(:controller => 'ezfaq', :action => 'show', :id => project, :faq_id => faq) + mail :to => mail_addresses.compact.uniq, + :subject => "[#{faq.project.name} - #{l(:label_faq_updated)} - #{l(:label_faq)}##{faq.id}] #{faq.question}" end end diff --git a/app/views/ezfaq/_add_faq_category_modal.html.erb b/app/views/ezfaq/_add_faq_category_modal.html.erb new file mode 100644 index 0000000..90be17e --- /dev/null +++ b/app/views/ezfaq/_add_faq_category_modal.html.erb @@ -0,0 +1,11 @@ +

<%=l(:label_faq_category_new)%>

+ +<% form = labelled_form_for :category, @category, :url => { :action => 'add_faq_category' }, :html => { :class => 'tabular'}, :remote => true do |f| %> +<%= render :partial => 'faq_categories/form', :locals => { :f => f } %> +

+<%= submit_tag l(:button_create) %> +<%= submit_tag l(:button_cancel), :onclick => "hideModal(this);" %> +

+<% end %> + +<%= form if Rails::VERSION::MAJOR >= 3 %> diff --git a/app/views/ezfaq/_edit.html.erb b/app/views/ezfaq/_edit.html.erb deleted file mode 100644 index 7d67ea9..0000000 --- a/app/views/ezfaq/_edit.html.erb +++ /dev/null @@ -1,50 +0,0 @@ - - -

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

-

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

- -
-

<%= f.select :category_id, (@faq_categories.collect {|c| [c.name, c.id]}), :include_blank => true %> -<%= prompt_to_remote(l(:label_faq_category_new), - l(:label_faq_category_new), 'category[name]', - {:controller => 'ezfaq', :action => 'add_faq_category', :id => @project}, - :class => 'small', :tabindex => 199) if authorize_for('ezfaq', 'add_faq_category') %>

-

-<%= f.select :difficulty, (1..10), {}, :required => true, :onchange => "change_stars();"%> -<%= image_tag("stars_#{@faq.difficulty}.png", :plugin => "ezfaq_plugin", :id => "stars_img", :alt => "#{l(:field_difficulty)}#{@faq.difficulty}", :title => "#{l(:field_difficulty)}#{@faq.difficulty}") %> -

-

<%= f.text_field :related_issue_id, :size => 10 %> <%= l(:label_info_for_input_id) %>

-

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

-
- -
-

<%= f.select :assigned_to_id, (@project.assignable_users.collect {|m| [m.name, m.id]}), :include_blank => true %>

-

<%= f.text_field :due_date, :size => 10 %><%= calendar_for('faq_due_date') %>

-

<%= f.text_field :related_message_id, :size => 10 %> <%= l(:label_info_for_input_id) %>

-

<%= f.select :is_valid, [[l(:label_valid), true], [l(:label_invalid), false]] %>

-
- -<%= hidden_field_tag 'difficulty_label', l(:field_difficulty) %> -<%= f.hidden_field :version %> - -

-

<%= render :partial => 'attachments/form' %>

- -<%= wikitoolbar_for 'faq_answer' %> diff --git a/app/views/ezfaq/_faq_category_modal_create.js.erb b/app/views/ezfaq/_faq_category_modal_create.js.erb new file mode 100644 index 0000000..c2eaf9e --- /dev/null +++ b/app/views/ezfaq/_faq_category_modal_create.js.erb @@ -0,0 +1,6 @@ +hideModal(); +<% +faq_categories = FaqCategory.find(:all, :conditions => "project_id = #{@project.id}") +select = content_tag('select', content_tag('option') + options_from_collection_for_select(faq_categories, 'id', 'name', @category.id), :id => 'faq_category_id', :name => 'faq[category_id]') +%> +$('#faq_category_id').replaceWith('<%= escape_javascript(select) %>'); diff --git a/app/views/ezfaq/_form.html.erb b/app/views/ezfaq/_form.html.erb index ddfbcf4..df3941d 100644 --- a/app/views/ezfaq/_form.html.erb +++ b/app/views/ezfaq/_form.html.erb @@ -1,13 +1,13 @@