Commit f4818bdb72f383e0f1613fe3781b555c260d1b9d
Committed by
Leandro Santos
1 parent
af08948e
Exists in
staging
and in
42 other branches
require_auth_to_comment: option to display login popup when click in post comment button
Showing
4 changed files
with
53 additions
and
2 deletions
Show diff stats
plugins/require_auth_to_comment/controllers/require_auth_to_comment_plugin_admin_controller.rb
0 → 100644
@@ -0,0 +1,14 @@ | @@ -0,0 +1,14 @@ | ||
1 | +class RequireAuthToCommentPluginAdminController < AdminController | ||
2 | + | ||
3 | + def index | ||
4 | + settings = params[:settings] | ||
5 | + settings ||= {} | ||
6 | + @settings = Noosfero::Plugin::Settings.new(environment, RequireAuthToCommentPlugin, settings) | ||
7 | + if request.post? | ||
8 | + @settings.save! | ||
9 | + session[:notice] = 'Settings succefully saved.' | ||
10 | + redirect_to :action => 'index' | ||
11 | + end | ||
12 | + end | ||
13 | + | ||
14 | +end |
plugins/require_auth_to_comment/lib/require_auth_to_comment_plugin.rb
@@ -21,11 +21,20 @@ class RequireAuthToCommentPlugin < Noosfero::Plugin | @@ -21,11 +21,20 @@ class RequireAuthToCommentPlugin < Noosfero::Plugin | ||
21 | end | 21 | end |
22 | 22 | ||
23 | def stylesheet? | 23 | def stylesheet? |
24 | - true | 24 | + !display_login_popup? |
25 | + end | ||
26 | + | ||
27 | + def display_login_popup? | ||
28 | + settings = Noosfero::Plugin::Settings.new(context.environment, self.class) | ||
29 | + settings.require_type == 'display_login_popup' | ||
30 | + end | ||
31 | + | ||
32 | + def self.require_type_default_setting | ||
33 | + 'hide_button' | ||
25 | end | 34 | end |
26 | 35 | ||
27 | def js_files | 36 | def js_files |
28 | - ['hide_comment_form.js', 'jquery.livequery.min.js'] | 37 | + ['hide_comment_form.js', 'jquery.livequery.min.js'] + (display_login_popup? ? ['comment_require_login.js'] : []) |
29 | end | 38 | end |
30 | 39 | ||
31 | def body_beginning | 40 | def body_beginning |
plugins/require_auth_to_comment/public/comment_require_login.js
0 → 100644
@@ -0,0 +1,8 @@ | @@ -0,0 +1,8 @@ | ||
1 | +(function($) { | ||
2 | + $(window).bind('userDataLoaded', function(event, data) { | ||
3 | + if (!data.login && $('meta[name="profile.allow_unauthenticated_comments"]').length <= 0) { | ||
4 | + $('.display-comment-form').unbind(); | ||
5 | + $('.display-comment-form').addClass('require-login-popup'); | ||
6 | + } | ||
7 | + }); | ||
8 | +})(jQuery); |
plugins/require_auth_to_comment/views/require_auth_to_comment_plugin_admin/index.html.erb
0 → 100644
@@ -0,0 +1,20 @@ | @@ -0,0 +1,20 @@ | ||
1 | +<h1><%= _('Require auth to comment Settings')%></h1> | ||
2 | + | ||
3 | +<% form_for(:settings) do |f| %> | ||
4 | + | ||
5 | + <div class="require-type"> | ||
6 | + <strong> | ||
7 | + <div class="hide-button"> | ||
8 | + <%= radio_button(:settings, :require_type, 'hide_button') %> <%= _('Hide button') %> | ||
9 | + </div> | ||
10 | + <div class="display-login-popup"> | ||
11 | + <%= radio_button(:settings, :require_type, 'display_login_popup') %> <%= _('Display login popup') %> | ||
12 | + </div> | ||
13 | + </strong> | ||
14 | + </div> | ||
15 | + | ||
16 | + <% button_bar do %> | ||
17 | + <%= submit_button(:save, _('Save'), :cancel => {:controller => 'plugins', :action => 'index'}) %> | ||
18 | + <% end %> | ||
19 | + | ||
20 | +<% end %> |