source: trunk/www/admin/users/edit_default_membership.jsp @ 5921

Last change on this file since 5921 was 5921, checked in by Nicklas Nordborg, 10 years ago

References #1655: GUI improvements

Edit dialogs for all items in the first level under the Administrate menu.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 8.4 KB
Line 
1<%-- $Id: edit_default_membership.jsp 5921 2012-01-10 12:30:57Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2007 Nicklas Nordborg
4
5  This file is part of BASE - BioArray Software Environment.
6  Available at http://base.thep.lu.se/
7
8  BASE is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License
10  as published by the Free Software Foundation; either version 3
11  of the License, or (at your option) any later version.
12
13  BASE is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  GNU General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with BASE. If not, see <http://www.gnu.org/licenses/>.
20  ------------------------------------------------------------------
21
22
23  @author Nicklas
24  @version 2.0
25--%>
26<%@ page pageEncoding="UTF-8" session="false"
27  import="net.sf.basedb.core.SessionControl"
28  import="net.sf.basedb.core.DbControl"
29  import="net.sf.basedb.core.SystemItems"
30  import="net.sf.basedb.core.Item"
31  import="net.sf.basedb.core.Type"
32  import="net.sf.basedb.core.ItemContext"
33  import="net.sf.basedb.core.Permission"
34  import="net.sf.basedb.core.Group"
35  import="net.sf.basedb.core.User"
36  import="net.sf.basedb.core.Quota"
37  import="net.sf.basedb.core.Role"
38  import="net.sf.basedb.core.Directory"
39  import="net.sf.basedb.core.QuotaType"
40  import="net.sf.basedb.core.Location"
41  import="net.sf.basedb.core.Include"
42  import="net.sf.basedb.core.ItemQuery"
43  import="net.sf.basedb.core.ItemResultList"
44  import="net.sf.basedb.core.PermissionDeniedException"
45  import="net.sf.basedb.core.query.Orders"
46  import="net.sf.basedb.core.query.Hql"
47  import="net.sf.basedb.core.query.Restrictions"
48  import="net.sf.basedb.core.query.Expressions"
49  import="net.sf.basedb.clients.web.Base"
50  import="net.sf.basedb.clients.web.util.HTML"
51  import="net.sf.basedb.util.Values"
52  import="net.sf.basedb.util.formatter.Formatter"
53  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
54  import="net.sf.basedb.clients.web.formatter.FormatterSettings"
55  import="java.util.Date"
56%>
57<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
58<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
59<%
60final Item itemType = Item.USER;
61final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
62final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
63final int itemId = cc.getId();
64final String ID = sc.getId();
65final float scale = Base.getScale(sc);
66final DbControl dc = sc.newDbControl();
67try
68{
69  String title = "Default group and role membership";
70
71  // Query to retrieve default groups
72  ItemQuery<Group> groupQuery = Group.getQuery();
73  groupQuery.include(Include.ALL);
74  groupQuery.restrict(
75    Restrictions.eq(
76      Hql.property("default"), 
77      Expressions.parameter("isDefault", true, Type.BOOLEAN)
78    )
79  );
80  groupQuery.order(Orders.asc(Hql.property("name")));;
81
82  // Query to retrieve default roles
83  ItemQuery<Role> roleQuery = Role.getQuery();
84  roleQuery.include(Include.ALL);
85  roleQuery.restrict(
86    Restrictions.eq(
87      Hql.property("default"), 
88      Expressions.parameter("isDefault", true, Type.BOOLEAN)
89    )
90  );
91  roleQuery.order(Orders.asc(Hql.property("name")));;
92
93
94  final boolean readGroups = sc.hasPermission(Permission.READ, Item.GROUP);
95  final boolean useGroups = sc.hasPermission(Permission.USE, Item.GROUP);
96  final boolean writeGroups = sc.hasPermission(Permission.WRITE, Item.GROUP);
97  final boolean writeRoles = sc.hasPermission(Permission.WRITE, Item.ROLE);
98  final boolean writeMembership = writeGroups && writeRoles;
99 
100  final String clazz = "class=\"text\"";
101  final String requiredClazz = "class=\"text required\"";
102  %>
103
104  <base:page type="popup" title="<%=title%>">
105  <base:head scripts="tabcontrol.js,linkitems.js" styles="tabcontrol.css">
106    <script language="JavaScript">   
107    // Validate the "Membership" tab
108    function validateMembership()
109    {
110      return true;
111    }
112
113    // Submit the form
114    function saveSettings()
115    {
116      var frm = document.forms['user'];
117      if (validateMembership())
118      {
119        frm.addRoles.value = Link.getActionIds(1, 'R').join(',');
120        frm.removeRoles.value = Link.getActionIds(-1, 'R').join(',');
121        frm.addGroups.value = Link.getActionIds(1, 'G').join(',');
122        frm.removeGroups.value = Link.getActionIds(-1, 'G').join(',');
123        frm.submit();
124      }
125    }
126   
127    function init()
128    {
129      initMembership();
130    }
131    function initMembership()
132    {
133      var members = document.forms['user'].membership;
134      Link.addNewSection(members, new Section('G', 'Groups'));
135      <%
136      ItemResultList<Group> groups = groupQuery.list(dc);
137      for (Group group : groups)
138      {
139        %>
140        Link.addNewItem(members, new Item('G', <%=group.getId()%>, '<%=HTML.javaScriptEncode(group.getName())%>'));
141        <%
142      }
143      %>
144      Link.addNewSection(members, new Section('R', 'Roles'));
145      <%
146      ItemResultList<Role> roles = roleQuery.list(dc);
147      for (Role role : roles)
148      {
149        %>
150        Link.addNewItem(members, new Item('R', <%=role.getId()%>, '<%=HTML.javaScriptEncode(role.getName())%>'));
151        <%
152      }
153      %>
154    }
155    function addRolesOnClick()
156    {
157      var roles = Link.getListIds(document.forms['user'].membership, 'R');
158      var url = '../roles/index.jsp?ID=<%=ID%>&cmd=UpdateContext&mode=selectmultiple&callback=addRoleCallback';
159      url += '&exclude='+roles.join(',');
160      Main.openPopup(url, 'AddRoles', 1000, 700);
161    }
162    function addRoleCallback(roleId, name)
163    {
164      var item = Link.getItem('R', roleId);
165      if (!item) item = new Item('R', roleId, name);
166      Link.addItem(document.forms['user'].membership, item);
167    }
168    function addGroupsOnClick()
169    {
170      var groups = Link.getListIds(document.forms['user'].membership, 'G');
171      groups[groups.length] = <%=SystemItems.getId(Group.EVERYONE)%>;
172      var url = '../groups/index.jsp?ID=<%=ID%>&cmd=UpdateContext&mode=selectmultiple&callback=addGroupCallback';
173      url += '&exclude='+groups.join(',');
174      Main.openPopup(url, 'AddGroups', 1000, 700);
175    }
176    function addGroupCallback(groupId, name)
177    {
178      var item = Link.getItem('G', groupId);
179      if (!item) item = new Item('G', groupId, name);
180      Link.addItem(document.forms['user'].membership, item);
181    }
182    function removeOnClick()
183    {
184      Link.removeSelected(document.forms['user'].membership);
185    }
186 
187    </script>
188  </base:head>
189  <base:body onload="init()">
190    <h1><%=title%> <base:help helpid="user.edit.default_membership" /></h1>
191    <form action="index.jsp?ID=<%=ID%>" method="post" name="user" onsubmit="return false;">
192    <input type="hidden" name="cmd" value="UpdateDefaultMembership">
193
194    <div class="content filled">
195      <div>
196      <table class="fullform smaller bottomborder">
197      <tr class="dynamic">
198      <th>Member in</th>
199      <td>
200        <div class="selectionlist">
201          <table>
202          <tr>
203            <td>
204              <select name="membership" size="12" multiple <%=!writeMembership ? "disabled readonly class=\"disabled\"" : ""%> style="width: 15em;">
205              </select>
206              <input type="hidden" name="removeGroups" value="">
207              <input type="hidden" name="addGroups" value="">
208              <input type="hidden" name="removeRoles" value="">
209              <input type="hidden" name="addRoles" value="">
210            </td>
211            <td style="vertical-align: top;">
212              <base:buttongroup vertical="true">
213                <base:button 
214                  subclass="leftaligned"
215                  style="width: 12em;"
216                  onclick="addGroupsOnClick()" 
217                  title="Add&nbsp;groups&hellip;" 
218                  tooltip="Add groups to this user"
219                  disabled="<%=!writeMembership %>" 
220                />
221                <base:button 
222                  subclass="leftaligned"
223                  style="width: 12em;"
224                  onclick="addRolesOnClick()" 
225                  title="Add&nbsp;roles&hellip;" 
226                  tooltip="Add roles to this user"
227                  disabled="<%=!writeMembership %>" 
228                />
229                <base:button 
230                  subclass="leftaligned"
231                  style="width: 12em;"
232                  onclick="removeOnClick()" 
233                  title="Remove" 
234                  tooltip="Remove the user from the selected items"
235                  disabled="<%=!writeMembership%>" 
236                />
237              </base:buttongroup>
238            </td>
239          </tr>
240          </table>
241        </div>
242      </td>
243      </tr>
244      </table>
245      </div>
246     
247      <div class="padded">
248        The selected roles and groups will automatically be assigned to new users.
249      </div>
250    </div>
251    </form>
252    <base:buttongroup subclass="dialogbuttons">
253      <base:button onclick="saveSettings()" title="Save" />
254      <base:button onclick="window.close()" title="Cancel" />
255    </base:buttongroup>
256  </base:body>
257  </base:page>
258  <%
259}
260finally
261{
262  if (dc != null) dc.close();
263}
264%>
Note: See TracBrowser for help on using the repository browser.