// used by answer sheets (function($) { $(function() { $(document).on('click', '.save_button', function() { $.fe.pageHandler.savePage($(this).closest('.answer-page'), true); }); $(document).on('keydown', '#payment_staff_first, #payment_staff_last', function(e) { if (e.which == 13) { $('#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(''); }); }); $.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(/
') var csrf_token = $('meta[name=csrf-token]').attr('content'), csrf_param = $('meta[name=csrf-param]').attr('content'), dom_id = '#attachment_field_' + id, metadata_input = '', file_field = '