Skip to content

Commit

Permalink
updated to version 0.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
zouchaoqun committed Feb 3, 2009
1 parent b4cde43 commit 3bdd623
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 7 deletions.
3 changes: 2 additions & 1 deletion README
Expand Up @@ -25,7 +25,8 @@ Installed plugins are listed on 'Admin -> Information' screen.
=== Changelog

0.0.4 -> Add faq into project's activity.
Add preview ablility to new and edit page.
Add preview ablility to faq's new and edit page.
Add copy ablility to faq's show page.
Use redmine's pagination instead of will_paginate(so will_paginate is no longer needed).
Add de.yml language.

Expand Down
26 changes: 23 additions & 3 deletions app/controllers/ezfaq_controller.rb
Expand Up @@ -20,7 +20,7 @@ class EzfaqController < ApplicationController

layout 'base'
before_filter :find_project, :authorize
before_filter :find_faq, :only => [:show, :edit, :destroy, :history, :show_history_version]
before_filter :find_faq, :only => [:show, :edit, :copy, :destroy, :history, :show_history_version]

helper :attachments
include AttachmentsHelper
Expand Down Expand Up @@ -97,7 +97,27 @@ def edit
# Optimistic locking exception
flash.now[:error] = l(:notice_locking_conflict)
end


def copy
@allowed_projects = []
# find projects to which the user is allowed to copy the faq
if User.current.admin?
# admin is allowed to copy faqs to any active (visible) project
@allowed_projects = Project.find(:all, :conditions => Project.visible_by(User.current))
else
User.current.memberships.each {|m| @allowed_projects << m.project if m.role.allowed_to?(:edit_faqs)}
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?
@faq.copy(@target_project)
flash[:notice] = l(:notice_successful_update)
redirect_to :controller => 'ezfaq', :action => 'index', :id => @project
return
end
render :layout => false if request.xhr?
end

def destroy
@faq.destroy
redirect_to :action => 'index', :id => @project
Expand All @@ -112,7 +132,7 @@ def history
:limit => limit,
:offset => @version_pages.current.offset

render :template => 'ezfaq/history.html.erb', :layout => !request.xhr?
render :layout => false if request.xhr?
end

def show_history_version
Expand Down
10 changes: 10 additions & 0 deletions app/models/faq.rb
Expand Up @@ -91,4 +91,14 @@ def to_s
"##{id}: #{question}"
end

# Copies a faq in current project or to a new project
def copy(new_project)
faq = self.clone
if (faq.project_id != new_project.id)
faq.project_id = new_project.id
faq.category = nil
end
faq.save
end

end
15 changes: 15 additions & 0 deletions app/views/ezfaq/copy.html.erb
@@ -0,0 +1,15 @@
<h2><%= l(:button_copy) %></h2>

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

<% 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>
<%= select_tag "new_project_id",
project_tree_options_for_select(@allowed_projects, :selected => @target_project) %></p>

</div>

<%= submit_tag l(:button_copy) %>
<% end %>
1 change: 1 addition & 0 deletions app/views/ezfaq/show.html.erb
@@ -1,6 +1,7 @@
<div class="contextual">
<%= link_to_if_authorized(l(:button_update), {:controller => 'ezfaq', :action => 'edit', :id => @project, :faq_id => @faq}, :class => 'icon icon-edit', :accesskey => accesskey(:edit)) %>
<%= link_to_if_authorized l(:button_delete), {:controller => 'ezfaq', :action => 'destroy', :id => @project, :faq_id => @faq}, :confirm => l(:text_are_you_sure), :method => :post, :class => 'icon icon-del' %>
<%= link_to_if_authorized l(:button_copy), {:controller => 'ezfaq', :action => 'copy', :id => @project, :faq_id => @faq }, :class => 'icon icon-copy' %>
<%= link_to(l(:label_history), {:action => 'history', :id => @project, :faq_id => @faq}, :class => 'icon icon-history') %>
</div>

Expand Down
2 changes: 1 addition & 1 deletion init.rb
Expand Up @@ -36,7 +36,7 @@
project_module :ezfaq do
permission :view_faqs, {:ezfaq => [:index, :show, :history, :diff, :show_history_version]}, :public => true
permission :add_faqs, {:ezfaq => [:new, :preview]}, :require => :loggedin
permission :edit_faqs, {:ezfaq => [:edit, :preview, :destroy, :list_invalid_faqs]}, :require => :member
permission :edit_faqs, {:ezfaq => [:edit, :preview, :copy, :destroy, :list_invalid_faqs]}, :require => :member
permission :manage_faq_categories, {:ezfaq => [:add_faq_category], :faq_categories => [:index, :change_order, :edit, :destroy]}, :require => :member
permission :faq_setting, {:ezfaq => [:faq_setting]}, :require => :member
end
Expand Down
14 changes: 12 additions & 2 deletions lang/de.yml
@@ -1,4 +1,4 @@
# ezFAQ plugin
# ezFAQ plugin
label_ezfaq: ezFAQ plugin
label_title_ezfaq: FAQ
label_faq: FAQ
Expand Down Expand Up @@ -32,4 +32,14 @@ text_faq_category_destroy_question: Manche FAQs (%d) sind dieser Kategorie zugeo
text_faq_category_destroy_assignments: Entferne die Zuordnungen
text_faq_category_reassign_to: FAQ wieder dieser Kategorie zuordnen
text_faq_added: FAQ %s wurde von %s erstellt.
text_faq_updated: FAQ %s wurde von %s verändert.
text_faq_updated: FAQ %s wurde von %s verändert.

permission_view_faqs: View FAQ
permission_add_faqs: New FAQ
permission_edit_faqs: Edit FAQ
permission_manage_faq_categories: Manage FAQ Categories
permission_faq_setting: FAQ Settings

project_module_ezfaq: FAQ

label_faq_plural: FAQ
2 changes: 2 additions & 0 deletions lang/en.yml
Expand Up @@ -41,3 +41,5 @@ permission_manage_faq_categories: Manage FAQ Categories
permission_faq_setting: FAQ Settings

project_module_ezfaq: FAQ

label_faq_plural: FAQ

0 comments on commit 3bdd623

Please sign in to comment.