From 6b03fc9c46969a3a0fe06765ffceca7e0cb5074b Mon Sep 17 00:00:00 2001 From: Fabio Teixeira Date: Tue, 22 Jul 2014 17:09:33 -0300 Subject: [PATCH] incomplete_registration: Using session to hide the percentage message --- lib/mpog_software_plugin.rb | 39 ++++++++++++++------------------------- public/mpog-incomplete-registration.js | 13 +++++++++++++ public/mpog-user-validations.js | 12 ------------ views/mpog_software_plugin_myprofile/_incomplete_registration.html.erb | 2 +- 4 files changed, 28 insertions(+), 38 deletions(-) create mode 100644 public/mpog-incomplete-registration.js diff --git a/lib/mpog_software_plugin.rb b/lib/mpog_software_plugin.rb index 5e0afed..bf63bd6 100644 --- a/lib/mpog_software_plugin.rb +++ b/lib/mpog_software_plugin.rb @@ -136,7 +136,7 @@ class MpogSoftwarePlugin < Noosfero::Plugin end def js_files - ["mpog-software-validations.js", "mpog-user-validations.js", "mpog-institution-validations.js"] + ["mpog-software-validations.js", "mpog-user-validations.js", "mpog-institution-validations.js", "mpog-incomplete-registration.js"] end def add_new_organization_button @@ -150,12 +150,6 @@ class MpogSoftwarePlugin < Noosfero::Plugin person.has_permission_without_plugins?(permission, target) end - def create_url_to_edit_profile person - new_url = person.public_profile_url - new_url[:controller] = 'profile_editor' - new_url[:action] = 'edit' - new_url - end def incomplete_registration params return if params.nil? or params[:user].nil? @@ -170,11 +164,18 @@ class MpogSoftwarePlugin < Noosfero::Plugin @profile_empty_fields = profile_required_empty_list person @percentege = calc_percentage_registration(person) - if @percentege >= 0 and @percentege <= 100 + if @percentege >= 0 and @percentege <= 100 and context.session[:hide_incomplete_percentage] != true expanded_template('mpog_software_plugin_myprofile/_incomplete_registration.html.erb') end end + + def manage_software + [{:title => _('Manage Software'), :url => {:controller => 'mpog_software_plugin', :action => 'archive_software'}}] + end + + protected + def calc_percentage_registration person required_list = profile_required_list empty_fields = profile_required_empty_list person @@ -185,25 +186,13 @@ class MpogSoftwarePlugin < Noosfero::Plugin percentege end - def add_link_to_complete_registration person - #find a better way to do it - if context.session[:hide_incomplete_percentage] != true - _new_url = create_url_to_edit_profile(person) - Proc::new do - content_tag(:div, - link_to( _("Percentage incomplete: #{person.percentage_incomplete.to_s} %" ), _new_url) + - link_to(image_tag("/images/icon_filter_exclude.png"), "#", :class => "hide-incomplete-percentage", :alt => "Hide Incomplete Percentage"), :class=>"mpog-incomplete-percentage" - ) - end - end + def create_url_to_edit_profile person + new_url = person.public_profile_url + new_url[:controller] = 'profile_editor' + new_url[:action] = 'edit' + new_url end - def manage_software - [{:title => _('Manage Software'), :url => {:controller => 'mpog_software_plugin', :action => 'archive_software'}}] - end - - protected - def profile_required_list required_list = ["cell_phone","contact_phone","institution","comercial_phone","country","city","state","organization_website","role","area_interest","image"] end diff --git a/public/mpog-incomplete-registration.js b/public/mpog-incomplete-registration.js new file mode 100644 index 0000000..e490d90 --- /dev/null +++ b/public/mpog-incomplete-registration.js @@ -0,0 +1,13 @@ +function hide_incomplete_percentage(evt) { + evt.preventDefault(); + + jQuery.get("/plugin/mpog_software/hide_registration_incomplete_percentage", {hide:true}, function(response){ + if( response == true ) + jQuery("#incomplete_registration").fadeOut(); + }); +} + + +jQuery(document).ready(function(){ + jQuery(".hide-incomplete-percentage").click(hide_incomplete_percentage); +}); diff --git a/public/mpog-user-validations.js b/public/mpog-user-validations.js index 4fddbc4..cb8b5ac 100644 --- a/public/mpog-user-validations.js +++ b/public/mpog-user-validations.js @@ -73,16 +73,6 @@ function institution_autocomplete() { } -function hide_incomplete_percentage(evt) { - evt.preventDefault(); - var link_div = jQuery(this).parent(); - - jQuery.get("/plugin/mpog_software/hide_registration_incomplete_percentage", {hide:true}, function(response){ - if( response == true ) - link_div.hide(); - }); -} - jQuery(document).ready(function(){ jQuery('#secondary_email_field').blur( validate_email_format @@ -92,8 +82,6 @@ jQuery(document).ready(function(){ put_brazil_based_on_email ); - jQuery(".hide-incomplete-percentage").click(hide_incomplete_percentage); - jQuery('#secondary_email_field').focus(function() { jQuery('#secondary-email-balloon').fadeIn('slow'); }); jQuery('#secondary_email_field').blur(function() { jQuery('#secondary-email-balloon').fadeOut('slow'); }); diff --git a/views/mpog_software_plugin_myprofile/_incomplete_registration.html.erb b/views/mpog_software_plugin_myprofile/_incomplete_registration.html.erb index b513ed4..1320475 100644 --- a/views/mpog_software_plugin_myprofile/_incomplete_registration.html.erb +++ b/views/mpog_software_plugin_myprofile/_incomplete_registration.html.erb @@ -21,7 +21,7 @@ <%= @profile_edit_link %> - <%= _("Hide this message") %> + <%= link_to _("Hide this message"), "#", :class=>"hide-incomplete-percentage" %> -- libgit2 0.21.2