source: trunk/www/admin/annotationtypes/list_annotationtypes.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: 18.7 KB
Line 
1<%-- $Id: list_annotationtypes.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.Item"
31  import="net.sf.basedb.core.AnnotationType"
32  import="net.sf.basedb.core.AnnotationTypeCategory"
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.PermissionUtil"
53  import="net.sf.basedb.clients.web.ModeInfo"
54  import="net.sf.basedb.clients.web.util.HTML"
55  import="net.sf.basedb.util.Values"
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.ANNOTATIONTYPE;
66  private static final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.LIST);
67 
68  private static final Enumeration<String, String> items = new Enumeration<String, String>();
69  private static Enumeration<String, String> types = new Enumeration<String, String>();
70  static
71  {
72    for (Item item : Metadata.getAnnotatableItems())
73    {
74      items.add(Integer.toString(item.getValue()), item.toString());
75    }
76    for (Type v : Type.values())
77    {
78      types.add(Integer.toString(v.getValue()), v.toString());
79    }
80  }
81%>
82<%
83final SessionControl sc = Base.getExistingSessionControl(pageContext, Permission.DENIED, itemType);
84final String ID = sc.getId();
85final boolean createPermission = sc.hasPermission(Permission.CREATE, itemType);
86final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
87
88final ModeInfo mode = ModeInfo.get(request.getParameter("mode"));
89final String callback = request.getParameter("callback");
90final String title = mode.generateTitle("annotation type", "annotation types");
91final DbControl dc = sc.newDbControl();
92ItemResultIterator<AnnotationType> annotationTypes = null;
93try
94{
95  // Query for categories of the current annotation type
96  final ItemQuery<AnnotationTypeCategory> categoryQuery = AnnotationTypeCategory.getQuery();
97  categoryQuery.include(cc.getInclude());
98  categoryQuery.join(Hql.innerJoin("annotationTypes", "atp"));
99  categoryQuery.restrict(Restrictions.eq(Hql.alias("atp"), Expressions.parameter("annotationType")));
100  categoryQuery.order(Orders.asc(Hql.property("name"))); 
101
102  Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext);
103  try
104  {
105    final ItemQuery<AnnotationType> query = Base.getConfiguredQuery(cc, true, AnnotationType.getQuery(null), mode);
106    annotationTypes = query.iterate(dc);
107  }
108  catch (Throwable ex)
109  {
110    cc.setMessage(ex.getMessage());
111  }
112  int numListed = 0;
113  %>
114  <base:page title="<%=title==null ? "Annotation types" : title%>" type="<%=mode.getPageType()%>">
115    <m:menu 
116      id="newAnnotationType"
117      style="display: none;">
118      <%
119      for (Type valueType : Type.values())
120      {
121        %>
122        <m:menuitem 
123          title="<%=valueType.toString()+" annotation type"%>" 
124          onclick="<%="newItem('"+valueType.name()+"')"%>"
125        />
126        <%
127      }
128      %>
129    </m:menu>
130 
131  <base:head scripts="menu.js,table.js" styles="menu.css,table.css">
132    <script language="JavaScript">
133    var submitPage = 'index.jsp';
134    var formId = 'annotationTypes';
135    function newItem(valueType)
136    {
137      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', 0, true, '&value_type='+valueType);
138    }
139    function editItem(itemId)
140    {
141      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', itemId, true);
142    }
143    function viewItem(itemId)
144    {
145      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', itemId, false);
146    }
147    function itemOnClick(evt, itemId)
148    {
149      Table.itemOnClick(formId, evt, itemId, '<%=mode.getName()%>', viewItem, editItem, returnSelected);
150    }
151    function deleteItems()
152    {
153      var frm = document.forms[formId];
154      if (Forms.numChecked(frm) == 0)
155      {
156        alert('Please select at least one item in the list');
157        return;
158      }
159      frm.action = submitPage;
160      frm.cmd.value = 'DeleteItems';
161      frm.submit();
162    }
163    function restoreItems()
164    {
165      var frm = document.forms[formId];
166      if (Forms.numChecked(frm) == 0)
167      {
168        alert('Please select at least one item in the list');
169        return;
170      }
171      frm.action = submitPage;
172      frm.cmd.value = 'RestoreItems';
173      frm.submit();
174    }
175    function takeOwnership()
176    {
177      var frm = document.forms[formId];
178      if (Forms.numChecked(frm) == 0)
179      {
180        alert('Please select at least one item in the list');
181        return;
182      }
183      if (confirm('Are you sure that you want to take ownership of the selected items? It can\'t be undone.'))
184      {
185        frm.action = submitPage;
186        frm.cmd.value = 'TakeOwnershipOfItems';
187        frm.submit();
188      }
189    }
190    function shareItem(itemId)
191    {
192      Main.openPopup('index.jsp?ID=<%=ID%>&cmd=ShareItem&item_id='+itemId, 'ShareAnnoationTypes', 500, 400);
193    }
194    function shareItems()
195    {
196      Table.shareItems(submitPage, '<%=ID%>', formId, '<%=itemType.name()%>', 'ShareItems');
197    }
198    function configureColumns()
199    {
200      Table.configureColumns('<%=ID%>', formId, '<%=itemType.name()%>', '<%=(String)cc.getObject("defaultColumns")%>');
201    }
202    function runPlugin(cmd)
203    {
204      Table.submitToPopup(formId, cmd, 740, 540);
205    }
206    function returnSelected()
207    {
208      Table.returnSelected(formId, <%=callback != null ? "window.opener."+callback : "null" %>);
209      window.close();
210    }
211    function presetOnChange()
212    {
213      Table.presetOnChange('<%=ID%>', formId, '<%=itemType.name()%>', '<%=(String)cc.getObject("defaultColumns")%>');
214    }
215    </script>
216  </base:head>
217 
218  <base:body>
219    <%
220    if (cc.getMessage() != null)
221    {
222      %>
223      <div class="error"><%=cc.getMessage()%></div>
224      <%
225      cc.setMessage(null);
226    }
227    %>
228    <tbl:table 
229      id="annotationTypes" 
230      clazz="itemlist" 
231      columns="<%=cc.getSetting("columns")%>"
232      sortby="<%=cc.getSortProperty()%>" 
233      direction="<%=cc.getSortDirection()%>"
234      title="<%=title%>"
235      action="index.jsp"
236      sc="<%=sc%>"
237      item="<%=itemType%>"
238      >
239      <tbl:hidden 
240        name="mode" 
241        value="<%=mode.getName()%>" 
242      />
243      <tbl:hidden 
244        name="callback" 
245        value="<%=callback%>" 
246        skip="<%=callback == null%>" 
247      />
248      <tbl:columndef 
249        id="name"
250        property="name"
251        datatype="string"
252        title="Name"
253        sortable="true" 
254        filterable="true"
255        exportable="true"
256        show="always" 
257      />
258      <tbl:columndef 
259        id="externalId"
260        property="externalId"
261        datatype="string"
262        title="External id"
263        sortable="true" 
264        filterable="true"
265        exportable="true"
266      />
267      <tbl:columndef 
268        id="valueType"
269        property="valueType"
270        datatype="int"
271        enumeration="<%=types%>"
272        title="Value type"
273        sortable="true" 
274        filterable="true"
275        exportable="true"
276      />
277      <tbl:columndef 
278        id="requiredForMiame"
279        property="requiredForMiame"
280        datatype="boolean"
281        title="Required for MIAME"
282        sortable="true" 
283        filterable="true"
284        exportable="true"
285      />
286      <tbl:columndef 
287        id="isEnumeration"
288        property="enumeration"
289        datatype="boolean"
290        title="Enumeration"
291        sortable="true" 
292        filterable="true"
293        exportable="true"
294      />
295      <tbl:columndef 
296        id="isProtocolParameter"
297        property="protocolParameter"
298        datatype="boolean"
299        title="Protocol parameter"
300        sortable="true" 
301        filterable="true"
302        exportable="true"
303      />
304      <tbl:columndef 
305        id="multiplicity"
306        property="multiplicity"
307        datatype="int"
308        title="Multiplicity"
309        sortable="true" 
310        filterable="true"
311        exportable="true"
312      />
313      <tbl:columndef 
314        id="defaultValue"
315        property="defaultValue"
316        datatype="string"
317        title="Default value"
318        sortable="true" 
319        filterable="true"
320        exportable="true"
321      />
322      <tbl:columndef 
323        id="itemTypes"
324        property="@itemTypes"
325        datatype="int"
326        enumeration="<%=items%>"
327        title="Item types"
328        sortable="false" 
329        filterable="true"
330        exportable="false"
331      />
332      <tbl:columndef 
333        id="categories"
334        title="Categories"
335      />
336      <tbl:columndef 
337        id="owner"
338        property="owner.name"
339        datatype="string"
340        title="Owner"
341        sortable="true" 
342        filterable="true"
343        exportable="true"
344      />
345      <tbl:columndef 
346        id="description"
347        property="description"
348        datatype="string"
349        title="Description" 
350        sortable="true" 
351        filterable="true" 
352        exportable="true"
353      />
354      <tbl:columndef
355        id="permission"
356        title="Permission"
357      />
358      <tbl:columndef 
359        id="sharedTo"
360        title="Shared to"
361      />
362      <tbl:toolbar
363        visible="<%=mode.hasToolbar()%>"
364        >
365        <tbl:button 
366          disabled="<%=createPermission ? false : true%>" 
367          image="<%=createPermission ? "new.gif" : "new_disabled.gif"%>" 
368          onclick="Menu.toggleTopMenu(document.getElementById('newAnnotationType'), event.clientX, event.clientY); event.cancelBubble = true;" 
369          title="New&hellip;" 
370          tooltip="<%=createPermission ? "Create new annotation type" : "You do not have permission to create annotation types"%>" 
371        />
372        <tbl:button 
373          image="delete.gif"
374          onclick="deleteItems()" 
375          title="Delete" 
376          tooltip="Delete the selected items" 
377        />
378        <tbl:button 
379          image="restore.gif"
380          onclick="restoreItems()" 
381          title="Restore" 
382          tooltip="Restore the selected (deleted) items"
383        />
384        <tbl:button 
385          image="share.gif"
386          onclick="shareItems()" 
387          title="Share&hellip;" 
388          tooltip="Share the selected items"
389        />
390        <tbl:button 
391          image="take_ownership.png"
392          onclick="takeOwnership()" 
393          title="Take ownership&hellip;"
394          tooltip="Take ownership of the selected items"
395        />
396        <tbl:button 
397          image="columns.gif" 
398          onclick="configureColumns()" 
399          title="Columns&hellip;" 
400          tooltip="Show, hide and re-order columns" 
401        />
402        <tbl:button 
403          image="import.gif" 
404          onclick="runPlugin('ImportItems')" 
405          title="Import&hellip;" 
406          tooltip="Import data" 
407          visible="<%=pluginCount.containsKey(Plugin.MainType.IMPORT)%>"
408        />
409        <tbl:button 
410          image="export.gif" 
411          onclick="runPlugin('ExportItems')" 
412          title="Export&hellip;" 
413          tooltip="Export data" 
414          visible="<%=pluginCount.containsKey(Plugin.MainType.EXPORT)%>"
415        />
416        <tbl:button 
417          image="runplugin.gif" 
418          onclick="runPlugin('RunListPlugin')" 
419          title="Run plugin&hellip;" 
420          tooltip="Run a plugin" 
421          visible="<%=pluginCount.containsKey(Plugin.MainType.OTHER)%>"
422        />
423      </tbl:toolbar>
424      <tbl:navigator
425        page="<%=cc.getPage()%>" 
426        rowsperpage="<%=cc.getRowsPerPage()%>" 
427        totalrows="<%=annotationTypes == null ? 0 : annotationTypes.getTotalCount()%>" 
428        visible="<%=mode.hasNavigator()%>"
429      />
430      <tbl:data>
431        <tbl:columns>
432        <tbl:presetselector 
433          clazz="columnheader"
434          colspan="3"
435          onchange="presetOnChange()"
436        />
437        </tbl:columns>
438
439        <tr>
440          <tbl:header 
441            clazz="index"
442            >&nbsp;</tbl:header>
443          <tbl:header 
444            clazz="check" 
445            visible="<%=mode.hasCheck()%>"
446            ><base:icon 
447              image="check_uncheck.gif" 
448              tooltip="Check/uncheck all" 
449              onclick="Forms.checkUncheck(document.forms[formId])" style="align: left;"
450            /></tbl:header>
451          <tbl:header 
452            clazz="check" 
453            visible="<%=mode.hasRadio()%>"
454            >&nbsp;</tbl:header>
455          <tbl:header 
456            clazz="icons" 
457            visible="<%=mode.hasIcons()%>"
458            >&nbsp;</tbl:header>
459          <tbl:propertyfilter />
460        </tr>
461         
462          <tbl:rows>
463          <%
464          int index = cc.getPage()*cc.getRowsPerPage();
465          int selectedItemId = cc.getId();
466         
467          if (annotationTypes != null)
468          {
469            while (annotationTypes.hasNext())
470            {
471              AnnotationType item = annotationTypes.next();
472              int itemId = item.getId();
473              String openSharePopup = "shareItem("+itemId+")";
474              boolean sharePermission = item.hasPermission(Permission.SET_PERMISSION);
475              boolean writePermission = item.hasPermission(Permission.WRITE);
476              String name = HTML.encodeTags(item.getName());
477              String tooltip = mode.isSelectionMode() ? 
478                  "Select this item" : "View this item" + (writePermission ? " (use CTRL, ALT or SHIFT to edit)" : "");
479              index++;
480              numListed++;
481              Set<Item> itemTypes = item.getEnabledItems();
482              %>
483              <tbl:row>
484                <tbl:header 
485                  clazz="index"
486                  ><%=index%></tbl:header>
487                <tbl:header 
488                  clazz="check" 
489                  visible="<%=mode.hasCheck()%>"
490                  ><input 
491                    type="checkbox" 
492                    name="<%=itemId%>" 
493                    value="<%=itemId%>" 
494                    title="<%=name%>" 
495                    <%=cc.getSelected().contains(itemId) ? "checked" : ""%> 
496                  ></tbl:header>
497                <tbl:header 
498                  clazz="check" 
499                  visible="<%=mode.hasRadio()%>"
500                  ><input 
501                    type="radio" 
502                    name="item_id" 
503                    value="<%=itemId%>" 
504                    title="<%=name%>" 
505                    <%=selectedItemId == itemId ? "checked" : ""%>
506                  ></tbl:header>
507                <tbl:header 
508                  clazz="icons" 
509                  visible="<%=mode.hasIcons()%>"
510                  ><base:icon 
511                    image="deleted.gif" 
512                    tooltip="This item has been scheduled for deletion" 
513                    visible="<%=item.isRemoved()%>"
514                  /><base:icon 
515                    image="<%=sharePermission ? "shared.gif" : "shared_disabled.gif"%>" 
516                    onclick="<%=sharePermission ? openSharePopup : null%>"
517                    tooltip="This item is shared to other users, groups and/or projects" 
518                    visible="<%=item.isShared()%>"
519                  />&nbsp;</tbl:header>
520                <tbl:cell column="name"><div class="link" 
521                  onclick="itemOnClick(<%=writePermission ? "event" : null%>, <%=itemId%>)" 
522                  title="<%=tooltip%>"><%=name%></div></tbl:cell>
523                <tbl:cell column="externalId"><%=HTML.encodeTags(item.getExternalId())%></tbl:cell>
524                <tbl:cell column="valueType"><%=item.getValueType()%></tbl:cell>
525                <tbl:cell column="isEnumeration"><%=item.isEnumeration() ? 
526                  HTML.encodeTags(Values.getString(item.getValues(), ", ", true)) : 
527                  "<i>- no -</i>"%></tbl:cell>
528                <tbl:cell column="requiredForMiame"><%=item.isRequiredForMiame() ? "yes" : "no"%></tbl:cell>
529                <tbl:cell column="isProtocolParameter"><%=item.isProtocolParameter() ? "yes" : "no"%></tbl:cell>
530                <tbl:cell column="multiplicity"><%=item.getMultiplicity() == 0 ? "<i>- unlimited -</i>" : item.getMultiplicity()%></tbl:cell>
531                <tbl:cell column="defaultValue"><%=HTML.encodeTags(item.getDefaultValue())%></tbl:cell>
532                <tbl:cell column="itemTypes"><%=itemTypes.isEmpty() ? "<i>- none -</i>" : Values.getString(itemTypes, ", ", true)%></tbl:cell>
533                <tbl:cell column="owner"
534                  ><base:propertyvalue 
535                    item="<%=item%>" 
536                    property="owner"
537                    enableEditLink="<%=mode.hasEditLink()%>" 
538                    enablePropertyLink="<%=mode.hasPropertyLink()%>"
539                  /></tbl:cell>
540                <tbl:cell column="description"><%=HTML.encodeTags(item.getDescription())%></tbl:cell>
541                <tbl:cell column="permission"><%=PermissionUtil.getShortPermissions(item)%></tbl:cell>
542                <tbl:cell column="categories">
543                  <%
544                  categoryQuery.setParameter("annotationType", itemId, Type.INT);
545                  try
546                  {
547                    String separator = "";
548                    for (AnnotationTypeCategory c : categoryQuery.list(dc))
549                    {
550                      out.write(separator);
551                      if (mode.hasPropertyLink())
552                      {
553                        out.write(Base.getLinkedName(ID, c, false, mode.hasEditLink()));
554                      }
555                      else
556                      {
557                        out.write(HTML.encodeTags(c.getName()));
558                      }
559                      separator = ", ";
560                    }
561                  }
562                  catch (Throwable t)
563                  {
564                    %>
565                    <div class="error"><%=t.getMessage()%></div>
566                    <%
567                  }
568                  %>
569                </tbl:cell>
570                <tbl:cell column="sharedTo">
571                  <%
572                  Iterator<Nameable> sharees = ShareableUtil.getSharedTo(dc, item).iterator();
573                  while(sharees.hasNext())
574                  {
575                    Nameable n = sharees.next();
576                    if (mode.hasPropertyLink())
577                    {
578                      out.write(Base.getLinkedName(ID, n, false, mode.hasEditLink()));
579                    }
580                    else
581                    {
582                      out.write(HTML.encodeTags(n.getName()));
583                    }
584                    out.write(sharees.hasNext() ? ", " : "");
585                  }
586                  %>
587                </tbl:cell>
588              </tbl:row>
589              <%
590            }
591          }
592          %>
593          </tbl:rows>
594      </tbl:data>
595      <%
596      if (numListed == 0)
597      {
598        %>
599        <tbl:panel><%=annotationTypes == null || annotationTypes.getTotalCount() == 0 ? "No annotation types were found" : "No annotation types on this page. Please select another page!" %></tbl:panel>
600        <%
601      }
602      else
603      {
604        %>
605        <tbl:navigator
606          page="<%=cc.getPage()%>" 
607          rowsperpage="<%=cc.getRowsPerPage()%>" 
608          totalrows="<%=annotationTypes == null ? 0 : annotationTypes.getTotalCount()%>" 
609          visible="<%=mode.hasNavigator()%>"
610          locked="true"
611        />
612        <%
613      }
614      %>
615    </tbl:table>
616    <base:buttongroup align="center" clazz="fixedatbottom">
617      <base:button onclick="returnSelected();" title="Ok" visible="<%=mode.hasOkButton()%>" />
618      <base:button onclick="window.close();" title="Cancel" visible="<%=mode.hasCancelButton()%>" />
619      <base:button onclick="window.close();" title="Close" visible="<%=mode.hasCloseButton()%>" />
620    </base:buttongroup>
621    <br><br><br>
622  </base:body>
623  </base:page>
624  <%
625}
626finally
627{
628  if (annotationTypes != null) annotationTypes.close();
629  if (dc != null) dc.close();
630}
631%>
Note: See TracBrowser for help on using the repository browser.