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