1(function (window, $) { 2 'use strict'; 3 4 if (!!window.JSIblockElementAddForm) { 5 return; 6 } 7 8 window.JSIblockElementAddForm = function (params) { 9 this.params = params; 10 this.initElements(); 11 this.initEvents(); 12 } 13 14 window.JSIblockElementAddForm.prototype.initElements = function () { 15 this.form = document.querySelector('form#iblock_add_' + this.params.IBLOCK_ID); 16 this.button = this.form.querySelector<HTMLButtonElement>( 17 'button[type="submit"]' 18 ); 19 this.error = this.form.querySelector('.form-error'); 20 } 21 22 window.JSIblockElementAddForm.prototype.initEvents = function () { 23 if (this.form) { 24 this.form.addEventListener('submit', (e) => { 25 e.preventDefault(); 26 let ar = {}; 27 for (const arKey in this.form.elements) { 28 if (arKey.includes('PROPERTY')) { 29 let newKey = arKey.replace('PROPERTY[', '',).replace(']', '') 30 ar[newKey] = this.form.elements[arKey].value 31 } 32 } 33 this.sendForm(ar) 34 }) 35 } 36 } 37 38 window.JSIblockElementAddForm.prototype.handlerFormReset = function () { 39 this.form.reset(); 40 const formInputs = this.form.querySelectorAll< 41 HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement 42 >('select, input, textarea'); 43 for (let key in formInputs) { 44 let input = formInputs[key]; 45 input.dispatchEvent(new Event('change')); 46 } 47 if (this.button) { 48 this.button.removeAttribute('disabled'); 49 this.button.classList.remove('btn--loading'); 50 } 51 }; 52 53 window.JSIblockElementAddForm.prototype.handleFormSuccess = function (message = 'ФоÑма оÑпÑавлена') { 54 if (document.querySelector('#modal-notification.is-open')) { 55 window.MicroModal.close('modal-notification'); 56 } 57 this.handlerFormReset(); 58 window.MicroModal.show('modal-notification'); 59 document.querySelector('#modal-notification .js-notification-text').textContent = message; 60 }; 61 62 window.JSIblockElementAddForm.prototype.handleFormError = function (message = 'ÐÑибка оÑпÑавки ÑоÑмÑ.') { 63 if (!this.error) { 64 this.error = document.createElement('div'); 65 this.error.classList.add('form-error'); 66 if (this.button) { 67 this.button.insertAdjacentElement('afterend', this.error); 68 } 69 } 70 this.error.textContent = message; 71 if (this.button) { 72 this.button.removeAttribute('disabled'); 73 this.button.classList.remove('btn--loading'); 74 } 75 }; 76 77 window.JSIblockElementAddForm.prototype.sendForm = function (postData) { 78 if (this.button) { 79 this.button.setAttribute('disabled', 'disabled'); 80 this.button.classList.add('btn--loading'); 81 } 82 if (this.error) { 83 this.error.remove(); 84 } 85 86 BX.ajax.runComponentAction('custom:ajax', "sendForm", { 87 mode: 'class', 88 signedParameters: this.params.signedParameters, 89 data: { 90 postData: postData, 91 iblockId: this.params.IBLOCK_ID, 92 }, 93 }).then((response) => { 94 if (response.status === 'success' && response.data.LAST_ERROR == "") { 95 this.handleFormSuccess() 96 } else { 97 this.handleFormError(response.data.LAST_ERROR ?? undefined); 98 } 99 100 this.initElements(); 101 this.initEvents(); 102 }); 103 } 104 105})(window, $);
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.