source: trunk/www/admin/hardware/view_hardware.jsp @ 4889

Last change on this file since 4889 was 4889, checked in by Nicklas Nordborg, 13 years ago

References #1290: Change source files to UTF-8

Changed 'Hakkinen' to 'Häkkinen'.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 13.2 KB
Line 
1<%-- $Id: view_hardware.jsp 4889 2009-04-06 12:52:39Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg, Martin Svensson
4  Copyright (C) 2007 Martin Svensson
5
6  This file is part of BASE - BioArray Software Environment.
7  Available at http://base.thep.lu.se/
8
9  BASE is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License
11  as published by the Free Software Foundation; either version 3
12  of the License, or (at your option) any later version.
13
14  BASE is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  GNU General Public License for more details.
18
19  You should have received a copy of the GNU General Public License
20  along with BASE. If not, see <http://www.gnu.org/licenses/>.
21  ------------------------------------------------------------------
22
23  @author Nicklas
24  @version 2.0
25--%>
26<%@ page session="false"
27  import="net.sf.basedb.core.SessionControl"
28  import="net.sf.basedb.core.DbControl"
29  import="net.sf.basedb.core.SystemItems"
30  import="net.sf.basedb.core.Group"
31  import="net.sf.basedb.core.Item"
32  import="net.sf.basedb.core.ItemContext"
33  import="net.sf.basedb.core.ItemResultIterator"
34  import="net.sf.basedb.core.Permission"
35  import="net.sf.basedb.core.Hardware"
36  import="net.sf.basedb.core.HardwareType"
37  import="net.sf.basedb.core.User"
38  import="net.sf.basedb.core.MultiPermissions"
39  import="net.sf.basedb.core.PermissionDeniedException"
40  import="net.sf.basedb.core.PluginDefinition"
41  import="net.sf.basedb.core.plugin.GuiContext"
42  import="net.sf.basedb.core.plugin.Plugin"
43  import="net.sf.basedb.core.Project"
44  import="net.sf.basedb.clients.web.Base"
45  import="net.sf.basedb.clients.web.PermissionUtil"
46  import="net.sf.basedb.clients.web.util.HTML"
47  import="net.sf.basedb.util.Values"
48  import="net.sf.basedb.util.formatter.Formatter"
49  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
50  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
51  import="net.sf.basedb.clients.web.extensions.JspContext"
52  import="net.sf.basedb.clients.web.extensions.renderer.PrefixSuffixRenderer"
53  import="net.sf.basedb.clients.web.extensions.toolbar.ToolbarUtil"
54  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
55  import="java.util.Date"
56  import="java.util.Collections"
57  import="java.util.Map"
58  import="java.util.Set"
59%>
60<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
61<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
62<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
63<%@ taglib prefix="p" uri="/WEB-INF/path.tld" %>
64<%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %>
65<%!
66  private static final Item itemType = Item.HARDWARE;
67  private static final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.ITEM);
68%>
69<%
70final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
71final String ID = sc.getId();
72final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
73final int itemId = cc.getId();
74final float scale = Base.getScale(sc);
75final DbControl dc = sc.newDbControl();
76try
77{
78  Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc);
79  Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext);
80
81  String title = null;
82  Hardware hardware = Hardware.getById(dc, itemId);
83 
84  final boolean writePermission = hardware.hasPermission(Permission.WRITE);
85  final boolean deletePermission = hardware.hasPermission(Permission.DELETE);
86  final boolean sharePermission = hardware.hasPermission(Permission.SET_PERMISSION);
87  final boolean setOwnerPermission = hardware.hasPermission(Permission.SET_OWNER);
88  final boolean isOwner = hardware.isOwner();
89  final boolean isRemoved = hardware.isRemoved();
90  final boolean isUsed = isRemoved && hardware.isUsed();
91  final boolean deletePermanentlyPermission = deletePermission && !isUsed;
92  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, guiContext, hardware);
93  ExtensionsInvoker invoker = ToolbarUtil.useExtensions(jspContext);
94  %>
95  <base:page title="<%=title%>">
96  <base:head scripts="table,js,tabcontrol.js" styles="table.css,toolbar.css,headertabcontrol.css,path.css">
97    <ext:scripts context="<%=jspContext%>" />
98    <ext:stylesheets context="<%=jspContext%>" />
99    <script language="JavaScript">
100    function editItem()
101    {
102      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', <%=itemId%>, true);
103    }
104    function shareItem()
105    {
106      Main.openPopup('index.jsp?ID=<%=ID%>&cmd=ShareItem&item_id=<%=itemId%>', 'ShareHardware', 600, 400);
107    }
108    function deleteItem()
109    {
110      location.replace('index.jsp?ID=<%=ID%>&cmd=DeleteItem&item_id=<%=itemId%>');
111    }
112    function restoreItem()
113    {
114      location.replace('index.jsp?ID=<%=ID%>&cmd=RestoreItem&item_id=<%=itemId%>');
115    }
116    function deleteItemPermanently()
117    {
118      Main.deleteItemPermanently('<%=ID%>', true, '<%=itemType.name()%>', <%=itemId%>, '&callback=itemDeleted');
119    }
120    function itemDeleted()
121    {
122      Main.listItems('<%=ID%>', '<%=itemType.name()%>');
123    }
124    function showUsingItems()
125    {
126      Main.showUsingItems('<%=ID%>', '<%=itemType.name()%>', <%=itemId%>);
127    }
128    function setOwner()
129    {
130      Main.openPopup('index.jsp?ID=<%=ID%>&cmd=SetOwnerOfItem&item_id=<%=itemId%>', 'SetOwnerOfItem', 450, 150);
131    }
132    function runPlugin(cmd)
133    {
134      Main.openPopup('index.jsp?ID=<%=ID%>&cmd='+cmd+'&item_id=<%=itemId%>', 'RunPlugin'+cmd, 740, 540);
135    }
136    </script>
137  </base:head>
138  <base:body>
139    <p>
140    <p:path>
141      <p:pathelement title="Hardware" href="<%="index.jsp?ID="+ID%>" />
142      <p:pathelement title="<%=HTML.encodeTags(hardware.getName())%>" />
143    </p:path>
144   
145    <t:tabcontrol id="main" active="properties">
146    <t:tab id="properties" title="Properties">
147   
148    <tbl:toolbar
149      >
150      <tbl:button 
151        disabled="<%=writePermission ? false : true%>" 
152        image="<%=writePermission ? "edit.gif" : "edit_disabled.gif"%>" 
153        onclick="editItem()" 
154        title="Edit&hellip;" 
155        tooltip="<%=writePermission ? "Edit this hardware" : "You do not have permission to edit this hardware"%>" 
156      />
157      <tbl:button 
158        disabled="<%=deletePermission ? false : true%>" 
159        image="<%=deletePermission ? "delete.gif" : "delete_disabled.gif"%>" 
160        onclick="deleteItem()" 
161        title="Delete"
162        visible="<%=!hardware.isRemoved()%>"
163        tooltip="<%=deletePermission ? "Delete this hardware" : "You do not have permission to delete this hardware"%>" 
164      />
165      <tbl:button 
166        disabled="<%=writePermission ? false : true%>" 
167        image="<%=writePermission ? "restore.gif" : "restore_disabled.gif"%>" 
168        onclick="restoreItem()" 
169        title="Restore"
170        visible="<%=hardware.isRemoved()%>"
171        tooltip="<%=writePermission ? "Restore this hardware" : "You do not have permission to restore this hardware"%>" 
172      />
173      <tbl:button 
174        disabled="<%=sharePermission ? false : true%>"
175        image="<%=sharePermission ? "share.gif" : "share_disabled.gif"%>"
176        onclick="shareItem()" 
177        title="Share&hellip;" 
178        tooltip="<%=sharePermission ? "Share this hardware to other user, groups and projects" : "You do not have permission to share this hardware"%>"
179      />
180      <tbl:button 
181        disabled="<%=setOwnerPermission ? false : true%>"
182        image="<%=setOwnerPermission ? "take_ownership.png" : "take_ownership_disabled.png"%>"
183        onclick="setOwner()" 
184        title="Set owner&hellip;"
185        tooltip="<%=setOwnerPermission ? "Change owner of this item" : "You do not have permission to change ownership of this item"%>"
186      />
187      <tbl:button 
188        image="import.gif" 
189        onclick="runPlugin('ImportItem')" 
190        title="Import&hellip;" 
191        tooltip="Import data" 
192        visible="<%=pluginCount.containsKey(Plugin.MainType.IMPORT)%>"
193      />
194      <tbl:button 
195        image="export.gif" 
196        onclick="runPlugin('ExportItem')" 
197        title="Export&hellip;" 
198        tooltip="Export data" 
199        visible="<%=pluginCount.containsKey(Plugin.MainType.EXPORT)%>"
200      />
201      <tbl:button 
202        image="runplugin.gif" 
203        onclick="runPlugin('RunPlugin')" 
204        title="Run plugin&hellip;" 
205        tooltip="Run a plugin" 
206        visible="<%=pluginCount.containsKey(Plugin.MainType.OTHER)%>"
207      />
208      <ext:render extensions="<%=invoker%>" context="<%=jspContext%>" 
209        wrapper="<%=new PrefixSuffixRenderer(jspContext, "<td>", "</td>") %>"/>
210      <tbl:button
211        image="help.gif"
212        onclick="<%="Main.openHelp('" + ID +"', 'hardware.view.properties')"%>"
213        title="Help&hellip;"
214        tooltip="Get help about this page"
215      />
216      </tbl:toolbar>
217    <div class="boxedbottom">
218      <div class="itemstatus">Permissions on this item: <i><%=PermissionUtil.getFullPermissionNames(hardware)%></i></div>
219      <%
220      if (hardware.isRemoved() || hardware.isShared())
221      {
222        %>
223        <div class="itemstatus">
224          <base:icon 
225            image="<%=deletePermanentlyPermission ? "deleted.gif" : "deleted_disabled.gif"%>"
226            onclick="<%=deletePermanentlyPermission ? "deleteItemPermanently()" : null%>"
227            tooltip="<%=deletePermanentlyPermission ? "Permanently delete this item" : null%>"
228            visible="<%=isRemoved%>"> This item has been flagged for deletion<br></base:icon>
229          <base:icon image="used.gif" 
230            onclick="showUsingItems()"
231            tooltip="Show the items that are using this one"
232            visible="<%=isUsed%>"> This item is used by other items and can't be permanently deleted<br></base:icon>
233          <base:icon image="shared.gif" 
234            visible="<%=hardware.isShared()%>"> This item is shared to other users, groups and/or projects</base:icon>
235        </div>
236        <%
237      }
238      %>
239      <table class="form" cellspacing=0>
240      <tr>
241        <td class="prompt">Name</td>
242        <td><%=HTML.encodeTags(hardware.getName())%></td>
243      </tr>
244      <tr>
245        <td class="prompt">Registered</td>
246        <td><%=dateFormatter.format(hardware.getEntryDate())%></td>
247      </tr>
248      <tr>
249        <td class="prompt">Type</td>
250        <td><base:propertyvalue item="<%=hardware%>" property="hardwareType" /></td>
251      </tr>
252      <tr>
253        <td class="prompt">Version</td>
254        <td><%=HTML.encodeTags(hardware.getVersionString())%></td>
255      </tr>
256      <tr>
257        <td class="prompt">Owner</td>
258        <td><base:propertyvalue item="<%=hardware%>" property="owner" /></td>
259      </tr>
260      <tr>
261        <td class="prompt">Description</td>
262        <td><%=HTML.niceFormat(hardware.getDescription())%></td>
263      </tr>
264      </table>
265      <%     
266     
267      // Tables with users/groups/projects that this item is shared to
268      MultiPermissions mp = new MultiPermissions(Collections.singleton(hardware));
269      ItemResultIterator<User> users = mp.getUsers().iterate(dc);
270      ItemResultIterator<Group> groups = mp.getGroups().iterate(dc);
271      ItemResultIterator<Project> projects = mp.getProjects().iterate(dc);
272     
273      if (users.hasNext() || groups.hasNext() || projects.hasNext())
274      {
275        %>
276        <h4 class="docked">Shared to</h4>
277        <tbl:table 
278          id="itemsSharedTo"
279          clazz="itemlist"
280          columns="all"
281        >
282          <tbl:columndef 
283            id="itemType"
284            title="Item type"
285          />
286          <tbl:columndef 
287            id="name"
288            title="Name"
289          />
290          <tbl:columndef 
291            id="permissions"
292            title="Permissions"
293          />
294          <tbl:data>
295            <tbl:columns>
296            </tbl:columns>
297            <tbl:rows>
298            <%
299            while(projects.hasNext())
300            {
301              Project project = projects.next();
302              Set<Permission> permissions = mp.getPermissions(project).values().iterator().next();
303              %>     
304              <tbl:row>
305                <tbl:cell column="itemType"><%=project.getType()%></tbl:cell>
306                <tbl:cell column="name"><base:icon 
307                  image="deleted.gif" 
308                  tooltip="This item has been scheduled for deletion" 
309                  visible="<%=project.isRemoved()%>"
310                /><%=Base.getLinkedName(ID, project, false, true)%></tbl:cell>
311                <tbl:cell column="permissions">
312                  <%=PermissionUtil.translatePermissionsToString(permissions)%>
313                </tbl:cell>
314              </tbl:row>
315              <%
316            }
317            while(groups.hasNext())
318            {
319              Group group = groups.next();
320              Set<Permission> permissions = mp.getPermissions(group).values().iterator().next();
321              %>
322              <tbl:row>             
323                <tbl:cell column="itemType"><%=group.getType()%></tbl:cell>
324                <tbl:cell column="name"><base:icon 
325                  image="deleted.gif" 
326                  tooltip="This item has been scheduled for deletion" 
327                  visible="<%=group.isRemoved()%>"
328                /><%=Base.getLinkedName(ID, group, false, true)%></tbl:cell>
329                <tbl:cell column="permissions">
330                  <%=PermissionUtil.translatePermissionsToString(permissions)%>
331                </tbl:cell>
332              </tbl:row>
333              <% 
334            }
335            while (users.hasNext())
336            {
337              User user = users.next();
338              Set<Permission> permissions = mp.getPermissions(user).values().iterator().next();
339              %>
340              <tbl:row>             
341                <tbl:cell column="itemType"><%=user.getType()%></tbl:cell>
342                <tbl:cell column="name"><base:icon 
343                  image="deleted.gif" 
344                  tooltip="This item has been scheduled for deletion" 
345                  visible="<%=user.isRemoved()%>"
346                /><%=Base.getLinkedName(ID, user, false, true)%></tbl:cell>
347                <tbl:cell column="permissions">
348                  <%=PermissionUtil.translatePermissionsToString(permissions)%>
349                </tbl:cell>
350              </tbl:row>
351              <%
352            }
353            %>
354            </tbl:rows>
355          </tbl:data>
356        </tbl:table>
357        <%
358      }
359      else
360      {
361        %>
362        <h4>Shared to</h4>
363        This hardware is not shared
364        (or, you don't have permission to view the ones it is shared to).
365        <%
366      }
367      %>
368    </div>
369      </t:tab>
370      </t:tabcontrol>
371
372
373  </base:body>
374  </base:page>
375  <%
376}
377finally
378{
379  if (dc != null) dc.close();
380}
381
382%>
Note: See TracBrowser for help on using the repository browser.