(self.webpackChunkHoroshop=self.webpackChunkHoroshop||[]).push([[759],{7063:function(t,e,n){!function(t,e,n){var i=function(){!1!==this.trigger("beforeInit")&&(this.init(),this.trigger("afterInit"))},r=function(e,n){this.container=t(e),this.owner=n,this.name=this.container.data("component"),i.call(this)};r.extend=function(e){var n=this,i=function(){n.apply(this,arguments)};i.extend=r.extend,t.extend(i.prototype,n.prototype),t.extend(i.prototype,e);var o=t.extend({},n.prototype);return i.prototype.parent=function(t){o[t].apply(this,Array.prototype.slice.call(arguments,1))},i},r.prototype={init:function(){},performAction:function(t,e,n){var i=this;return!1!==this.trigger("beforeAction",t,e)&&(this.trigger("beforeAjax"),this.owner.performAction("component/"+this.name+"/"+t,e,(function(r,o){"function"==typeof n&&n(r,o),i.trigger("afterAction",t,e),i.trigger("afterAjax")})))},render:function(){var t=this;!1!==this.trigger("beforeRender")&&this.performAction("index",{},(function(e,n){"OK"===e&&t.replaceHtml(n.html),t.trigger("afterRender")}))},replaceHtml:function(e){if(!1!==this.trigger("beforeReplaceHtml")){var n=t(e),i=n.prop("attributes");this.container.html(n.html());var r=this.container;t.each(i,(function(){r.attr(this.name,this.value)})),this.trigger("afterReplaceHtml")}},getFieldName:function(t){var e=t.indexOf("["),n=-1!==e?t.substr(0,e):t,i=-1!==e?t.substr(e):"";return this.name+"["+n+"]"+i},disableComponent:function(){this.container.addClass(this.owner.disabledClass)},enableComponent:function(){this.container.removeClass(this.owner.disabledClass)}},t.extend(r.prototype,TMEvents),e.CheckoutComponent=r}(n(3053),window)},5419:function(t,e,n){var i,r,o,a=n(3053);i=a,r=window,o=CheckoutRecipient.extend({initSearch:function(){this.parent("initSearch"),this.initCountrySearch()},setCountry:function(t,e){var n=this,r=this.container.find(':input[name="'+this.getFieldName("delivery_country")+'"]'),o=this.container.find(':input[name="'+this.getFieldName("delivery_city")+'"]'),a=r.siblings(".j-country-loader"),s=this.container.find(':input[name="'+this.getFieldName("delivery_country_id")+'"]');s.attr("value",t),a.show(),e=i.trim(e),r.val(e),this.trigger("onBeforeChangeCountry"),this.performAction("setCountry",{value:e,id:t},(function(t,i){r.errorBox(),o.errorBox(),a.hide(),"OK"===t&&(s.attr("value",i.country_id),n.checkCity(),n.container.find('input[name="'+n.getFieldName("delivery_city")+'"]').val(i.city),n.trigger("changeCountry",r,e)),"VALIDATION_ERROR"===t&&n.owner.setErrors(i.errors),"EMPTY"===t&&answer([{label:l10n("Ничего не найдено"),value:null,disabled:!0}])})),this.countryName=e},setCity:function(t,e){var n=this,r=this.container.find(':input[name="'+this.getFieldName("delivery_city")+'"]'),o=this.container.find(':input[name="'+this.getFieldName("delivery_city_id")+'"]');t=i.trim(t),e=i.trim(e),r.val(t),o.val(e),this.trigger("onBeforeChangeCity"),this.performAction("setCity",{cityName:t,cityId:e},(function(e,i){"OK"===e&&(r.val(""!=t&&""==i.city?t:i.city),n.trigger("changeCity"),i.city_id&&o.val(i.city_id)),"VALIDATION_ERROR"===e&&n.owner.setErrors(i.errors)})),this.cityVal=t},checkCity:function(){var t=this.container.find(':input[name="'+this.getFieldName("delivery_country_id")+'"]'),e=this.container.find(".delivery_city");""===i.trim(t.val())?e.hide():e.show()},initCountrySearch:function(){var t=this,e=this.container.find('input[name="'+this.getFieldName("delivery_country")+'"]'),n=e.siblings(".j-country-loader"),r=e.siblings(".j-search-icon");e.on("input",(function(){t.container.find(':input[name="'+t.getFieldName("delivery_country_id")+'"]').attr("value",""),t.checkCity()})),e.on("focus",(function(){r.show(),e.parent().addClass("form-item--search")})).on("focusout",(function(){r.hide(),e.parent().removeClass("form-item--search")})),0!==e.length&&(e.autocomplete({autoFocus:!0,minLength:2,source:function(e,i){n.show(),t.performAction("findCountries",{term:e.term},(function(t,e){n.hide(),"OK"===t&&i(e.countries),"EMPTY"===t&&i([{label:l10n("Ничего не найдено"),value:null,disabled:!0}])}))},select:function(e,n){t.setCountry(n.item.id,n.item.label)},change:function(e,n){var r=n.item?n.item.label:i(this).val(),o=n.item?n.item.id:"";t.changeProcess=setTimeout((function(){t.countryName!==r&&t.setCountry(o,r)}),300)},create:function(t){i.browser.chrome&&t.target.setAttribute("autocomplete","disabled")}}).data("ui-autocomplete")._renderItem=function(t,e){return i("<li>").append(e.label).addClass(e.disabled?"ui-state-disabled":"").appendTo(t)}),this.checkCity()}}),r.CheckoutCountryRecipient=o},2020:function(t,e,n){var i,r,o,a=n(3053);i=a,r=window,o=CheckoutComponent.extend({init:function(){var t=this;this.attachEventHandler("afterReplaceHtml",(function(){t.initDeliveryType(),t.trigger("replaceDeliveryHtml",t.delivery_type,t.delivery_type.val())})),this.initDeliveryType()},initDeliveryType:function(){this.delivery_method=this.container.find(".j-delivery-method"),this.delivery_type=this.container.find(".j-delivery-type");var t=this;this.delivery_type.off("change").on("change",(function(){t.setDeliveryType(i(this).val())}))},setDeliveryType:function(t){if(this.delivery_type.val(t),i.fn.selectBoxIt)try{this.delivery_type.selectBoxIt("refresh")}catch(t){}var e=this;this.performAction("set_delivery_type/"+t,{},(function(n,i){"OK"===n&&(e.delivery_method.empty().append(i.method),e.trigger("replaceDeliveryHtml"),e.owner.initAttributes(),e.trigger("changeDeliveryType",e.delivery_type,t,i))}))},reload:function(){var t=this;this.performAction("reload",{},(function(e,n){"OK"===e&&(t.container.empty().append(n.html),t.init(),t.owner.initAttributes())}))}}),r.CheckoutDelivery=o},7359:function(t,e,n){var i,r,o,a,s,c,l,d=n(3053);i=d,r=window,a=null,s=null,c=[],l=function(t){this.container=i(t),this.theme="default",this.disabledClass="horoshop_default"===r.GLOBAL.theme?"__disabled":"is-disabled",this.attachEventHandler("afterAjax",(function(){this.updateComponents()})),this.init()},l.prototype={init:function(){!1!==this.trigger("beforeInit")&&(this.components=[],this.isPostponeSubmit=!1,this.moduleUri=null,this.initAttributes(),this.initForm(),this.initComponents(),this.trigger("afterInit"))},setUseChangeEvent:function(t){var e=this,n=this.attributes.filter(":not([type=checkbox], [type=radio], .j-has-action)").off("change.CheckoutModule");t&&n.on("change.CheckoutModule",(function(){var t=i(this),n=[{name:t.attr("name"),value:t.val()}];e.setAttributes(n)}))},setTheme:function(t){this.theme=t},setModuleUri:function(t){this.moduleUri=t},initAttributes:function(){var t=this;this.attributes=this.container.find(":input:not(.j-ignore)"),this.attributes=this.attributes.filter((function(){return""!=i(this).attr("name")})),this.setUseChangeEvent(!0),this.attributes.filter("[type=radio]").off("click.CheckoutModule").on("click.CheckoutModule",(function(){var e=i(this),n=[{name:e.attr("name"),value:e.val()}];t.setAttributes(n)})),this.attributes.filter("[type=checkbox]").off("click.CheckoutModule").on("click.CheckoutModule",(function(){var e,n=i(this),r=n.siblings('[name="'+n.attr("name")+'"]');e=r.length?n.is(":checked")?n.val():r.val():n.is(":checked")?n.val():0;var o=[{name:n.attr("name"),value:e}];t.setAttributes(o)})),this.attributes.filter("[type=text]").off("keypress.CheckoutModule").on("keypress.CheckoutModule",(function(t){return 13!=t.which}))},clearErrors:function(){this.container.find("input").errorBox()},clearValid:function(){i.fn.validBox&&this.container.find("input").validBox()},setErrors:function(t){for(var e=this.getFields(),n=0;n<e.length;n++){for(var r=i(e[n]).attr("name"),o=i(e[n]).attr("data-relationInput"),a=!0,s=[],c=0;c<t.length;c++)r!=t[c].field&&o!=t[c].field||(s=t[c],a=!1);a?this.setValid(r,"",""):this.setError(s.field,s.message)}this.trigger("onInputErrors",t)},setError:function(t,e,n){this.container.find('[name="'+t+'"]').errorBox(e,n)},setValid:function(t,e,n){i.fn.validBox&&this.container.find('[name="'+t+'"]').validBox(e,n)},getFields:function(){return this.container.find(":input").filter((function(){var t=i(this);return t.is("select")||!t.is(":hidden, :submit")}))},initComponents:function(){this.clearComponents(),this.updateComponents()},initForm:function(){var t=this.container.is("form")?this.container:this.container.find("form"),e=this;this.submitting=!1,t.off("submit").on("submit",(function(){return i(t).find("input").blur(),AjaxCart.getInstance().getIsBusy()?setTimeout((function(){i(t).submit()}),500):e.submit(),!1})),this.submit_btn=t.find(".j-submit")},submit:function(){if(this.submitting)return this.isPostponeSubmit=!0,void this.trigger("onSubmitPending");if(!1!==this.trigger("onBeforeSubmit")){this.submitting=!0;var t=(this.container.is("form")?this.container:this.container.find("form")).serializeArray();t.push({name:"analytics",value:JSON.stringify(AnalyticsHelper.getDataInJson())});var e=this;this.performAction("submit",t,(function(t,n){e.clearErrors(),e.clearValid(),e.trigger("onAfterSubmit",t,n);var i=!1;if("OK"===t){i=!0;var o=n.attributes;r.triggerMarketingEvent&&r.triggerMarketingEvent("checkout_success",o?[o.order_id,o.cart,o.name,o.email,o.phone,o.eventId]:null),window.location.href=n.redirect}else"ERROR_VALIDATION"===t?e.setErrors(n.errors):"ERROR_OTHER"===t?(AjaxCart.getInstance().reloadHtml(),e.setErrors(n.errors)):["ERROR_DISCOUNT","ERROR_UNAVAILABLE_PRODUCTS"].includes(t)?e.renderModal(n.modal):"ERROR_NO_PRODUCTS_FOR_ORDER"===t&&window.location.reload();e.submitting=i}))}else this.trigger("onSubmitError")},renderModal:function(t){var e=i(t).attr("id"),n=i("#checkoutModalContainer");i("#"+e).remove(),n.append(t),this.trigger("onModalAppend",e)},attachComponent:function(t){var e=i(t),n=e.attr("data-component-handler")?e.attr("data-component-handler"):e.attr("data-component"),a="Checkout"+e.attr("data-component"),s=r[n]!==o?r[n]:r[a]!==o?r[a]:CheckoutComponent;this.components.push(new s(t,this)),this.componentsObjects=this.componentsObjects.add(e)},updateComponents:function(){var t=this,e=this.container.find(".j-component");e.each((function(){i(this).is(t.componentsObjects)||t.attachComponent(this)}));var n=this.components.slice();this.components=[];for(var r=0,o=n.length;r<o;++r){var a=n[r];a.container.is(e)&&this.components.push(a)}},clearComponents:function(){this.components=[],this.componentsObjects=i()},getComponents:function(){return this.components},getComponentByName:function(t){for(var e=this.components.length;--e>=0;){var n=this.components[e];if(n.name==t)return n}return null},reload:function(t){this.performAction("reload",{},t)},performAction:function(t,e,n){var i=this;if(!1===this.trigger("beforeAction",t,e))return!1;var r=this.container.find("[name=configPresetName]").val(),a=this.container.find("[name=orderId]").val(),s=this.container.find("[name=userId]").val(),c=this.container.find("[name=handlerId]").val();return e===o?e={configPresetName:r,theme:this.theme}:e instanceof Array?(e.push({name:"configPresetName",value:r}),e.push({name:"theme",value:this.theme})):e===e+""?e+="&configPresetName="+encodeURIComponent(r)+"&theme="+encodeURIComponent(this.theme):(e.configPresetName=r,e.theme=this.theme),void 0!==a&&void 0!==s&&void 0!==c&&(e instanceof Array?(e.push({name:"orderId",value:a}),e.push({name:"userId",value:s}),e.push({name:"handlerId",value:c})):"string"==typeof e?e+="&orderId="+encodeURIComponent(a)+"&userId="+encodeURIComponent(s)+"&handlerId="+encodeURIComponent(c):(e.orderId=a,e.userId=s,e.handlerId=c)),this.trigger("beforeAjax"),sendAjax(this.moduleUri+t+"/",e,(function(r,a){if(!a.redirect&&a.render_data){for(var s in a.render_data)if(a.render_data.hasOwnProperty(s)){var c=a.render_data[s],l=i.getComponentByName(s);l&&l.replaceHtml(c)}i.initAttributes()}a.enabled===o||i.isPostponeSubmit||(a.enabled?i.enableSubmitButton():i.disableSubmitButton()),"function"==typeof n&&n(r,a),i.trigger("afterAction",t,e),i.trigger("afterAjax"),"EXCEPTION"===r?i.trigger("AJAX_EXCEPTION",a):"OK"===r&&i.trigger("afterActionResponded",t,a)}))},setAttributes:function(t,e){this.trigger("onBeforeSetAttributes",t);var n=this;this.submitting=!0,this.performAction("setAttributes",t,(function(i,r){n.trigger("onAfterSetAttributes",i,t),n.submitting=!1,n.isPostponeSubmit&&(n.isPostponeSubmit=!1,n.submit()),"function"==typeof e&&e(i,r)}))},setFormDataAttributes:function(t,e){var n=this,i=this.container.find("[name=configPresetName]").val();t.append("configPresetName",i),t.append("theme",this.theme);var r={method:"post",body:t,headers:{"X-Requested-With":"XMLHttpRequest"}};"undefined"!=typeof GLOBAL&&(r.headers["X-CSRF-Token"]=GLOBAL.GLOBAL_CSRF_TOKEN),fetch(this.moduleUri+"setAttributes/",r).then((function(t){return t.json()})).then((function(t){var i=t.response,r=t.status;if(!i.redirect){if(i.render_data){for(var a in i.render_data)if(i.render_data.hasOwnProperty(a)){var s=i.render_data[a],c=n.getComponentByName(a);c&&c.replaceHtml(s)}n.initAttributes()}i.enabled!==o&&(i.enabled?n.submit_btn.removeClass(n.disabledClass).prop("disabled",!1):n.submit_btn.addClass(n.disabledClass).prop("disabled",!0)),"ERROR_VALIDATION"===r&&n.setErrors(i.errors)}"function"==typeof e&&e(r,i),"EXCEPTION"===r&&n.trigger("AJAX_EXCEPTION",i)}))},disableSubmitButton:function(){this.submit_btn.addClass(this.disabledClass).prop("disabled",!0)},enableSubmitButton:function(){this.submit_btn.removeClass(this.disabledClass).prop("disabled",!1)}},l.setSelector=function(t){t!==a&&(a=t,s=null)},l.getInstance=function(){return null===s&&(s=new l(a),c.push(s)),s},l.getInstances=function(){return c},i.extend(l.prototype,TMEvents),r.CheckoutModule=l},6739:function(t,e,n){var i,r,o,a=n(3053);i=a,r=window,o=CheckoutComponent.extend({init:function(){var t=this;this.attachEventHandler("afterReplaceHtml",(function(){t.initPaymentType(),t.initWarning(),t.trigger("replacePaymentHtml",t.payment_type,t.payment_type.val())})),this.initPaymentType()},initPaymentType:function(){var t=this;this.initInstallmentSelect(),this.payment_type=this.container.find(".j-payment-type"),this.payment_type.off("change.trigger").on("change.trigger",(function(){t.setPaymentType(t.payment_type.val())})),this.trigger("onPaymentTypeInit")},setPaymentType:function(t){var e=this,n=t?"set_payment_type/"+t:"set_default_payment_type";this.performAction(n,{},(function(n,i){"OK"===n&&(e.container.empty().append(i.html),e.trigger("replacePaymentHtml"),e.initPaymentType(),e.initWarning(),e.owner.initAttributes(),e.trigger("changePaymentType",e.payment_type,t))}))},initInstallmentSelect:function(){var t=this.container[0].querySelector(".j-payment-parts"),e=this.container[0].querySelector(".j-payments-text");t&&i(t).on("change",(function(t){e.innerHTML=t.target.options[t.target.selectedIndex].dataset.paymentsText}))},initWarning:function(){var t=this;this.warningContainer=this.container[0].querySelector("#payment-warning"),this.warningContainer&&(this.warningContainer.querySelectorAll(".j-remove-disallowed-products").forEach((function(e){e.addEventListener("click",(function(e){t.removeDisallowedProducts(),e.preventDefault()}))})),this.trigger("onInitWarning"))},removeDisallowedProducts:function(){var t=this,e=AjaxCart.getInstance(),n=this.warningContainer.querySelectorAll(".j-disallowed-product"),i=0;confirm(l10n("Вы уверены что хотите удалить товары?"))&&(this.trigger("beforeAjax"),n.forEach((function(t){e.removeProductByHash(t.dataset.id)})),e.Cart.attachEventHandler("onProductRemove",(function(){++i===n.length&&t.trigger("afterAjax")})),this.trigger("removedDisallowedProducts"))}}),r.CheckoutPayment=o},2414:function(t,e,n){!function(t,e,n){var i=CheckoutComponent.extend({init:function(){var t=this;this.attachEventHandler("afterReplaceHtml",(function(){t.initSearch(),t.initEmailSearch(),t.initComment()})),this.initSearch(),t.initEmailSearch(),this.initComment()},initComment:function(){var e=t(".j-comment-head"),n=t(".j-comment-body");n.find(".j-comment-opener").off("click").on("click",(function(){return e.show().removeClass("is-hidden"),n.removeClass("__closed"),n.find(":input").show().focus(),n.find(".j-comment-opener").hide(),!1}))},initEmailSearch:function(){var e,n=this,i=this.container.find(':input[name="'+this.getFieldName("delivery_email")+'"]'),r=i.siblings(".j-email-loader"),o=/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/gim,a=i.val();i.off("keyup.checkout").on("keyup.checkout",(function(){var i=t(this),s=i.val();clearTimeout(e),e=setTimeout((function(){-1!==s.search(o)&&s!==a&&(a=s,r.show(),n.emailInUse(s,(function(t,e){r.hide(),"USED"===t?i.errorBox(e.message,e.authorizationRequired?"error":"info"):i.errorBox()})))}),300)}))},emailInUse:function(t,e){this.performAction("emailInUse",{email:t},e)},initSearch:function(){this.initCitySearch()},initCitySearch:function(){var t=this.container.find('input[name="'+this.getFieldName("delivery_city")+'"]');0!==t.length&&(this.cityVal=t.val(),this.trigger("initCitySearch"))},setCity:function(t,e){var n=this,i=this.container.find(':input[name="'+this.getFieldName("delivery_city")+'"]'),r=this.container.find(':input[name="'+this.getFieldName("delivery_city_id")+'"]');i.val(t),r.val(e),this.trigger("onBeforeChangeCity"),this.owner.setAttributes([{name:r.attr("name"),value:e},{name:i.attr("name"),value:t}],(function(){n.trigger("changeCity")})),this.cityVal=t}});e.CheckoutRecipient=i}(n(3053),window)},3918:function(t,e,n){var i,r=n(3053);function o(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,i=new Array(e);n<e;n++)i[n]=t[n];return i}i=r,window.NovaPoshta=CheckoutComponent.extend({init:function(){var t=this.owner.getComponentByName("Delivery");if(t){var e=this;t.attachEventHandler("changeDeliveryType",(function(){e.initAll()})),t.attachEventHandler("afterReplaceHtml",(function(){e.initAll()}))}(t=this.owner.getComponentByName("Recipient")).attachEventHandler("afterReplaceHtml",(function(){e.initAll()})),this.attachEventHandler("afterReplaceHtml",(function(){e.initAll()})),this.cartEvents=!1,this.initAll(),this.attachEventHandlers({afterReplaceHtml:function(){e.initAll()},beforeAction:function(t){if("city_search"!==t){var n=this.getItemsToDisable();n.prop("disabled",!0),n.addClass("__disabled"),e.showLoader()}},afterAction:function(){e.toogleFieldsVisibility(),e.hideLoader()}})},initCitySearch:function(){var t=this.container.find(".j-np-sender-city"),e=this,n=[],r="";t.autocomplete({source:function(t,i){e.performAction("city_search",{text:t.term},(function(t,e){"OK"===t&&(n=e,i(e))}))},select:function(n,i){e.changeWarehouses(i.item.label),r=i.item.label,t.errorBox()},create:function(t){i.browser.chrome&&t.target.setAttribute("autocomplete","disabled")}}),t.off("change").on("change",(function(){var i=t[0].value;if(i!==r){t.errorBox();var a,s=!1,c=function(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return o(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?o(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var i=0,r=function(){};return{s:r,n:function(){return i>=t.length?{done:!0}:{done:!1,value:t[i++]}},e:function(t){throw t},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,s=!0,c=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return s=t.done,t},e:function(t){c=!0,a=t},f:function(){try{s||null==n.return||n.return()}finally{if(c)throw a}}}}(n);try{for(c.s();!(a=c.n()).done;)if(i===a.value.label){s=!0;break}}catch(t){c.e(t)}finally{c.f()}s?e.changeWarehouses(i):t.errorBox("Выберите город из списка")}}))},changeWarehouses:function(t){var e=this.container.find(".j-np-sender-warehouse");e[0].options.length=0,this.performAction("get_warehouses",{cityTitle:t},(function(t,n){if("OK"===t)for(var i=0;i<n.warehouses.length;i++)e[0].options[i]=new Option(n.warehouses[i].title,n.warehouses[i].id)}))},initCartEvents:function(){if(!this.cartEvents){var t=this;setTimeout((function(){t.cartEvents=!0;var e=AjaxCart.getInstance(),n=t.container.parents("form").find(".j-delivery-type");e.attachEventHandler("onChange",(function(){sendAjax("/adminLegacy/params/ajax_router.php",{param_full_name:"nova_poshta",current_currency_id:GLOBAL.currency.id,totalSum:this.total.sum},(function(e,i){setTimeout((function(){var e=t.container.find(".j-np-cost");if(n.length){var r=n.find(":selected"),o=(1*r.data("by-carrier")?0:1*r.data("price"))+i.uahTotalSum;e.val(o).trigger("change")}}),1e3)}))}))}),500)}},getItemsToDisable:function(){var t=this.container.parents("form:first"),e=t.find(":input:not(.j-ignore, .j-admin_comment), .j-cart-search");return(e=(e=e.add(t.find(".j-remove-p, .j-coupon-remove, .j-coupon-add, .j-markup-add"))).add(t.find(".j-place-input, .j-np-place-add, .j-np-place-duplicate, .j-np-place-remove"))).filter(':not(:input[type="button"], :input[type="submit"])')},toogleFieldsVisibility:function(){var t=this.container.is(".j-disabled");t?this.getItemsToDisable().addClass("__disabled"):this.getItemsToDisable().removeClass("__disabled"),this.getItemsToDisable().prop("disabled",t)},showLoader:function(){this.container.find(".j-np-loader").show()},hideLoader:function(){this.container.find(".j-np-loader").hide()},initAll:function(){this.container=i(this.owner.container).find('.j-component[data-component="'+this.name+'"]'),this.toogleFieldsVisibility();var t=this.container.find(".j-print"),e=this.container.find(".j-remove"),n=this.container.find(".j-np-sender"),r=this.container.find(".j-np-payment-method"),o=this.container.find(".j-np-sender-city"),a=this.container.find(".j-np-sender-payer"),s=this.container.find(".j-np-sender-warehouse"),c=this.container.find(".j-np-cost"),l=this.container.find(".j-np-contact-person");this.initGeneralWeightVolumeFields(this.container),this.initSeparatedWeightVolumeFields(this.container);var d=this.container.find(".j-calculate"),u=this;d.off("click").on("click",(function(){return u.calculate(),!1})),t.off("mousedown mouseup").on("mousedown mouseup",(function(e){return 0==e.button||(t.blur(),e.preventDefault(),!1)})).off("click").on("click",(function(){return!!confirm("Вы уверены что хотите распечатать накладную?\r\nПосле распечатки Вы не сможете редактировать данные ТТН.")&&(setTimeout((function(){u.render()}),100),i(window).one("focus",(function(){u.render()})),!0)})),e.off("click").on("click",(function(){return confirm("Вы уверены что хотите удалить ТТН?")&&u.remove(),!1}));var h=function(){n.find(":selected").data("allow-non-cash")&&1==a.val()?r.prop("disabled",!1):(r.val(1),setTimeout((function(){r.prop("disabled",!0)}),100))};n.off("change").on("change",(function(){var t=i(this).val();u.performAction("set_sender",{id:t},(function(t,e){if("OK"===t){o[0].value=e.city,s.empty().append(e.wares),l.empty();for(var n=0;n<e.contactPersons.length;n++){var i=!1;0===n&&(i=!0),l.append(new Option(e.contactPersons[n].text,e.contactPersons[n].value,!1,i))}h(),r=e.editLink,s.children().length>0?(d.removeClass("__disabled").removeAttr("disabled").prop("disabled",!1),s.removeClass("__disabled").removeAttr("disabled").prop("disabled",!1)):(d.addClass("__disabled").attr("disabled","disabled").prop("disabled",!0),s.addClass("__disabled").attr("disabled","disabled").prop("disabled",!0),o.html("У отправителя не указан город отправки. Нажмите <a href='"+r+"'>сюда</a> что-бы отредактировать"))}var r}))})),a.off("change.NPInitAll").on("change.NPInitAll",h);var f=this.container.parents("form:first");this.container.find(".np-disallow-edit").length>0?(f.addClass("__readonly"),this.getItemsToDisable().addClass("__disabled j-disabled").prop("disabled",!0)):(f.removeClass("__readonly"),this.getItemsToDisable().removeClass("__disabled j-disabled").prop("disabled",!1)),c.numberMask({type:"float",afterPoint:2}),u.initCartEvents(),u.initCitySearch(),h()},remove:function(){var t=this;this.performAction("remove_np",{},(function(e,n){if("OK"===e)i(n.html).insertAfter(t.container),t.container.remove(),t.trigger("afterReplaceHtml");else if("NP_EXCEPTION"===e){for(var r=[],o=0,a=n.errors.length;o<a;++o)r.push(n.errors[o]);r.length&&alert("При обработке накладной Новая Почта вернула такие ошибки:\r\n- "+r.join("\r\n- "))}}))},render:function(){var t=this;this.performAction("render_np",{},(function(e,n){"OK"===e&&(i(n.html).insertAfter(t.container),t.container.remove(),t.trigger("afterReplaceHtml"))}))},calculate:function(){var t=this.container.find(":input"),e=[];t.each((function(){var t=i(this);if(!t.is(":disabled")){if((t.is("[type=checkbox]")||t.is("[type=radio]"))&&!t.is(":checked"))return!0;e.push({name:t.attr("name"),value:t.val()})}}));var n=this;this.performAction("calculate_np",e,(function(t,e){if(n.owner.container.find(":input").errorBox(),"OK"===t)i(e.html).insertAfter(n.container),n.container.remove(),n.trigger("afterReplaceHtml");else if("VALIDATION_ERROR"===t){for(var r="Delivery[delivery_method]",o=0,a=(l=e.errors).length;o<a;++o){var s=l[o];if("FilterFormArray"===s.validator)var c=n.container.find(':input[name="'+r+s.code+'"]');else c=-1===s.code.indexOf("[")?n.container.find(':input[name="'+r+"["+s.code+']"]'):n.owner.container.find(':input[name="'+s.code+'"]');c.errorBox(s.message)}n.trigger("onValidationError")}else if("NP_EXCEPTION"===t){var l=[];for(o=0,a=e.errors.length;o<a;++o)l.push(e.errors[o]);l.length&&alert("При обработке накладной Новая Почта вернула такие ошибки:\r\n- "+l.join("\r\n- "))}}))},performAction:function(t,e,n){var i=this;if(!1===this.trigger("beforeAction",t,e))return!1;this.trigger("beforeAjax");var r=this.owner.getComponentByName("Delivery");return this.owner.performAction("component/"+r.name+"/delivery_action/"+t,e,(function(r,o){"function"==typeof n&&n(r,o),i.owner.initAttributes(),i.trigger("afterAction",t,e),i.trigger("afterAjax")}))},initGeneralWeightVolumeFields:function(t){var e=t.find(".j-np-weight"),n=t.find(".j-np-volume-general"),i=t.find(".j-np-volume-weight"),r=t.find(".j-np-seats-amount");e.numberMask({type:"float",afterPoint:3}),n.numberMask({type:"float",afterPoint:6}),r.numberMask({type:"int"});var o=function(){var t,e=1*n.val();t=0===e?"<i>Укажите объем</i>":250*e,i.empty().append(t)};o(),e.off("change.NP").on("change.NP",o),n.off("change.NP").on("change.NP",o)},initSeparatedWeightVolumeFields:function(t){var e=this;t.find(".j-np-separated-place").each((function(){e.initWeightVolumeRow(i(this))})),this.initPlaceAttributeSetter(t),t.find(".j-np-place-add").off("click").on("click",(function(){e.performAction("np_place_add",{},(function(t,n){"OK"===t&&(i(n.html).insertAfter(e.container),e.container.remove(),e.trigger("afterReplaceHtml"))}))})),t.find(".j-np-place-remove").off("click").on("click",(function(){var t=i(this).attr("data-place-id");e.performAction("np_place_remove",{placeId:t},(function(t,n){"OK"===t&&(i(n.html).insertAfter(e.container),e.container.remove(),e.trigger("afterReplaceHtml"))}))})),t.find(".j-np-place-duplicate").off("click").on("click",(function(){var t=i(this).attr("data-place-id");e.performAction("np_place_duplicate",{placeId:t},(function(t,n){"OK"===t&&(i(n.html).insertAfter(e.container),e.container.remove(),e.trigger("afterReplaceHtml"))}))}))},initWeightVolumeRow:function(t){var e=t.find(".j-np-place-weight"),n=t.find(".j-np-place-width"),i=t.find(".j-np-place-length"),r=t.find(".j-np-place-height"),o=t.find(".j-np-place-volume-weight");e.numberMask({type:"float",afterPoint:3}),n.numberMask({type:"int"}),i.numberMask({type:"int"}),r.numberMask({type:"int"});var a=function(){var t,e=1*n.val(),a=1*i.val(),s=1*r.val();t=0==Math.min(e,a,s)?"<i>Укажите габариты</i>":(e*a*s/4e3).toFixed(4),o.empty().append(t)};a(),n.off("change.NP").on("change.NP",a),i.off("change.NP").on("change.NP",a),r.off("change.NP").on("change.NP",a)},initPlaceAttributeSetter:function(t){var e=this;t.find(".j-np-separated-place :input").off("change.CheckoutModule").on("change.CheckoutModule",(function(){var n=t.find(".j-np-separated-place .j-place-input").map((function(){var t=i(this),e=t.val();return"checkbox"===t.attr("type")&&(e=t.is(":checked")?1:0),{name:t.attr("name"),value:e}})).toArray();e.owner.setAttributes(n)}))}})}}]);