diff --git a/plugins/comment_paragraph/controllers/comment_paragraph_plugin_admin_controller.rb b/plugins/comment_paragraph/controllers/comment_paragraph_plugin_admin_controller.rb index d768af6..c7a07cd 100644 --- a/plugins/comment_paragraph/controllers/comment_paragraph_plugin_admin_controller.rb +++ b/plugins/comment_paragraph/controllers/comment_paragraph_plugin_admin_controller.rb @@ -13,6 +13,7 @@ class CommentParagraphPluginAdminController < AdminController end if request.post? + @settings.settings[:auto_marking_article_types].reject! { |type| type.blank? } @settings.save! redirect_to :controller => 'plugins', :action => 'index' end diff --git a/plugins/comment_paragraph/lib/comment_paragraph_plugin/comment_paragraph_helper.rb b/plugins/comment_paragraph/lib/comment_paragraph_plugin/comment_paragraph_helper.rb index 7fce74e..0c3bf9f 100644 --- a/plugins/comment_paragraph/lib/comment_paragraph_plugin/comment_paragraph_helper.rb +++ b/plugins/comment_paragraph/lib/comment_paragraph_plugin/comment_paragraph_helper.rb @@ -1,8 +1,8 @@ module CommentParagraphPlugin::CommentParagraphHelper - def self.auto_marking_enabled?(plugin_settings, article_type) - auto_marking_setting = plugin_settings.get_setting('article_types_with_auto_marking') - auto_marking_setting.include?(article_type) ? true : false + def auto_marking_enabled?(plugin_settings, article_type) + auto_marking_setting = plugin_settings.get_setting('auto_marking_article_types') + auto_marking_setting && auto_marking_setting.include?(article_type) ? true : false end end diff --git a/plugins/comment_paragraph/public/comment_paragraph_admin.js b/plugins/comment_paragraph/public/comment_paragraph_admin.js new file mode 100644 index 0000000..cca8597 --- /dev/null +++ b/plugins/comment_paragraph/public/comment_paragraph_admin.js @@ -0,0 +1,39 @@ +function check_fields(check, table_id, start) { + var checkboxes = jQuery("#" + table_id + " tbody tr td input[type='checkbox']"); + for (var i = start; i < checkboxes.length; i++) { + checkboxes[i].checked = check; + } +} + +function verify_checked() { + var checkboxes = jQuery("#auto_marking_article_types_conf tbody tr td input[type='checkbox']"); + var allchecked = true + for (var j = 1; j < checkboxes.length; j++) { + if(!checkboxes[j].checked) { + allchecked = false + break + } + } + + var checkbox = checkboxes.first(); + checkboxes.first().attr('checked', allchecked); +} + +function check_all() { + jQuery("input[type='checkbox']").first().click(function () { + check_fields(this.checked, "auto_marking_article_types_conf", 0) + }); + verify_checked(); +} + +jQuery(document).ready(function() { + check_all(); + jQuery("input[type='checkbox']").click(function () { + var checkbox = jQuery(this).attr("id").split("_"); + verify_checked(); + + if(this.checked == false) { + jQuery("#" + checkbox.first() + "_" + checkbox.last()).attr("checked", false) + } + }); +}); diff --git a/plugins/comment_paragraph/views/comment_paragraph_plugin_admin/index.html.erb b/plugins/comment_paragraph/views/comment_paragraph_plugin_admin/index.html.erb index 30f3300..fa07820 100644 --- a/plugins/comment_paragraph/views/comment_paragraph_plugin_admin/index.html.erb +++ b/plugins/comment_paragraph/views/comment_paragraph_plugin_admin/index.html.erb @@ -1,25 +1,32 @@ +<% extend CommentParagraphPlugin::CommentParagraphHelper %> +

<%= _("Comment paragraph plugin settings") %>

<%= form_for(:settings) do |f| %> - +<%= hidden_field_tag 'settings[auto_marking_article_types][]' %> + +
- - + + + + + <% @article_types.each do |type| %> - - + <% end %>
  <%= _('Article type') %><%= _('Article type description') %><%= _('Automatic marking active') %>
<%= _('Check/Uncheck All') %><%= check_box_tag 'article_active', '' %>
<%= check_box_tag 'settings[article_types_with_auto_marking][]', type[:class_name], CommentParagraphPlugin::CommentParagraphHelper.auto_marking_enabled?(@settings, type[:class_name]) %><%= _(type[:class_name]) %> <%= _(type[:short_description]) %><%= check_box_tag 'settings[auto_marking_article_types][]', type[:class_name], auto_marking_enabled?(@settings, type[:class_name]) %>
- <% button_bar do %> <%= submit_button(:save, _('Save'), :cancel => {:controller => 'plugins', :action => 'index'}) %> <% end %> <% end %> + +<%= javascript_include_tag 'plugins/comment_paragraph/comment_paragraph_admin' %> -- libgit2 0.21.2