group-create.jsp 14.4 KB
Newer Older
Matt Tucker's avatar
Matt Tucker committed
1 2 3 4 5 6 7 8 9 10
<%--
  -	$RCSfile$
  -	$Revision$
  -	$Date$
  -
  - Copyright (C) 2004 Jive Software. All rights reserved.
  -
  - This software is published under the terms of the GNU Public License (GPL),
  - a copy of which is included in this distribution.
--%>
11 12

<%@ page import="org.jivesoftware.util.*,
Matt Tucker's avatar
Matt Tucker committed
13 14 15 16 17 18 19 20 21 22 23 24
                 java.util.HashMap,
                 java.util.Map,
                 java.util.*,
                 org.jivesoftware.messenger.*,
                 org.jivesoftware.admin.*,
                 java.io.StringWriter,
                 java.io.StringWriter,
                 java.io.IOException,
                 org.jivesoftware.messenger.auth.UnauthorizedException,
                 java.io.PrintStream,
                 org.dom4j.xpath.DefaultXPath,
                 org.dom4j.*,
Derek DeMoro's avatar
Derek DeMoro committed
25
                 org.jivesoftware.messenger.group.*,
26 27 28 29 30 31 32
                 java.net.URLEncoder,
                 org.jivesoftware.messenger.user.UserManager,
                 org.jivesoftware.messenger.user.UserNotFoundException"
    errorPage="error.jsp"
%>

<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
33
<%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt" %>
34

35 36
<jsp:useBean id="webManager" class="org.jivesoftware.util.WebManager" />
<jsp:useBean id="errors" class="java.util.HashMap" />
37 38 39 40

<%  webManager.init(request, response, session, application, out); %>

<%  // Get parameters //
Matt Tucker's avatar
Matt Tucker committed
41 42
    boolean create = request.getParameter("create") != null;
    boolean cancel = request.getParameter("cancel") != null;
43 44 45 46 47 48 49 50 51 52 53 54 55 56
    String name = ParamUtils.getParameter(request, "name");
    String description = ParamUtils.getParameter(request, "description");
    String users = ParamUtils.getParameter(request, "users", true);

    boolean enableRosterGroups = ParamUtils.getBooleanParameter(request,"enableRosterGroups");
    String groupDisplayName = ParamUtils.getParameter(request,"groupDisplayName");
    String showGroup = ParamUtils.getParameter(request,"showGroup");
    String[] groupNames = ParamUtils.getParameters(request, "groupNames");

//    String showInRosterType = ParamUtils.getParameter(request, "show");
//    boolean showInRoster = "onlyGroup".equals(showInRosterType) || "everybody".equals(showInRosterType);
//    String displayName = ParamUtils.getParameter(request, "display");
//    String groupList = ParamUtils.getParameter(request, "groupList");

