source: trunk/www/my_base/projects/view_project.jsp @ 5937

Last change on this file since 5937 was 5937, checked in by Nicklas Nordborg, 11 years ago

References #1655: GUI improvements

  • Fixes rest of view pages in biomaterials menu.
  • Use SVG filter to make disabled button images grayscale.
  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 14.4 KB
Line 
1<%-- $Id: view_project.jsp 5937 2012-01-27 11:00:26Z nicklas $
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 import="net.sf.basedb.core.Subtypable"%>
26<%@ page pageEncoding="UTF-8" session="false"
27  import="net.sf.basedb.core.SessionControl"
28  import="net.sf.basedb.core.BasicItem"
29  import="net.sf.basedb.core.Nameable"
30  import="net.sf.basedb.core.DbControl"
31  import="net.sf.basedb.core.SystemItems"
32  import="net.sf.basedb.core.Item"
33  import="net.sf.basedb.core.ItemContext"
34  import="net.sf.basedb.core.Include"
35  import="net.sf.basedb.core.Permission"
36  import="net.sf.basedb.core.Project"
37  import="net.sf.basedb.core.User"
38  import="net.sf.basedb.core.Group"
39  import="net.sf.basedb.core.ItemQuery"
40  import="net.sf.basedb.core.ItemResultList"
41  import="net.sf.basedb.core.PermissionDeniedException"
42  import="net.sf.basedb.core.PluginDefinition"
43  import="net.sf.basedb.core.plugin.GuiContext"
44  import="net.sf.basedb.core.plugin.Plugin"
45  import="net.sf.basedb.core.query.Orders"
46  import="net.sf.basedb.core.RawDataType"
47  import="net.sf.basedb.core.query.Hql"
48  import="net.sf.basedb.clients.web.Base"
49  import="net.sf.basedb.clients.web.PermissionUtil"
50  import="net.sf.basedb.clients.web.util.HTML"
51  import="net.sf.basedb.util.Values"
52  import="net.sf.basedb.util.formatter.Formatter"
53  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
54  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
55  import="net.sf.basedb.clients.web.extensions.JspContext"
56  import="net.sf.basedb.clients.web.extensions.renderer.PrefixSuffixRenderer"
57  import="net.sf.basedb.clients.web.extensions.toolbar.ToolbarUtil"
58  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
59  import="java.util.Date"
60  import="java.util.Map"
61  import="java.util.Set"
62  import="java.util.List"
63%>
64<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
65<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
66<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
67<%@ taglib prefix="p" uri="/WEB-INF/path.tld" %>
68<%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %>
69<%!
70  private static final Item itemType = Item.PROJECT;
71  private static final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.ITEM);
72%>
73<%
74final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
75final String ID = sc.getId();
76final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
77final int itemId = cc.getId();
78final String tab = Values.getString(request.getParameter("tab"), "properties");
79final float scale = Base.getScale(sc);
80final DbControl dc = sc.newDbControl();
81try
82{
83  Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc);
84  Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext);
85
86  String title = null;
87  Project project = Project.getById(dc, itemId);
88 
89  final boolean usePermission = project.hasPermission(Permission.USE);
90  final boolean writePermission = project.hasPermission(Permission.WRITE);
91  final boolean deletePermission = project.hasPermission(Permission.DELETE);
92  final boolean setOwnerPermission = project.hasPermission(Permission.SET_OWNER);
93  final boolean isRemoved = project.isRemoved();
94  final boolean isUsed = isRemoved && project.isUsed();
95  final boolean deletePermanentlyPermission = deletePermission && !isUsed;
96  final boolean isOwner = project.isOwner();
97  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, guiContext, project);
98  ExtensionsInvoker invoker = ToolbarUtil.useExtensions(jspContext);
99  %>
100  <base:page title="<%=title%>">
101  <base:head scripts="table.js,tabcontrol.js" styles="table.css,toolbar.css,headertabcontrol.css,path.css">
102    <ext:scripts context="<%=jspContext%>" />
103    <ext:stylesheets context="<%=jspContext%>" />
104    <script language="JavaScript">
105    function editItem()
106    {
107      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', <%=itemId%>, true);
108    }
109    function deleteItem()
110    {
111      location.replace('index.jsp?ID=<%=ID%>&cmd=DeleteItem&item_id=<%=itemId%>');
112    }
113    function restoreItem()
114    {
115      location.replace('index.jsp?ID=<%=ID%>&cmd=RestoreItem&item_id=<%=itemId%>');
116    }
117    function deleteItemPermanently()
118    {
119      Main.deleteItemPermanently('<%=ID%>', true, '<%=itemType.name()%>', <%=itemId%>, '&callback=itemDeleted');
120    }
121    function itemDeleted()
122    {
123      Main.listItems('<%=ID%>', '<%=itemType.name()%>');
124    }
125    function showUsingItems()
126    {
127      Main.showUsingItems('<%=ID%>', '<%=itemType.name()%>', <%=itemId%>);
128    }
129    function setOwner()
130    {
131      Main.openPopup('index.jsp?ID=<%=ID%>&cmd=SetOwnerOfItem&item_id=<%=itemId%>', 'SetOwnerOfItem', 450, 300);
132    }
133    function runPlugin(cmd)
134    {
135      Main.openPopup('index.jsp?ID=<%=ID%>&cmd='+cmd+'&item_id=<%=itemId%>', 'RunPlugin'+cmd, 750, 500);
136    }
137    function setToActive()
138    {
139      Main.openPopup('set_active.jsp?ID=<%=ID%>&project_id=<%=itemId%>', 'ActivateProject', 300, 140);
140    }
141    function viewItems()
142    {
143      location.href = 'items/index.jsp?ID=<%=ID%>&project_id=<%=itemId%>';
144    }
145    function switchTab(tabControlId, tabId)
146    {
147      if (tabId == 'items')
148      {
149        viewItems();
150      }
151      else
152      {
153        TabControl.setActiveTab(tabControlId, tabId);
154      }
155    }
156    </script>
157  </base:head>
158  <base:body>
159    <p>
160    <p:path>
161      <p:pathelement title="Projects" href="<%="index.jsp?ID="+ID%>" />
162      <p:pathelement title="<%=HTML.encodeTags(project.getName())%>" />
163    </p:path>
164   
165    <t:tabcontrol id="main" active="<%=tab%>" switch="switchTab">
166    <t:tab id="properties" title="Properties">
167
168    <tbl:toolbar
169      >
170      <tbl:button 
171        disabled="<%=writePermission ? false : true%>" 
172        image="edit.gif" 
173        onclick="editItem()" 
174        title="Edit&hellip;" 
175        tooltip="<%=writePermission ? "Edit this project" : "You do not have permission to edit this project"%>" 
176      />
177      <tbl:button 
178        disabled="<%=deletePermission ? false : true%>" 
179        image="delete.gif" 
180        onclick="deleteItem()" 
181        title="Delete"
182        visible="<%=!project.isRemoved()%>"
183        tooltip="<%=deletePermission ? "Delete this project" : "You do not have permission to delete this project"%>" 
184      />
185      <tbl:button 
186        disabled="<%=writePermission ? false : true%>" 
187        image="restore.gif" 
188        onclick="restoreItem()" 
189        title="Restore"
190        visible="<%=project.isRemoved()%>"
191        tooltip="<%=writePermission ? "Restore this project" : "You do not have permission to restore this project"%>" 
192      />
193      <tbl:button 
194        disabled="<%=setOwnerPermission ? false : true%>"
195        image="take_ownership.png"
196        onclick="setOwner()" 
197        title="Set owner&hellip;"
198        tooltip="<%=setOwnerPermission ? "Change owner of this item" : "You do not have permission to change ownership of this item"%>"
199      />
200      <tbl:button 
201        onclick="setToActive()" 
202        image="bullet.gif"
203        title="Set active"
204        tooltip="Set this project to the active project"
205      />
206      <tbl:button 
207        image="import.gif" 
208        onclick="runPlugin('ImportItem')" 
209        title="Import&hellip;" 
210        tooltip="Import data" 
211        visible="<%=pluginCount.containsKey(Plugin.MainType.IMPORT)%>"
212      />
213      <tbl:button 
214        image="export.gif" 
215        onclick="runPlugin('ExportItem')" 
216        title="Export&hellip;" 
217        tooltip="Export data" 
218        visible="<%=pluginCount.containsKey(Plugin.MainType.EXPORT)%>"
219      />
220      <tbl:button 
221        image="runplugin.gif" 
222        onclick="runPlugin('RunPlugin')" 
223        title="Run plugin&hellip;" 
224        tooltip="Run a plugin" 
225        visible="<%=pluginCount.containsKey(Plugin.MainType.OTHER)%>"
226      />
227      <ext:render extensions="<%=invoker%>" context="<%=jspContext%>" 
228        wrapper="<%=new PrefixSuffixRenderer(jspContext, "<td>", "</td>") %>"/>
229      <tbl:button
230        image="help.png"
231        onclick="<%="Main.openHelp('" + ID +"', 'project.view.properties')"%>"
232        title="Help&hellip;"
233        tooltip="Get help about this page"
234      />
235      </tbl:toolbar>
236    <div class="boxedbottom">
237      <div class="itemstatus">Permissions on this item: <i><%=PermissionUtil.getFullPermissionNames(project)%></i></div>
238      <%
239      if (project.isRemoved())
240      {
241        %>
242        <div class="itemstatus">
243          <base:icon 
244            image="<%=deletePermanentlyPermission ? "deleted.gif" : "deleted_disabled.gif"%>"
245            onclick="<%=deletePermanentlyPermission ? "deleteItemPermanently()" : null%>"
246            tooltip="<%=deletePermanentlyPermission ? "Permanently delete this item" : null%>"
247            visible="<%=isRemoved%>"> This item has been flagged for deletion<br></base:icon>
248          <base:icon image="used.gif" 
249            onclick="showUsingItems()"
250            tooltip="Show the items that are using this one"
251            visible="<%=isUsed%>"> This item is used by other items and can't be permanently deleted<br></base:icon>
252        </div>
253        <%
254      }
255      %>
256      <table class="form" cellspacing=0>
257      <tr>
258        <td class="prompt">Name</td>
259        <td><%=HTML.encodeTags(project.getName())%></td>
260      </tr>
261      <tr>
262        <td class="prompt">Registered</td>
263        <td><%=dateFormatter.format(project.getEntryDate())%></td>
264      </tr>
265      <tr>
266        <td class="prompt">Owner</td>
267        <td><base:propertyvalue item="<%=project%>" property="owner" /></td>
268      </tr>
269      <tr>
270        <td class="prompt">Default permissions</td>
271        <td><base:propertyvalue item="<%=project%>" property="permissionTemplate" 
272          nulltext="<%=PermissionUtil.getFullPermissionNames(project.getAutoPermission())%>" /></td>
273      </tr>
274      <tr>
275        <td class="prompt">Description</td>
276        <td><%=HTML.niceFormat(project.getDescription())%></td>
277      </tr>
278      </table>
279      <%
280      // Query to retrieve child groups
281      ItemQuery<Group> groupQuery = project.getGroups();
282      groupQuery.include(Include.ALL);
283      groupQuery.order(Orders.asc(Hql.property("name")));
284      ItemResultList<Group> groups = groupQuery.list(dc);
285     
286      // Query to retrieve user members
287      ItemQuery<User> userQuery = project.getUsers();
288      userQuery.include(Include.ALL);
289      userQuery.order(Orders.asc(Hql.property("name")));
290      ItemResultList<User> users = userQuery.list(dc);
291      if (groups.size() + users.size() == 0)
292      {
293        %>
294        <h4>Members</h4>
295        There are no members in this project
296        (or, you don't have permission to view them).
297        <%
298      }
299      else
300      {
301        %>
302      <base:section
303        id="membersSection"
304        title="<%="Members (" + (groups.size() + users.size()) + ")"%>"
305        context="<%=cc%>"
306        >     
307        <tbl:table
308          id="members"
309         
310          columns="all"
311          >
312          <tbl:columndef
313            id="type"
314            title="User/Group"
315          />
316          <tbl:columndef
317            id="name"
318            title="Name"
319          />
320          <tbl:columndef
321            id="permissions"
322            title="Permissions"
323          />
324          <tbl:data>
325            <tbl:columns />
326            <tbl:rows>
327            <%         
328            for (Group group : groups)
329            {
330              Set<Permission> permissions = project.getPermissions(group);
331              %>
332              <tbl:row>
333                <tbl:cell column="type">Group</tbl:cell>
334                <tbl:cell column="name"><base:icon 
335                    image="deleted.gif" 
336                    tooltip="This item has been scheduled for deletion" 
337                    visible="<%=group.isRemoved()%>"
338                  /><%=Base.getLinkedName(ID, group, false, true)%></tbl:cell>
339                <tbl:cell column="permissions"><%=permissions.toString().replaceAll("\\[|\\]", "")%></tbl:cell>
340              </tbl:row>
341              <%
342            }
343            for (User user : users)
344            {
345              Set<Permission> permissions = project.getPermissions(user);
346              %>
347              <tbl:row>
348                <tbl:cell column="type">User</tbl:cell>
349                <tbl:cell column="name"><base:icon 
350                    image="deleted.gif" 
351                    tooltip="This item has been scheduled for deletion" 
352                    visible="<%=user.isRemoved()%>"
353                  /><%=Base.getLinkedName(ID, user, false, true)%></tbl:cell>
354                <tbl:cell column="permissions"><%=permissions.toString().replaceAll("\\[|\\]", "")%></tbl:cell>
355              </tbl:row>
356              <%
357            }
358            %>
359            </tbl:rows>
360          </tbl:data>
361        </tbl:table>
362      </base:section>
363      <%
364      }
365      List<BasicItem> defaultItems = project.getDefaultItems(dc);
366      if (defaultItems.size() == 0 && project.getDefaultRawDataType() == null)
367      {
368        %>
369        <h4>Default items</h4>
370        There are no default items in this project
371        (or, you don't have permission to view them).
372        <%
373      }
374      else
375      {
376        %>
377      <base:section 
378        id="defaultSection" 
379        title="Default items"
380        context="<%=cc%>"
381        >     
382        <tbl:table 
383          id="defaults"
384         
385          columns="all"
386        >
387        <tbl:columndef
388          id="item"
389          title="Item"
390        />
391        <tbl:columndef
392          id="type"
393          title="Type"
394        />
395        <tbl:data>
396          <tbl:columns />
397            <tbl:rows>     
398            <%
399            if (project.getDefaultRawDataType() != null)
400            {
401              %>
402              <tbl:row>
403                <tbl:cell column="item"><%=project.getDefaultRawDataType().getName()%></tbl:cell>
404                <tbl:cell column="type">Raw data type</tbl:cell>
405              </tbl:row>
406              <%
407            }
408            for (BasicItem item : defaultItems)
409            {
410              %>
411              <tbl:row>
412                <tbl:cell column="item"><base:propertyvalue item="<%=item%>" /></tbl:cell>
413                <tbl:cell column="type">
414                  <%
415                  if (item instanceof Subtypable)
416                  {
417                    %>
418                    <base:propertyvalue item="<%=item%>" property="itemSubtype" nulltext="" /> (<%=item.getType()%>)
419                    <%
420                  }
421                  else
422                  {
423                    %>
424                    <%=item.getType()%>
425                    <%
426                  }
427                  %>
428                </tbl:cell>
429              </tbl:row>
430              <%
431            }
432            %>
433            </tbl:rows>
434          </tbl:data>
435        </tbl:table>
436      </base:section>
437      <%
438      }
439      %>
440           
441      <jsp:include page="../../common/anytoany/list_anytoany.jsp">
442        <jsp:param name="ID" value="<%=ID%>" />
443        <jsp:param name="item_type" value="<%=itemType.name()%>" />
444        <jsp:param name="item_id" value="<%=itemId%>" />
445        <jsp:param name="title" value="Other items related to this project" />
446      </jsp:include>
447    </div>
448      </t:tab>
449     
450      <t:tab id="items" title="Items" tooltip="List all items in this project" />
451     
452      </t:tabcontrol>
453
454  </base:body>
455  </base:page>
456  <%
457  dc.commit();
458}
459finally
460{
461  if (dc != null) dc.close();
462}
463
464%>
Note: See TracBrowser for help on using the repository browser.