|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
var AjaxForm = { initialize: function (afConfig) { if (!jQuery().ajaxForm) { document.write('<script src="' + afConfig['assetsUrl'] + 'js/lib/jquery.form.min.js"><\/script>'); } if (!jQuery().jGrowl) { document.write('<script src="' + afConfig['assetsUrl'] + 'js/lib/jquery.jgrowl.min.js"><\/script>'); } $(document).ready(function () { $.jGrowl.defaults.closerTemplate = '<div>[ ' + afConfig['closeMessage'] + ' ]</div>'; }); $(document).off('submit', afConfig['formSelector']).on('submit', afConfig['formSelector'], function (e) { $(this).ajaxSubmit({ dataType: 'json', data: {pageId: afConfig['pageId']}, url: afConfig['actionUrl'], beforeSerialize: function (form) { form.find(':submit').each(function () { if (!form.find('input[type="hidden"][name="' + $(this).attr('name') + '"]').length) { $(form).append( $('<input type="hidden">').attr({ name: $(this).attr('name'), value: $(this).attr('value') }) ); } }) }, beforeSubmit: function (fields, form) { //noinspection JSUnresolvedVariable if (typeof(afValidated) != 'undefined' && afValidated == false) { return false; } form.find('.error').html(''); form.find('.error').removeClass('error'); form.find('input,textarea,select,button').attr('disabled', true); return true; }, success: function (response, status, xhr, form) { form.find('input,textarea,select,button').attr('disabled', false); response.form = form; $(document).trigger('af_complete', response); if (!response.success) { AjaxForm.Message.error(response.message); if (response.data) { var key, value, focused; for (key in response.data) { if (response.data.hasOwnProperty(key)) { if (!focused) { form.find('[name="' + key + '"]').focus(); focused = true; } value = response.data[key]; form.find('.error_' + key).html(value).addClass('error'); form.find('[name="' + key + '"]').addClass('error'); } } } } else { /* send calltouch */ try { var fio = form.find('input[name*="name"]').val(); var phone = form.find('input[name*="phone"],input[name*="tel"]').val(); var mail = form.find('input[name*="email"]').val(); var comment = form.find('input[name*="comment"]').val(); var ct_site_id = '55755'; var sub = 'Заявка с ' + location.hostname; var ct_data = { fio: fio, phoneNumber: phone, email: mail, comment: comment, subject: sub, requestUrl: location.href, sessionId: window.call_value }; console.log(ct_data); if (!!phone || !!mail){ jQuery.ajax({ url: 'https://api.calltouch.ru/calls-service/RestAPI/requests/'+ct_site_id+'/register/', dataType: 'json', type: 'POST', data: ct_data, async: false }); } } catch(e) { console.log(e); } /* send calltouch */ AjaxForm.Message.success(response.message); form.find('.error').removeClass('error'); form[0].reset(); //noinspection JSUnresolvedVariable if (typeof(grecaptcha) != 'undefined') { //noinspection JSUnresolvedVariable grecaptcha.reset(); } } } }); e.preventDefault(); return false; }); $(document).on('keypress change', '.error', function () { var key = $(this).attr('name'); $(this).removeClass('error'); $('.error_' + key).html('').removeClass('error'); }); $(document).on('reset', afConfig['formSelector'], function () { $(this).find('.error').html(''); AjaxForm.Message.close(); }); } }; //noinspection JSUnusedGlobalSymbols AjaxForm.Message = { success: function (message, sticky) { if (message) { if (!sticky) { sticky = false; } $.jGrowl(message, {theme: 'af-message-success', sticky: sticky}); } }, error: function (message, sticky) { if (message) { if (!sticky) { sticky = false; } $.jGrowl(message, {theme: 'af-message-error', sticky: sticky}); } }, info: function (message, sticky) { if (message) { if (!sticky) { sticky = false; } $.jGrowl(message, {theme: 'af-message-info', sticky: sticky}); } }, close: function () { $.jGrowl('close'); }, }; |