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

Last change on this file since 3655 was 3655, checked in by Nicklas Nordborg, 16 years ago

Fixes #720: Progress reporter when emptying trashcan

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 9.7 KB
Line 
1<%-- $Id: list_trash.jsp 3655 2007-08-10 12:22:57Z nicklas $
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      Main.openPopup('../../common/progress_reporter.jsp?ID=<%=ID%>&progress=trashcan&title=Empty trashcan', 'Progress', 400, 200);
104      var frm = document.forms[formId];
105      frm.action = submitPage;
106      frm.cmd.value = 'DeleteAllPermanently';
107      frm.submit();
108    }
109    function deleteItems()
110    {
111      var frm = document.forms[formId];
112      var numChecked = Forms.numChecked(frm, /item:/);
113      if (numChecked == 0)
114      {
115        alert('Please select at least one item in the list');
116        return;
117      }
118      else
119      {
120        var items = numChecked == 1 ? 'item' : 'items';
121        if (!confirm('You are about to PERMANENTLY DELETE '+numChecked+' '+items+'.\n This can\'t be undone. Continue?'))
122        {
123          return;
124        }
125      }
126      Main.openPopup('../../common/progress_reporter.jsp?ID=<%=ID%>&progress=trashcan&title=Delete items', 'Progress', 400, 200);
127      frm.action = submitPage;
128      frm.cmd.value = 'DeleteItemsPermanently';
129      frm.submit();
130    }
131    function restoreItems()
132    {
133      var frm = document.forms[formId];
134      if (Forms.numChecked(frm, /item:/) == 0)
135      {
136        alert('Please select at least one item in the list');
137        return;
138      }
139      frm.action = submitPage;
140      frm.cmd.value = 'RestoreItems';
141      frm.submit();
142    }
143    function configureColumns()
144    {
145      Table.configureColumns('<%=ID%>', formId, '<%=itemType.name()%>', '<%=(String)cc.getObject("defaultColumns")%>', '<%=subContext%>');
146    }
147    function presetOnChange()
148    {
149      Table.presetOnChange('<%=ID%>', formId, '<%=itemType.name()%>', '<%=(String)cc.getObject("defaultColumns")%>', '<%=subContext%>');
150    }
151    function showUsingItems(itemType, itemId)
152    {
153      var url = 'index.jsp?ID=<%=ID%>&cmd=ViewUsingItems&item_type='+itemType+'&item_id='+itemId;
154      location.href = url;
155    }
156    </script>
157  </base:head>
158 
159  <base:body>
160    <%
161    if (cc.getMessage() != null)
162    {
163      %>
164      <div class="error"><%=cc.getMessage()%></div>
165      <%
166      cc.setMessage(null);
167    }
168    %>
169    <tbl:table 
170      id="trashcan" 
171      clazz="itemlist" 
172      columns="<%=cc.getSetting("columns")%>"
173      action="index.jsp"
174      sc="<%=sc%>"
175      item="<%=itemType%>"
176      subcontext="<%=subContext%>"
177      >
178      <tbl:columndef
179        id="type"
180        property="type"
181        datatype="string"
182        title="Item type"
183        enumeration="<%=items%>"
184        filterable="true"
185        show="always"
186      />
187      <tbl:columndef 
188        id="name"
189        title="Name"
190        show="always" 
191      />
192      <tbl:columndef 
193        id="description"
194        title="Description"
195      />
196      <tbl:toolbar>
197        <tbl:button
198          image="<%=totalCount > 0 ? "deleteall.png" : "deleteall_disabled.png"%>"
199          onclick="deleteAllItems()"
200          title="Empty trash&hellip;"
201          tooltip="Delete all items from the trashcan"
202          disabled="<%=totalCount <= 0%>"
203        />
204        <tbl:button 
205          image="<%=totalCount > 0 ? "delete_permanently.png" : "delete_permanently_disabled.png"%>"
206          onclick="deleteItems()" 
207          title="Delete permanently&hellip;" 
208          tooltip="Delete the selected items permanently" 
209          disabled="<%=totalCount <= 0%>"
210        />
211        <tbl:button 
212          image="<%=totalCount > 0 ? "restore.gif" : "restore_disabled.gif"%>"
213          onclick="restoreItems()" 
214          title="Restore" 
215          tooltip="Restore the selected items"
216          disabled="<%=totalCount <= 0%>"
217        />
218        <tbl:button 
219          image="columns.gif" 
220          onclick="configureColumns()" 
221          title="Columns&hellip;" 
222          tooltip="Show, hide and re-order columns" 
223        />
224      </tbl:toolbar>
225      <tbl:navigator
226        page="<%=cc.getPage()%>" 
227        rowsperpage="<%=cc.getRowsPerPage()%>" 
228        totalrows="<%=trash == null ? 0 : trash.getTotalCount()%>"
229      />
230      <tbl:data>
231        <tbl:columns>
232          <tbl:presetselector 
233            clazz="columnheader"
234            colspan="3"
235            onchange="presetOnChange()"
236          />
237        </tbl:columns>
238        <tr>
239          <tbl:header 
240            clazz="index"
241            >&nbsp;</tbl:header>
242          <tbl:header 
243            clazz="check" 
244            ><base:icon 
245              image="check_uncheck.gif" 
246              tooltip="Check/uncheck all" 
247              onclick="Forms.checkUncheck(document.forms[formId], /item:/)" style="align: left;"
248            /></tbl:header>
249          <tbl:header 
250            clazz="icons" 
251            >&nbsp;</tbl:header>
252           
253          <tbl:propertyfilter />
254        </tr>
255
256          <tbl:rows>
257          <%
258          int index = cc.getPage()*cc.getRowsPerPage();
259          if (trash != null)
260          {
261            for (Removable item : trash)
262            {
263              BasicItem basicItem = (BasicItem)item;
264              boolean isUsed = basicItem.isUsed();
265              int itemId = item.getId();
266              String name = "";
267              String description = "";
268              if (item instanceof File)
269              {
270                File file = (File)item;
271                name = file.getPath().toString();
272                description = file.getDescription();
273              }
274              else if (item instanceof Directory)
275              {
276                Directory dir = (Directory)item;
277                name = dir.getPath().toString();
278                description = dir.getDescription();
279              }
280              else if (item instanceof Nameable)
281              {
282                Nameable nameable = (Nameable)item;
283                name = nameable.getName();
284                description = nameable.getDescription();
285              }
286              else
287              {
288                name = item.toString();
289              }
290              String link = Base.getLink(ID, HTML.encodeTags(name), item.getType(), itemId, true);
291              index++;
292              numListed++;
293              %>
294              <tbl:row>
295                <tbl:header 
296                  clazz="index"
297                  ><%=index%></tbl:header>
298                <tbl:header 
299                  clazz="check" 
300                  ><input 
301                    type="checkbox" 
302                    name="item:<%=item.getType().name()%>" 
303                    value="<%=itemId%>"
304                  ></tbl:header>
305                <tbl:header 
306                  clazz="icons" 
307                  ><base:icon 
308                    image="used.gif" 
309                    tooltip="This item is used by other items and cannot be deleted"
310                    visible="<%=isUsed%>"
311                    onclick="<%="showUsingItems('" + item.getType().name() + "', " +  itemId + ")"%>"
312                  />&nbsp;</tbl:header>
313                <tbl:cell column="type"><%=item.getType()%></tbl:cell>
314                <tbl:cell column="name"><%=link%></tbl:cell>
315                <tbl:cell column="description"><%=HTML.encodeTags(description)%></tbl:cell>
316              </tbl:row>
317              <%
318              }
319            }
320          %>
321          </tbl:rows>
322      </tbl:data>
323      <%
324      if (numListed == 0)
325      {
326        %>
327        <tbl:panel><%=trash == null || trash.size() == 0 ? "No items were found" : "No items on this page. Please select another page!" %></tbl:panel>
328        <%
329      }
330      else
331      {
332        %>
333        <tbl:navigator
334          page="<%=cc.getPage()%>" 
335          rowsperpage="<%=cc.getRowsPerPage()%>" 
336          totalrows="<%=trash == null ? 0 : trash.getTotalCount()%>" 
337          locked="true"
338        />
339        <%
340      }
341      %>
342    </tbl:table>
343    <br><br><br>
344  </base:body>
345  </base:page>
346  <%
347}
348finally
349{
350  if (dc != null) dc.close();
351}
352%>
Note: See TracBrowser for help on using the repository browser.