Liferay.Loader.define("wiki-web@7.0.59/wiki/js/WikiPortlet.es",["module","exports","require","frontend-js-web"],(function(t,e,n){window;{Object.defineProperty(e,"__esModule",{value:!0}),e.default=void 0;var o=n("frontend-js-web");const t=Liferay.Language.get("uploads-are-in-progress-confirmation"),a=Liferay.Language.get("you-may-lose-formatting-when-switching-from-x-to-x");class i{constructor({constants:e,currentAction:n,namespace:o,renderUrl:s,rootNodeId:i,strings:r={confirmDiscardImages:t,confirmLoseFormatting:a}}){this._constants=e,this._currentAction=n,this._namespace=o,this._renderUrl=s,this._strings=r,this.rootNode=document.getElementById(i),this.workflowActionInputNode=document.getElementById("".concat(o,"workflowAction")),this._events=[],this._attachEvents()}dispose(){this._events.forEach((({event:t,listener:e,target:n})=>n.removeEventListener(t,e))),this._events=[]}_addEventListener(t,e,n){t.addEventListener(e,n),this._events.push({event:e,fn:n,target:t})}_attachEvents(){const t=this._namespace,e=document.getElementById("".concat(t,"format"));e&&(this._currentFormatLabel=e.options[e.selectedIndex].text.trim(),this._currentFormatIndex=e.selectedIndex,this._addEventListener(e,"change",(t=>{this._changeWikiFormat(t)})));const n=document.getElementById("".concat(t,"publishButton"));n&&this._addEventListener(n,"click",(()=>{this.workflowActionInputNode.value=this._constants.ACTION_PUBLISH,this._save()}));const o=document.getElementById("".concat(t,"saveButton"));o&&this._addEventListener(o,"click",(()=>{this.workflowActionInputNode.value=this._constants.ACTION_SAVE_DRAFT,this._save()}));const s="".concat(t,"pageAttachments");Liferay.componentReady(s).then((t=>{t.get("contentBox").delegate("click",this._removeAttachment.bind(this),".delete-attachment")})),this.searchContainerId=s}_changeWikiFormat(t){const e=t.currentTarget,n=e.options[e.selectedIndex].text.trim(),s=(0,o.sub)(this._strings.confirmLoseFormatting,this._currentFormatLabel,n);(0,o.openConfirmModal)({message:s,onConfirm:t=>{if(t){this.rootNode.querySelector('[name="'.concat(this._namespace,'fm"]')).setAttribute("action",this._renderUrl),this._save()}else e.selectedIndex=this.currentFormatIndex}})}_removeAttachment(t){const e=t.currentTarget,n=e.getAttribute("data-url");(0,o.fetch)(n).then((()=>{Liferay.componentReady(this.searchContainerId).then((t=>{t.deleteRow(e.ancestor("tr"),e.getAttribute("data-rowid")),t.updateDataStore()}))}))}_maybeRemoveTempImages(t){const e=this.rootNode.querySelector("img[data-random-id]");e&&e.length?(0,o.openConfirmModal)({message:this._strings.confirmDiscardImages,onConfirm:n=>{n&&(e.forEach((t=>{t.parentElement.remove()})),t())}}):t()}_save(){const t=this._namespace;this._maybeRemoveTempImages((()=>{document.getElementById(t+this._constants.CMD).value=this._currentAction;const e=window["".concat(t,"contentEditor")];e&&(document.getElementById("".concat(t,"content")).value=e.getHTML()),submitForm(document["".concat(t,"fm")])}))}}var s=i;e.default=s}}));
//# sourceMappingURL=WikiPortlet.es.js.map