1/** 2 * Ðлагин, позволÑÑÑий оÑкÑÑваÑÑ Ð´Ð¸Ð°Ð»Ð¾Ð³Ð¾Ð²Ñе окна Ñ Ð¿ÑедваÑиÑелÑной загÑÑзкой даннÑÑ ÑеÑез AJAX. 3 * ÐеÑÐµÐ²Ð¾Ð´Ð¸Ñ Ð»ÑбÑÑ Ð¾ÑпÑÐ°Ð²ÐºÑ ÑоÑÐ¼Ñ Ð²Ð½ÑÑÑи окна в Ñежим AJAX. 4 * 5 * ÐавиÑÐ¸Ñ Ð¾Ñ RsJsCore.plugins.modal 6 */ 7new class OpenDialog extends RsJsCore.classes.plugin { 8 9 constructor() { 10 super(); 11 let defaults = { 12 inDialogSelector: '.rs-in-dialog', 13 disableClass: 'disabled', 14 skipFormAjaxClass: 'no-ajax' 15 }; 16 this.settings = {...defaults, ...this.getExtendsSettings()}; 17 18 if (RsJsCore.plugins.modal) { 19 this.modal = RsJsCore.plugins.modal; 20 } else { 21 console.error(lang.t('Ðлагин Ð´Ð»Ñ Ð¼Ð¾Ð´Ð°Ð»ÑнÑÑ Ð¾ÐºÐ¾Ð½ RsJsCore.plugins.modal не ÑÑÑановлен')); 22 } 23 24 this._bindEvents(); 25 } 26 27 /** 28 * УÑÑÐ°Ð½Ð°Ð²Ð»Ð¸Ð²Ð°ÐµÑ Ð½ÐµÐ¾Ð±Ñ Ð¾Ð´Ð¸Ð¼Ñе обÑабоÑÑики ÑобÑÑий 29 * 30 * @private 31 */ 32 _bindEvents() { 33 document.addEventListener('click', (e) => { 34 let element = e.target.closest(this.settings.inDialogSelector); 35 if (element) { 36 let href = element.dataset.href ? element.dataset.href : element.href; 37 if (href) { 38 if (!element.classList.contains(this.settings.disableClass)) { 39 this.show({ 40 url: href 41 }); 42 } 43 44 e.preventDefault(); 45 } 46 } 47 }); 48 } 49 50 /** 51 * ÐагÑÑÐ¶Ð°ÐµÑ Ð´Ð°Ð½Ð½Ñе по URL, оÑкÑÑÐ²Ð°ÐµÑ Ð´Ð¸Ð°Ð»Ð¾Ð³Ð¾Ð²Ð¾Ðµ окно Ñ Ð·Ð°Ð³ÑÑженнÑми даннÑми 52 * @param options 53 * @param requestOptions 54 */ 55 show(options, requestOptions) { 56 let defaults = { 57 url:'', 58 data: {}, 59 callback: null, 60 bindSubmit: true 61 }; 62 this.options = {...defaults, ...options}; 63 64 let url = new URL(this.options.url, window.location.origin); 65 url.searchParams.append('dialogWrap', 1); 66 Object.keys(this.options.data).forEach(key => url.searchParams.append(key, this.options.data[key])); 67 68 this._requestContent(url, requestOptions); 69 } 70 71 /** 72 * ÐÑполнÑÐµÑ Ð·Ð°Ð¿ÑÐ¾Ñ Ðº ÑеÑвеÑÑ Ð½Ð° полÑÑение конÑенÑа и оÑкÑÑÐ²Ð°ÐµÑ ÐµÐ³Ð¾ в модалÑном окне 73 * 74 * @param url 75 * @param options 76 * @private 77 */ 78 _requestContent(url, options) { 79 this.showOverlay(); 80 81 return RsJsCore.utils.fetchJSON(url, options).then(response => { 82 this._prepareResponse(response); 83 if (response.html) { 84 this.modal.open(response.html, (event) => { 85 this._prepareHtml(response, event.target); 86 }); 87 } 88 89 }).finally(() => { 90 this.hideOverlay(); 91 }); 92 } 93 94 /** 95 * ÐбÑабаÑÑÐ²Ð°ÐµÑ ÑпеÑиÑиÑеÑкие json клÑÑи, коÑоÑÑе оÑвеÑаÑÑ Ð·Ð° дейÑÑвиÑ. 96 * 97 * @param response 98 * @private 99 */ 100 _prepareResponse(response) { 101 if (response.closeDialog) { 102 if (this.modal && this.modal.isOpen()) { 103 this.modal.close(); 104 response.html = null; 105 } 106 } 107 108 if (response.redirect) { 109 this.show({ 110 url: response.redirect 111 }); 112 response.html = null; 113 } 114 115 return true; 116 } 117 118 /** 119 * ÐÑполнÑÐµÑ Ð¾Ð±ÑабоÑÐºÑ Ð¿Ð¾Ð»ÑÑенного Ñ ÑеÑвеÑа HTML-кода. 120 * ÐавеÑÐ¸Ð²Ð°ÐµÑ Ð½ÐµÐ¾Ð±Ñ Ð¾Ð´Ð¸Ð¼Ñе ÑобÑÑÐ¸Ñ 121 * 122 * @param response 123 * @param element 124 * @private 125 */ 126 _prepareHtml(response, element) 127 { 128 if (this.options.bindSubmit) { 129 element.querySelectorAll('form').forEach((form) => { 130 if (!form.classList.contains(this.settings.skipFormAjaxClass)) { 131 this._ajaxForm(form); 132 } 133 }); 134 } 135 136 if (this.options.callback) { 137 this.options.callback.call(this, response, element); 138 } 139 } 140 141 /** 142 * ÐÑпÑавлÑÐµÑ Ð²Ñе ÑоÑÐ¼Ñ Ð² диалоговом окне на ÑеÑÐ²ÐµÑ Ñ Ð¿Ð¾Ð¼Ð¾ÑÑÑ AJAX 143 * 144 * @param form 145 * @private 146 */ 147 _ajaxForm(form) { 148 form.addEventListener('submit', (event) => { 149 event.preventDefault(); 150 151 let data = new FormData(form); 152 let formAction = form.dataset.ajaxAction ? form.dataset.ajaxAction : form.getAttribute('action'); 153 if (!formAction) formAction = ''; 154 formAction += formAction.indexOf('?') === -1 ? '?dialogWrap=1' : '&dialogWrap=1'; 155 156 form.querySelectorAll('button[type="submit"], input[type="submit"]').forEach((element) => { 157 element.disabled = true; 158 }); 159 160 this._requestContent(formAction, { 161 method: 'POST', 162 body: data 163 }) 164 .finally(() => { 165 form.querySelectorAll('button[type="submit"], input[type="submit"]').forEach((element) => { 166 setTimeout(() => { 167 element.disabled = false;
168 }, 500); 169 }); 170 }); 171 }); 172 } 173 174 /** 175 * ÐÑобÑÐ°Ð¶Ð°ÐµÑ Ð¿ÑелоадеÑ, в моменÑ, когда пÑоиÑÑ Ð¾Ð´Ð¸Ñ Ð·Ð°Ð³ÑÑзка 176 * даннÑÑ Ñ ÑеÑвеÑа, до оÑкÑÑÑÐ¸Ñ Ð¾ÐºÐ½Ð° 177 */ 178 showOverlay() { 179 if (this.modal.isOpen()) { 180 this.modal.showLoader(); 181 } 182 } 183 184 /** 185 * СкÑÑÐ²Ð°ÐµÑ Ð¿ÑÐµÐ»Ð¾Ð°Ð´ÐµÑ Ð¿ÑедÑеÑÑвÑÑÑий оÑобÑÐ°Ð¶ÐµÐ½Ð¸Ñ Ð¾ÐºÐ½Ð° 186 */ 187 hideOverlay() { 188 if (this.modal.isOpen()) { 189 this.modal.hideLoader(); 190 } 191 } 192};
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.