//= 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(/
0) { matchable_answers = [1, '1', true, 'true', 'yes']; } vals = $([$element_li.find("input[type=radio]:checked").val()]); } else if ($element_li.hasClass('fe::choicefield') && $element_li.hasClass('checkbox')) { vals = $element_li.find("input[type=checkbox]:checked").map(function(i, el) { return $(el).val(); }); } else { vals = $([$element_li.find("input:visible, select:visible").val()]); } match = $(matchable_answers).filter(vals).length > 0; console.log('checkConditional match: ' + match); switch ($element_li.data('conditional_type')) { case 'Fe::Element': if (match) { $("#element_" + $element_li.data('conditional_id')).show(); } else { $("#element_" + $element_li.data('conditional_id')).hide(); } case 'Fe::Page': li_id = "li#fe_application_" + $element_li.data('application_id') + '-fe_page_' + $element_li.data('conditional_id') + '-li'; if (match) { $(li_id).show(); } else { $(li_id).hide(); } } } }; $(document).on('click', "li.conditional input, li.conditional select", function() { console.log('click'); $.fe.pageHandler.checkConditional($(this).closest('li')); }); $(document).on('keyup', "li.conditional input, li.conditional select", function() { $(this).click(); }); $(document).on('blug', "li.conditional input, li.conditional select", function() { $(this).click(); }); $(document).on('change', "li.conditional select", function() { $(this).click(); }); })(jQuery); $(function() { fixGridColumnWidths(); }); function updateTotal(id) { try { total = 0; $(".col_" + id ).each(function(e) { total += Number(e.val()); }); $('#total_' + id).val(total); } catch(e) {} } function submitToFrame(id, url) { form = $('
') 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 = '