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

Matt Tucker's avatar
Matt Tucker committed
11
<%@ page import="org.jivesoftware.util.Log,
12
                 org.jivesoftware.util.ParamUtils,
13 14
                 org.jivesoftware.openfire.group.Group,
                 org.jivesoftware.openfire.group.GroupAlreadyExistsException"
15 16
    errorPage="error.jsp"
%>
17 18 19
<%@ page import="java.net.URLEncoder"%>
<%@ page import="java.util.HashMap"%>
<%@ page import="java.util.Map"%>
20 21

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

24
<jsp:useBean id="webManager" class="org.jivesoftware.util.WebManager" />
25 26 27
<%  webManager.init(request, response, session, application, out); %>

<%  // Get parameters //
28 29
    String groupName = ParamUtils.getParameter(request, "group");

Matt Tucker's avatar
Matt Tucker committed
30
    boolean create = request.getParameter("create") != null;
31
    boolean edit = request.getParameter("edit") != null;
Matt Tucker's avatar
Matt Tucker committed
32
    boolean cancel = request.getParameter("cancel") != null;
33
    String name = ParamUtils.getParameter(request, "name");
Matt Tucker's avatar
Matt Tucker committed
34
    String description = ParamUtils.getParameter(request, "description", true);
35
    
36 37
    Map<String, String> errors = new HashMap<String, String>();

Matt Tucker's avatar
Matt Tucker committed
38 39
    // Handle a cancel
    if (cancel) {
40 41 42 43 44 45
        if (groupName == null) {
            response.sendRedirect("group-summary.jsp");
        }
        else {
            response.sendRedirect("group-edit.jsp?group=" + URLEncoder.encode(groupName, "UTF-8"));    
        }
Matt Tucker's avatar
Matt Tucker committed
46 47 48 49 50 51
        return;
    }
    // Handle a request to create a group:
    if (create) {
        // Validate
        if (name == null) {
52
            errors.put("name", "");
Matt Tucker's avatar
Matt Tucker committed
53 54 55 56 57 58 59 60
        }
        // 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);
                }
Derek DeMoro's avatar
Derek DeMoro committed
61

Matt Tucker's avatar
Matt Tucker committed
62 63 64 65
                newGroup.getProperties().put("sharedRoster.showInRoster", "nobody");
                newGroup.getProperties().put("sharedRoster.displayName", "");
                newGroup.getProperties().put("sharedRoster.groupList", "");

Matt Tucker's avatar
Matt Tucker committed
66
                // Successful, so redirect
Matt Tucker's avatar
Matt Tucker committed
67
                response.sendRedirect("group-edit.jsp?creategroupsuccess=true&group=" + URLEncoder.encode(newGroup.getName(), "UTF-8"));
Matt Tucker's avatar
Matt Tucker committed
68 69 70
                return;
            }
            catch (GroupAlreadyExistsException e) {
71
                errors.put("groupAlreadyExists", "");
Matt Tucker's avatar
Matt Tucker committed
72 73
            }
            catch (Exception e) {
74
                errors.put("general", "");
Matt Tucker's avatar
Matt Tucker committed
75 76 77 78
                Log.error(e);
            }
        }
    }
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
    // Handle a request to edit a group:
    if (edit) {
        // Validate
        if (name == null) {
            errors.put("name", "");
        }
        // do a create if there were no errors
        if (errors.size() == 0) {
            try {
                Group group = webManager.getGroupManager().getGroup(groupName);
                group.setName(name);
                if (description != null) {
                    group.setDescription(description);
                }

                // Successful, so redirect
                response.sendRedirect("group-edit.jsp?groupChanged=true&group=" + URLEncoder.encode(group.getName(), "UTF-8"));
                return;
            }
            catch (Exception e) {
                errors.put("general", "");
                Log.error(e);
            }
        }
    }
Matt Tucker's avatar
Matt Tucker committed
104
%>
105

106
<html>
107
<head>
108 109 110 111 112 113 114 115 116 117 118 119 120 121
<title><%
           // If editing the group.
           if (groupName != null) {
        %>
        <fmt:message key="group.edit.title" />
        <% }
           // Otherwise creating a new group.
           else {
        %>
        <fmt:message key="group.create.title" />
        <% } %>
