//= require jquery //= require jquery_ujs //= require jquery-ui //= require fe/fe.common.js //= require fe/jquery.scrollTo-min.js //= require fe/rails.extra.js //= require fe/jquery.validate.pack.js // used by answer sheets (function($) { //debugger; $(function() { $(document).on('click', '.save_button', function() { $.fe.pageHandler.savePage($(this).closest('.answer-page'), true); }); //debugger; $(document).on('keydown', '#payment_staff_first, #payment_staff_last', function(e) { //debugger; if (e.which == 13) { console.log('staff_search click'); $('#staff_search').trigger('click'); return false; } }); $(document).on('click', '.reference_send_invite', function() { var el = this; var data = $(el).closest('form').serializeArray(); data.push({name: 'answer_sheet_type', value: answer_sheet_type}); $.ajax({url: $(el).attr('href'), data: data, dataType: 'script', type: 'POST', beforeSend: function (xhr) { $('body').trigger('ajax:loading', xhr); }, complete: function (xhr) { $('body').trigger('ajax:complete', xhr); }, error: function (xhr, status, error) { $('body').trigger('ajax:failure', [xhr, status, error]); } }); return false; }); $(document).on('focus', 'textarea[maxlength]', function() { var max = parseInt($(this).attr('maxlength')); $(this).parent().find('.charsRemaining').html('You have ' + (max - $(this).val().length) + ' characters remaining'); }).on('keyup', 'textarea[maxlength]', function(){ var max = parseInt($(this).attr('maxlength')); if($(this).val().length > max){ $(this).val($(this).val().substr(0, $(this).attr('maxlength'))); } $(this).parent().find('.charsRemaining').html('You have ' + (max - $(this).val().length) + ' characters remaining'); }).on('blur', 'textarea[maxlength]', function() { $(this).parent().find('.charsRemaining').html(''); }); // Payment submission $(document).on('click', '.submit_payment', function() { var form = $(this).closest('form'); $this = $(this); $.ajax({url: $(this).attr('data-url'), data: form.serializeArray(), type: 'POST', dataType:'script', beforeSend: function (xhr) { $('body').trigger('ajax:loading', xhr); if ($this.data('disable-with') !== null) { $this.attr('disabled','disabled'); $this.data('enabled-text', $(this).html()); $this.attr('value', $this.data('disable-with')); } }, complete: function (xhr) { $('body').trigger('ajax:complete', xhr); $this.removeAttr('disabled'); $this.attr('value', $this.data('enabled-text')); }, error: function (xhr, status, error) { $('body').trigger('ajax:failure', [xhr, status, error]); $this.removeAttribute('disabled'); $this.attr('value', $this.data('enabled-text')); } }); return false; }); }); $.fe = {}; $.fe.pageHandler = { initialize : function(page) { this.auto_save_frequency = 30; // seconds this.timer_id = null; this.suspendLoad = false; this.current_page = page; $('#' + page).data('form_data', this.captureForm($('#' + page))); this.registerAutoSave(); this.page_validation = {}; // validation objects for each page this.enableValidation(page); // this.background_load = false; // this.final_submission = false; }, // swap to a different page showPage : function(page) { // hide the old $('#' + this.current_page + '-li').removeClass('active'); $('#' + this.current_page).hide(); // HACK: Need to clear the main error message when returning to the submit page // It is very confusing to users to be there when they revisit the page if ((page=='submit_page') && ($('#submit_message')[0] != null)) $('#submit_message').hide(); if ((page=='submit_page') && ($('#application_errors')[0] != null)) $('#application_errors').html(''); // show the new // $('#' + page + '-li').removeClass('incomplete'); // $('#' + page + '-li').removeClass('valid'); $('#' + page + '-li').addClass('active'); $('#' + page).show(); this.current_page = page; this.registerAutoSave(page); this.suspendLoad = false; fixGridColumnWidths(); }, // callback onSuccess pageLoaded : function(response) { // var response = new String(transport.responseText); var match = response.match(/