source: trunk/www/admin/annotationtypes/list_annotationtypes.jsp @ 3452

Last change on this file since 3452 was 3452, checked in by Nicklas Nordborg, 16 years ago

Fixes #558 and #568

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