Commit 184394a0dcd6b051f63a390f1c13baa23d8143d5
1 parent
ddf73337
Exists in
master
and in
28 other branches
small refactoring on signup_complement
Showing
1 changed file
with
39 additions
and
48 deletions
Show diff stats
plugins/stoa/public/javascripts/signup_complement.js
| 1 | -jQuery("#usp_id_field").observe_field(1, function(){ | 1 | +jQuery(function($) { |
| 2 | + | ||
| 3 | +$("#usp_id_field").observe_field(1, function(){ | ||
| 2 | var me=this; | 4 | var me=this; |
| 3 | - jQuery('#usp-id-invalid').hide(); | ||
| 4 | - jQuery(this).addClass('checking').removeClass('validated'); | ||
| 5 | - jQuery('#usp-id-checking').show(); | ||
| 6 | - jQuery.getJSON('/plugin/stoa/check_usp_id?usp_id='+me.value, | 5 | + $('#usp-id-invalid').hide(); |
| 6 | + $(this).addClass('checking').removeClass('validated'); | ||
| 7 | + $('#usp-id-checking').show(); | ||
| 8 | + $.getJSON('/plugin/stoa/check_usp_id?usp_id='+me.value, | ||
| 7 | function(data){ | 9 | function(data){ |
| 8 | - jQuery('#usp-id-checking').hide(); | 10 | + $('#usp-id-checking').hide(); |
| 9 | if(data.exists) { | 11 | if(data.exists) { |
| 10 | - jQuery('#usp-id-invalid').hide(); | ||
| 11 | - jQuery.getJSON('/plugin/stoa/check_cpf?usp_id='+me.value, | 12 | + $('#usp-id-invalid').hide(); |
| 13 | + $.getJSON('/plugin/stoa/check_cpf?usp_id='+me.value, | ||
| 12 | function(data){ | 14 | function(data){ |
| 13 | if(data.exists){ | 15 | if(data.exists){ |
| 14 | - jQuery('#signup-birth-date').hide(); | ||
| 15 | - jQuery('#signup-cpf').show(); | ||
| 16 | - jQuery('#confirmation_field').remove(); | ||
| 17 | - jQuery('<input id="confirmation_field" type="hidden" value="cpf" name="confirmation_field">').insertAfter('#usp_id_field'); | 16 | + $('#signup-birth-date').hide(); |
| 17 | + $('#signup-cpf').show(); | ||
| 18 | + $('#confirmation_field').remove(); | ||
| 19 | + $('<input id="confirmation_field" type="hidden" value="cpf" name="confirmation_field">').insertAfter('#usp_id_field'); | ||
| 18 | } | 20 | } |
| 19 | else { | 21 | else { |
| 20 | - jQuery('#signup-cpf').hide(); | ||
| 21 | - jQuery('#signup-birth-date').show(); | ||
| 22 | - jQuery('#confirmation_field').remove(); | ||
| 23 | - jQuery('<input id="confirmation_field" type="hidden" value="birth_date" name="confirmation_field">').insertAfter('#usp_id_field'); | 22 | + $('#signup-cpf').hide(); |
| 23 | + $('#signup-birth-date').show(); | ||
| 24 | + $('#confirmation_field').remove(); | ||
| 25 | + $('<input id="confirmation_field" type="hidden" value="birth_date" name="confirmation_field">').insertAfter('#usp_id_field'); | ||
| 24 | } | 26 | } |
| 25 | - jQuery('#signup-form .submit').attr('disabled', false); | ||
| 26 | - jQuery(me).removeClass('checking').addClass('validated'); | 27 | + $('#signup-form .submit').attr('disabled', false); |
| 28 | + $(me).removeClass('checking').addClass('validated'); | ||
| 27 | }); | 29 | }); |
| 28 | } | 30 | } |
| 29 | else { | 31 | else { |
| 30 | - jQuery(me).removeClass('checking'); | 32 | + $(me).removeClass('checking'); |
| 31 | if(me.value) { | 33 | if(me.value) { |
| 32 | - jQuery('#signup-form .submit').attr('disabled', true); | ||
| 33 | - jQuery(me).addClass('invalid'); | ||
| 34 | - jQuery('#usp-id-invalid').show(); | 34 | + $('#signup-form .submit').attr('disabled', true); |
| 35 | + $(me).addClass('invalid'); | ||
| 36 | + $('#usp-id-invalid').show(); | ||
| 35 | } | 37 | } |
| 36 | else { | 38 | else { |
| 37 | - jQuery('#signup-form .submit').attr('disabled', false); | ||
| 38 | - jQuery(me).removeClass('invalid'); | ||
| 39 | - jQuery(me).removeClass('validated'); | 39 | + $('#signup-form .submit').attr('disabled', false); |
| 40 | + $(me).removeClass('invalid'); | ||
| 41 | + $(me).removeClass('validated'); | ||
| 40 | } | 42 | } |
| 41 | - jQuery('#signup-birth-date').hide(); | ||
| 42 | - jQuery('#signup-cpf').hide(); | 43 | + $('#signup-birth-date').hide(); |
| 44 | + $('#signup-cpf').hide(); | ||
| 43 | } | 45 | } |
| 44 | if(data.error) displayValidationUspIdError(data.error); | 46 | if(data.error) displayValidationUspIdError(data.error); |
| 45 | } | 47 | } |
| 46 | ); | 48 | ); |
| 47 | }); | 49 | }); |
| 50 | +}); | ||
| 48 | 51 | ||
| 49 | function displayValidationUspIdError(error){ | 52 | function displayValidationUspIdError(error){ |
| 50 | jQuery.colorbox({html: '<h2>'+error.message+'</h2>'+error.backtrace.join("<br />"), | 53 | jQuery.colorbox({html: '<h2>'+error.message+'</h2>'+error.backtrace.join("<br />"), |
| @@ -52,32 +55,20 @@ function displayValidationUspIdError(error){ | @@ -52,32 +55,20 @@ function displayValidationUspIdError(error){ | ||
| 52 | width: "70%" }); | 55 | width: "70%" }); |
| 53 | } | 56 | } |
| 54 | 57 | ||
| 55 | -jQuery('#usp_id_field').focus(function() { | ||
| 56 | - jQuery('#usp-id-balloon').fadeIn('slow'); | ||
| 57 | -}); | ||
| 58 | - | 58 | +jQuery('#usp_id_field').focus(function() { jQuery('#usp-id-balloon').fadeIn('slow'); }); |
| 59 | jQuery('#usp_id_field').blur(function() { jQuery('#usp-id-balloon').fadeOut('slow'); }); | 59 | jQuery('#usp_id_field').blur(function() { jQuery('#usp-id-balloon').fadeOut('slow'); }); |
| 60 | 60 | ||
| 61 | -jQuery('#signup-birth-date #birth_date').focus(function() { | ||
| 62 | - jQuery('#usp-birth-date-balloon').fadeIn('slow'); | ||
| 63 | -}); | ||
| 64 | -jQuery('#signup-birth-date #birth_date').blur(function() { | ||
| 65 | - jQuery('#usp-birth-date-balloon').fadeOut('slow'); | ||
| 66 | - if (jQuery(this).val() == '') { | ||
| 67 | - jQuery(this).removeClass('validated'); | ||
| 68 | - } | ||
| 69 | - else { | ||
| 70 | - jQuery(this).addClass('validated'); | ||
| 71 | - } | ||
| 72 | -}); | 61 | +jQuery('#signup-birth-date #birth_date').focus(function() { jQuery('#usp-birth-date-balloon').fadeIn('slow'); }); |
| 62 | +jQuery('#signup-birth-date #birth_date').blur(function() { jQuery('#usp-birth-date-balloon').fadeOut('slow'); }); | ||
| 73 | 63 | ||
| 74 | -jQuery('#signup-cpf #cpf').focus(function() { | ||
| 75 | - jQuery('#usp-cpf-balloon').fadeIn('slow'); | ||
| 76 | -}); | ||
| 77 | -jQuery('#signup-cpf #cpf').blur(function() { | ||
| 78 | - jQuery('#usp-cpf-balloon').fadeOut('slow'); | 64 | +jQuery('#signup-cpf #cpf').focus(function() { jQuery('#usp-cpf-balloon').fadeIn('slow'); }); |
| 65 | +jQuery('#signup-cpf #cpf').blur(function() { jQuery('#usp-cpf-balloon').fadeOut('slow'); }); | ||
| 66 | + | ||
| 67 | +jQuery('#signup-birth-date #birth_date, #signup-cpf #cpf').each(function() { | ||
| 68 | + jQuery(this).bind('blur', function() { | ||
| 79 | if (jQuery(this).val() == '') { | 69 | if (jQuery(this).val() == '') { |
| 80 | jQuery(this).removeClass('validated'); | 70 | jQuery(this).removeClass('validated'); |
| 81 | } | 71 | } |
| 82 | else jQuery(this).addClass('validated'); | 72 | else jQuery(this).addClass('validated'); |
| 73 | + }); | ||
| 83 | }); | 74 | }); |