source: trunk/www/admin/groups/list_groups.jsp @ 5077

Last change on this file since 5077 was 5077, checked in by Nicklas Nordborg, 14 years ago

Fixes #1182: Groups with hidden members

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 17.0 KB
Line 
1<%-- $Id: list_groups.jsp 5077 2009-08-26 12:03:37Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg, Martin Svensson
4  Copyright (C) 2007 Johan Enell, Nicklas Nordborg
5
6  This file is part of BASE - BioArray Software Environment.
7  Available at http://base.thep.lu.se/
8
9  BASE is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License
11  as published by the Free Software Foundation; either version 3
12  of the License, or (at your option) any later version.
13
14  BASE is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  GNU General Public License for more details.
18
19  You should have received a copy of the GNU General Public License
20  along with BASE. If not, see <http://www.gnu.org/licenses/>.
21  ------------------------------------------------------------------
22
23  @author Nicklas
24  @version 2.0
25--%>
26<%@ page session="false"
27  import="net.sf.basedb.core.SessionControl"
28  import="net.sf.basedb.core.DbControl"
29  import="net.sf.basedb.core.Item"
30  import="net.sf.basedb.core.Group"
31  import="net.sf.basedb.core.User"
32  import="net.sf.basedb.core.ItemQuery"
33  import="net.sf.basedb.core.Include"
34  import="net.sf.basedb.core.ItemResultIterator"
35  import="net.sf.basedb.core.ItemResultList"
36  import="net.sf.basedb.core.ItemContext"
37  import="net.sf.basedb.core.Permission"
38  import="net.sf.basedb.core.Type"
39  import="net.sf.basedb.core.PluginDefinition"
40  import="net.sf.basedb.core.query.Orders"
41  import="net.sf.basedb.core.query.Hql"
42  import="net.sf.basedb.core.query.Restrictions"
43  import="net.sf.basedb.core.query.Expressions"
44  import="net.sf.basedb.core.plugin.GuiContext"
45  import="net.sf.basedb.core.plugin.Plugin"
46  import="net.sf.basedb.util.Enumeration"
47  import="net.sf.basedb.clients.web.Base"
48  import="net.sf.basedb.clients.web.PermissionUtil"
49  import="net.sf.basedb.clients.web.ModeInfo"
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.extensions.ExtensionsControl"
55  import="net.sf.basedb.clients.web.extensions.JspContext"
56  import="net.sf.basedb.clients.web.extensions.renderer.PrefixSuffixRenderer"
57  import="net.sf.basedb.clients.web.extensions.toolbar.ToolbarUtil"
58  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
59  import="java.util.Date"
60  import="java.util.List"
61  import="java.util.Map"
62%>
63<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
64<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
65<%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %>
66<%!
67  private static final Item itemType = Item.GROUP;
68  private static final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.LIST);
69%>
70<%
71final SessionControl sc = Base.getExistingSessionControl(pageContext, Permission.DENIED, itemType);
72final String ID = sc.getId();
73final boolean createPermission = sc.hasPermission(Permission.CREATE, itemType);
74final boolean writePermission = sc.hasPermission(Permission.WRITE, itemType);
75final boolean deletePermission = sc.hasPermission(Permission.DELETE, itemType);
76final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
77
78final ModeInfo mode = ModeInfo.get(request.getParameter("mode"));
79final String callback = request.getParameter("callback");
80final String title = mode.generateTitle("group", "groups");
81final DbControl dc = sc.newDbControl();
82ItemResultIterator<Group> groups = null;
83try
84{
85  Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc);
86  // Query for groups relatated to the current group
87  final ItemQuery<Group> groupQuery = Group.getQuery();
88  groupQuery.include(cc.getInclude());
89  groupQuery.join(Hql.innerJoin("parents", "p"));
90  groupQuery.restrict(Restrictions.eq(Hql.alias("p"), Expressions.parameter("group")));
91  groupQuery.order(Orders.asc(Hql.property("name"))); 
92
93  // Query for users relatated to the current group
94  final ItemQuery<User> userQuery = User.getQuery();
95  userQuery.include(cc.getInclude());
96  userQuery.join(Hql.innerJoin("groups", "grp"));
97  userQuery.restrict(Restrictions.eq(Hql.alias("grp"), Expressions.parameter("group")));
98  userQuery.order(Orders.asc(Hql.property("name"))); 
99
100  Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext);
101  try
102  {
103    final ItemQuery<Group> query = Base.getConfiguredQuery(cc, true, Group.getQuery(), mode);
104    groups = query.iterate(dc);
105  }
106  catch (Throwable t)
107  {
108    cc.setMessage(t.getMessage());
109  }
110  int numListed = 0;
111  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, guiContext, null);
112  ExtensionsInvoker invoker = ToolbarUtil.useExtensions(jspContext);
113  %>
114  <base:page title="<%=title==null ? "Groups" : title%>" type="<%=mode.getPageType()%>">
115  <base:head scripts="menu.js,table.js" styles="menu.css,table.css">
116    <ext:scripts context="<%=jspContext%>" />
117    <ext:stylesheets context="<%=jspContext%>" />
118    <script language="JavaScript">
119    var submitPage = 'index.jsp';
120    var formId = 'groups';
121    function newItem()
122    {
123      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', 0, true);
124    }
125    function editItem(itemId)
126    {
127      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', itemId, true);
128    }
129    function viewItem(itemId)
130    {
131      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', itemId, false);
132    }
133    function itemOnClick(evt, itemId)
134    {
135      Table.itemOnClick(formId, evt, itemId, '<%=mode.getName()%>', viewItem, editItem, returnSelected);
136    }
137    function deleteItems()
138    {
139      var frm = document.forms[formId];
140      if (Forms.numChecked(frm) == 0)
141      {
142        alert('Please select at least one item in the list');
143        return;
144      }
145      frm.action = submitPage;
146      frm.cmd.value = 'DeleteItems';
147      frm.submit();
148    }
149    function restoreItems()
150    {
151      var frm = document.forms[formId];
152      if (Forms.numChecked(frm) == 0)
153      {
154        alert('Please select at least one item in the list');
155        return;
156      }
157      frm.action = submitPage;
158      frm.cmd.value = 'RestoreItems';
159      frm.submit();
160    }
161    function deleteItemPermanently(itemId)
162    {
163      Main.deleteItemPermanently('<%=ID%>', true, '<%=itemType.name()%>', itemId);
164    }
165    function configureColumns()
166    {
167      Table.configureColumns('<%=ID%>', formId, '<%=itemType.name()%>', '<%=(String)cc.getObject("defaultColumns")%>');
168    }
169    function runPlugin(cmd)
170    {
171      Table.submitToPopup(formId, cmd, 740, 540);
172    }
173    function returnSelected()
174    {
175      Table.returnSelected(formId, <%=callback != null ? "window.opener."+callback : "null" %>);
176      window.close();
177    }
178    function presetOnChange()
179    {
180      Table.presetOnChange('<%=ID%>', formId, '<%=itemType.name()%>', '<%=(String)cc.getObject("defaultColumns")%>');
181    }
182    </script>
183  </base:head>
184 
185  <base:body>
186    <%
187    if (cc.getMessage() != null)
188    {
189      %>
190      <div class="error"><%=cc.getMessage()%></div>
191      <%
192      cc.setMessage(null);
193    }
194    %>
195    <tbl:table 
196      id="groups" 
197      clazz="itemlist" 
198      columns="<%=cc.getSetting("columns")%>"
199      sortby="<%=cc.getSortProperty()%>" 
200      direction="<%=cc.getSortDirection()%>"
201      title="<%=title%>"
202      action="index.jsp"
203      sc="<%=sc%>"
204      item="<%=itemType%>"
205      >
206      <tbl:hidden 
207        name="mode" 
208        value="<%=mode.getName()%>" 
209      />
210      <tbl:hidden 
211        name="callback" 
212        value="<%=callback%>" 
213        skip="<%=callback == null%>" 
214      />
215      <tbl:columndef 
216        id="name"
217        property="name"
218        datatype="string"
219        title="Name"
220        sortable="true" 
221        filterable="true"
222        exportable="true"
223        show="always" 
224      />
225      <tbl:columndef 
226        id="id"
227        clazz="uniquecol"
228        property="id"
229        datatype="int"
230        title="ID"
231        sortable="true"
232        filterable="true"
233        exportable="true"
234      />
235      <tbl:columndef 
236        id="entryDate"
237        property="entryDate"
238        datatype="date"
239        title="Registered"
240        sortable="true" 
241        filterable="true"
242        exportable="true"
243        formatter="<%=dateFormatter%>"
244      />
245      <tbl:columndef 
246        id="systemId"
247        clazz="uniquecol"
248        property="systemId"
249        datatype="string"
250        title="System ID"
251        sortable="true"
252        filterable="true"
253        exportable="true"
254      />
255      <tbl:columndef 
256        id="quota"
257        property="quota.name"
258        datatype="string"
259        title="Quota"
260        sortable="true" 
261        filterable="true"
262        exportable="true"
263      />
264      <tbl:columndef 
265        id="isDefault"
266        property="default"
267        datatype="boolean"
268        title="Is default"
269        sortable="true" 
270        filterable="true"
271        exportable="true"
272      />
273      <tbl:columndef 
274        id="hiddenMembers"
275        property="hiddenMembers"
276        datatype="boolean"
277        title="Hidden members"
278        sortable="true" 
279        filterable="true"
280        exportable="true"
281      />
282      <tbl:columndef
283        id="users"
284        title="Users"
285        property="&users(name)"
286        datatype="string"
287        filterable="true"
288        exportable="true"
289      />
290      <tbl:columndef
291        id="groups"
292        title="Groups"
293        property="&children(name)"
294        datatype="string"
295        filterable="true"
296        exportable="true"
297      />
298      <tbl:columndef 
299        id="description"
300        property="description"
301        datatype="string"
302        title="Description" 
303        sortable="true" 
304        filterable="true" 
305        exportable="true"
306      />
307      <tbl:toolbar
308        visible="<%=mode.hasToolbar()%>"
309        >
310        <tbl:button 
311          disabled="<%=createPermission ? false : true%>" 
312          image="<%=createPermission ? "new.gif" : "new_disabled.gif"%>" 
313          onclick="newItem()" 
314          title="New&hellip;" 
315          tooltip="<%=createPermission ? "Create new group" : "You do not have permission to create groups"%>" 
316        />
317        <tbl:button 
318          disabled="<%=deletePermission ? false : true%>" 
319          image="<%=deletePermission ? "delete.gif" : "delete_disabled.gif"%>" 
320          onclick="deleteItems()" 
321          title="Delete" 
322          tooltip="<%=deletePermission ? "Delete the selected items" : "You do not have permission to delete groups" %>" 
323        />
324        <tbl:button 
325          disabled="<%=writePermission ? false : true%>" 
326          image="<%=writePermission ? "restore.gif" : "restore_disabled.gif"%>" 
327          onclick="restoreItems()" 
328          title="Restore" 
329          tooltip="<%=writePermission ? "Restore the selected (deleted) items" : "You do not have permission to edit groups" %>" 
330        />
331        <tbl:button 
332          image="columns.gif" 
333          onclick="configureColumns()" 
334          title="Columns&hellip;" 
335          tooltip="Show, hide and re-order columns" 
336        />
337        <tbl:button 
338          image="import.gif" 
339          onclick="runPlugin('ImportItems')" 
340          title="Import&hellip;" 
341          tooltip="Import data" 
342          visible="<%=pluginCount.containsKey(Plugin.MainType.IMPORT)%>"
343        />
344        <tbl:button 
345          image="export.gif" 
346          onclick="runPlugin('ExportItems')" 
347          title="Export&hellip;" 
348          tooltip="Export data" 
349          visible="<%=pluginCount.containsKey(Plugin.MainType.EXPORT)%>"
350        />
351        <tbl:button 
352          image="runplugin.gif" 
353          onclick="runPlugin('RunListPlugin')" 
354          title="Run plugin&hellip;" 
355          tooltip="Run a plugin" 
356          visible="<%=pluginCount.containsKey(Plugin.MainType.OTHER)%>"
357        />
358        <ext:render extensions="<%=invoker%>" context="<%=jspContext%>" 
359          wrapper="<%=new PrefixSuffixRenderer(jspContext, "<td>", "</td>") %>"/>
360      </tbl:toolbar>
361      <tbl:navigator
362        page="<%=cc.getPage()%>" 
363        rowsperpage="<%=cc.getRowsPerPage()%>" 
364        totalrows="<%=groups == null ? 0 : groups.getTotalCount()%>" 
365        visible="<%=mode.hasNavigator()%>"
366      />
367      <tbl:data>
368        <tbl:columns>
369        <tbl:presetselector 
370          clazz="columnheader"
371          colspan="3"
372          onchange="presetOnChange()"
373        />
374        </tbl:columns>
375
376        <tr>
377          <tbl:header 
378            clazz="index"
379            >&nbsp;</tbl:header>
380          <tbl:header 
381            clazz="check" 
382            visible="<%=mode.hasCheck()%>"
383            ><base:icon 
384              image="check_uncheck.gif" 
385              tooltip="Check/uncheck all" 
386              onclick="Forms.checkUncheck(document.forms[formId])" style="align: left;"
387            /></tbl:header>
388          <tbl:header 
389            clazz="check" 
390            visible="<%=mode.hasRadio()%>"
391            >&nbsp;</tbl:header>
392          <tbl:header 
393            clazz="icons" 
394            visible="<%=mode.hasIcons()%>"
395            >&nbsp;</tbl:header>
396          <tbl:propertyfilter />
397        </tr>
398         
399          <tbl:rows>
400          <%
401          int index = cc.getPage()*cc.getRowsPerPage();
402          int selectedItemId = cc.getId();
403          if (groups != null)
404          {           
405            while (groups.hasNext())
406            {
407              Group item = groups.next();
408              int itemId = item.getId();
409              String name = HTML.encodeTags(item.getName());
410              String tooltip = mode.isSelectionMode() ? 
411                  "Select this item" : "View this item" + (writePermission ? " (use CTRL, ALT or SHIFT to edit)" : "");
412              String deletePermanently = "deleteItemPermanently("+itemId+")";
413              index++;
414              numListed++;
415              %>
416              <tbl:row>
417                <tbl:header 
418                  clazz="index"
419                  ><%=index%></tbl:header>
420                <tbl:header 
421                  clazz="check" 
422                  visible="<%=mode.hasCheck()%>"
423                  ><input 
424                    type="checkbox" 
425                    name="<%=itemId%>" 
426                    value="<%=itemId%>" 
427                    title="<%=name%>" 
428                    <%=cc.getSelected().contains(itemId) ? "checked" : ""%> 
429                  ></tbl:header>
430                <tbl:header 
431                  clazz="check" 
432                  visible="<%=mode.hasRadio()%>"
433                  ><input 
434                    type="radio" 
435                    name="item_id" 
436                    value="<%=itemId%>" 
437                    title="<%=name%>" 
438                    <%=selectedItemId == itemId ? "checked" : ""%>
439                  ></tbl:header>
440                <tbl:header 
441                  clazz="icons" 
442                  visible="<%=mode.hasIcons()%>"
443                  ><base:icon 
444                    image="<%=deletePermission ? "deleted.gif" : "deleted_disabled.gif"%>"
445                    onclick="<%=deletePermission ? deletePermanently : null%>"
446                    tooltip="This item has been scheduled for deletion" 
447                    visible="<%=item.isRemoved()%>"
448                  /><base:icon
449                    image="systemitem.gif"
450                    tooltip="This item is a system item"
451                    visible="<%=item.isSystemItem()%>" 
452                  />&nbsp;</tbl:header>
453                <tbl:cell column="name"><div class="link" 
454                  onclick="itemOnClick(<%=writePermission ? "event" : null%>, <%=itemId%>)" 
455                  title="<%=tooltip%>"><%=name%></div></tbl:cell>
456                <tbl:cell column="id"><%=item.getId()%></tbl:cell>
457                <tbl:cell column="entryDate" value="<%=item.getEntryDate()%>" />
458                <tbl:cell column="systemId"><%=HTML.encodeTags(item.getSystemId())%></tbl:cell>
459                <tbl:cell column="quota"
460                  ><base:propertyvalue 
461                    item="<%=item%>" 
462                    property="quota"
463                    enableEditLink="<%=mode.hasEditLink()%>" 
464                    enablePropertyLink="<%=mode.hasPropertyLink()%>"
465                  /></tbl:cell>
466                <tbl:cell column="isDefault"><%=item.isDefault() ? "yes" : "no" %></tbl:cell>
467                <tbl:cell column="hiddenMembers"><%=item.hasHiddenMembers() ? "yes" : "no" %></tbl:cell>
468                <tbl:cell column="description"><%=HTML.encodeTags(item.getDescription())%></tbl:cell>
469                <tbl:cell column="groups">
470                  <%
471                  groupQuery.setParameter("group", itemId, Type.INT);
472                  try
473                  {
474                    String separator = "";
475                    for (Group g : groupQuery.list(dc))
476                    {
477                      out.write(separator);
478                      if (mode.hasPropertyLink())
479                      {
480                        out.write(Base.getLinkedName(ID, g, false, mode.hasEditLink()));
481                      }
482                      else
483                      {
484                        out.write(HTML.encodeTags(g.getName()));
485                      }
486                      separator = ", ";
487                    }
488                  }
489                  catch (Throwable t)
490                  {
491                    %>
492                    <div class="error"><%=t.getMessage()%></div>
493                    <%
494                  }
495                  %>
496                </tbl:cell>
497                <tbl:cell column="users">
498                  <%
499                  userQuery.setParameter("group", itemId, Type.INT);
500                  try
501                  {
502                    String separator = "";
503                    for (User u : userQuery.list(dc))
504                    {
505                      out.write(separator);
506                      if (mode.hasPropertyLink())
507                      {
508                        out.write(Base.getLinkedName(ID, u, false, mode.hasEditLink()));
509                      }
510                      else
511                      {
512                        out.write(HTML.encodeTags(u.getName()));
513                      }
514                      separator = ", ";
515                    }
516                  }
517                  catch (Throwable t)
518                  {
519                    %>
520                    <div class="error"><%=t.getMessage()%></div>
521                    <%
522                  }
523                  %>
524                </tbl:cell>
525              </tbl:row>
526              <%
527              }
528            }
529          %>
530          </tbl:rows>
531      </tbl:data>
532      <%
533      if (numListed == 0)
534      {
535        %>
536        <tbl:panel><%=groups == null || groups.getTotalCount() == 0 ? "No groups were found" : "No groups on this page. Please select another page!" %></tbl:panel>
537        <%
538      }
539      else
540      {
541        %>
542        <tbl:navigator
543          page="<%=cc.getPage()%>" 
544          rowsperpage="<%=cc.getRowsPerPage()%>" 
545          totalrows="<%=groups == null ? 0 : groups.getTotalCount()%>" 
546          visible="<%=mode.hasNavigator()%>"
547          locked="true"
548        />
549        <%
550      }
551      %>
552    </tbl:table>
553    <base:buttongroup align="center" clazz="fixedatbottom">
554      <base:button onclick="returnSelected();" title="Ok" visible="<%=mode.hasOkButton()%>" />
555      <base:button onclick="window.close();" title="Cancel" visible="<%=mode.hasCancelButton()%>" />
556      <base:button onclick="window.close();" title="Close" visible="<%=mode.hasCloseButton()%>" />
557    </base:buttongroup>
558    <br><br><br>
559  </base:body>
560  </base:page>
561  <%
562}
563finally
564{
565  if (groups != null) groups.close();
566  if (dc != null) dc.close();
567}
568%>
Note: See TracBrowser for help on using the repository browser.