1jQuery(document).ready(function( $ ) { 2 /** 3 * Check the file size in the input file field. 4 */ 5 $('form.personio-application-form input[type="file"]').on('change', function() { 6 if( $(this).get()[0].files[0].size >= 20000000 ) { 7 alert(customJsVarsFormPro.file_to_big); 8 } 9 }); 10 11 /** 12 * Submit application via AJAX. 13 */ 14 $('body.personio-application-ajax form.personio-application-form').on("submit", function(e) { 15 e.preventDefault(); 16 17 // get form as object. 18 let form = $(this); 19 20 // collect data from fields. 21 let formData = new FormData(); 22 $(this).find("input, textarea, select").each(function() { 23 // handle file-fields separate 24 if( $(this).prop('nodeName') === 'INPUT' && $(this).attr('type') === 'file' ) { 25 let files = $(this)[0].files; 26 if( files.length > 0 ) { 27 formData.append($(this).attr('name'), files[0]); 28 } 29 } 30 else { 31 formData.append($(this).attr('name'), $(this).val()); 32 } 33 }); 34 35 // submit them via ajax. 36 $.ajax({
37 url: customJsVarsFormPro.rest_personioapplications, 38 type: 'POST', 39 data: formData, 40 dataType: 'json', 41 contentType: false, 42 processData: false, 43 beforeSend: function( xhr ) { 44 // set header for authentication. 45 xhr.setRequestHeader('X-WP-Nonce', customJsVarsFormPro.rest_nonce); 46 }, 47 success: function(result){ 48 if( result.type ) { 49 switch( result.type ) { 50 case 'simpleMessage': 51 personio_integration_rest_submission_simple_message_above_form( form, result ); 52 break; 53 case 'simpleMessageAfterForm': 54 personio_integration_rest_submission_simple_message_after_form( form, result ); 55 break; 56 case 'onlyMessage': 57 personio_integration_rest_submission_only_message( form, result ); 58 break; 59 case 'forward': 60 case 'forward_url': 61 personio_integration_rest_submission_forward_url( form, result ); 62 break; 63 } 64 } 65 }, 66 }); 67 }); 68 69 /** 70 * Delete uploaded file after click via AJAX. 71 */ 72 $('a.pi_delete_file').on("click", function(e) { 73 e.preventDefault(); 74 let link = $(this); 75 $.ajax({
76 type: "POST", 77 url: customJsVarsFormPro.ajax_url, 78 data: { 79 'action': 'personio_delete_file', 80 'file': $(this).data('file'), 81 'nonce': customJsVarsFormPro.run_delete_file 82 }, 83 success: function(result) { 84 if( result.success ) { 85 // remove hidden field with filename. 86 link.parent().parent().find('input[type="hidden"]').remove(); 87 88 // set file-field to require. 89 link.parent().parent().find('input[type="file"]').attr('required', true); 90 91 // remove file-info. 92 link.parent().remove(); 93 } 94 } 95 }); 96 }); 97 98 /** 99 * Remove static honeypot. 100 */ 101 $('#' + customJsVarsFormPro.field_name ).remove(); 102 103 /** 104 * Honeypot for application form. 105 */ 106 if( customJsVarsFormPro.enable_honeypot ) { 107 let field = "<div class='personio-my-name-field' style='display:none;height:0;width:0;'><label><input type='text' name='" + customJsVarsFormPro.field_name + "' value='" + customJsVarsFormPro.field_value + "' aria-hidden='true' /></label></div>"; 108 $('form.personio-application-form').append(field); 109 } 110 111 /** 112 * Handler for general application form. 113 */ 114 personio_integration_get_general_application_form(); 115}); 116 117/** 118 * Show simple message above the form after submission of application via REST. 119 * 120 * @dependent SimpleMessage.php 121 */ 122function personio_integration_rest_submission_simple_message_above_form( form, result ) { 123 // remove all other hints. 124 jQuery('.personio-application-hint, .personio-application-field-hint').remove(); 125 126 // add hint from response before formular. 127 if( result.message ) { 128 jQuery(result.message).insertBefore(form); 129 } 130 131 if( result.fields ) { 132 jQuery.each( result.fields, function( field_name, field_key ) { 133 let obj = jQuery('#' + field_name ); 134 obj.parent().addClass( 'personio-application-field-error' ); 135 jQuery( '<div class="entry-content personio-application-field-hint error"><p>' + customJsVarsFormPro.text_error + '</p></div>' ).insertAfter( obj ); 136 }); 137 } 138 139 // scroll to given application-id to show result. 140 if( result.personioId ) { 141 jQuery('html, body').animate({ 142 scrollTop: jQuery("#applicationform" + result.personioId).offset().top - 20 143 }, 20); 144 } 145} 146 147/** 148 * Show simple message under the form after submission of application via REST. 149 * 150 * @dependent SimpleMessageAfterForm.php 151 */ 152function personio_integration_rest_submission_simple_message_after_form( form, result ) { 153 // remove all other hints. 154 jQuery('.personio-application-hint, .personio-application-field-hint').remove(); 155 156 // add hint from response before formular. 157 if( result.message ) { 158 jQuery(result.message).insertAfter(form); 159 } 160 161 if( result.fields ) { 162 jQuery.each( result.fields, function( field_name, field_key ) { 163 let obj = jQuery('#' + field_name ); 164 obj.parent().addClass( 'personio-application-field-error' ); 165 jQuery( '<div class="entry-content personio-application-field-hint error"><p>' + customJsVarsFormPro.text_error + '</p></div>' ).insertAfter( obj ); 166 }); 167 } 168 169 // scroll to given application-id to show result. 170 if( result.personioId ) { 171 jQuery('html, body').animate({ 172 scrollTop: jQuery("#applicationform" + result.personioId).offset().top - 20 173 }, 20); 174 } 175} 176 177/** 178 * Show simple message without after submission of application via REST. 179 * 180 * @dependent OnlyMessage.php 181 */ 182function personio_integration_rest_submission_only_message( form, result ) { 183 // remove all other hints. 184 jQuery('.personio-application-hint').remove(); 185 186 // add hint from response before formular. 187 if( result.message ) { 188 jQuery(result.message).insertBefore(form); 189 } 190 191 // remove the form. 192 form.remove(); 193} 194 195/** 196 * Forward user after submission of application via REST. 197 * 198 * @dependent Forward_Url.php, Forward.php 199 */ 200function personio_integration_rest_submission_forward_url( form, result ) { 201 // forward the user if URL is given. 202 if( result.message ) { 203 location.href = result.message; 204 } 205} 206 207/** 208 * Handler for general application form. 209 */ 210function personio_integration_get_general_application_form() { 211 jQuery('form.personio-application-form .office select').off().on( 'change', function() { 212 // secure the object. 213 let obj = jQuery(this); 214 215 // request the form via AJAX. 216 jQuery.ajax({ 217 type: "POST", 218 url: customJsVarsFormPro.ajax_url, 219 data: { 220 'action': 'personio_integration_get_form_by_office', 221 'office': jQuery(this).val(), 222 'nonce': customJsVarsFormPro.get_form_by_office_nonce 223 }, 224 success: function(result) { 225 // replace the existing form with the resulting form. 226 obj.parents('.entry-content.personio-integration-form-wrapper').replaceWith( result ); 227 228 // reset the handler. 229 personio_integration_get_general_application_form(); 230 } 231 }); 232 }) 233 jQuery('form.personio-application-form .position select').off().on( 'change', function() { 234 // secure the object. 235 let obj = jQuery(this); 236 237 // request the form via AJAX. 238 jQuery.ajax({ 239 type: "POST", 240 url: customJsVarsFormPro.ajax_url, 241 data: { 242 'action': 'personio_integration_get_form_by_office', 243 'office': obj.parents('.entry-content.personio-integration-form-wrapper').find('.office select').val(), 244 'position': jQuery(this).val(), 245 'nonce': customJsVarsFormPro.get_form_by_office_nonce 246 }, 247 success: function(result) { 248 // replace the existing form with the resulting form. 249 obj.parents('.entry-content.personio-integration-form-wrapper').replaceWith( result ); 250 251 // reset the handler. 252 personio_integration_get_general_application_form(); 253 } 254 }); 255 }); 256 jQuery('form.personio-application-form:has(.office) input[type="submit"]').each(function() { 257 if( jQuery(this).parents( 'form' ).find('#personioId').length === 0 ) { 258 jQuery(this).hide(); 259 } 260 }); 261}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.