From 466559b59a96f1e4c6ef54091fbcf05bc475ff2d Mon Sep 17 00:00:00 2001 From: Fabio Teixeira Date: Tue, 3 Mar 2015 16:41:21 -0300 Subject: [PATCH] Execute complete_registration javascript only when needed --- lib/software_communities_plugin.rb | 2 +- public/initializer.js | 10 ++++++++-- public/mpog-incomplete-registration.js | 38 -------------------------------------- public/views/complete-registration.js | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ views/incomplete_registration.html.erb | 12 ------------ 5 files changed, 69 insertions(+), 53 deletions(-) delete mode 100644 public/mpog-incomplete-registration.js create mode 100644 public/views/complete-registration.js diff --git a/lib/software_communities_plugin.rb b/lib/software_communities_plugin.rb index bb7624e..ba453ce 100644 --- a/lib/software_communities_plugin.rb +++ b/lib/software_communities_plugin.rb @@ -132,9 +132,9 @@ class SoftwareCommunitiesPlugin < Noosfero::Plugin views/new-software.js views/user-edit-profile.js views/create-institution.js + views/complete-registration.js initializer.js app.js - mpog-incomplete-registration.js mpog-search.js software-catalog.js mpog-software-block.js diff --git a/public/initializer.js b/public/initializer.js index 713f622..a3f0674 100644 --- a/public/initializer.js +++ b/public/initializer.js @@ -3,11 +3,12 @@ var dependencies = [ 'EditSoftware', 'NewSoftware', 'UserEditProfile', - 'CreateInstitution' + 'CreateInstitution', + 'CompleteRegistration' ]; -modulejs.define('Initializer', dependencies, function(cp, es, ns, uep, ci) { +modulejs.define('Initializer', dependencies, function(cp, es, ns, uep, ci, cr) { 'use strict'; @@ -36,6 +37,11 @@ modulejs.define('Initializer', dependencies, function(cp, es, ns, uep, ci) { if( ci.isCreateInstitution() ) { ci.init(); } + + + if( cr.isCompleteRegistration() ) { + cr.init(); + } } }; }); diff --git a/public/mpog-incomplete-registration.js b/public/mpog-incomplete-registration.js deleted file mode 100644 index 66575fc..0000000 --- a/public/mpog-incomplete-registration.js +++ /dev/null @@ -1,38 +0,0 @@ -(function() { - var AJAX_URL = { - hide_registration_incomplete_percentage: - url_with_subdirectory("/plugin/software_communities/hide_registration_incomplete_percentage") - }; - - - function hide_incomplete_percentage(evt) { - evt.preventDefault(); - - jQuery.get(AJAX_URL.hide_registration_incomplete_percentage, {hide:true}, function(response){ - if( response == true ) - jQuery("#complete_registration").fadeOut(); - }); - } - - function show_complete_progressbar() { - var percentage = jQuery("#complete_registration_message span").html(); - var canvas_tag = document.getElementById("complete_registration_percentage"); - - if( canvas_tag != null ) { - var context = canvas_tag.getContext("2d"); - - percentage = canvas_tag.width*(percentage/100.0); - - context.beginPath(); - context.rect(0, 0, percentage, canvas_tag.height); - context.fillStyle = '#00FF00'; - context.fill(); - } - } - - jQuery(document).ready(function(){ - jQuery(".hide-incomplete-percentage").click(hide_incomplete_percentage); - - show_complete_progressbar(); - }); -})(); \ No newline at end of file diff --git a/public/views/complete-registration.js b/public/views/complete-registration.js new file mode 100644 index 0000000..2d4686e --- /dev/null +++ b/public/views/complete-registration.js @@ -0,0 +1,60 @@ +modulejs.define('CompleteRegistration', ['jquery', 'NoosferoRoot'], function($, NoosferoRoot) { + 'use strict'; + + + var AJAX_URL = { + hide_registration_incomplete_percentage: + NoosferoRoot.urlWithSubDirectory("/plugin/software_communities/hide_registration_incomplete_percentage") + }; + + + function hide_incomplete_percentage(evt) { + evt.preventDefault(); + + jQuery.get(AJAX_URL.hide_registration_incomplete_percentage, {hide:true}, function(response){ + if( response === true ) { + jQuery("#complete_registration").fadeOut(); + } + }); + } + + + function show_complete_progressbar() { + var percentage = jQuery("#complete_registration_message span").html(); + var canvas_tag = document.getElementById("complete_registration_percentage"); + + if( canvas_tag !== null ) { + var context = canvas_tag.getContext("2d"); + + percentage = canvas_tag.width*(percentage/100.0); + + context.beginPath(); + context.rect(0, 0, percentage, canvas_tag.height); + context.fillStyle = '#00FF00'; + context.fill(); + } + } + + + function repositioning_bar_percentage() { + var complete_message = $("#complete_registration").remove(); + + $(".profile-info-options").before(complete_message); + } + + + return { + isCompleteRegistration: function() { + return $("#complete_registration").length === 1; + }, + + + init: function() { + repositioning_bar_percentage(); + + jQuery(".hide-incomplete-percentage").click(hide_incomplete_percentage); + + show_complete_progressbar(); + } + } +}); \ No newline at end of file diff --git a/views/incomplete_registration.html.erb b/views/incomplete_registration.html.erb index 9fe71de..8eb6af2 100644 --- a/views/incomplete_registration.html.erb +++ b/views/incomplete_registration.html.erb @@ -9,15 +9,3 @@ - - \ No newline at end of file -- libgit2 0.21.2