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