|
| 1 | +/* eslint-disable */ |
| 2 | +import $ from 'jquery'; |
| 3 | + |
| 4 | +function wizard() { |
| 5 | + |
| 6 | + $(".input").focus(function(){ |
| 7 | + $(this).addClass("is-active is-completed"); |
| 8 | + }); |
| 9 | + |
| 10 | + $(".input").focusout(function(){ |
| 11 | + if($(this).val() === "") { |
| 12 | + $(this).removeClass("is-completed"); |
| 13 | + } |
| 14 | + $(this).removeClass("is-active"); |
| 15 | + }) |
| 16 | + |
| 17 | + |
| 18 | + $('[name="IsJob"]').on('change', function(event) { |
| 19 | + if ($(this).val() == 2) { |
| 20 | + $('.filter-on').css('display', 'none'); |
| 21 | + $('#trabaho_atual').attr('required', false); |
| 22 | + } else { |
| 23 | + $('.filter-on').css('display', 'table'); |
| 24 | + $('#trabaho_atual').attr('required', true); |
| 25 | + } |
| 26 | + }); |
| 27 | + |
| 28 | + $('#curso').on('change', function(event) { |
| 29 | + let value = $(this).val(); |
| 30 | + |
| 31 | + if (value == '' || value == 0) { |
| 32 | + $('.filter-university').css('display', 'none'); |
| 33 | + $('#Semester').attr('required', false); |
| 34 | + } else { |
| 35 | + $('.filter-university').css('display', 'table'); |
| 36 | + $('#Semester').attr('required', true); |
| 37 | + } |
| 38 | + }); |
| 39 | + |
| 40 | + const checkButtons = (activeStep, stepsCount) => { |
| 41 | + const nextBtn = $('.wizard-next'); |
| 42 | + const submBtn = $('.wizard-subm'); |
| 43 | + |
| 44 | + switch (activeStep / stepsCount) { |
| 45 | + case 0: // Primeiro Step |
| 46 | + submBtn.hide(); |
| 47 | + nextBtn.show(); |
| 48 | + break; |
| 49 | + case 1: // Ultimo Step |
| 50 | + nextBtn.hide(); |
| 51 | + submBtn.show(); |
| 52 | + break; |
| 53 | + default: |
| 54 | + submBtn.hide(); |
| 55 | + nextBtn.show(); |
| 56 | + } |
| 57 | + }; |
| 58 | + |
| 59 | + const setWizardHeight = (activeStepHeight) => { |
| 60 | + $('.wizard-body').height(activeStepHeight); |
| 61 | + }; |
| 62 | + |
| 63 | + let wizardSteps = $('.wizard-step'); |
| 64 | + let steps = $('.wizard-body .step'); |
| 65 | + let stepsCount = steps.length - 1; |
| 66 | + let viewHeight = $(window).height(); |
| 67 | + let activeStep = 0; |
| 68 | + let activeStepHeight = $(steps[activeStep]).height(); |
| 69 | + |
| 70 | + checkButtons(activeStep, stepsCount); |
| 71 | + setWizardHeight(activeStepHeight); |
| 72 | + |
| 73 | + $(window).resize(() => { |
| 74 | + setWizardHeight($(steps[activeStep]).height()); |
| 75 | + }); |
| 76 | + |
| 77 | + const scrollWindow = (activeStepHeight, viewHeight) => { |
| 78 | + if (viewHeight < activeStepHeight) { |
| 79 | + $(window).scrollTop($(steps[activeStep]).offset().top - viewHeight / 2); |
| 80 | + } |
| 81 | + }; |
| 82 | + |
| 83 | + $('.button').click((e) => { |
| 84 | + e.preventDefault(); |
| 85 | + |
| 86 | + var that = e; |
| 87 | + const curInputs = $(steps[activeStep]).find('input[required=true], input[required=required],input[required="true"], input[type=radio],textarea, select'); |
| 88 | + let isValid = true; |
| 89 | + |
| 90 | + $('#first-step-header').hide(); |
| 91 | + $('.input-group, .card').removeClass('-has-error'); |
| 92 | + |
| 93 | + // eslint-disable-next-line |
| 94 | + for (let i = 0; i < curInputs.length; i++) { |
| 95 | + if ( !curInputs[i].validity.valid || $(curInputs[i]).closest('.input-group').is('.-has-incomplete')) { |
| 96 | + isValid = false; |
| 97 | + $(curInputs[i]).closest('.input-group').addClass('-has-error'); |
| 98 | + $(curInputs[i]).closest('.card').addClass('-has-error'); |
| 99 | + } |
| 100 | + } |
| 101 | + |
| 102 | + if (isValid) { |
| 103 | + if (that.target.id === 'wizard-subm') { |
| 104 | + $('button').html('Aguarde, enviando').attr('disabled', 'disabled').addClass('load'); |
| 105 | + setTimeout(function(){ |
| 106 | + $('form').submit(); |
| 107 | + }, 5000) |
| 108 | + }else{ |
| 109 | + $(steps[activeStep]).removeClass('inital').addClass('off').removeClass('active'); |
| 110 | + $(wizardSteps[activeStep]).removeClass('site-nav__current'); |
| 111 | + |
| 112 | + activeStep += 1; |
| 113 | + |
| 114 | + if (activeStep === 2) { |
| 115 | + $('.wizard-body').css('overflow', 'hidden'); |
| 116 | + } |
| 117 | + |
| 118 | + $(steps[activeStep]).addClass('active'); |
| 119 | + $(wizardSteps[activeStep]).addClass('site-nav__current'); |
| 120 | + activeStepHeight = $(steps[activeStep]).height(); |
| 121 | + setWizardHeight(activeStepHeight); |
| 122 | + checkButtons(activeStep, stepsCount); |
| 123 | + scrollWindow(activeStepHeight, viewHeight); |
| 124 | + } |
| 125 | + }else{ |
| 126 | + $(window).scrollTop($('.-has-error').eq(0).offset().top); |
| 127 | + $('.-has-error').eq(0).find('input').focus(); |
| 128 | + } |
| 129 | + }); |
| 130 | +} |
| 131 | + |
| 132 | +export default foto(); |
0 commit comments