Created
June 12, 2013 19:12
-
-
Save walter/5768220 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| nextStep = (event) -> | |
| button = event.delegateTarget | |
| steps = $(button).attr('data-relevant-steps').split(', ') | |
| currentStep = $(button).attr 'data-current-step' | |
| currentStepId = stepId(currentStep) | |
| currentStepIndex = steps.indexOf(currentStep) | |
| nextStepIndex = currentStepIndex + 1 | |
| nextStepName = steps[nextStepIndex] | |
| nextStepId = stepId(nextStepName) | |
| nextStepNumber = nextStepIndex + 1 | |
| valid = true | |
| $('[data-validate]:input:visible').each -> | |
| settings = window.ClientSideValidations.forms['new_question'] | |
| valid = false if !$(this).isValid(settings.validators) | |
| if currentStep == 'recipient' and | |
| $('input[name="question[person_id]"]:checked').length is 0 | |
| personError() | |
| valid = false | |
| # do the rest of next step processing | |
| if valid | |
| scrollOffset = $('section.question').offset().top - 60 | |
| $(window).stop().scrollTo(scrollOffset, 500) | |
| $(currentStepId).fadeTo 100, 0, -> | |
| $(currentStepId).hide() | |
| $(nextStepId).fadeTo 200, 1 | |
| reloadValidationForForm() | |
| $(nextStepId + ' input[type=text]:eq(0)').focus() | |
| $(button).attr 'data-current-step', nextStepName | |
| $('.step-number').text nextStepNumber | |
| # last step, hide progress area | |
| if nextStepNumber is steps.length | |
| $(button).hide() | |
| $('.count').hide() | |
| else | |
| $(button).show() | |
| $('.count').show() | |
| valid | |
| $('#next-button').click (event) -> | |
| nextStep event | |
| beginAgain = (event) -> | |
| nextButton = $('#next-button') | |
| steps = $(nextButton).attr('data-relevant-steps').split(', ') | |
| firstStep = steps[0] | |
| lastStep = steps[steps.length - 1] | |
| $(nextButton).attr 'data-current-step', firstStep | |
| $(stepId(lastStep)).hide() | |
| $(stepId(firstStep)).fadeTo 200, 1 | |
| $('.step-number').text 1 | |
| $(nextButton).show() if $(nextButton).is(':hidden') | |
| $('.count').show() if $('.count').is(':hidden') | |
| $('#edit-button').click (event) -> | |
| beginAgain event | |
| $('#question_title').keyup (event) -> | |
| value = $('#question_title').val() | |
| $('#confirm-question-title').text value | |
| $('#question_body').keyup (event) -> | |
| value = $('#question_body').val() | |
| $('#confirm-question-body').text value | |
| $('#firstname').keyup (event) -> | |
| $('.author .firstname').text $('#firstname').val() | |
| $('#lastname').keyup (event) -> | |
| $('.author .lastname').text $('#lastname').val() | |
| $('#question_subject').change (event) -> | |
| value = $('#question_subject').val() | |
| $('#question-subject').text value | |
| $('#confirm-issue-value').text value | |
| if value? and value isnt '' | |
| $('#confirm-issue').show() | |
| else | |
| $('#confirm-issue').hide() | |
| # since we have a multi-step form | |
| # each time we change the visibility of inputs | |
| # we have to re-enable client side validations | |
| reloadValidationForForm = (-> | |
| $('#new_question').enableClientSideValidations() | |
| ) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment