001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * For further information about Alkacon Software, please see the
018 * company website: http://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: http://www.opencms.org
022 *
023 * You should have received a copy of the GNU Lesser General Public
024 * License along with this library; if not, write to the Free Software
025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
026 */
027
028package org.opencms.ade.publish.client;
029
030import org.opencms.ade.publish.shared.CmsPublishData;
031import org.opencms.gwt.client.A_CmsEntryPoint;
032import org.opencms.gwt.client.CmsCoreProvider;
033import org.opencms.gwt.client.rpc.CmsRpcPrefetcher;
034import org.opencms.gwt.client.ui.CmsErrorDialog;
035import org.opencms.gwt.client.ui.contenteditor.I_CmsContentEditorHandler;
036import org.opencms.gwt.client.util.CmsJsUtil;
037import org.opencms.util.CmsUUID;
038
039import com.google.gwt.event.logical.shared.CloseEvent;
040import com.google.gwt.event.logical.shared.CloseHandler;
041import com.google.gwt.user.client.Window;
042import com.google.gwt.user.client.ui.PopupPanel;
043
044/**
045 * The entry point for the publish module.
046 *
047 * @since 8.0.0
048 */
049public class CmsPublishEntryPoint extends A_CmsEntryPoint {
050
051    /**
052     * @see org.opencms.gwt.client.A_CmsEntryPoint#onModuleLoad()
053     */
054    @Override
055    public void onModuleLoad() {
056
057        super.onModuleLoad();
058        CmsPublishData initData = null;
059        try {
060            initData = (CmsPublishData)CmsRpcPrefetcher.getSerializedObjectFromDictionary(
061                CmsPublishDialog.getService(),
062                CmsPublishData.DICT_NAME);
063            String closeLink = initData.getCloseLink();
064            if (closeLink == null) {
065                closeLink = CmsCoreProvider.get().getDefaultWorkplaceLink();
066            }
067            final String constCloseLink = closeLink;
068            final boolean confirm = initData.isShowConfirmation();
069            CloseHandler<PopupPanel> closeHandler = new CloseHandler<PopupPanel>() {
070
071                public void onClose(CloseEvent<PopupPanel> event) {
072
073                    CmsPublishDialog dialog = (CmsPublishDialog)(event.getTarget());
074                    if (confirm && (dialog.hasSucceeded() || dialog.hasFailed())) {
075                        CmsPublishConfirmationDialog confirmation = new CmsPublishConfirmationDialog(
076                            dialog,
077                            constCloseLink);
078                        confirmation.center();
079                    } else {
080                        // 'cancel' case
081                        CmsJsUtil.closeWindow();
082                        // in case the window isn't successfully closed, go to the workplace
083                        Window.Location.assign(constCloseLink);
084                    }
085                }
086            };
087
088            CmsPublishDialog.showPublishDialog(initData, closeHandler, new Runnable() {
089
090                public void run() {
091
092                    Window.Location.reload();
093                }
094
095            }, new I_CmsContentEditorHandler() {
096
097                public void onClose(
098                    String sitePath,
099                    CmsUUID structureId,
100                    boolean isNew,
101                    boolean hasChangedSettings,
102                    boolean usedPublishDialog) {
103
104                    // nothing to do
105                }
106            });
107        } catch (Exception e) {
108            CmsErrorDialog.handleException(e);
109        }
110    }
111}