group-create.jsp 13.7 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 33
                 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" %>

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

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

<%  // Get parameters //
Matt Tucker's avatar
Matt Tucker committed
40 41
    boolean create = request.getParameter("create") != null;
    boolean cancel = request.getParameter("cancel") != null;
42 43 44 45 46 47 48 49 50 51 52 53 54 55
    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
56 57 58 59 60 61 62 63 64
    // Handle a cancel
    if (cancel) {
        response.sendRedirect("group-summary.jsp");
        return;
    }
    // Handle a request to create a group:
    if (create) {
        // Validate
        if (name == null) {
65
            errors.put("name", "");
Matt Tucker's avatar
Matt Tucker committed
66
        }
67 68 69 70 71 72 73
        if (enableRosterGroups) {
            if (groupDisplayName == null) {
                errors.put("groupDisplayName", "");
            }
            if ("spefgroups".equals(showGroup) && groupNames == null) {
                errors.put("groupNames","");
            }
74
        }
Matt Tucker's avatar
Matt Tucker committed
75 76 77 78 79 80 81
        // 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);
                }
82 83 84 85
                if (enableRosterGroups) {
                    if ("spefgroups".equals(showGroup)) {
                        showGroup = "onlyGroup";
                    }
86
                    newGroup.getProperties().put("sharedRoster.showInRoster", showGroup);
87 88 89
                    if (groupDisplayName != null) {
                        newGroup.getProperties().put("sharedRoster.displayName", groupDisplayName);
                    }
90
                    newGroup.getProperties().put("sharedRoster.groupList", toList(groupNames));
91 92
                }
                else {
93 94 95
                    newGroup.getProperties().put("sharedRoster.showInRoster", "nobody");
                    newGroup.getProperties().put("sharedRoster.displayName", "");
                    newGroup.getProperties().put("sharedRoster.groupList", "");
96
                }
Derek DeMoro's avatar
Derek DeMoro committed
97

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

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

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

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

140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
<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">
                Error creating the group. Please check your error logs.
            </td>
        </tr>
    </tbody>
    </table>
    </div><br>

<%  } %>

165
<p>
Bill Lynch's avatar
Bill Lynch committed
166
Use the form below to create a group.
167
</p>
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237

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

<fieldset>
    <legend>Create New Group</legend>
    <div>

    <table cellpadding="3" cellspacing="0" border="0" width="100%">
    <tr valign="top">
        <td width="1%" nowrap>
            <label for="gname">Group Name:</label> *
        </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) { %>
                    <span class="jive-error-text">Invalid group name.</span>
                <%  } else if (errors.get("groupAlreadyExists") != null) { %>
                    <span class="jive-error-text">Group already exists - please choose a different name.</span>
                <%  } %>
            </td>
        </tr>

    <%  } %>

    <tr valign="top">
        <td width="1%" nowrap>
            <label for="gdesc">Description:</label>
        </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%">
                <span class="jive-error-text">Invalid description.</span>
            </td>
        </tr>

    <%  } %>

    <tr>
        <td nowrap width="1%" valign="top">
            Initial Member(s):
        </td>
        <td nowrap class="c1" align="left">
            <textarea name="users" cols="30" rows="3" id="gdesc"
             ><%= ((users != null) ? users : "") %></textarea>
        </td>
    </tr>
    </table>

    <br>
    <p><b>Shared Roster Groups</b></p>

Bill Lynch's avatar
Bill Lynch committed
238 239 240 241 242
    <p>
    You can use the form below to show this group in users' rosters. Select from one of three
    options for who should see this group in their rosters.
    </p>

243 244 245 246 247 248 249
    <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%">
250
                <label for="rb201">Disable sharing group in rosters</label>
251 252 253 254 255 256 257
            </td>
        </tr>
        <tr>
            <td width="1%">
                <input type="radio" name="enableRosterGroups" value="true" id="rb202" <%= enableRosterGroups ? "checked" : "" %>>
            </td>
            <td width="99%">
258
                <label for="rb202">Enable sharing group in rosters</label>
259 260 261 262 263 264 265 266 267
            </td>
        </tr>
        <tr>
            <td width="1%">
                &nbsp;
            </td>
            <td width="99%">

                <table cellpadding="3" cellspacing="0" border="0" width="100%">
268 269
                <tbody>
                    <tr>
270
                        <td width="1%" nowrap>
271
                            Group Display Name
272
                        </td>
273 274 275
                        <td width="99%">
                            <input type="text" name="groupDisplayName" size="30" maxlength="100" value="<%= (groupDisplayName != null ? groupDisplayName : "") %>"
                             onclick="this.form.enableRosterGroups[1].checked=true;">
276 277 278
                        </td>
                    </tr>
                </tbody>
279 280
                </table>

281
                <table cellpadding="3" cellspacing="0" border="0" width="100%">
282 283
                <tbody>
                    <tr>
284
                        <td width="1%" nowrap>
285 286 287
                            <input type="radio" name="showGroup" value="everybody" id="rb002"
                             onclick="this.form.enableRosterGroups[1].checked=true;"
                             <%= ("everybody".equals(showGroup) ? "checked" : "") %>>
288 289
                        </td>
                        <td width="99%">
290 291
                            <label for="rb002"
                             >Show group in all users' rosters.</label>
292 293
                        </td>
                    </tr>
294
                    <tr>
295
                        <td width="1%" nowrap>
296 297 298
                            <input type="radio" name="showGroup" value="onlyGroup" id="rb001"
                             onclick="this.form.enableRosterGroups[1].checked=true;"
                             <%= ("onlyGroup".equals(showGroup) ? "checked" : "") %>>
299 300
                        </td>
                        <td width="99%">
301 302
                            <label for="rb001"
                             >Show group in group members' rosters</label>
Gaston Dombiak's avatar
Gaston Dombiak committed
303 304
                        </td>
                    </tr>
305 306
                    <tr>
                        <td width="1%" nowrap>
307
                            <input type="radio" name="showGroup" value="spefgroups" id="rb003"
308 309
                             onclick="this.form.enableRosterGroups[1].checked=true;"
                             <%= (groupNames != null && groupNames.length > 0) ? "checked" : "" %>>
310 311
                        </td>
                        <td width="99%">
312
                            <label for="rb003"
313
                             >Show group to members' rosters of these groups:</label>
314 315 316
                        </td>
                    </tr>
                    <tr>
317 318
                        <td width="1%" nowrap>
                            &nbsp;
319 320
                        </td>
                        <td width="99%">
321 322
                            <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;">
323 324 325 326 327

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

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

                            <%  } %>
331

332
                            </select>
333 334
                        </td>
                    </tr>
335
                </tbody>
336
                </table>
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365

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

    <br>
    <span class="jive-description">* Required fields </span>
    </div>

</fieldset>

<br><br>

<input type="submit" name="create" value="Create Group">
<input type="submit" name="cancel" value="Cancel">

</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 "";
366
        }
367 368 369 370 371 372 373 374
        StringBuffer buf = new StringBuffer();
        String sep = "";
        for (int i=0; i<array.length; i++) {
            buf.append(sep).append(array[i]);
            sep = ",";
        }
        return buf.toString();
    }
375 376 377 378 379 380 381 382 383 384 385 386

    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;
    }
387
%>