source: trunk/www/admin/annotationtypecategories/list_categories.jsp @ 3190

Last change on this file since 3190 was 3190, checked in by Johan Enell, 16 years ago

Merged log:branches/2.2.2#3116:3186 to trunk.

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