Commit 2fa2b24b66522d81797c2cd62e6deb7cee3374aa
1 parent
c4d925d6
Exists in
master
comment_paragraph: add plugin config page
Showing
4 changed files
with
65 additions
and
1 deletions
Show diff stats
controllers/comment_paragraph_plugin_admin_controller.rb
0 → 100644
| ... | ... | @@ -0,0 +1,28 @@ |
| 1 | +class CommentParagraphPluginAdminController < AdminController | |
| 2 | + append_view_path File.join(File.dirname(__FILE__) + '/../views') | |
| 3 | + | |
| 4 | + def index | |
| 5 | + @settings = Noosfero::Plugin::Settings.new(environment, CommentParagraphPlugin, params[:settings]) | |
| 6 | + @article_types = [] | |
| 7 | + available_article_types.each do |type| | |
| 8 | + @article_types.push({ | |
| 9 | + :class_name => type.name, | |
| 10 | + :short_description => type.short_description, | |
| 11 | + :description => type.description | |
| 12 | + }) | |
| 13 | + end | |
| 14 | + | |
| 15 | + if request.post? | |
| 16 | + @settings.save! | |
| 17 | + redirect_to :controller => 'plugins', :action => 'index' | |
| 18 | + end | |
| 19 | + end | |
| 20 | + | |
| 21 | + protected | |
| 22 | + | |
| 23 | + def available_article_types | |
| 24 | + articles = [TinyMceArticle, TextileArticle] + @plugins.dispatch(:content_types) | |
| 25 | + articles | |
| 26 | + end | |
| 27 | + | |
| 28 | +end | ... | ... |
lib/comment_paragraph_plugin.rb
| ... | ... | @@ -42,7 +42,10 @@ class CommentParagraphPlugin < Noosfero::Plugin |
| 42 | 42 | def cms_controller_filters |
| 43 | 43 | block = proc do |
| 44 | 44 | if params['commit'] == 'Save' |
| 45 | - unless @article.id.blank? | |
| 45 | + | |
| 46 | + settings = Noosfero::Plugin::Settings.new(environment, CommentParagraphPlugin, params[:settings]) | |
| 47 | + | |
| 48 | + if !@article.id.blank? && CommentParagraphPlugin::CommentParagraphHelper.auto_marking_enabled?(settings, @article.class.name) | |
| 46 | 49 | |
| 47 | 50 | parsed_paragraphs = [] |
| 48 | 51 | paragraph_id = 0 | ... | ... |
lib/comment_paragraph_plugin/comment_paragraph_helper.rb
0 → 100644
| ... | ... | @@ -0,0 +1,8 @@ |
| 1 | +module CommentParagraphPlugin::CommentParagraphHelper | |
| 2 | + | |
| 3 | + def self.auto_marking_enabled?(plugin_settings, article_type) | |
| 4 | + auto_marking_setting = plugin_settings.get_setting('article_types_with_auto_marking') | |
| 5 | + auto_marking_setting.include?(article_type) ? true : false | |
| 6 | + end | |
| 7 | + | |
| 8 | +end | ... | ... |
| ... | ... | @@ -0,0 +1,25 @@ |
| 1 | +<h1><%= _("Comment paragraph plugin settings") %></h1> | |
| 2 | + | |
| 3 | +<%= form_for(:settings) do |f| %> | |
| 4 | + | |
| 5 | +<table> | |
| 6 | + <tr> | |
| 7 | + <th> </th> | |
| 8 | + <th align="left"><%= _('Article type') %></th> | |
| 9 | + <th align="left"><%= _('Article type description') %></th> | |
| 10 | + </tr> | |
| 11 | + <% @article_types.each do |type| %> | |
| 12 | + <tr> | |
| 13 | + <td><%= check_box_tag 'settings[article_types_with_auto_marking][]', type[:class_name], CommentParagraphPlugin::CommentParagraphHelper.auto_marking_enabled?(@settings, type[:class_name]) %></td> | |
| 14 | + <td><%= _(type[:class_name]) %></td> | |
| 15 | + <td><%= _(type[:short_description]) %></td> | |
| 16 | + </tr> | |
| 17 | + <% end %> | |
| 18 | +</table> | |
| 19 | + | |
| 20 | + | |
| 21 | + <% button_bar do %> | |
| 22 | + <%= submit_button(:save, _('Save'), :cancel => {:controller => 'plugins', :action => 'index'}) %> | |
| 23 | + <% end %> | |
| 24 | + | |
| 25 | +<% end %> | ... | ... |