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