source: trunk/www/admin/hardwaretypes/view_hardwaretype.jsp @ 5042

Last change on this file since 5042 was 5042, checked in by Martin Svensson, 13 years ago

References #360 Covering the submenu items in 'Administrate' menu.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 10.3 KB
Line 
1<%-- $Id: view_hardwaretype.jsp 5042 2009-08-11 10:48:42Z martin $
2  ------------------------------------------------------------------
3  Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg, Martin Svensson
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 3
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 BASE. If not, see <http://www.gnu.org/licenses/>.
20  ------------------------------------------------------------------
21
22  @author Nicklas
23  @version 2.0
24--%>
25<%@ page session="false"
26  import="net.sf.basedb.core.SessionControl"
27  import="net.sf.basedb.core.DbControl"
28  import="net.sf.basedb.core.SystemItems"
29  import="net.sf.basedb.core.Include"
30  import="net.sf.basedb.core.Item"
31  import="net.sf.basedb.core.ItemContext"
32  import="net.sf.basedb.core.ItemQuery"
33  import="net.sf.basedb.core.ItemResultList"
34  import="net.sf.basedb.core.Permission"
35  import="net.sf.basedb.core.HardwareType"
36  import="net.sf.basedb.core.Hardware"
37  import="net.sf.basedb.core.PermissionDeniedException"
38  import="net.sf.basedb.core.PluginDefinition"
39  import="net.sf.basedb.core.plugin.GuiContext"
40  import="net.sf.basedb.core.plugin.Plugin"
41  import="net.sf.basedb.core.query.Orders"
42  import="net.sf.basedb.core.query.Hql"
43  import="net.sf.basedb.clients.web.Base"
44  import="net.sf.basedb.clients.web.PermissionUtil"
45  import="net.sf.basedb.clients.web.util.HTML"
46  import="net.sf.basedb.util.Values"
47  import="net.sf.basedb.util.formatter.Formatter"
48  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
49  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
50  import="net.sf.basedb.clients.web.extensions.JspContext"
51  import="net.sf.basedb.clients.web.extensions.renderer.PrefixSuffixRenderer"
52  import="net.sf.basedb.clients.web.extensions.toolbar.ToolbarUtil"
53  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
54  import="java.util.Date"
55  import="java.util.Map"
56%>
57<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
58<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
59<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
60<%@ taglib prefix="p" uri="/WEB-INF/path.tld" %>
61<%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %>
62<%!
63  private static final Item itemType = Item.HARDWARETYPE;
64  private static final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.ITEM);
65%>
66<%
67final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
68final String ID = sc.getId();
69final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
70final int itemId = cc.getId();
71final float scale = Base.getScale(sc);
72final DbControl dc = sc.newDbControl();
73try
74{
75  Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc);
76  Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext);
77
78  String title = null;
79  HardwareType hardwareType = HardwareType.getById(dc, itemId);
80 
81  final boolean usePermission = hardwareType.hasPermission(Permission.USE);
82  final boolean writePermission = hardwareType.hasPermission(Permission.WRITE);
83  final boolean deletePermission = hardwareType.hasPermission(Permission.DELETE);
84  final boolean isRemoved = hardwareType.isRemoved();
85  final boolean isUsed = isRemoved && hardwareType.isUsed();
86  final boolean deletePermanentlyPermission = deletePermission && !isUsed;
87  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, guiContext, hardwareType);
88  ExtensionsInvoker invoker = ToolbarUtil.useExtensions(jspContext);
89  %>
90  <base:page title="<%=title%>">
91  <base:head scripts="tabcontrol.js" styles="toolbar.css,headertabcontrol.css,path.css,table.css">
92    <ext:scripts context="<%=jspContext%>" />
93    <ext:stylesheets context="<%=jspContext%>" />
94    <script language="JavaScript">
95    function editItem()
96    {
97      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', <%=itemId%>, true);
98    }
99    function deleteItem()
100    {
101      location.replace('index.jsp?ID=<%=ID%>&cmd=DeleteItem&item_id=<%=itemId%>');
102    }
103    function restoreItem()
104    {
105      location.replace('index.jsp?ID=<%=ID%>&cmd=RestoreItem&item_id=<%=itemId%>');
106    }
107    function deleteItemPermanently()
108    {
109      Main.deleteItemPermanently('<%=ID%>', true, '<%=itemType.name()%>', <%=itemId%>, '&callback=itemDeleted');
110    }
111    function itemDeleted()
112    {
113      Main.listItems('<%=ID%>', '<%=itemType.name()%>');
114    }
115    function showUsingItems()
116    {
117      Main.showUsingItems('<%=ID%>', '<%=itemType.name()%>', <%=itemId%>);
118    }
119    function runPlugin(cmd)
120    {
121      Main.openPopup('index.jsp?ID=<%=ID%>&cmd='+cmd+'&item_id=<%=itemId%>', 'RunPlugin'+cmd, 740, 540);
122    }
123    function newHardware()
124    {
125      Main.viewOrEditItem('<%=ID%>', 'HARDWARE', 0, true, '&hardwaretype_id=<%=itemId%>');
126    }
127    </script>
128  </base:head>
129  <base:body>
130    <p>
131    <p:path>
132      <p:pathelement title="Hardware types" href="<%="index.jsp?ID="+ID%>" />
133      <p:pathelement title="<%=HTML.encodeTags(hardwareType.getName())%>" />
134    </p:path>
135   
136    <t:tabcontrol id="main" active="properties">
137    <t:tab id="properties" title="Properties">
138   
139    <tbl:toolbar
140      >
141      <tbl:button 
142        disabled="<%=writePermission ? false : true%>" 
143        image="<%=writePermission ? "edit.gif" : "edit_disabled.gif"%>" 
144        onclick="editItem()" 
145        title="Edit&hellip;" 
146        tooltip="<%=writePermission ? "Edit this hardware type" : "You do not have permission to edit this hardware type"%>" 
147      />
148      <tbl:button 
149        disabled="<%=deletePermission ? false : true%>" 
150        image="<%=deletePermission ? "delete.gif" : "delete_disabled.gif"%>" 
151        onclick="deleteItem()" 
152        title="Delete"
153        visible="<%=!hardwareType.isRemoved()%>"
154        tooltip="<%=deletePermission ? "Delete this hardware type" : "You do not have permission to delete this hardware type"%>" 
155      />
156      <tbl:button 
157        disabled="<%=writePermission ? false : true%>" 
158        image="<%=writePermission ? "restore.gif" : "restore_disabled.gif"%>" 
159        onclick="restoreItem()" 
160        title="Restore"
161        visible="<%=hardwareType.isRemoved()%>"
162        tooltip="<%=writePermission ? "Restore this hardware type" : "You do not have permission to restore this hardware type"%>" 
163      />
164      <tbl:button
165        image="add.png"
166        onclick="newHardware()"
167        title="New hardware&hellip;"
168        tooltip="Create a new hardware of this type"
169        visible="<%=sc.hasPermission(Permission.CREATE, Item.HARDWARE) && usePermission%>"
170      />
171      <tbl:button 
172        image="export.gif" 
173        onclick="runPlugin('ExportItem')" 
174        title="Export&hellip;" 
175        tooltip="Export data" 
176        visible="<%=pluginCount.containsKey(Plugin.MainType.EXPORT)%>"
177      />
178      <tbl:button 
179        image="runplugin.gif" 
180        onclick="runPlugin('RunPlugin')" 
181        title="Run plugin&hellip;" 
182        tooltip="Run a plugin" 
183        visible="<%=pluginCount.containsKey(Plugin.MainType.OTHER)%>"
184      />
185      <ext:render extensions="<%=invoker%>" context="<%=jspContext%>" 
186        wrapper="<%=new PrefixSuffixRenderer(jspContext, "<td>", "</td>") %>"/>
187      <tbl:button
188        image="help.gif"
189        onclick="<%="Main.openHelp('" + ID +"', 'hardwaretype.view.properties')"%>"
190        title="Help&hellip;"
191        tooltip="Get help about this page"
192      />
193      </tbl:toolbar>
194    <div class="boxedbottom">
195      <div class="itemstatus">Permissions on this item: <i><%=PermissionUtil.getFullPermissionNames(hardwareType)%></i></div>
196      <%
197      if (hardwareType.isRemoved())
198      {
199        %>
200        <div class="itemstatus">
201          <base:icon 
202            image="<%=deletePermanentlyPermission ? "deleted.gif" : "deleted_disabled.gif"%>"
203            onclick="<%=deletePermanentlyPermission ? "deleteItemPermanently()" : null%>"
204            tooltip="<%=deletePermanentlyPermission ? "Permanently delete this item" : null%>"
205            visible="<%=isRemoved%>"> This item has been flagged for deletion<br></base:icon>
206          <base:icon image="used.gif" 
207            onclick="showUsingItems()"
208            tooltip="Show the items that are using this one"
209            visible="<%=isUsed%>"> This item is used by other items and can't be permanently deleted<br></base:icon>
210        </div>
211        <%
212      }
213      %>
214      <table class="form" cellspacing=0>
215      <tr>
216        <td class="prompt">Name</td>
217        <td><%=HTML.encodeTags(hardwareType.getName())%></td>
218      </tr>
219      <tr>
220        <td class="prompt">Registered</td>
221        <td><%=dateFormatter.format(hardwareType.getEntryDate())%></td>
222      </tr>
223      <tr>
224        <td class="prompt">System ID</td>
225        <td><%=HTML.encodeTags(hardwareType.getSystemId())%></td>
226      </tr>
227      <tr>
228        <td class="prompt">Description</td>
229        <td><%=HTML.niceFormat(hardwareType.getDescription())%></td>
230      </tr>
231      </table>
232
233      <%
234      ItemQuery<Hardware> hardwareQuery = hardwareType.getHardware();
235      hardwareQuery.include(Include.ALL);
236      hardwareQuery.order(Orders.asc(Hql.property("name")));
237      ItemResultList<Hardware> hardware = hardwareQuery.list(dc);
238      if (hardware.size() == 0)
239      {
240        %>
241        <h4>Hardware</h4>
242        No hardware of this type exists
243        (or, you don't have permission to view them).
244        <%
245      }
246      else
247      {
248        %>
249        <base:section
250          id="hardware"
251          title="<%="Hardware (" + hardware.size() + ")"%>"
252          context="<%=cc%>"
253          >
254          <tbl:table
255            id="hardware"
256            clazz="itemlist"
257            columns="all"
258            >
259          <tbl:columndef 
260            id="name"
261            title="Name"
262          />
263          <tbl:columndef
264            id="version"
265            title="Version"
266          />
267          <tbl:columndef 
268            id="description"
269            title="Description"
270          />
271          <tbl:data>
272            <tbl:columns>
273            </tbl:columns>
274            <tbl:rows>
275            <%
276            for (Hardware item : hardware)
277            {
278              %>
279              <tbl:row>
280                <tbl:cell column="name"><base:icon 
281                    image="deleted.gif" 
282                    tooltip="This item has been scheduled for deletion" 
283                    visible="<%=item.isRemoved()%>"
284                  /><%=Base.getLinkedName(ID, item, false, true)%></tbl:cell>
285                <tbl:cell column="version"><%=HTML.encodeTags(item.getVersionString())%></tbl:cell>
286                <tbl:cell column="description"><%=HTML.encodeTags(item.getDescription())%></tbl:cell>
287              </tbl:row>
288              <%
289            }
290            %>
291            </tbl:rows>
292          </tbl:data>
293          </tbl:table>
294        </base:section>
295        <%
296      }
297      %>
298     
299    </div>
300      </t:tab>
301      </t:tabcontrol>
302
303  </base:body>
304  </base:page>
305  <%
306}
307finally
308{
309  if (dc != null) dc.close();
310}
311
312%>
Note: See TracBrowser for help on using the repository browser.