</title>

<% if (groupName == null) { %>
122
<meta name="pageID" content="group-create"/>
123 124 125 126 127 128
<% }
   else { %>
<meta name="subPageID" content="group-edit"/>
<meta name="extraParams" content="<%= "group="+URLEncoder.encode(groupName, "UTF-8") %>"/>
<% } %>
    
129 130 131
<meta name="helpPage" content="create_a_group.html"/>
</head>
<body>
132 133 134 135

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

<%  if (errors.get("general") != null) { %>
136
    <div class="jive-error">
137 138 139 140
    <table cellpadding="0" cellspacing="0" border="0">
    <tbody>
        <tr>
            <td class="jive-icon">
141
                <img src="images/error-16x16.gif" width="16" height="16" border="0" alt="">
142 143
            </td>
            <td class="jive-icon-label">
144
                <fmt:message key="group.create.error" />
145 146 147 148 149 150 151
            </td>
        </tr>
    </tbody>
    </table>
    </div><br>
<%  } %>

152
<p>
153 154 155 156 157 158 159 160 161 162 163
    <%
        // If editing the group.
        if (groupName != null) {
    %>
    <fmt:message key="group.edit.details_info" />
    <% }
       // Otherwise creating a new group.
       else {
    %>
    <fmt:message key="group.create.form" />
    <% } %>
164
</p>
165 166 167

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

168 169 170 171 172
   <% if (groupName != null) { %>
    <input type="hidden" name="group" value="<%= groupName %>" id="existingName">
   <% } %>

    <!-- BEGIN create group -->
173
	<div class="jive-contentBoxHeader">
174 175 176 177 178 179 180 181 182 183 184 185
        <%
            // If editing the group.
            if (groupName != null) {
        %>
        <fmt:message key="group.edit.title" />
        <% }
           // Otherwise creating a new group.
           else {
        %>
        <fmt:message key="group.create.new_group_title" />
        <% } %>
    </div>
186
	<div class="jive-contentBox">
187
		<table cellpadding="3" cellspacing="0" border="0">
188 189
    <tr valign="top">
        <td width="1%" nowrap>
190
            <label for="gname"><fmt:message key="group.create.group_name" /></label> *
191 192 193 194 195 196 197 198 199 200 201 202 203
        </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) { %>
204
                    <span class="jive-error-text"><fmt:message key="group.create.invalid_group_name" /></span>
205
                <%  } else if (errors.get("groupAlreadyExists") != null) { %>
206
                    <span class="jive-error-text"><fmt:message key="group.create.invalid_group_info" /></span>
207 208 209 210 211 212 213 214
                <%  } %>
            </td>
        </tr>

    <%  } %>

    <tr valign="top">
        <td width="1%" nowrap>
215
            <label for="gdesc"><fmt:message key="group.create.label_description" /></label>
216 217 218 219 220 221 222 223 224 225 226 227 228 229
        </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%">
230
                <span class="jive-error-text"><fmt:message key="group.create.invalid_description" /></span>
231 232 233 234 235
            </td>
        </tr>

    <%  } %>

236 237 238
	<tr>
		<td></td>
		<td>
239 240 241 242 243 244 245 246 247 248 249 250
            <%
               // If editing the group.
               if (groupName != null) {
            %>
            <input type="submit" name="edit" value="<fmt:message key="group.edit.title" />">
            <% }
               // Otherwise creating a new group.
               else {
            %>
            <input type="submit" name="create" value="<fmt:message key="group.create.create" />">
            <% } %>
            <input type="submit" name="cancel" value="<fmt:message key="global.cancel" />">
251 252
		</td>
	</tr>
253
    </table>
254 255 256
	</div>
	<span class="jive-description">* <fmt:message key="group.create.required_fields" /> </span>
	<!-- END create group -->
257 258 259 260 261 262 263

</form>

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

264
</body>
Matt Tucker's avatar
Matt Tucker committed
265
</html>%>