001: /*
002: * File : $Source: /usr/local/cvs/opencms/src/org/opencms/widgets/CmsOrgUnitWidget.java,v $
003: * Date : $Date: 2008-02-27 12:05:43 $
004: * Version: $Revision: 1.4 $
005: *
006: * This library is part of OpenCms -
007: * the Open Source Content Management System
008: *
009: * Copyright (c) 2002 - 2008 Alkacon Software GmbH (http://www.alkacon.com)
010: *
011: * This library is free software; you can redistribute it and/or
012: * modify it under the terms of the GNU Lesser General Public
013: * License as published by the Free Software Foundation; either
014: * version 2.1 of the License, or (at your option) any later version.
015: *
016: * This library is distributed in the hope that it will be useful,
017: * but WITHOUT ANY WARRANTY; without even the implied warranty of
018: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: * Lesser General Public License for more details.
020: *
021: * For further information about Alkacon Software GmbH, please see the
022: * company website: http://www.alkacon.com
023: *
024: * For further information about OpenCms, please see the
025: * project website: http://www.opencms.org
026: *
027: * You should have received a copy of the GNU Lesser General Public
028: * License along with this library; if not, write to the Free Software
029: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
030: */
031:
032: package org.opencms.widgets;
033:
034: import org.opencms.file.CmsObject;
035: import org.opencms.main.OpenCms;
036: import org.opencms.security.CmsRole;
037: import org.opencms.util.CmsStringUtil;
038: import org.opencms.workplace.CmsWorkplace;
039:
040: /**
041: * Provides a OpenCms orgaizational unit selection widget, for use on a widget dialog.<p>
042: *
043: * @author Raphael Schnuck
044: * @author Michael Moossen
045: *
046: * @version $Revision: 1.4 $
047: *
048: * @since 6.5.6
049: */
050: public class CmsOrgUnitWidget extends A_CmsWidget {
051:
052: /** Configuration parameter to set the role the current user must have in the selected ou, optional. */
053: public static final String CONFIGURATION_ROLE = "role";
054:
055: /** The role used in the popup window. */
056: private CmsRole m_role;
057:
058: /**
059: * Creates a new organizational unit selection widget.<p>
060: */
061: public CmsOrgUnitWidget() {
062:
063: // empty constructor is required for class registration
064: this ("");
065: }
066:
067: /**
068: * Creates a new user selection widget with the parameters to configure the popup window behaviour.<p>
069: *
070: * @param role the role to restrict the organizational unit selection, can be <code>null</code>
071: */
072: public CmsOrgUnitWidget(CmsRole role) {
073:
074: m_role = role;
075: }
076:
077: /**
078: * Creates a new organizational unit selection widget with the given configuration.<p>
079: *
080: * @param configuration the configuration to use
081: */
082: public CmsOrgUnitWidget(String configuration) {
083:
084: super (configuration);
085:
086: }
087:
088: /**
089: * @see org.opencms.widgets.A_CmsWidget#getConfiguration()
090: */
091: public String getConfiguration() {
092:
093: StringBuffer result = new StringBuffer(8);
094:
095: // append flags to configuration
096: if (m_role != null) {
097: if (result.length() > 0) {
098: result.append("|");
099: }
100: result.append(CONFIGURATION_ROLE);
101: result.append("=");
102: result.append(m_role.getGroupName());
103: }
104:
105: return result.toString();
106: }
107:
108: /**
109: * @see org.opencms.widgets.I_CmsWidget#getDialogIncludes(org.opencms.file.CmsObject, org.opencms.widgets.I_CmsWidgetDialog)
110: */
111: public String getDialogIncludes(CmsObject cms,
112: I_CmsWidgetDialog widgetDialog) {
113:
114: StringBuffer result = new StringBuffer(16);
115: result.append(getJSIncludeFile(CmsWorkplace.getSkinUri()
116: + "components/widgets/orgunitselector.js"));
117: return result.toString();
118: }
119:
120: /**
121: * @see org.opencms.widgets.I_CmsWidget#getDialogWidget(org.opencms.file.CmsObject, org.opencms.widgets.I_CmsWidgetDialog, org.opencms.widgets.I_CmsWidgetParameter)
122: */
123: public String getDialogWidget(CmsObject cms,
124: I_CmsWidgetDialog widgetDialog, I_CmsWidgetParameter param) {
125:
126: String id = param.getId();
127: StringBuffer result = new StringBuffer(128);
128:
129: result.append("<td class=\"xmlTd\">");
130: result
131: .append("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"maxwidth\"><tr><td style=\"width: 100%;\">");
132: result.append("<input style=\"width: 99%;\" class=\"xmlInput");
133: if (param.hasError()) {
134: result.append(" xmlInputError");
135: }
136: result.append("\" value=\"");
137: result.append(param.getStringValue(cms));
138: result.append("\" name=\"");
139: result.append(id);
140: result.append("\" id=\"");
141: result.append(id);
142: result.append("\"></td>");
143: result.append(widgetDialog.dialogHorizontalSpacer(10));
144: result
145: .append("<td><table class=\"editorbuttonbackground\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr>");
146:
147: StringBuffer buttonJs = new StringBuffer(8);
148: buttonJs.append("javascript:openOrgUnitWin('");
149: buttonJs.append(OpenCms.getSystemInfo().getOpenCmsContext());
150: buttonJs
151: .append("/system/workplace/commons/orgunit_selection.jsp");
152: buttonJs.append("','EDITOR', '");
153: buttonJs.append(id);
154: buttonJs.append("', document, ");
155: if (m_role != null) {
156: buttonJs.append("'");
157: buttonJs.append(m_role.getGroupName());
158: buttonJs.append("'");
159: } else {
160: buttonJs.append("null");
161: }
162: buttonJs.append(");");
163:
164: result
165: .append(widgetDialog
166: .button(
167: buttonJs.toString(),
168: null,
169: "orgunit",
170: org.opencms.workplace.Messages.GUI_DIALOG_BUTTON_SEARCH_0,
171: widgetDialog.getButtonStyle()));
172: result.append("</tr></table>");
173: result.append("</td></tr></table>");
174:
175: result.append("</td>");
176:
177: return result.toString();
178: }
179:
180: /**
181: * Returns the role, or <code>null</code> if none.<p>
182: *
183: * @return the role, or <code>null</code> if none
184: */
185: public CmsRole getRole() {
186:
187: return m_role;
188: }
189:
190: /**
191: * @see org.opencms.widgets.I_CmsWidget#newInstance()
192: */
193: public I_CmsWidget newInstance() {
194:
195: return new CmsOrgUnitWidget(getConfiguration());
196: }
197:
198: /**
199: * @see org.opencms.widgets.A_CmsWidget#setConfiguration(java.lang.String)
200: */
201: public void setConfiguration(String configuration) {
202:
203: m_role = null;
204: if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(configuration)) {
205: int roleIndex = configuration.indexOf(CONFIGURATION_ROLE);
206: if (roleIndex != -1) {
207: // role is given
208: String groupName = configuration
209: .substring(CONFIGURATION_ROLE.length() + 1);
210: if (groupName.indexOf('|') != -1) {
211: // cut eventual following configuration values
212: groupName = groupName.substring(0, groupName
213: .indexOf('|'));
214: }
215: m_role = CmsRole.valueOfGroupName(groupName);
216: }
217: }
218: super.setConfiguration(configuration);
219: }
220: }
|