(self.webpackChunkPlesk=self.webpackChunkPlesk||[]).push([["app/change-customers-owner"],{1108:(e,t,s)=>{"use strict";s.r(t);var n=s(144);class c extends n.ConfirmationPopupManager.PopupForm{_initConfiguration(e){super._initConfiguration({locale:n.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>".concat(this.lmsg("ownerHint"),"</p>").concat(this.getOwnerSelectorHtml()),document.getElementById("owners").addEventListener("change",this.onOwnerChange.bind(this)),document.getElementById(this._formListAreaId).innerHTML='<table cellspacing="0" width="100%">'+'<tbody id="'.concat(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 $A(this._response.owners).each((t=>{e+='<option value="'.concat(t.id,'">').concat((0,n.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-".concat(e.id)).innerHTML=this.getPlanSelectorHtml(e),document.getElementById("ipV4-box-".concat(e.id)).innerHTML=this.getIpAddressSelectorHtml(e,"ipV4"),document.getElementById("ipV6-box-".concat(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="'.concat(this._itemClass,'">')+"<td><b>".concat((0,n.escapeHtml)(e.name),"</b></td>")+"<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>";(0,n.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="'.concat(this._itemClass,'">')+"<td><b>".concat((0,n.escapeHtml)(t),"</b></td>")+"<td>".concat((0,n.escapeHtml)(e.name),"</td>")+'<td id="plans-box-'.concat(e.id,'">').concat(this.getPlanSelectorHtml(e),"</td>")+'<td id="ipV4-box-'.concat(e.id,'">').concat(this.getIpAddressSelectorHtml(e,"ipV4"),"</td>")+'<td id="ipV6-box-'.concat(e.id,'">').concat(this.getIpAddressSelectorHtml(e,"ipV6"),"</td>")+"</tr>";(0,n.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['.concat(e,']" id="plans-').concat(e,'">');return $H(t.plans).each((({value:e})=>{void 0!==e.id&&(s+='<option value="'.concat(e.id,'">').concat((0,n.escapeHtml)(e.name),"</option>"))})),s+="</select>",s}getIpAddressSelectorHtml(e,t){const s=this.getSelectedOwner();if(void 0===s[t])return"";const{id:n}=e;let c='<select class="'.concat(t,'" name="').concat(t,"[").concat(n,']" id="').concat(t,"-").concat(n,'">');return $H(s[t]).each((({value:s})=>{if(void 0!==s.id){const n=s.id==e[t].id?"selected":"";c+='<option value="'.concat(s.id,'" ').concat(n,">").concat(s.description,"</option>")}})),c+="</select>",e[t].isDedicated&&(c+='<div class="hint-sub hint-attention">'.concat(this.lmsg("ipAddressHint"),"</div>")),c}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-".concat(t))?document.getElementById("ipV4-".concat(t)).value:0,n=document.getElementById("ipV6-".concat(t))?document.getElementById("ipV6-".concat(t)).value:0;s||n||(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[".concat(t.replace("plans-",""),"]"),s)})),document.querySelectorAll(".ipV4").forEach((({id:t,value:s})=>{e.set("ipV4[".concat(t.replace("ipV4-",""),"]"),s)})),document.querySelectorAll(".ipV6").forEach((({id:t,value:s})=>{e.set("ipV6[".concat(t.replace("ipV6-",""),"]"),s)})),e}}t.default=c}}]);
//# sourceMappingURL=change-customers-owner.js.map?f2699aef49251c3d5d94