Matt Tucker's avatar
Matt Tucker committed
57 58 59 60 61 62 63 64 65
    // Handle a cancel
    if (cancel) {
        response.sendRedirect("group-summary.jsp");
        return;
    }
    // Handle a request to create a group:
    if (create) {
        // Validate
        if (name == null) {
66
            errors.put("name", "");
Matt Tucker's avatar
Matt Tucker committed
67
        }
68 69 70 71
        if (enableRosterGroups) {
            if (groupDisplayName == null) {
                errors.put("groupDisplayName", "");
            }
72
            if ("spefgroups".equals(showGroup) && (groupNames == null || groupNames.length == 0)) {
73 74
                errors.put("groupNames","");
            }
75
        }
Matt Tucker's avatar
Matt Tucker committed
76 77 78 79 80 81 82
        // do a create if there were no errors
        if (errors.size() == 0) {
            try {
                Group newGroup = webManager.getGroupManager().createGroup(name);
                if (description != null) {
                    newGroup.setDescription(description);
                }
83 84 85 86
                if (enableRosterGroups) {
                    if ("spefgroups".equals(showGroup)) {
                        showGroup = "onlyGroup";
                    }
87
                    newGroup.getProperties().put("sharedRoster.showInRoster", showGroup);
88 89 90
                    if (groupDisplayName != null) {
                        newGroup.getProperties().put("sharedRoster.displayName", groupDisplayName);
                    }
91
                    newGroup.getProperties().put("sharedRoster.groupList", toList(groupNames));
92 93
                }
                else {
94 95 96
                    newGroup.getProperties().put("sharedRoster.showInRoster", "nobody");
                    newGroup.getProperties().put("sharedRoster.displayName", "");
                    newGroup.getProperties().put("sharedRoster.groupList", "");
97
                }
Derek DeMoro's avatar
Derek DeMoro committed
98

99
                if (users.length() > 0){
100
                    StringTokenizer tokenizer = new StringTokenizer(users, ", \t\n\r\f");
Derek DeMoro's avatar
Derek DeMoro committed
101
                    while (tokenizer.hasMoreTokens()) {
102
                        String username = tokenizer.nextToken();
Matt Tucker's avatar
Matt Tucker committed
103 104 105
                        try {
                            UserManager.getInstance().getUser(username);
                            newGroup.getMembers().add(username);
Derek DeMoro's avatar
Derek DeMoro committed
106
                        }
Matt Tucker's avatar
Matt Tucker committed
107
                        catch (UserNotFoundException unfe) { }
108 109
                    }
                }
Matt Tucker's avatar
Matt Tucker committed
110
                // Successful, so redirect
Matt Tucker's avatar
Matt Tucker committed
111
                response.sendRedirect("group-edit.jsp?creategroupsuccess=true&group=" + URLEncoder.encode(newGroup.getName(), "UTF-8"));
Matt Tucker's avatar
Matt Tucker committed
112 113 114
                return;
            }
            catch (GroupAlreadyExistsException e) {
115
                errors.put("groupAlreadyExists", "");
Matt Tucker's avatar
Matt Tucker committed
116 117
            }
            catch (Exception e) {
118
                errors.put("general", "");
Matt Tucker's avatar
Matt Tucker committed
119 120 121 122
                Log.error(e);
            }
        }
    }
Bill Lynch's avatar
Bill Lynch committed
123 124 125 126

    if (errors.size() == 0) {
        showGroup = "everybody";
    }
Matt Tucker's avatar
Matt Tucker committed
127
%>
128 129 130

<jsp:useBean id="pageinfo" scope="request" class="org.jivesoftware.admin.AdminPageBean"/>

131
<% // Title of this page and breadcrumbs
132
    String title = LocaleUtils.getLocalizedString("group.create.title");
Matt Tucker's avatar
Matt Tucker committed
133
    pageinfo.setTitle(title);
134
    pageinfo.getBreadcrumbs().add(new AdminPageBean.Breadcrumb(LocaleUtils.getLocalizedString("global.main"), "index.jsp"));
Matt Tucker's avatar
Matt Tucker committed
135 136 137
    pageinfo.getBreadcrumbs().add(new AdminPageBean.Breadcrumb(title, "group-create.jsp"));
    pageinfo.setPageID("group-create");
%>
Gaston Dombiak's avatar
Gaston Dombiak committed
138

139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
<jsp:include page="top.jsp" flush="true"/>
<jsp:include page="title.jsp" flush="true"/>

<c:set var="submit" value="${param.create}"/>
<c:set var="errors" value="${errors}"/>

<%  if (errors.get("general") != null) { %>

    <div class="jive-success">
    <table cellpadding="0" cellspacing="0" border="0">
    <tbody>
        <tr>
            <td class="jive-icon">
                <img src="images/success-16x16.gif" width="16" height="16" border="0">
            </td>
            <td class="jive-icon-label">
155
                <fmt:message key="group.create.error" />
156 157 158 159 160 161 162 163
            </td>
        </tr>
    </tbody>
    </table>
    </div><br>

<%  } %>

164
<p>
165
<fmt:message key="group.create.form" />
166
</p>
167 168 169 170

<form name="f" action="group-create.jsp" method="post">

<fieldset>
171
    <legend><fmt:message key="group.create.new_group_title" /></legend>
172 173 174 175 176
    <div>

    <table cellpadding="3" cellspacing="0" border="0" width="100%">
    <tr valign="top">
        <td width="1%" nowrap>
