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 GmbH & Co. KG, 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.workplace.tools.accounts;
029
030import org.opencms.main.OpenCms;
031import org.opencms.security.CmsOrganizationalUnit;
032import org.opencms.widgets.CmsDisplayWidget;
033import org.opencms.workplace.CmsWidgetDialogParameter;
034
035import javax.servlet.http.HttpServletRequest;
036import javax.servlet.http.HttpServletResponse;
037import javax.servlet.jsp.PageContext;
038
039/**
040 * Dialog to get an overview of an organizational unit in the administration view.<p>
041 *
042 * @since 6.5.6
043 */
044public class CmsOrgUnitOverviewDialog extends A_CmsOrgUnitDialog {
045
046    /**
047     * Public constructor with JSP variables.<p>
048     *
049     * @param context the JSP page context
050     * @param req the JSP request
051     * @param res the JSP response
052     */
053    public CmsOrgUnitOverviewDialog(PageContext context, HttpServletRequest req, HttpServletResponse res) {
054
055        super(context, req, res);
056    }
057
058    /**
059     * @see org.opencms.workplace.CmsWidgetDialog#actionCommit()
060     */
061    @Override
062    public void actionCommit() {
063
064        // noop
065    }
066
067    /**
068     * Creates the dialog HTML for all defined widgets of the named dialog (page).<p>
069     *
070     * This overwrites the method from the super class to create a layout variation for the widgets.<p>
071     *
072     * @param dialog the dialog (page) to get the HTML for
073     * @return the dialog HTML for all defined widgets of the named dialog (page)
074     */
075    @Override
076    protected String createDialogHtml(String dialog) {
077
078        StringBuffer result = new StringBuffer(1024);
079
080        result.append(createWidgetTableStart());
081        // show error header once if there were validation errors
082        result.append(createWidgetErrorHeader());
083
084        if (dialog.equals(PAGES[0])) {
085            // create the widgets for the first dialog page
086            result.append(dialogBlockStart(key(Messages.GUI_ORGUNIT_EDITOR_LABEL_IDENTIFICATION_BLOCK_0)));
087            result.append(createWidgetTableStart());
088            result.append(createDialogRowsHtml(0, 2));
089            result.append(createWidgetTableEnd());
090            result.append(dialogBlockEnd());
091        }
092
093        result.append(createWidgetTableEnd());
094        return result.toString();
095    }
096
097    /**
098     * @see org.opencms.workplace.CmsWidgetDialog#defaultActionHtmlEnd()
099     */
100    @Override
101    protected String defaultActionHtmlEnd() {
102
103        return "";
104    }
105
106    /**
107     * @see org.opencms.workplace.CmsWidgetDialog#defineWidgets()
108     */
109    @Override
110    protected void defineWidgets() {
111
112        // initialize the user object to use for the dialog
113        initOrgUnitObject();
114
115        setKeyPrefix(KEY_PREFIX);
116
117        // widgets to display
118        addWidget(new CmsWidgetDialogParameter(m_orgUnitBean, "name", PAGES[0], new CmsDisplayWidget()));
119        addWidget(new CmsWidgetDialogParameter(m_orgUnitBean, "description", PAGES[0], new CmsDisplayWidget()));
120        addWidget(new CmsWidgetDialogParameter(m_orgUnitBean, "parentOu", PAGES[0], new CmsDisplayWidget()));
121    }
122
123    /**
124     * Initializes the organizational unit object to work with depending on the dialog state and request parameters.<p>
125     *
126     */
127    @Override
128    protected void initOrgUnitObject() {
129
130        try {
131            CmsOrganizationalUnit orgunit = OpenCms.getOrgUnitManager().readOrganizationalUnit(
132                getCms(),
133                getParamOufqn());
134            m_orgUnitBean = new CmsOrgUnitBean();
135            m_orgUnitBean.setDescription(orgunit.getDescription(getLocale()));
136            m_orgUnitBean.setName(orgunit.getName());
137            if (!orgunit.getName().equals("")) {
138                m_orgUnitBean.setParentOu(orgunit.getParentFqn());
139            }
140            m_orgUnitBean.setFqn(orgunit.getName());
141            setResourcesInBean(
142                m_orgUnitBean,
143                OpenCms.getOrgUnitManager().getResourcesForOrganizationalUnit(getCms(), orgunit.getName()));
144        } catch (Exception e) {
145            // noop
146        }
147    }
148}