source: trunk/www/views/trashcan/list_trash.jsp @ 3549

Last change on this file since 3549 was 3549, checked in by Martin Svensson, 16 years ago

References #611. Added new icon and text on the delete button in trashcan-listpage.
Added item-is-used-icon for those child items which are deleted but not possible to delete from trashcan.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 9.4 KB
Line 
1<%-- $Id: list_trash.jsp 3549 2007-07-04 12:59:34Z 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.Trashcan"
31  import="net.sf.basedb.core.Item"
32  import="net.sf.basedb.core.ItemContext"
33  import="net.sf.basedb.core.Permission"
34  import="net.sf.basedb.core.BasicItem"
35  import="net.sf.basedb.core.Removable"
36  import="net.sf.basedb.core.Nameable"
37  import="net.sf.basedb.core.File"
38  import="net.sf.basedb.core.Directory"
39  import="net.sf.basedb.core.Metadata"
40  import="net.sf.basedb.core.query.ResultList"
41  import="net.sf.basedb.util.Enumeration"
42  import="net.sf.basedb.clients.web.Base"
43  import="net.sf.basedb.clients.web.util.HTML"
44  import="net.sf.basedb.util.Values"
45%>
46<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
47<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
48<%!
49  private static final Item itemType = Item.SYSTEM;
50  private static final String subContext = "trashcan";
51
52  private static final Enumeration<String, String> items = new Enumeration<String, String>();
53  static
54  {
55    for (Item item : Metadata.getRemovableItems())
56    {
57      items.add(item.name(), item.toString());
58    }
59  }
60%>
61<%
62final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
63final String ID = sc.getId();
64final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subContext, null, null);
65
66final DbControl dc = sc.newDbControl();
67ResultList<Removable> trash = null;
68try
69{
70  long totalCount = 0;
71  try
72  {
73    String filterItem = cc.getPropertyValue("type");
74    trash = Trashcan.getItems(dc, filterItem == null ? null : Item.valueOf(filterItem), 
75      cc.getPage() * cc.getRowsPerPage(), cc.getRowsPerPage());
76    totalCount = trash.getTotalCount();
77  }
78  catch (Throwable t)
79  {
80    cc.setMessage(t.getMessage());
81  }
82  int numListed = 0;
83  %>
84  <base:page title="Trashcan">
85  <base:head scripts="menu.js,table.js" styles="menu.css,table.css">
86    <script language="JavaScript">
87    var submitPage = 'index.jsp';
88    var formId = 'trashcan';
89    function viewItem(itemId)
90    {
91      Main.openPopup('index.jsp?ID=<%=ID%>&cmd=ViewItem&item_id='+itemId, 'ViewJob', 740, 540);
92    }
93    function itemOnClick(evt, itemId)
94    {
95      viewItem(itemId);
96    }
97    function deleteAllItems()
98    {
99      if (!confirm('You are about to PERMANENTLY DELETE all item.\n This can\'t be undone. Continue?'))
100      {
101        return;
102      }
103      var frm = document.forms[formId];
104      frm.action = submitPage;
105      frm.cmd.value = 'DeleteAllPermanently';
106      frm.submit();
107    }
108    function deleteItems()
109    {
110      var frm = document.forms[formId];
111      var numChecked = Forms.numChecked(frm, /item:/);
112      if (numChecked == 0)
113      {
114        alert('Please select at least one item in the list');
115        return;
116      }
117      else
118      {
119        var items = numChecked == 1 ? 'item' : 'items';
120        if (!confirm('You are about to PERMANENTLY DELETE '+numChecked+' '+items+'.\n This can\'t be undone. Continue?'))
121        {
122          return;
123        }
124      }
125      frm.action = submitPage;
126      frm.cmd.value = 'DeleteItemsPermanently';
127      frm.submit();
128    }
129    function restoreItems()
130    {
131      var frm = document.forms[formId];
132      if (Forms.numChecked(frm, /item:/) == 0)
133      {
134        alert('Please select at least one item in the list');
135        return;
136      }
137      frm.action = submitPage;
138      frm.cmd.value = 'RestoreItems';
139      frm.submit();
140    }
141    function configureColumns()
142    {
143      Table.configureColumns('<%=ID%>', formId, '<%=itemType.name()%>', '<%=(String)cc.getObject("defaultColumns")%>', '<%=subContext%>');
144    }
145    function presetOnChange()
146    {
147      Table.presetOnChange('<%=ID%>', formId, '<%=itemType.name()%>', '<%=(String)cc.getObject("defaultColumns")%>', '<%=subContext%>');
148    }
149    function showUsingItems(itemType, itemId)
150    {
151      var url = 'index.jsp?ID=<%=ID%>&cmd=ViewUsingItems&item_type='+itemType+'&item_id='+itemId;
152      location.href = url;
153    }
154    </script>
155  </base:head>
156 
157  <base:body>
158    <%
159    if (cc.getMessage() != null)
160    {
161      %>
162      <div class="error"><%=cc.getMessage()%></div>
163      <%
164      cc.setMessage(null);
165    }
166    %>
167    <tbl:table 
168      id="trashcan" 
169      clazz="itemlist" 
170      columns="<%=cc.getSetting("columns")%>"
171      action="index.jsp"
172      sc="<%=sc%>"
173      item="<%=itemType%>"
174      subcontext="<%=subContext%>"
175      >
176      <tbl:columndef
177        id="type"
178        property="type"
179        datatype="string"
180        title="Item type"
181        enumeration="<%=items%>"
182        filterable="true"
183        show="always"
184      />
185      <tbl:columndef 
186        id="name"
187        title="Name"
188        show="always" 
189      />
190      <tbl:columndef 
191        id="description"
192        title="Description"
193      />
194      <tbl:toolbar>
195        <tbl:button
196          image="<%=totalCount > 0 ? "deleteall.png" : "deleteall_disabled.png"%>"
197          onclick="deleteAllItems()"
198          title="Empty trash&hellip;"
199          tooltip="Delete all items from the trashcan"
200          disabled="<%=totalCount <= 0%>"
201        />
202        <tbl:button 
203          image="<%=totalCount > 0 ? "delete_permanently.png" : "delete_permanently_disabled.png"%>"
204          onclick="deleteItems()" 
205          title="Delete permanently&hellip;" 
206          tooltip="Delete the selected items permanently" 
207          disabled="<%=totalCount <= 0%>"
208        />
209        <tbl:button 
210          image="<%=totalCount > 0 ? "restore.gif" : "restore_disabled.gif"%>"
211          onclick="restoreItems()" 
212          title="Restore" 
213          tooltip="Restore the selected items"
214          disabled="<%=totalCount <= 0%>"
215        />
216        <tbl:button 
217          image="columns.gif" 
218          onclick="configureColumns()" 
219          title="Columns&hellip;" 
220          tooltip="Show, hide and re-order columns" 
221        />
222      </tbl:toolbar>
223      <tbl:navigator
224        page="<%=cc.getPage()%>" 
225        rowsperpage="<%=cc.getRowsPerPage()%>" 
226        totalrows="<%=trash == null ? 0 : trash.getTotalCount()%>"
227      />
228      <tbl:data>
229        <tbl:columns>
230          <tbl:presetselector 
231            clazz="columnheader"
232            colspan="3"
233            onchange="presetOnChange()"
234          />
235        </tbl:columns>
236        <tr>
237          <tbl:header 
238            clazz="index"
239            >&nbsp;</tbl:header>
240          <tbl:header 
241            clazz="check" 
242            ><base:icon 
243              image="check_uncheck.gif" 
244              tooltip="Check/uncheck all" 
245              onclick="Forms.checkUncheck(document.forms[formId], /item:/)" style="align: left;"
246            /></tbl:header>
247          <tbl:header 
248            clazz="icons" 
249            >&nbsp;</tbl:header>
250           
251          <tbl:propertyfilter />
252        </tr>
253
254          <tbl:rows>
255          <%
256          int index = cc.getPage()*cc.getRowsPerPage();
257          if (trash != null)
258          {
259            for (Removable item : trash)
260            {
261              BasicItem basicItem = (BasicItem)item;
262              boolean isUsed = basicItem.isUsed();
263              int itemId = item.getId();
264              String name = "";
265              String description = "";
266              if (item instanceof File)
267              {
268                File file = (File)item;
269                name = file.getPath().toString();
270                description = file.getDescription();
271              }
272              else if (item instanceof Directory)
273              {
274                Directory dir = (Directory)item;
275                name = dir.getPath().toString();
276                description = dir.getDescription();
277              }
278              else if (item instanceof Nameable)
279              {
280                Nameable nameable = (Nameable)item;
281                name = nameable.getName();
282                description = nameable.getDescription();
283              }
284              else
285              {
286                name = item.toString();
287              }
288              String link = Base.getLink(ID, HTML.encodeTags(name), item.getType(), itemId, true);
289              index++;
290              numListed++;
291              %>
292              <tbl:row>
293                <tbl:header 
294                  clazz="index"
295                  ><%=index%></tbl:header>
296                <tbl:header 
297                  clazz="check" 
298                  ><input 
299                    type="checkbox" 
300                    name="item:<%=item.getType().name()%>" 
301                    value="<%=itemId%>"
302                  ></tbl:header>
303                <tbl:header 
304                  clazz="icons" 
305                  ><base:icon 
306                    image="used.gif" 
307                    tooltip="This item is used by other items and cannot be deleted"
308                    visible="<%=isUsed%>"
309                    onclick="<%="showUsingItems('" + item.getType().name() + "', " +  itemId + ")"%>"
310                  />&nbsp;</tbl:header>
311                <tbl:cell column="type"><%=item.getType()%></tbl:cell>
312                <tbl:cell column="name"><%=link%></tbl:cell>
313                <tbl:cell column="description"><%=HTML.encodeTags(description)%></tbl:cell>
314              </tbl:row>
315              <%
316              }
317            }
318          %>
319          </tbl:rows>
320      </tbl:data>
321      <%
322      if (numListed == 0)
323      {
324        %>
325        <tbl:panel><%=trash == null || trash.size() == 0 ? "No items were found" : "No items on this page. Please select another page!" %></tbl:panel>
326        <%
327      }
328      else
329      {
330        %>
331        <tbl:navigator
332          page="<%=cc.getPage()%>" 
333          rowsperpage="<%=cc.getRowsPerPage()%>" 
334          totalrows="<%=trash == null ? 0 : trash.getTotalCount()%>" 
335          locked="true"
336        />
337        <%
338      }
339      %>
340    </tbl:table>
341    <br><br><br>
342  </base:body>
343  </base:page>
344  <%
345}
346finally
347{
348  if (dc != null) dc.close();
349}
350%>
Note: See TracBrowser for help on using the repository browser.