diff --git a/plugins/require_auth_to_comment/controllers/require_auth_to_comment_plugin_admin_controller.rb b/plugins/require_auth_to_comment/controllers/require_auth_to_comment_plugin_admin_controller.rb new file mode 100644 index 0000000..20b839a --- /dev/null +++ b/plugins/require_auth_to_comment/controllers/require_auth_to_comment_plugin_admin_controller.rb @@ -0,0 +1,14 @@ +class RequireAuthToCommentPluginAdminController < AdminController + + def index + settings = params[:settings] + settings ||= {} + @settings = Noosfero::Plugin::Settings.new(environment, RequireAuthToCommentPlugin, settings) + if request.post? + @settings.save! + session[:notice] = 'Settings succefully saved.' + redirect_to :action => 'index' + end + end + +end diff --git a/plugins/require_auth_to_comment/lib/require_auth_to_comment_plugin.rb b/plugins/require_auth_to_comment/lib/require_auth_to_comment_plugin.rb index da41a1a..8d8dbc3 100644 --- a/plugins/require_auth_to_comment/lib/require_auth_to_comment_plugin.rb +++ b/plugins/require_auth_to_comment/lib/require_auth_to_comment_plugin.rb @@ -21,11 +21,20 @@ class RequireAuthToCommentPlugin < Noosfero::Plugin end def stylesheet? - true + !display_login_popup? + end + + def display_login_popup? + settings = Noosfero::Plugin::Settings.new(context.environment, self.class) + settings.require_type == 'display_login_popup' + end + + def self.require_type_default_setting + 'hide_button' end def js_files - ['hide_comment_form.js', 'jquery.livequery.min.js'] + ['hide_comment_form.js', 'jquery.livequery.min.js'] + (display_login_popup? ? ['comment_require_login.js'] : []) end def body_beginning diff --git a/plugins/require_auth_to_comment/public/comment_require_login.js b/plugins/require_auth_to_comment/public/comment_require_login.js new file mode 100644 index 0000000..9a104bc --- /dev/null +++ b/plugins/require_auth_to_comment/public/comment_require_login.js @@ -0,0 +1,8 @@ +(function($) { + $(window).bind('userDataLoaded', function(event, data) { + if (!data.login && $('meta[name="profile.allow_unauthenticated_comments"]').length <= 0) { + $('.display-comment-form').unbind(); + $('.display-comment-form').addClass('require-login-popup'); + } + }); +})(jQuery); diff --git a/plugins/require_auth_to_comment/views/require_auth_to_comment_plugin_admin/index.html.erb b/plugins/require_auth_to_comment/views/require_auth_to_comment_plugin_admin/index.html.erb new file mode 100644 index 0000000..cc5ae02 --- /dev/null +++ b/plugins/require_auth_to_comment/views/require_auth_to_comment_plugin_admin/index.html.erb @@ -0,0 +1,20 @@ +

<%= _('Require auth to comment Settings')%>

+ +<% form_for(:settings) do |f| %> + +
+ +
+ <%= radio_button(:settings, :require_type, 'hide_button') %> <%= _('Hide button') %> +
+ +
+
+ + <% button_bar do %> + <%= submit_button(:save, _('Save'), :cancel => {:controller => 'plugins', :action => 'index'}) %> + <% end %> + +<% end %> -- libgit2 0.21.2