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

Last change on this file since 3190 was 3190, checked in by Johan Enell, 16 years ago

Merged log:branches/2.2.2#3116:3186 to trunk.

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