177
            <label for="gname"><fmt:message key="group.create.group_name" /></label> *
178 179 180 181 182 183 184 185 186 187 188 189 190
        </td>
        <td width="99%">
            <input type="text" name="name" size="30" maxlength="75"
             value="<%= ((name != null) ? name : "") %>" id="gname">
        </td>
    </tr>

    <%  if (errors.get("name") != null || errors.get("groupAlreadyExists") != null) { %>

        <tr valign="top">
            <td width="1%" nowrap>&nbsp;</td>
            <td width="99%">
                <%  if (errors.get("name") != null) { %>
191
                    <span class="jive-error-text"><fmt:message key="group.create.invalid_group_name" /></span>
192
                <%  } else if (errors.get("groupAlreadyExists") != null) { %>
193
                    <span class="jive-error-text"><fmt:message key="group.create.invalid_group_info" /></span>
194 195 196 197 198 199 200 201
                <%  } %>
            </td>
        </tr>

    <%  } %>

    <tr valign="top">
        <td width="1%" nowrap>
202
            <label for="gdesc"><fmt:message key="group.create.label_description" /></label>
203 204 205 206 207 208 209 210 211 212 213 214 215 216
        </td>
        <td width="99%">
            <textarea name="description" cols="30" rows="3" id="gdesc"
             ><%= ((description != null) ? description : "") %></textarea>
        </td>
    </tr>

    <%  if (errors.get("description") != null) { %>

        <tr valign="top">
            <td width="1%" nowrap>
                &nbsp;
            </td>
            <td width="99%">
217
                <span class="jive-error-text"><fmt:message key="group.create.invalid_description" /></span>
218 219 220 221 222 223 224
            </td>
        </tr>

    <%  } %>

    <tr>
        <td nowrap width="1%" valign="top">
225
            <fmt:message key="group.create.label_initial_member" />
226 227 228 229 230 231 232 233 234
        </td>
        <td nowrap class="c1" align="left">
            <textarea name="users" cols="30" rows="3" id="gdesc"
             ><%= ((users != null) ? users : "") %></textarea>
        </td>
    </tr>
    </table>

    <br>
235
    <p><b><fmt:message key="group.create.share_groups_title" /></b></p>
236

Bill Lynch's avatar
Bill Lynch committed
237
    <p>
238
    <fmt:message key="group.create.share_groups_info" />
Bill Lynch's avatar
Bill Lynch committed
239 240
    </p>

241 242 243 244 245 246 247
    <table cellpadding="3" cellspacing="0" border="0" width="100%">
    <tbody>
        <tr>
            <td width="1%">
                <input type="radio" name="enableRosterGroups" value="false" id="rb201" <%= !enableRosterGroups ? "checked" : "" %>>
            </td>
            <td width="99%">
248
                <label for="rb201"><fmt:message key="group.create.disable_share_group" /></label>
249 250 251 252 253 254 255
            </td>
        </tr>
        <tr>
            <td width="1%">
                <input type="radio" name="enableRosterGroups" value="true" id="rb202" <%= enableRosterGroups ? "checked" : "" %>>
            </td>
            <td width="99%">
256
                <label for="rb202"><fmt:message key="group.create.enable_share_group" /></label>
257 258 259 260 261 262 263 264 265
            </td>
        </tr>
        <tr>
            <td width="1%">
                &nbsp;
            </td>
            <td width="99%">

                <table cellpadding="3" cellspacing="0" border="0" width="100%">
266 267
                <tbody>
                    <tr>
268
                        <td width="1%" nowrap>
269
                            <fmt:message key="group.create.group_display_name" />
270
                        </td>
271 272 273
                        <td width="99%">
                            <input type="text" name="groupDisplayName" size="30" maxlength="100" value="<%= (groupDisplayName != null ? groupDisplayName : "") %>"
                             onclick="this.form.enableRosterGroups[1].checked=true;">
274 275 276

                            <%  if (errors.get("groupDisplayName") != null) { %>

277
                                    <span class="jive-error-text"><fmt:message key="group.create.enter_a_group_name" /></span>
278 279

                            <%  } %>
