"use strict";(self.webpackChunkPlesk=self.webpackChunkPlesk||[]).push([["app/change-customers-owner"],{2617:(e,t,s)=>{s.r(t),s.d(t,{default:()=>d});var i=s(89);class n extends i.ConfirmationPopupManager.PopupForm{_initConfiguration(e){super._initConfiguration({locale:i.Locale.getSection("admin.components.confirmations.change-customer-owner"),...e})}_onSuccessPreparePopup(e){if(this._clearMessages(),this._owners=$H(),this._response=e,"success"===this._response.status){document.getElementById(this._formBoxAreaId).innerHTML=`<p>${this.lmsg("ownerHint")}</p>${this.getOwnerSelectorHtml()}`,document.getElementById("owners").addEventListener("change",this.onOwnerChange.bind(this)),document.getElementById(this._formListAreaId).innerHTML=`<table cellspacing="0" width="100%"><tbody id="${this._formListItemsAreaId}"></tbody></table>`;let e=!1;$H(this._response.customers).each((({value:t})=>{0!==t.subscriptions.length&&(e=!0),this.addCustomer(t)})),e||(document.getElementById(this._formDescriptionId).innerHTML="")}else this._addErrorMessage(this._response.message)}getOwnerSelectorHtml(){let e='<select class="owners" name="owners" id="owners">';return(this._response.owners||[]).forEach((t=>{e+=`<option value="${t.id}">${(0,i.escapeHtml)(t.name)}</option>`,this._owners.set(t.id,t)})),e+="</select>",e}onOwnerChange(){$H(this._response.customers).each((({value:e})=>{0!==e.subscriptions.length&&$H(e.subscriptions).each((({value:e})=>{document.getElementById(`plans-box-${e.id}`).innerHTML=this.getPlanSelectorHtml(e),document.getElementById(`ipV4-box-${e.id}`).innerHTML=this.getIpAddressSelectorHtml(e,"ipV4"),document.getElementById(`ipV6-box-${e.id}`).innerHTML=this.getIpAddressSelectorHtml(e,"ipV6")}))}))}addCustomer(e){if(0===e.subscriptions.length){this._itemClass="odd"===this._itemClass?"even":"odd";const t=`<tr class="${this._itemClass}"><td><b>${(0,i.escapeHtml)(e.name)}</b></td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>`;(0,i.render)(document.getElementById(this._formListItemsAreaId),t)}else{let t=e.name;$H(e.subscriptions).each((({value:e})=>{this.addSubscription(e,t),t=" "}))}}addSubscription(e,t){this._itemClass="odd"===this._itemClass?"even":"odd";const s=`<tr class="${this._itemClass}"><td><b>${(0,i.escapeHtml)(t)}</b></td><td>${(0,i.escapeHtml)(e.name)}</td><td id="plans-box-${e.id}">${this.getPlanSelectorHtml(e)}</td><td id="ipV4-box-${e.id}">${this.getIpAddressSelectorHtml(e,"ipV4")}</td><td id="ipV6-box-${e.id}">${this.getIpAddressSelectorHtml(e,"ipV6")}</td></tr>`;(0,i.render)(document.getElementById(this._formListItemsAreaId),s)}getPlanSelectorHtml({id:e}){const t=this.getSelectedOwner();if(0===t.plans.length)return"";let s=`<select class="plans" name="plans[${e}]" id="plans-${e}">`;return $H(t.plans).each((({value:e})=>{void 0!==e.id&&(s+=`<option value="${e.id}">${(0,i.escapeHtml)(e.name)}</option>`)})),s+="</select>",s}getIpAddressSelectorHtml(e,t){const s=this.getSelectedOwner();if(void 0===s[t])return"";const{id:i}=e;let n=`<select class="${t}" name="${t}[${i}]" id="${t}-${i}">`;return $H(s[t]).each((({value:s})=>{if(void 0!==s.id){const i=s.id==e[t].id?"selected":"";n+=`<option value="${s.id}" ${i}>${s.description}</option>`}})),n+="</select>",e[t].isDedicated&&(n+=`<div class="hint-sub hint-attention">${this.lmsg("ipAddressHint")}</div>`),n}getSelectedOwner(){return this._owners.get(document.getElementById("owners").value)}_isValid(){return this._valid=!0,this.getSelectedOwner().id?($H(this._response.customers).each((({value:e})=>{0!==e.subscriptions.length&&$H(e.subscriptions).each((({value:e})=>{if(this._valid){const{id:t}=e,s=document.getElementById(`ipV4-${t}`)?document.getElementById(`ipV4-${t}`).value:0,i=document.getElementById(`ipV6-${t}`)?document.getElementById(`ipV6-${t}`).value:0;s||i||(this._addErrorMessage(this.lmsg("ipAddressNotSelected")),this._valid=!1)}}))})),this._valid):(this._addErrorMessage(this.lmsg("ownerNotSelected")),!1)}_getAdditionalParams(e){return e.set("owner-id",document.getElementById("owners").value),document.querySelectorAll(".plans").forEach((({id:t,value:s})=>{e.set(`plans[${t.replace("plans-","")}]`,s)})),document.querySelectorAll(".ipV4").forEach((({id:t,value:s})=>{e.set(`ipV4[${t.replace("ipV4-","")}]`,s)})),document.querySelectorAll(".ipV6").forEach((({id:t,value:s})=>{e.set(`ipV6[${t.replace("ipV6-","")}]`,s)})),e}}const d=n}}]);
//# sourceMappingURL=change-customers-owner.js.map?cdcb0726d4c57f57788c