source: trunk/www/common/anytoany/list_anytoany.jsp @ 7761

Last change on this file since 7761 was 7761, checked in by Nicklas Nordborg, 3 years ago

References #2199: Implement a "File viewer" extension point

Implemented in the any-to-any lists.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 9.0 KB
Line 
1<%-- $Id: list_anytoany.jsp 7761 2019-11-27 14:23:27Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2006 Nicklas Nordborg
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 pageEncoding="UTF-8" session="false"
26  import="net.sf.basedb.core.SessionControl"
27  import="net.sf.basedb.core.DbControl"
28  import="net.sf.basedb.core.Item"
29  import="net.sf.basedb.core.Permission"
30  import="net.sf.basedb.core.BasicItem"
31  import="net.sf.basedb.core.AnyToAny"
32  import="net.sf.basedb.core.Nameable"
33  import="net.sf.basedb.core.ItemSubtype"
34  import="net.sf.basedb.core.Subtypable"
35  import="net.sf.basedb.core.Removable"
36  import="net.sf.basedb.core.File"
37  import="net.sf.basedb.core.ItemQuery"
38  import="net.sf.basedb.core.ItemContext"
39  import="net.sf.basedb.core.ItemResultList"
40  import="net.sf.basedb.core.PermissionDeniedException"
41  import="net.sf.basedb.core.ItemNotFoundException"
42  import="net.sf.basedb.core.query.Orders"
43  import="net.sf.basedb.core.query.Hql"
44  import="net.sf.basedb.core.plugin.GuiContext"
45  import="net.sf.basedb.util.Values"
46  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
47  import="net.sf.basedb.clients.web.Base"
48  import="net.sf.basedb.clients.web.util.HTML"
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.toolbar.ButtonAction" 
52  import="net.sf.basedb.clients.web.extensions.toolbar.ToolbarUtil"
53  import="net.sf.basedb.clients.web.extensions.list.ListColumnAction"
54  import="net.sf.basedb.clients.web.extensions.list.ListColumnUtil"
55  import="net.sf.basedb.clients.web.extensions.fileviewer.FileViewerContext"
56  import="net.sf.basedb.clients.web.extensions.fileviewer.FileViewerUtil"
57  import="net.sf.basedb.clients.web.extensions.renderer.PrefixSuffixRenderer"
58  import="java.util.List"
59%>
60<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
61<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
62<%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %>
63<%
64String root = request.getContextPath() + "/";
65final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
66final String ID = sc.getId();
67final Item itemType = Item.valueOf(request.getParameter("item_type"));
68final int itemId = Values.getInt(request.getParameter("item_id"));
69final float scale = Base.getScale(sc);
70final DbControl dc = sc.newDbControl();
71final ItemContext cc = sc.getCurrentContext(itemType);
72String title = Values.getString(request.getParameter("title"), "Related items");
73
74try
75{
76  final BasicItem item = itemType.getById(dc, itemId);
77  final boolean createPermission = item.hasPermission(Permission.WRITE);
78  final boolean deletePermission = createPermission;
79 
80  ItemQuery<AnyToAny> query = AnyToAny.getLinksFrom(item);
81  query.order(Orders.asc(Hql.property("name")));
82  ItemResultList<AnyToAny> links = query.list(dc);
83  long count = links.getTotalCount();
84 
85  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, new GuiContext(Item.ANYTOANY, GuiContext.Type.LIST), item);
86  ExtensionsInvoker<ButtonAction> invoker = ToolbarUtil.useExtensions(jspContext);
87  ExtensionsInvoker<ListColumnAction<AnyToAny,?>> columnsInvoker = ListColumnUtil.useExtensions(jspContext);
88  FileViewerContext fileContext = FileViewerContext.anyToAny(item);
89  FileViewerUtil fileViewer = new FileViewerUtil(jspContext, fileContext);
90  %>
91  <base:page type="include">
92  <base:head scripts="/common/anytoany/list.js" />
93  <base:body>
94    <ext:scripts context="<%=jspContext%>" />
95    <base:section 
96      id="anytoany" 
97      title="<%=title + " (" + (count) +")"%>"
98      context="<%=cc%>">
99
100        <tbl:table
101          id="links"
102          columns="all"
103          sc="<%=sc%>"
104          action="<%=root + "common/anytoany/index.jsp"%>"
105          >
106          <tbl:columndef 
107            id="name"
108            title="Name"
109          />
110          <tbl:columndef 
111            id="item"
112            title="Item"
113          />
114          <tbl:columndef 
115            id="description"
116            title="Description"
117          />
118          <tbl:columndef 
119            id="xt-columns" 
120            extensions="<%=columnsInvoker%>" 
121            jspcontext="<%=jspContext%>" 
122          />
123          <tbl:toolbar
124            subclass="topborder leftborder rightborder bg-filled-50"
125            >
126            <tbl:button 
127              id="btnNewLink"
128              disabled="<%=!createPermission%>" 
129              image="add.png" 
130              title="Add link&hellip;" 
131              tooltip="<%=createPermission ? "Create new link" : "You do not have permission to create links"%>" 
132              data-item-type="ANYTOANY"
133              data-extra-url="<%="&from_type="+itemType.name() + "&from_id="+itemId %>"
134            />
135            <tbl:button 
136              id="btnUnlinkItems"
137              image="delete_permanently.png"
138              title="Unlink&hellip;" 
139              tooltip="Unlink the selected items"
140              visible="<%=count > 0 %>"
141              disabled="<%=!deletePermission%>"
142            />
143            <ext:render extensions="<%=invoker%>" context="<%=jspContext%>" 
144              wrapper="<%=new PrefixSuffixRenderer<ButtonAction>(jspContext, "<td>", "</td>") %>"/>
145          </tbl:toolbar>
146          <tbl:data>
147            <tbl:headers style="<%=links.size() == 0 ? "display: none;" : "" %>">
148              <tbl:headerrow>
149              <tbl:header subclass="index" />
150              <tbl:header 
151                subclass="check"
152                ><base:icon 
153                  subclass="link table-check"
154                  image="check_uncheck.png" 
155                  tooltip="Toggle all (use CTRL, ALT or SHIFT to check/uncheck)" 
156                /></tbl:header>
157                <tbl:columnheaders />
158              </tbl:headerrow>
159            </tbl:headers>
160            <tbl:rows>
161            <%
162            int index = 0;
163            for (AnyToAny ata : links)
164            {
165              index++;
166              String name = HTML.encodeTags(ata.getName());
167              int ataId = ata.getId();
168              BasicItem to = null;
169              String subtype = ata.getToType().toString();
170              boolean readTo = true;
171              boolean missingTo = false;
172              try
173              {
174                to = ata.getTo();
175              }
176              catch (PermissionDeniedException ex)
177              {
178                readTo = false;
179              }
180              catch (ItemNotFoundException ex)
181              {
182                missingTo = true;
183              }
184             
185              String toLink = "";
186              if (to instanceof Nameable)
187              {
188                Nameable nameable = (Nameable)to;
189                toLink = Base.getLinkedName(ID, nameable, false, true);
190              }
191              else if (!readTo)
192              {
193                toLink = "<i>- denied -</i>";
194              }
195              else if (missingTo)
196              {
197                toLink = "<i>- missing -</i> (" + ata.getToType().toString() + "; id=" + ata.getToId() + ")";
198              }
199              else if (to == null)
200              {
201                toLink = "<i>- none -</i>";
202              }
203              else
204              {
205                toLink = Base.getLink(ID, to.toString(), to.getType(), to.getId(), true);
206              }
207              if (to instanceof File)
208              {
209                File toFile = (File)to;
210                fileContext.setCurrentAnyToAny(toFile, ata);
211                toLink += " " + fileViewer.renderAsString();
212              }
213              if (to instanceof Subtypable)
214              {
215                try
216                {
217                  ItemSubtype st = ((Subtypable)to).getItemSubtype();
218                  if (st != null) subtype = st.getName();
219                }
220                catch (RuntimeException ex)
221                {}
222              }
223              boolean isRemoved = false;
224              if (to instanceof Removable)
225              {
226                isRemoved = ((Removable)to).isRemoved();
227              }
228              toLink += " <span class=\"itemsubtype\">("+HTML.encodeTags(subtype)+")</span>";
229              %>
230              <tbl:row>
231                <tbl:header 
232                  clazz="index"
233                  ><%=index%></tbl:header>
234                <tbl:header 
235                  clazz="check" 
236                  ><input 
237                    type="checkbox" 
238                    name="<%=ataId%>" 
239                    value="<%=ataId%>" 
240                    title="<%=name%>"
241                  ></tbl:header>
242                <tbl:cell column="name"><%=Base.getLinkedName(ID, ata, false, true)%></tbl:cell>
243                <tbl:cell column="item"><base:icon image="deleted.png"
244                  tooltip="This item has been scheduled for deletion"
245                  visible="<%=isRemoved%>" />
246                  <%=toLink%></tbl:cell>
247                <tbl:cell column="description"><%=HTML.niceFormat(ata.getDescription())%></tbl:cell>
248                <tbl:xt-cells dc="<%=dc%>" item="<%=ata%>">
249                  <tbl:cell column="xt-columns" />
250                </tbl:xt-cells>
251              </tbl:row>
252              <%
253            }
254            if (count == 0)
255            {
256              %>
257              <tbl:panel>
258                There are no other items related to this
259                <%=itemType.toString().toLowerCase() %>.
260              </tbl:panel>
261              <%
262            }
263            %>
264            </tbl:rows>
265          </tbl:data>
266        </tbl:table>
267    </base:section>
268  </base:body>
269  </base:page>
270  <%
271}
272finally
273{
274  if (dc != null) dc.close();
275}
276
277%>
Note: See TracBrowser for help on using the repository browser.