Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
30 changes: 14 additions & 16 deletions app/controllers/ezfaq_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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', '<option></option>' + 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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/faq_categories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ 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")
end

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
Expand All @@ -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
Expand Down
26 changes: 0 additions & 26 deletions app/helpers/ezfaq_helper.rb

This file was deleted.

42 changes: 9 additions & 33 deletions app/models/faq_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
11 changes: 11 additions & 0 deletions app/views/ezfaq/_add_faq_category_modal.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<h3 class="title"><%=l(:label_faq_category_new)%></h3>

<% 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 } %>
<p class="buttons">
<%= submit_tag l(:button_create) %>
<%= submit_tag l(:button_cancel), :onclick => "hideModal(this);" %>
</p>
<% end %>

<%= form if Rails::VERSION::MAJOR >= 3 %>
50 changes: 0 additions & 50 deletions app/views/ezfaq/_edit.html.erb

This file was deleted.

6 changes: 6 additions & 0 deletions app/views/ezfaq/_faq_category_modal_create.js.erb
Original file line number Diff line number Diff line change
@@ -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) %>');
41 changes: 25 additions & 16 deletions app/views/ezfaq/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<script type="text/javascript">
//<![CDATA[
function change_stars() {
stars = $("stars_img");
difficulty = $("faq_difficulty");
position = stars.src.lastIndexOf("_") + 1;
new_img = stars.src.substring(0, position) + difficulty.value + ".png";
stars.src = new_img;
stars.alt = $("difficulty_label").value + difficulty.value;
stars.title = stars.alt;
stars = $("#stars_img");
difficulty = $("#faq_difficulty");
position = stars.attr("src").lastIndexOf("_") + 1;
new_img = stars.attr("src").substring(0, position) + difficulty.attr("value") + ".png";
stars.attr("src", new_img);
stars.attr("alt", $("#difficulty_label").attr("value") + difficulty.attr("value"));
stars.attr("title", stars.attr("alt"));
}

//]]>
Expand All @@ -22,16 +22,25 @@ function change_stars() {

<div class="splitcontentleft">
<p><%= 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') %></p>
<%= link_to(image_tag('add.png', :style => 'vertical-align: middle;'),
{:controller => 'ezfaq', :action => 'add_faq_category', :id => @project},
:remote => true,
:method => 'get',
:title => l(:label_faq_category_new),
:tabindex => 199) if authorize_for('ezfaq', 'add_faq_category') %></p>
<p>
<%= f.select :difficulty, (1..10), {}, :required => true, :onchange => "change_stars();"%>
<%= image_tag("stars_5.png", :plugin => "ezfaq_plugin", :id => "stars_img", :alt => "#{l(:field_difficulty)}5", :title => "#{l(:field_difficulty)}5") %>
<%= image_tag("stars_#{@faq.difficulty}.png", :plugin => "redmine_ezfaq_plugin", :id => "stars_img", :alt => "#{l(:field_difficulty)}#{@faq.difficulty}", :title => "#{l(:field_difficulty)}#{@faq.difficulty}") %>
</p>
<p><%= f.text_field :related_issue_id, :size => 10 %> <%= l(:label_info_for_input_id) %></p>
<p>
<%= f.text_field :related_issue_id, :size => 10 %> <%= l(:label_info_for_input_id) %>
<%= javascript_tag "observeAutocompleteField('faq_related_issue_id', '#{escape_javascript auto_complete_issues_path(:project_id => @project, :scope => (Setting.cross_project_issue_relations? ? 'all' : nil))}')" %>
</p>

<p><%= f.select :related_version_id, @project.versions.sort.collect {|v| [v.name, v.id]}, :include_blank => true %></p>
<% if !@faq.new_record? %>
<p><%= f.select :is_valid, [[l(:label_valid), true], [l(:label_invalid), false]] %> </p>
<% end %>
</div>

<div class="splitcontentright">
Expand All @@ -41,10 +50,10 @@ function change_stars() {
</div>

<%= hidden_field_tag 'difficulty_label', l(:field_difficulty) %>

<% if !@faq.new_record? %>
<%= f.hidden_field :version %>
<% end %>
<p />
<% if @faq.new_record? %>
<p><label><%=l(:label_attachment_plural)%></label><%= render :partial => 'attachments/form' %></p>
<% end %>

<%= wikitoolbar_for 'faq_answer' %>
8 changes: 8 additions & 0 deletions app/views/ezfaq/add_faq_category.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<h2><%=l(:label_faq_category_new)%></h2>

<% form = labelled_form_for :category, @category, :url => { :action => 'add_faq_category' }, :html => { :class => 'tabular'} do |f| %>
<%= render :partial => 'faq_categories/form', :locals => { :f => f } %>
<%= submit_tag l(:button_create) %>
<% end %>

<%= form if Rails::VERSION::MAJOR >= 3 %>
2 changes: 2 additions & 0 deletions app/views/ezfaq/add_faq_category.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
$('#ajax-modal').html('<%= escape_javascript(render :partial => 'add_faq_category_modal') %>');
showModal('ajax-modal', '600px');
6 changes: 0 additions & 6 deletions app/views/ezfaq/add_faq_category.rhtml

This file was deleted.

4 changes: 3 additions & 1 deletion app/views/ezfaq/copy.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<ul><%= content_tag('li', link_to("#{l(:label_faq)}##{@faq.id}", :controller => 'ezfaq', :action => 'show', :id => @project, :faq_id => @faq) + h(": #{@faq.question}")) %></ul>

<% form_tag({}, :id => 'move_form') do %>
<% form = form_tag({}, :id => 'move_form') do %>
<%= hidden_field_tag('faq_id', @faq.id) %>
<div class="box tabular">
<p><label for="new_project_id"><%=l(:field_project)%>:</label>
Expand All @@ -13,3 +13,5 @@

<%= submit_tag l(:button_copy) %>
<% end %>

<%= form if Rails::VERSION::MAJOR >= 3 %>
Loading