source: trunk/www/my_base/projects/items/list_items.jsp @ 3552

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

References #375. Only wants to do a commit before the weekend.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 11.9 KB
Line 
1<%-- $Id: list_items.jsp 3552 2007-07-06 14:53:14Z 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.Project"
35  import="net.sf.basedb.core.BasicItem"
36  import="net.sf.basedb.core.Shareable"
37  import="net.sf.basedb.core.SharedItem"
38  import="net.sf.basedb.core.Nameable"
39  import="net.sf.basedb.core.Removable"
40  import="net.sf.basedb.core.File"
41  import="net.sf.basedb.core.Directory"
42  import="net.sf.basedb.core.Metadata"
43  import="net.sf.basedb.core.query.ResultList"
44  import="net.sf.basedb.util.Enumeration"
45  import="net.sf.basedb.util.ShareableUtil"
46  import="net.sf.basedb.clients.web.Base"
47  import="net.sf.basedb.clients.web.ModeInfo"
48  import="net.sf.basedb.clients.web.PermissionUtil"
49  import="net.sf.basedb.clients.web.util.HTML"
50  import="net.sf.basedb.util.Values"
51 
52  import="java.util.Iterator"
53%>
54<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
55<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
56<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
57<%@ taglib prefix="p" uri="/WEB-INF/path.tld" %>
58<%!
59  private static final Item itemType = Item.PROJECT;
60  private static final String subContext = "items";
61
62  private static final Enumeration<String, String> itemTypes = new Enumeration<String, String>();
63  static
64  {
65    for (Item item : Metadata.getShareableItems())
66    {
67      itemTypes.add(item.name(), item.toString());
68    }
69  }
70%>
71<%
72final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
73final String ID = sc.getId();
74final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subContext, null, null);
75final int projectId = Values.getInt(request.getParameter("project_id"));
76final int activeProjectId = sc.getActiveProjectId();
77final DbControl dc = sc.newDbControl();
78final ModeInfo mode = ModeInfo.get(request.getParameter("mode"));
79ResultList<Shareable> items = null;
80try
81{
82  String filterItem = cc.getPropertyValue("type");
83  Project project = Project.getById(dc, projectId);
84  try
85  {
86    items = project.getItems(filterItem == null ? null : Item.valueOf(filterItem), 
87      cc.getPage() * cc.getRowsPerPage(), cc.getRowsPerPage(), cc.getItemPermission(),
88      cc.getInclude());
89  }
90  catch (Throwable t)
91  {
92    cc.setMessage(t.getMessage());
93  }
94  int numListed = 0;
95  %>
96  <base:page>
97  <base:head scripts="table.js,tabcontrol.js" styles="table.css,headertabcontrol.css,path.css">
98    <script language="JavaScript">
99    var submitPage = 'index.jsp';
100    var formId = 'items';
101    function deleteItems()
102    {
103      var frm = document.forms[formId];
104      var numChecked = Forms.numChecked(frm, /item:/);
105      if (numChecked == 0)
106      {
107        alert('Please select at least one item in the list');
108        return;
109      }
110      frm.action = submitPage;
111      frm.cmd.value = 'DeleteItems';
112      frm.submit();
113    }
114    function restoreItems()
115    {
116      var frm = document.forms[formId];
117      if (Forms.numChecked(frm, /item:/) == 0)
118      {
119        alert('Please select at least one item in the list');
120        return;
121      }
122      frm.action = submitPage;
123      frm.cmd.value = 'RestoreItems';
124      frm.submit();
125    }
126    function takeOwnership()
127    {
128      var frm = document.forms[formId];
129      if (Forms.numChecked(frm, /item:/) == 0)
130      {
131        alert('Please select at least one item in the list');
132        return;
133      }
134      if (confirm('Are you sure that you want to take ownership of the selected items? It can\'t be undone.'))
135      {
136        frm.action = submitPage;
137        frm.cmd.value = 'TakeOwnershipOfItems';
138        frm.submit();
139      }
140    }
141    function shareItem(itemId)
142    {
143      Main.openPopup('index.jsp?ID=<%=ID%>&cmd=ShareItem&item_id='+itemId, 'ShareProjectItems', 500, 400);
144    }
145    function shareItems()
146    {
147      Table.shareItems(submitPage, '<%=ID%>', formId, '<%=itemType.name()%>', 'ShareItems', /item:/);
148    }
149    function configureColumns()
150    {
151      Table.configureColumns('<%=ID%>', formId, '<%=itemType.name()%>', '<%=(String)cc.getObject("defaultColumns")%>', '<%=subContext%>');
152    }
153    function presetOnChange()
154    {
155      Table.presetOnChange('<%=ID%>', formId, '<%=itemType.name()%>', '<%=(String)cc.getObject("defaultColumns")%>', '<%=subContext%>');
156    }
157    function setToActive()
158    {
159      Main.openPopup('../set_active.jsp?ID=<%=ID%>&project_id=<%=projectId%>', 'ActivateProject', 300, 140);
160    }
161    function switchTab(tabControlId, tabId)
162    {
163      if (tabId == 'properties')
164      {
165        location.href = '../index.jsp?ID=<%=ID%>&cmd=ViewItem&item_id=<%=projectId%>&tab='+tabId;
166      }
167      else
168      {
169        TabControl.setActiveTab(tabControlId, tabId);
170      }
171    }
172    </script>
173  </base:head>
174 
175  <base:body>
176    <p>
177    <p:path>
178      <p:pathelement title="Projects" href="<%="../index.jsp?ID="+ID%>" />
179      <p:pathelement title="<%=HTML.encodeTags(project.getName())%>" />
180    </p:path>
181
182    <t:tabcontrol id="main" active="items" switch="switchTab">
183    <t:tab id="properties" title="Properties" />
184   
185    <t:tab id="items" title="Items">
186
187    <%
188    if (cc.getMessage() != null)
189    {
190      %>
191      <div class="error"><%=cc.getMessage()%></div>
192      <%
193      cc.setMessage(null);
194    }
195    %>
196    <tbl:table 
197      id="items" 
198      clazz="itemlist" 
199      columns="<%=cc.getSetting("columns")%>"
200      action="index.jsp"
201      sc="<%=sc%>"
202      item="<%=itemType%>"
203      subcontext="<%=subContext%>"
204      >
205      <tbl:hidden
206        name="project_id"
207        value="<%=Integer.toString(projectId)%>"
208      />
209      <tbl:columndef
210        id="type"
211        property="type"
212        datatype="string"
213        title="Item type"
214        enumeration="<%=itemTypes%>"
215        filterable="true"
216        show="always"
217      />
218      <tbl:columndef 
219        id="name"
220        title="Name"
221        show="always" 
222      />
223      <tbl:columndef 
224        id="owner"
225        title="Owner"
226      />
227      <tbl:columndef 
228        id="description"
229        title="Description"
230      />
231      <tbl:columndef
232        id="permission"
233        title="Permission"
234      />
235      <tbl:columndef 
236        id="sharedTo"
237        title="Shared to"
238      />
239      <tbl:toolbar>
240        <tbl:button 
241          image="delete.gif"
242          onclick="deleteItems()" 
243          title="Delete" 
244          tooltip="Delete the selected items" 
245        />
246        <tbl:button 
247          image="restore.gif"
248          onclick="restoreItems()" 
249          title="Restore" 
250          tooltip="Restore the selected items"
251        />
252        <tbl:button 
253          image="share.gif"
254          onclick="shareItems()" 
255          title="Share&hellip;" 
256          tooltip="Share the selected items"
257        />
258        <tbl:button 
259          image="take_ownership.png"
260          onclick="takeOwnership()" 
261          title="Take ownership&hellip;"
262          tooltip="Take ownership of the selected items"
263        />
264        <tbl:button 
265          image="columns.gif" 
266          onclick="configureColumns()" 
267          title="Columns&hellip;" 
268          tooltip="Show, hide and re-order columns" 
269        />
270      </tbl:toolbar>
271      <%
272      if (projectId != activeProjectId)
273      {
274        %>
275        <tbl:panel>
276          <div class="error" onclick="setToActive()" style="cursor: pointer;"
277            title="Click to make this project the active project">
278          This project is not the active project. The list can't display items
279          that are owned by other members of the project.
280          </div>
281        </tbl:panel>
282        <%
283      }
284      %>
285      <tbl:navigator
286        page="<%=cc.getPage()%>" 
287        rowsperpage="<%=cc.getRowsPerPage()%>" 
288        totalrows="<%=items == null ? 0 : items.getTotalCount()%>"
289      />
290      <tbl:data>
291        <tbl:columns>
292          <tbl:presetselector 
293            clazz="columnheader"
294            colspan="3"
295            onchange="presetOnChange()"
296            disablesharedto="true"
297            disableothers="<%=projectId != activeProjectId%>"
298          />
299        </tbl:columns>
300        <tr>
301          <tbl:header 
302            clazz="index"
303            >&nbsp;</tbl:header>
304          <tbl:header 
305            clazz="check" 
306            ><base:icon 
307              image="check_uncheck.gif" 
308              tooltip="Check/uncheck all" 
309              onclick="Forms.checkUncheck(document.forms[formId], /item:/)" style="align: left;"
310            /></tbl:header>
311          <tbl:header 
312            clazz="icons" 
313            >&nbsp;</tbl:header>
314           
315          <tbl:propertyfilter />
316        </tr>
317
318          <tbl:rows>
319          <%
320          int index = cc.getPage()*cc.getRowsPerPage();
321          if (items != null)
322          {
323            for (Shareable item : items)
324            {
325              BasicItem basicItem = (BasicItem)item;
326              int itemId = item.getId();
327              boolean removed = item instanceof Removable && ((Removable)item).isRemoved();
328              String name = "";
329              String description = "";
330              if (item instanceof File)
331              {
332                File file = (File)item;
333                name = file.getPath().toString();
334                description = file.getDescription();
335              }
336              else if (item instanceof Directory)
337              {
338                Directory dir = (Directory)item;
339                name = dir.getPath().toString();
340                description = dir.getDescription();
341              }
342              else if (item instanceof Nameable)
343              {
344                Nameable nameable = (Nameable)item;
345                name = nameable.getName();
346                description = nameable.getDescription();
347              }
348              else
349              {
350                name = item.toString();
351              }
352              String link = Base.getLink(ID, HTML.encodeTags(name), item.getType(), itemId, true);
353              index++;
354              numListed++;
355              %>
356              <tbl:row>
357                <tbl:header 
358                  clazz="index"
359                  ><%=index%></tbl:header>
360                <tbl:header 
361                  clazz="check" 
362                  ><input 
363                    type="checkbox" 
364                    name="item:<%=item.getType().name()%>" 
365                    value="<%=itemId%>"
366                  ></tbl:header>
367                <tbl:header 
368                  clazz="icons" 
369                  ><base:icon 
370                    image="deleted.gif" 
371                    tooltip="This item has been scheduled for deletion" 
372                    visible="<%=removed%>"
373                    />&nbsp;</tbl:header>
374                <tbl:cell column="type"><%=item.getType()%></tbl:cell>
375                <tbl:cell column="name"><%=link%></tbl:cell>
376                <tbl:cell column="owner"><base:propertyvalue item="<%=item%>" property="owner" /></tbl:cell>
377                <tbl:cell column="description"><%=HTML.encodeTags(description)%></tbl:cell>
378                <tbl:cell column="permission"><%=PermissionUtil.getShortPermissions(item)%></tbl:cell>
379                <tbl:cell column="sharedTo">
380                  <%
381                  if (item instanceof SharedItem)
382                  {
383                    Iterator<Nameable> sharees = ShareableUtil.getSharedTo(dc, (SharedItem)item).iterator();
384                    while(sharees.hasNext())
385                    {
386                      Nameable n = sharees.next();
387                      if (mode.hasPropertyLink())
388                      {
389                        out.write(Base.getLinkedName(ID, n, false, mode.hasEditLink()));
390                      }
391                      else
392                      {
393                        out.write(HTML.encodeTags(n.getName()));
394                      }
395                      out.write(sharees.hasNext() ? ", " : "");
396                    }
397                  }
398                  %>
399                </tbl:cell>
400              </tbl:row>
401              <%
402              }
403            }
404          %>
405          </tbl:rows>
406      </tbl:data>
407      <%
408      if (numListed == 0)
409      {
410        %>
411        <tbl:panel><%=items == null || items.size() == 0 ? "No items were found" : "No items on this page. Please select another page!" %></tbl:panel>
412        <%
413      }
414      else
415      {
416        %>
417        <tbl:navigator
418          page="<%=cc.getPage()%>" 
419          rowsperpage="<%=cc.getRowsPerPage()%>" 
420          totalrows="<%=items == null ? 0 : items.getTotalCount()%>" 
421          locked="true"
422        />
423        <%
424      }
425      %>
426    </tbl:table>
427
428    </t:tab>
429    </t:tabcontrol>
430
431  </base:body>
432  </base:page>
433  <%
434}
435finally
436{
437  if (dc != null) dc.close();
438}
439%>
Note: See TracBrowser for help on using the repository browser.