280 281 282
                        </td>
                    </tr>
                </tbody>
283 284
                </table>

285
                <table cellpadding="3" cellspacing="0" border="0" width="100%">
286 287
                <tbody>
                    <tr>
288
                        <td width="1%" nowrap>
289 290 291
                            <input type="radio" name="showGroup" value="everybody" id="rb002"
                             onclick="this.form.enableRosterGroups[1].checked=true;"
                             <%= ("everybody".equals(showGroup) ? "checked" : "") %>>
292 293
                        </td>
                        <td width="99%">
294
                            <label for="rb002"><fmt:message key="group.create.show_group_in_all_users" /></label>
295 296
                        </td>
                    </tr>
297
                    <tr>
298
                        <td width="1%" nowrap>
299 300
                            <input type="radio" name="showGroup" value="onlyGroup" id="rb001"
                             onclick="this.form.enableRosterGroups[1].checked=true;"
301
                             <%= ("onlyGroup".equals(showGroup) && (groupNames == null || groupNames.length == 0) ? "checked" : "") %>>
302 303
                        </td>
                        <td width="99%">
304
                            <label for="rb001"><fmt:message key="group.create.show_group_in_group_members" /></label>
Gaston Dombiak's avatar
Gaston Dombiak committed
305 306
                        </td>
                    </tr>
307 308
                    <tr>
                        <td width="1%" nowrap>
309
                            <input type="radio" name="showGroup" value="spefgroups" id="rb003"
310 311
                             onclick="this.form.enableRosterGroups[1].checked=true;"
                             <%= (groupNames != null && groupNames.length > 0) ? "checked" : "" %>>
312 313
                        </td>
                        <td width="99%">
314
                            <label for="rb003"><fmt:message key="group.create.show_group_in_roster_group" /></label>
315 316 317
                        </td>
                    </tr>
                    <tr>
318 319
                        <td width="1%" nowrap>
                            &nbsp;
320 321
                        </td>
                        <td width="99%">
322 323
                            <select name="groupNames" size="6" onclick="this.form.showGroup[2].checked=true;this.form.enableRosterGroups[1].checked=true;"
                             multiple style="width:300px;font-family:verdana,arial,helvetica,sans-serif;font-size:8pt;">
324 325 326 327 328

                            <%  for (Group group : webManager.getGroupManager().getGroups()) { %>

                                <option value="<%= URLEncoder.encode(group.getName(), "UTF-8") %>"
                                 <%= (contains(groupNames, group.getName()) ? "selected" : "") %>
329 330 331
                                 ><%= group.getName() %></option>

                            <%  } %>
332

333
                            </select>
334 335
                        </td>
                    </tr>
336
                </tbody>
337
                </table>
338 339 340 341 342 343 344

            </td>
        </tr>
    </tbody>
    </table>

    <br>
345
    <span class="jive-description">* <fmt:message key="group.create.required_fields" /> </span>
346 347 348 349 350 351
    </div>

</fieldset>

<br><br>

352 353
<input type="submit" name="create" value="<fmt:message key="group.create.create" />">
<input type="submit" name="cancel" value="<fmt:message key="global.cancel" />">
354 355 356 357 358 359 360 361 362 363 364 365 366

</form>

<script language="JavaScript" type="text/javascript">
document.f.name.focus();
</script>

<jsp:include page="bottom.jsp" flush="true"/>

<%!
    private static String toList(String[] array) {
        if (array == null || array.length == 0) {
            return "";
367
        }
368 369 370 371 372 373 374 375
        StringBuffer buf = new StringBuffer();
        String sep = "";
        for (int i=0; i<array.length; i++) {
            buf.append(sep).append(array[i]);
            sep = ",";
        }
        return buf.toString();
    }
376 377 378 379 380 381 382 383 384 385 386 387

    private static boolean contains(String[] array, String item) {
        if (array == null || array.length == 0 || item == null) {
            return false;
        }
        for (int i=0; i<array.length; i++) {
            if (item.equals(array[i])) {
                return true;
            }
        }
        return false;
    }
388
%>