AUI.add("liferay-staging",function(b){Liferay.StagingBar={init:function(a){var d=a.namespace;this.markAsReadyForPublicationURL=a.markAsReadyForPublicationURL;this.layoutRevisionStatusURL=a.layoutRevisionStatusURL;this._namespace=d;this.viewHistoryURL=a.viewHistoryURL;Liferay.publish({fireOnce:!0});Liferay.after("initStagingBar",function(){var c=b.getBody();if(c.hasClass("has-staging-bar")){var e=b.one(".staging-bar-level-3-message");c.addClass(null===e?"staging-ready":"staging-ready-level-3")}});
Liferay.fire("initStagingBar",a)}}},"",{requires:["aui-io-plugin-deprecated","aui-modal"]});
AUI.add("liferay-staging-branch",function(b){var d=b.Lang;b.mix(Liferay.StagingBar,{_getBranchDialog:function(){var a=this._branchDialog;a||(this._branchDialog=a=Liferay.Util.Window.getWindow({dialog:{bodyContent:b.one("#"+this._namespace+"addBranch").show()},title:"Branch"}));return a},addBranch:function(a){var c=this._getBranchDialog();d.isValue(a)&&c.set("title",a);c.show()}})},"",{requires:["liferay-staging"]});
AUI.add("liferay-staging-version",function(d){var g=Liferay.StagingBar,k={redo:"redo_layout_revision",undo:"undo_layout_revision"},l={redo:"Are you sure you want to redo your last changes?",undo:"Are you sure you want to undo your last changes?"};d.mix(g,{_cleanup:function(){this._eventHandles&&d.Array.invoke(this._eventHandles,"detach")},_onInit:function(){var a=this;a._cleanup();var b=a._namespace,c=[Liferay.on(b+"redo",a._onRevisionChange,a,"redo"),Liferay.on(b+"submit",a._onSubmit,a),Liferay.on(b+
"undo",a._onRevisionChange,a,"undo"),Liferay.on(b+"viewHistory",a._onViewHistory,a)],e=d.one("#"+b+"layoutRevisionDetails"),h=d.one("#"+b+"layoutRevisionStatus");e&&c.push(Liferay.after("updatedLayout",function(){Liferay.Util.fetch(a.markAsReadyForPublicationURL).then(function(f){return f.text()}).then(function(f){e.plug(d.Plugin.ParseContent);e.setContent(f);Liferay.fire("updatedStatus")}).catch(function(){e.setContent("There was an unexpected error. Please refresh the current page.")})}));h&&Liferay.after("updatedStatus",
function(){Liferay.Util.fetch(a.layoutRevisionStatusURL).then(function(f){return f.text()}).then(function(f){h.plug(d.Plugin.ParseContent);h.setContent(f)}).catch(function(){h.setContent("There was an unexpected error. Please refresh the current page.")})});a._eventHandles=c},_onRevisionChange:function(a,b){var c=k[b];confirm(l[b])&&this._updateRevision(c,a.layoutRevisionId,a.layoutSetBranchId)},_onSubmit:function(a){var b=this._namespace,c=d.one("#"+b+"layoutRevisionDetails"),e=c.one(".layout-revision-info");
e&&e.addClass("loading");(b=d.one("#"+b+"submitLink"))&&b.html("Loading...");Liferay.Util.fetch(a.publishURL).then(function(){a.incomplete?location.href=a.currentURL:Liferay.fire("updatedLayout")}).catch(function(){c.addClass("alert alert-danger");c.setContent("There was an unexpected error. Please refresh the current page.")})},_onViewHistory:function(){Liferay.Util.openWindow({dialog:{after:{destroy:function(){window.location.reload()}},destroyOnHide:!0},title:"History",uri:g.viewHistoryURL})},
_updateRevision:function(a,b,c){a={cmd:a,doAsUserId:themeDisplay.getDoAsUserIdEncoded(),layoutRevisionId:b,layoutSetBranchId:c,p_auth:Liferay.authToken,p_l_id:themeDisplay.getPlid(),p_v_l_s_g_id:themeDisplay.getSiteGroupId()};Liferay.Util.fetch(themeDisplay.getPathMain()+"/portal/update_layout",{body:Liferay.Util.objectToFormData(a),method:"POST"}).then(function(){window.location.reload()}).catch(function(){Liferay.Util.openToast({message:"There was an unexpected error. Please refresh the current page.",
toastProps:{autoClose:1E4},type:"warning"})})},destructor:function(){this._cleanup()}});Liferay.on("initStagingBar",g._onInit,g)},"",{requires:["aui-button","liferay-staging"]});
