source: trunk/www/admin/clients/list_clients.jsp @ 3552

Last change on this file since 3552 was 3552, checked in by Martin Svensson, 16 years ago

References #375. Only wants to do a commit before the weekend.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 14.0 KB
Line 
1<%-- $Id: list_clients.jsp 3552 2007-07-06 14:53:14Z martin $
2  ------------------------------------------------------------------
3  Copyright (C) Authors contributing to this file.
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 2
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 this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place - Suite 330,
21  Boston, MA  02111-1307, USA.
22  ------------------------------------------------------------------
23
24  @author Nicklas
25  @version 2.0
26--%>
27<%@ page session="false"
28  import="net.sf.basedb.core.SessionControl"
29  import="net.sf.basedb.core.DbControl"
30  import="net.sf.basedb.core.Item"
31  import="net.sf.basedb.core.Client"
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.Nameable"
38  import="net.sf.basedb.core.Permission"
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.plugin.GuiContext"
43  import="net.sf.basedb.core.plugin.Plugin"
44  import="net.sf.basedb.util.Enumeration"
45  import="net.sf.basedb.util.ShareableUtil"
46  import="net.sf.basedb.clients.web.Base"
47  import="net.sf.basedb.clients.web.PermissionUtil"
48  import="net.sf.basedb.clients.web.ModeInfo"
49  import="net.sf.basedb.clients.web.util.HTML"
50  import="net.sf.basedb.util.Values"
51  import="java.util.Iterator"
52  import="java.util.List"
53  import="java.util.Map"
54%>
55<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
56<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
57<%!
58  private static final Item itemType = Item.CLIENT;
59  private static final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.LIST);
60%>
61<%
62final SessionControl sc = Base.getExistingSessionControl(pageContext, Permission.DENIED, itemType);
63final String ID = sc.getId();
64final boolean createPermission = sc.hasPermission(Permission.CREATE, itemType);
65final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
66
67final ModeInfo mode = ModeInfo.get(request.getParameter("mode"));
68final String callback = request.getParameter("callback");
69final String title = mode.generateTitle("client application", "client applications");
70final DbControl dc = sc.newDbControl();
71ItemResultIterator<Client> clients = null;
72try
73{
74  final ItemQuery<Client> query = Base.getConfiguredQuery(cc, true, Client.getQuery(), mode);
75
76  Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext);
77  try
78  {
79    clients = query.iterate(dc);
80  }
81  catch (Throwable t)
82  {
83    cc.setMessage(t.getMessage());
84  }
85  int numListed = 0;
86  %>
87  <base:page title="<%=title==null ? "Client applications" : title%>" type="<%=mode.getPageType()%>">
88  <base:head scripts="menu.js,table.js" styles="menu.css,table.css">
89    <script language="JavaScript">
90    var submitPage = 'index.jsp';
91    var formId = 'clients';
92    function newItem()
93    {
94      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', 0, true);
95    }
96    function editItem(itemId)
97    {
98      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', itemId, true);
99    }
100    function viewItem(itemId)
101    {
102      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', itemId, false);
103    }
104    function itemOnClick(evt, itemId)
105    {
106      Table.itemOnClick(formId, evt, itemId, '<%=mode.getName()%>', viewItem, editItem, returnSelected);
107    }
108    function deleteItems()
109    {
110      var frm = document.forms[formId];
111      if (Forms.numChecked(frm) == 0)
112      {
113        alert('Please select at least one item in the list');
114        return;
115      }
116      frm.action = submitPage;
117      frm.cmd.value = 'DeleteItems';
118      frm.submit();
119    }
120    function restoreItems()
121    {
122      var frm = document.forms[formId];
123      if (Forms.numChecked(frm) == 0)
124      {
125        alert('Please select at least one item in the list');
126        return;
127      }
128      frm.action = submitPage;
129      frm.cmd.value = 'RestoreItems';
130      frm.submit();
131    }
132    function takeOwnership()
133    {
134      var frm = document.forms[formId];
135      if (Forms.numChecked(frm) == 0)
136      {
137        alert('Please select at least one item in the list');
138        return;
139      }
140      if (confirm('Are you sure that you want to take ownership of the selected items? It can\'t be undone.'))
141      {
142        frm.action = submitPage;
143        frm.cmd.value = 'TakeOwnershipOfItems';
144        frm.submit();
145      }
146    }
147    function shareItem(itemId)
148    {
149      Main.openPopup('index.jsp?ID=<%=ID%>&cmd=ShareItem&item_id='+itemId, 'ShareClients', 500, 400);
150    }
151    function shareItems()
152    {
153      Table.shareItems(submitPage, '<%=ID%>', formId, '<%=itemType.name()%>', 'ShareItems');
154    }
155    function configureColumns()
156    {
157      Table.configureColumns('<%=ID%>', formId, '<%=itemType.name()%>', '<%=(String)cc.getObject("defaultColumns")%>');
158    }
159    function runPlugin(cmd)
160    {
161      Table.submitToPopup(formId, cmd, 740, 540);
162    }
163    function returnSelected()
164    {
165      Table.returnSelected(formId, <%=callback != null ? "window.opener."+callback : "null" %>);
166      window.close();
167    }
168    function presetOnChange()
169    {
170      Table.presetOnChange('<%=ID%>', formId, '<%=itemType.name()%>', '<%=(String)cc.getObject("defaultColumns")%>');
171    }
172    </script>
173  </base:head>
174 
175  <base:body>
176    <%
177    if (cc.getMessage() != null)
178    {
179      %>
180      <div class="error"><%=cc.getMessage()%></div>
181      <%
182      cc.setMessage(null);
183    }
184    %>
185    <tbl:table 
186      id="clients" 
187      clazz="itemlist" 
188      columns="<%=cc.getSetting("columns")%>"
189      sortby="<%=cc.getSortProperty()%>" 
190      direction="<%=cc.getSortDirection()%>"
191      title="<%=title%>"
192      action="index.jsp"
193      sc="<%=sc%>"
194      item="<%=itemType%>"
195      >
196      <tbl:hidden 
197        name="mode" 
198        value="<%=mode.getName()%>" 
199      />
200      <tbl:hidden 
201        name="callback" 
202        value="<%=callback%>" 
203        skip="<%=callback == null%>" 
204      />
205      <tbl:columndef 
206        id="name"
207        property="name"
208        datatype="string"
209        title="Name"
210        sortable="true" 
211        filterable="true"
212        exportable="true"
213        show="always" 
214      />
215      <tbl:columndef 
216        id="externalId"
217        property="externalId"
218        datatype="string"
219        title="External ID"
220        sortable="true"
221        filterable="true"
222        exportable="true"
223      />
224      <tbl:columndef 
225        id="owner"
226        property="owner.name"
227        datatype="string"
228        title="Owner"
229        sortable="true" 
230        filterable="true"
231        exportable="true"
232      />
233      <tbl:columndef 
234        id="description"
235        property="description"
236        datatype="string"
237        title="Description" 
238        sortable="true" 
239        filterable="true" 
240        exportable="true"
241      />
242      <tbl:columndef
243        id="permission"
244        title="Permission"
245      />
246      <tbl:columndef 
247        id="sharedTo" 
248        title="Shared to" 
249      />
250      <tbl:toolbar
251        visible="<%=mode.hasToolbar()%>"
252        >
253        <tbl:button 
254          disabled="<%=createPermission ? false : true%>" 
255          image="<%=createPermission ? "new.gif" : "new_disabled.gif"%>" 
256          onclick="newItem()" 
257          title="New&hellip;" 
258          tooltip="<%=createPermission ? "Create new client application" : "You do not have permission to create client applications"%>" 
259        />
260        <tbl:button 
261          image="delete.gif"
262          onclick="deleteItems()" 
263          title="Delete" 
264          tooltip="Delete the selected items" 
265        />
266        <tbl:button 
267          image="restore.gif"
268          onclick="restoreItems()" 
269          title="Restore" 
270          tooltip="Restore the selected (deleted) items"
271        />
272        <tbl:button 
273          image="share.gif"
274          onclick="shareItems()" 
275          title="Share&hellip;" 
276          tooltip="Share the selected items"
277        />
278        <tbl:button 
279          image="take_ownership.png"
280          onclick="takeOwnership()" 
281          title="Take ownership&hellip;"
282          tooltip="Take ownership of the selected items"
283        />
284        <tbl:button 
285          image="columns.gif" 
286          onclick="configureColumns()" 
287          title="Columns&hellip;" 
288          tooltip="Show, hide and re-order columns" 
289        />
290        <tbl:button 
291          image="import.gif" 
292          onclick="runPlugin('ImportItems')" 
293          title="Import&hellip;" 
294          tooltip="Import data" 
295          visible="<%=pluginCount.containsKey(Plugin.MainType.IMPORT)%>"
296        />
297        <tbl:button 
298          image="export.gif" 
299          onclick="runPlugin('ExportItems')" 
300          title="Export&hellip;" 
301          tooltip="Export data" 
302          visible="<%=pluginCount.containsKey(Plugin.MainType.EXPORT)%>"
303        />
304        <tbl:button 
305          image="runplugin.gif" 
306          onclick="runPlugin('RunListPlugin')" 
307          title="Run plugin&hellip;" 
308          tooltip="Run a plugin" 
309          visible="<%=pluginCount.containsKey(Plugin.MainType.OTHER)%>"
310        />
311      </tbl:toolbar>
312      <tbl:navigator
313        page="<%=cc.getPage()%>" 
314        rowsperpage="<%=cc.getRowsPerPage()%>" 
315        totalrows="<%=clients == null ? 0 : clients.getTotalCount()%>" 
316        visible="<%=mode.hasNavigator()%>"
317      />
318      <tbl:data>
319        <tbl:columns>
320        <tbl:presetselector 
321          clazz="columnheader"
322          colspan="3"
323          onchange="presetOnChange()"
324        />
325        </tbl:columns>
326
327        <tr>
328          <tbl:header 
329            clazz="index"
330            >&nbsp;</tbl:header>
331          <tbl:header 
332            clazz="check" 
333            visible="<%=mode.hasCheck()%>"
334            ><base:icon 
335              image="check_uncheck.gif" 
336              tooltip="Check/uncheck all" 
337              onclick="Forms.checkUncheck(document.forms[formId])" style="align: left;"
338            /></tbl:header>
339          <tbl:header 
340            clazz="check" 
341            visible="<%=mode.hasRadio()%>"
342            >&nbsp;</tbl:header>
343          <tbl:header 
344            clazz="icons" 
345            visible="<%=mode.hasIcons()%>"
346            >&nbsp;</tbl:header>
347          <tbl:propertyfilter />
348        </tr>
349         
350          <tbl:rows>
351          <%
352          int index = cc.getPage()*cc.getRowsPerPage();
353          int selectedItemId = cc.getId();
354          if (clients != null)
355          {           
356            while (clients.hasNext())
357            {
358              Client item = clients.next();
359              int itemId = item.getId();
360              String openSharePopup = "shareItem("+itemId+")";
361              boolean sharePermission = item.hasPermission(Permission.SET_PERMISSION);
362              boolean writePermission = item.hasPermission(Permission.WRITE);
363              String name = HTML.encodeTags(item.getName());
364              String tooltip = mode.isSelectionMode() ? 
365                  "Select this item" : "View this item" + (writePermission ? " (use CTRL, ALT or SHIFT to edit)" : "");
366              index++;
367              numListed++;
368              %>
369              <tbl:row>
370                <tbl:header 
371                  clazz="index"
372                  ><%=index%></tbl:header>
373                <tbl:header 
374                  clazz="check" 
375                  visible="<%=mode.hasCheck()%>"
376                  ><input 
377                    type="checkbox" 
378                    name="<%=itemId%>" 
379                    value="<%=itemId%>" 
380                    title="<%=name%>" 
381                    <%=cc.getSelected().contains(itemId) ? "checked" : ""%> 
382                  ></tbl:header>
383                <tbl:header 
384                  clazz="check" 
385                  visible="<%=mode.hasRadio()%>"
386                  ><input 
387                    type="radio" 
388                    name="item_id" 
389                    value="<%=itemId%>" 
390                    title="<%=name%>" 
391                    <%=selectedItemId == itemId ? "checked" : ""%>
392                  ></tbl:header>
393                <tbl:header 
394                  clazz="icons" 
395                  visible="<%=mode.hasIcons()%>"
396                  ><base:icon 
397                    image="deleted.gif" 
398                    tooltip="This item has been scheduled for deletion" 
399                    visible="<%=item.isRemoved()%>"
400                  /><base:icon 
401                    image="<%=sharePermission ? "shared.gif" : "shared_disabled.gif"%>" 
402                    onclick="<%=sharePermission ? openSharePopup : null%>"
403                    tooltip="This item is shared to other users, groups and/or projects" 
404                    visible="<%=item.isShared()%>"
405                  />&nbsp;</tbl:header>
406                <tbl:cell column="name"><div class="link" 
407                  onclick="itemOnClick(<%=writePermission ? "event" : null%>, <%=itemId%>)" 
408                  title="<%=tooltip%>"><%=name%></div></tbl:cell>
409                <tbl:cell column="externalId"><%=Values.getString(item.getExternalId())%></tbl:cell>
410                <tbl:cell column="owner"
411                  ><base:propertyvalue 
412                    item="<%=item%>" 
413                    property="owner"
414                    enableEditLink="<%=mode.hasEditLink()%>" 
415                    enablePropertyLink="<%=mode.hasPropertyLink()%>"
416                  /></tbl:cell>
417                <tbl:cell column="description"><%=HTML.encodeTags(item.getDescription())%></tbl:cell>
418                <tbl:cell column="permission"><%=PermissionUtil.getShortPermissions(item)%></tbl:cell>
419                <tbl:cell column="sharedTo">
420                  <%
421                  Iterator<Nameable> sharees = ShareableUtil.getSharedTo(dc, item).iterator();
422                  while(sharees.hasNext())
423                  {
424                    Nameable n = sharees.next();
425                    if (mode.hasPropertyLink())
426                    {
427                      out.write(Base.getLinkedName(ID, n, false, mode.hasEditLink()));
428                    }
429                    else
430                    {
431                      out.write(HTML.encodeTags(n.getName()));
432                    }
433                    out.write(sharees.hasNext() ? ", " : "");
434                  }
435                  %>
436                </tbl:cell>
437              </tbl:row>
438              <%
439              }
440            }
441          %>
442          </tbl:rows>
443      </tbl:data>
444      <%
445      if (numListed == 0)
446      {
447        %>
448        <tbl:panel><%=clients == null || clients.getTotalCount() == 0 ? "No client applications were found" : "No client applications on this page. Please select another page!" %></tbl:panel>
449        <%
450      }
451      else
452      {
453        %>
454        <tbl:navigator
455          page="<%=cc.getPage()%>" 
456          rowsperpage="<%=cc.getRowsPerPage()%>" 
457          totalrows="<%=clients == null ? 0 : clients.getTotalCount()%>" 
458          visible="<%=mode.hasNavigator()%>"
459          locked="true"
460        />
461        <%
462      }
463      %>
464    </tbl:table>
465    <base:buttongroup align="center" clazz="fixedatbottom">
466      <base:button onclick="returnSelected();" title="Ok" visible="<%=mode.hasOkButton()%>" />
467      <base:button onclick="window.close();" title="Cancel" visible="<%=mode.hasCancelButton()%>" />
468      <base:button onclick="window.close();" title="Close" visible="<%=mode.hasCloseButton()%>" />
469    </base:buttongroup>
470    <br><br><br>
471  </base:body>
472  </base:page>
473  <%
474}
475finally
476{
477  if (clients != null) clients.close();
478  if (dc != null) dc.close();
479}
480%>
Note: See TracBrowser for help on using the repository browser.