source: trunk/www/biomaterials/labels/list_labels.jsp @ 2753

Last change on this file since 2753 was 2753, checked in by Nicklas Nordborg, 17 years ago

Fixes #404: Replace deprecated Values class with the new one in all JSP pages

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 12.6 KB
Line 
1<%-- $Id: list_labels.jsp 2753 2006-10-20 11:04:36Z 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
28  import="net.sf.basedb.core.SessionControl"
29  import="net.sf.basedb.core.DbControl"
30  import="net.sf.basedb.core.Item"
31  import="net.sf.basedb.core.Label"
32  import="net.sf.basedb.core.ItemQuery"
33  import="net.sf.basedb.core.ItemResultIterator"
34  import="net.sf.basedb.core.ItemContext"
35  import="net.sf.basedb.core.LabeledExtract"
36  import="net.sf.basedb.core.Permission"
37  import="net.sf.basedb.core.PluginDefinition"
38  import="net.sf.basedb.core.plugin.GuiContext"
39  import="net.sf.basedb.core.plugin.Plugin"
40  import="net.sf.basedb.core.query.Hql"
41  import="net.sf.basedb.core.query.Orders"
42  import="net.sf.basedb.clients.web.Base"
43  import="net.sf.basedb.clients.web.PermissionUtil"
44  import="net.sf.basedb.clients.web.ModeInfo"
45  import="net.sf.basedb.clients.web.util.HTML"
46  import="net.sf.basedb.util.Values"
47  import="java.util.List"
48  import="java.util.Map"
49%>
50<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
51<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
52<%!
53  private static final Item itemType = Item.LABEL;
54  private static final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.LIST);
55%>
56<%
57final SessionControl sc = Base.getExistingSessionControl(pageContext, Permission.DENIED, itemType);
58final String ID = sc.getId();
59final boolean createPermission = sc.hasPermission(Permission.CREATE, itemType);
60final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
61
62final ModeInfo mode = ModeInfo.get(request.getParameter("mode"));
63final String callback = request.getParameter("callback");
64final String title = mode.generateTitle("label", "labels");
65final DbControl dc = sc.newDbControl();
66ItemResultIterator<Label> labels = null;
67try
68{
69  final ItemQuery<Label> query = Base.getConfiguredQuery(cc, true, Label.getQuery(), mode);
70
71  Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext);
72  try
73  {
74    labels = query.iterate(dc);
75  }
76  catch (Throwable t)
77  {
78    cc.setMessage(t.getMessage());
79  }
80  int numListed = 0;
81  %>
82  <base:page title="<%=title==null ? "Labels" : title%>" type="<%=mode.getPageType()%>">
83  <base:head scripts="menu.js,table.js" styles="menu.css,table.css">
84    <script language="JavaScript">
85    var submitPage = 'index.jsp';
86    var formId = 'labels';
87    function newItem()
88    {
89      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', 0, true);
90    }
91    function editItem(itemId)
92    {
93      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', itemId, true);
94    }
95    function viewItem(itemId)
96    {
97      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', itemId, false);
98    }
99    function itemOnClick(evt, itemId)
100    {
101      Table.itemOnClick(formId, evt, itemId, '<%=mode.getName()%>', viewItem, editItem, returnSelected);
102    }
103    function deleteItems()
104    {
105      var frm = document.forms[formId];
106      if (Forms.numChecked(frm) == 0)
107      {
108        alert('Please select at least one item in the list');
109        return;
110      }
111      frm.action = submitPage;
112      frm.cmd.value = 'DeleteItems';
113      frm.submit();
114    }
115    function restoreItems()
116    {
117      var frm = document.forms[formId];
118      if (Forms.numChecked(frm) == 0)
119      {
120        alert('Please select at least one item in the list');
121        return;
122      }
123      frm.action = submitPage;
124      frm.cmd.value = 'RestoreItems';
125      frm.submit();
126    }
127    function shareItem(itemId)
128    {
129      Main.openPopup('index.jsp?ID=<%=ID%>&cmd=ShareItem&item_id='+itemId, 'ShareLabels', 500, 400);
130    }
131    function shareItems()
132    {
133      Table.shareItems(submitPage, '<%=ID%>', formId, '<%=itemType.name()%>', 'ShareItems');
134    }
135    function configureColumns()
136    {
137      Table.configureColumns('<%=ID%>', formId, '<%=itemType.name()%>', '<%=(String)cc.getObject("defaultColumns")%>');
138    }
139    function runPlugin(cmd)
140    {
141      Table.submitToPopup(formId, cmd, 740, 540);
142    }
143    function returnSelected()
144    {
145      Table.returnSelected(formId, <%=callback != null ? "window.opener."+callback : "null" %>);
146      window.close();
147    }
148    function presetOnChange()
149    {
150      Table.presetOnChange('<%=ID%>', formId, '<%=itemType.name()%>', '<%=(String)cc.getObject("defaultColumns")%>');
151    }
152    function newLabeledExtract(labelId)
153    {
154      Main.viewOrEditItem('<%=ID%>', 'LABELEDEXTRACT', 0, true, '&label_id='+labelId);
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="labels" 
171      clazz="itemlist" 
172      columns="<%=cc.getSetting("columns")%>"
173      sortby="<%=cc.getSortProperty()%>" 
174      direction="<%=cc.getSortDirection()%>"
175      title="<%=title%>"
176      action="index.jsp"
177      sc="<%=sc%>"
178      item="<%=itemType%>"
179      >
180      <tbl:hidden 
181        name="mode" 
182        value="<%=mode.getName()%>" 
183      />
184      <tbl:hidden 
185        name="callback" 
186        value="<%=callback%>" 
187        skip="<%=callback == null%>" 
188      />
189      <tbl:columndef 
190        id="name"
191        property="name"
192        datatype="string"
193        title="Name"
194        sortable="true" 
195        filterable="true"
196        exportable="true"
197        show="always" 
198      />
199      <tbl:columndef 
200        id="owner"
201        property="owner.name"
202        datatype="string"
203        title="Owner"
204        sortable="true" 
205        filterable="true"
206        exportable="true"
207      />
208      <tbl:columndef 
209        id="description"
210        property="description"
211        datatype="string"
212        title="Description" 
213        sortable="true" 
214        filterable="true" 
215        exportable="true"
216      />
217      <tbl:columndef
218        id="permission"
219        title="Permission"
220      />
221      <tbl:toolbar
222        visible="<%=mode.hasToolbar()%>"
223        >
224        <tbl:button 
225          disabled="<%=createPermission ? false : true%>" 
226          image="<%=createPermission ? "new.gif" : "new_disabled.gif"%>" 
227          onclick="newItem()" 
228          title="New&hellip;" 
229          tooltip="<%=createPermission ? "Create new label" : "You do not have permission to create labels"%>" 
230        />
231        <tbl:button 
232          image="delete.gif"
233          onclick="deleteItems()" 
234          title="Delete" 
235          tooltip="Delete the selected items" 
236        />
237        <tbl:button 
238          image="restore.gif"
239          onclick="restoreItems()" 
240          title="Restore" 
241          tooltip="Restore the selected (deleted) items"
242        />
243        <tbl:button 
244          image="share.gif"
245          onclick="shareItems()" 
246          title="Share&hellip;" 
247          tooltip="Share the selected items"
248        />
249        <tbl:button 
250          image="columns.gif" 
251          onclick="configureColumns()" 
252          title="Columns&hellip;" 
253          tooltip="Show, hide and re-order columns" 
254        />
255        <tbl:button 
256          image="import.gif" 
257          onclick="runPlugin('ImportItems')" 
258          title="Import&hellip;" 
259          tooltip="Import data" 
260          visible="<%=pluginCount.containsKey(Plugin.MainType.IMPORT)%>"
261        />
262        <tbl:button 
263          image="export.gif" 
264          onclick="runPlugin('ExportItems')" 
265          title="Export&hellip;" 
266          tooltip="Export data" 
267          visible="<%=pluginCount.containsKey(Plugin.MainType.EXPORT)%>"
268        />
269        <tbl:button 
270          image="runplugin.gif" 
271          onclick="runPlugin('RunListPlugin')" 
272          title="Run plugin&hellip;" 
273          tooltip="Run a plugin" 
274          visible="<%=pluginCount.containsKey(Plugin.MainType.OTHER)%>"
275        />
276      </tbl:toolbar>
277      <tbl:navigator
278        page="<%=cc.getPage()%>" 
279        rowsperpage="<%=cc.getRowsPerPage()%>" 
280        totalrows="<%=labels == null ? 0 : labels.getTotalCount()%>" 
281        visible="<%=mode.hasNavigator()%>"
282      />
283      <tbl:data>
284        <tbl:columns>
285        <tbl:presetselector 
286          clazz="columnheader"
287          colspan="3"
288          onchange="presetOnChange()"
289        />
290        </tbl:columns>
291
292        <tr>
293          <tbl:header 
294            clazz="index"
295            >&nbsp;</tbl:header>
296          <tbl:header 
297            clazz="check" 
298            visible="<%=mode.hasCheck()%>"
299            ><base:icon 
300              image="check_uncheck.gif" 
301              tooltip="Check/uncheck all" 
302              onclick="Forms.checkUncheck(document.forms[formId])" style="align: left;"
303            /></tbl:header>
304          <tbl:header 
305            clazz="check" 
306            visible="<%=mode.hasRadio()%>"
307            >&nbsp;</tbl:header>
308          <tbl:header 
309            clazz="icons" 
310            visible="<%=mode.hasIcons()%>"
311            >&nbsp;</tbl:header>
312          <tbl:propertyfilter />
313        </tr>
314         
315          <tbl:rows>
316          <%
317          int index = cc.getPage()*cc.getRowsPerPage();
318          int selectedItemId = cc.getId();
319          if (labels != null)
320          {           
321            while (labels.hasNext())
322            {
323              Label item = labels.next();
324              int itemId = item.getId();
325              ItemQuery<LabeledExtract> labeledExtractQuery = item.getLabeledExtracts();
326              labeledExtractQuery.include(cc.getInclude());
327              labeledExtractQuery.order(Orders.asc(Hql.property("name")));             
328              String openSharePopup = "shareItem("+itemId+")";
329              boolean sharePermission = item.hasPermission(Permission.SET_PERMISSION); 
330              boolean usePermission = item.hasPermission(Permission.USE);
331              boolean writePermission = item.hasPermission(Permission.WRITE);
332              String tooltip = mode.isSelectionMode() ? 
333                  "Select this item" : "View this item" + (writePermission ? " (use CTRL, ALT or SHIFT to edit)" : "");
334              String name = HTML.encodeTags(item.getName());
335              index++;
336              numListed++;
337              %>
338              <tbl:row>
339                <tbl:header 
340                  clazz="index"
341                  ><%=index%></tbl:header>
342                <tbl:header 
343                  clazz="check" 
344                  visible="<%=mode.hasCheck()%>"
345                  ><input 
346                    type="checkbox" 
347                    name="<%=itemId%>" 
348                    value="<%=itemId%>" 
349                    title="<%=name%>" 
350                    <%=cc.getSelected().contains(itemId) ? "checked" : ""%> 
351                  ></tbl:header>
352                <tbl:header 
353                  clazz="check" 
354                  visible="<%=mode.hasRadio()%>"
355                  ><input 
356                    type="radio" 
357                    name="item_id" 
358                    value="<%=itemId%>" 
359                    title="<%=name%>" 
360                    <%=selectedItemId == itemId ? "checked" : ""%>
361                  ></tbl:header>
362                <tbl:header 
363                  clazz="icons" 
364                  visible="<%=mode.hasIcons()%>"
365                  ><base:icon 
366                    image="deleted.gif" 
367                    tooltip="This item has been scheduled for deletion" 
368                    visible="<%=item.isRemoved()%>"
369                  /><base:icon 
370                    image="<%=sharePermission ? "shared.gif" : "shared_disabled.gif"%>" 
371                    onclick="<%=sharePermission ? openSharePopup : null%>"
372                    tooltip="This item is shared to other users, groups and/or projects" 
373                    visible="<%=item.isShared()%>"
374                  />&nbsp;</tbl:header>
375                <tbl:cell column="name"><div class="link" 
376                  onclick="itemOnClick(<%=writePermission ? "event" : null%>, <%=itemId%>)" 
377                  title="<%=tooltip%>"><%=name%></div></tbl:cell>
378                <tbl:cell column="owner"
379                  ><base:propertyvalue 
380                    item="<%=item%>" 
381                    property="owner"
382                    enableEditLink="<%=mode.hasEditLink()%>" 
383                    enablePropertyLink="<%=mode.hasPropertyLink()%>"
384                  /></tbl:cell>
385                <tbl:cell column="description"><%=HTML.encodeTags(item.getDescription())%></tbl:cell>
386                <tbl:cell column="permission"><%=PermissionUtil.getShortPermissions(item)%></tbl:cell>
387              </tbl:row>
388              <%
389              }
390            }
391          %>
392          </tbl:rows>
393      </tbl:data>
394      <%
395      if (numListed == 0)
396      {
397        %>
398        <tbl:panel><%=labels == null || labels.getTotalCount() == 0 ? "No labels where found" : "No labels on this page. Please select another page!" %></tbl:panel>
399        <%
400      }
401      else
402      {
403        %>
404        <tbl:navigator
405          page="<%=cc.getPage()%>" 
406          rowsperpage="<%=cc.getRowsPerPage()%>" 
407          totalrows="<%=labels == null ? 0 : labels.getTotalCount()%>" 
408          visible="<%=mode.hasNavigator()%>"
409          locked="true"
410        />
411        <%
412      }
413      %>
414    </tbl:table>
415    <base:buttongroup align="center" clazz="fixedatbottom">
416      <base:button onclick="returnSelected();" title="Ok" visible="<%=mode.hasOkButton()%>" />
417      <base:button onclick="window.close();" title="Cancel" visible="<%=mode.hasCancelButton()%>" />
418      <base:button onclick="window.close();" title="Close" visible="<%=mode.hasCloseButton()%>" />
419    </base:buttongroup>
420    <br><br><br>
421  </base:body>
422  </base:page>
423  <%
424}
425finally
426{
427  if (labels != null) labels.close();
428  if (dc != null) dc.close();
429}
430%>
Note: See TracBrowser for help on using the repository browser.