source: trunk/www/views/formulas/list_formulas.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:keywords set to Date Id
File size: 16.6 KB
Line 
1<%-- $Id: list_formulas.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 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.Formula"
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.Permission"
36  import="net.sf.basedb.core.RawDataTypes"
37  import="net.sf.basedb.core.RawDataType"
38  import="net.sf.basedb.core.PluginDefinition"
39  import="net.sf.basedb.core.plugin.GuiContext"
40  import="net.sf.basedb.core.plugin.Plugin"
41  import="net.sf.basedb.util.Enumeration"
42  import="net.sf.basedb.clients.web.Base"
43  import="net.sf.basedb.clients.web.ModeInfo"
44  import="net.sf.basedb.clients.web.PermissionUtil"
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.FORMULA;
54  private static final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.LIST);
55 
56  private static final Enumeration<String, String> types = new Enumeration<String, String>();
57  private static final Enumeration<String, String> parsers = new Enumeration<String, String>();
58  private static final Enumeration<String, String> rawEnumeration = new Enumeration<String, String>();
59  static
60  {
61    for (Formula.Type t : Formula.Type.values())
62    {
63      types.add(Integer.toString(t.getValue()), HTML.encodeTags(t.toString()));
64    }
65    for (Formula.Parser p : Formula.Parser.values())
66    {
67      parsers.add(Integer.toString(p.getValue()), HTML.encodeTags(p.toString()));
68    }
69    for (RawDataType rdt : RawDataTypes.getRawDataTypes())
70    {
71      rawEnumeration.add(rdt.getId(), HTML.encodeTags(rdt.getName()));
72    }
73  }
74%>
75<%
76final SessionControl sc = Base.getExistingSessionControl(pageContext, Permission.DENIED, itemType);
77final String ID = sc.getId();
78final boolean createPermission = sc.hasPermission(Permission.CREATE, itemType);
79final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
80
81final ModeInfo mode = ModeInfo.get(request.getParameter("mode"));
82final String callback = request.getParameter("callback");
83final String title = mode.generateTitle("formula", "formulas");
84final DbControl dc = sc.newDbControl();
85ItemResultIterator<Formula> formulas = null;
86try
87{
88  Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext);
89  try
90  {
91    final ItemQuery<Formula> query = Base.getConfiguredQuery(cc, false, Formula.getQuery(), mode);
92    formulas = query.iterate(dc);
93  }
94  catch (Throwable t)
95  {
96    cc.setMessage(t.getMessage());
97  }
98  int numListed = 0;
99  %>
100  <base:page title="<%=title==null ? "Formulas" : title%>" type="<%=mode.getPageType()%>">
101  <base:head scripts="menu.js,table.js" styles="menu.css,table.css">
102    <script language="JavaScript">
103    var submitPage = 'index.jsp';
104    var formId = 'formulas';
105    function newItem()
106    {
107      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', 0, true);
108    }
109    function editItem(itemId)
110    {
111      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', itemId, true);
112    }
113    function viewItem(itemId)
114    {
115      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', itemId, false);
116    }
117    function itemOnClick(evt, itemId)
118    {
119      Table.itemOnClick(formId, evt, itemId, '<%=mode.getName()%>', viewItem, editItem, returnSelected);
120    }
121    function deleteItems()
122    {
123      var frm = document.forms[formId];
124      if (Forms.numChecked(frm) == 0)
125      {
126        alert('Please select at least one item in the list');
127        return;
128      }
129      frm.action = submitPage;
130      frm.cmd.value = 'DeleteItems';
131      frm.submit();
132    }
133    function restoreItems()
134    {
135      var frm = document.forms[formId];
136      if (Forms.numChecked(frm) == 0)
137      {
138        alert('Please select at least one item in the list');
139        return;
140      }
141      frm.action = submitPage;
142      frm.cmd.value = 'RestoreItems';
143      frm.submit();
144    }
145    function takeOwnership()
146    {
147      var frm = document.forms[formId];
148      if (Forms.numChecked(frm) == 0)
149      {
150        alert('Please select at least one item in the list');
151        return;
152      }
153      if (confirm('Are you sure that you want to take ownership of the selected items? It can\'t be undone.'))
154      {
155        frm.action = submitPage;
156        frm.cmd.value = 'TakeOwnershipOfItems';
157        frm.submit();
158      }
159    }
160    function shareItem(itemId)
161    {
162      Main.openPopup('index.jsp?ID=<%=ID%>&cmd=ShareItem&item_id='+itemId, 'ShareItem', 500, 400);
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="formulas" 
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      <tbl:columndef 
219        id="name"
220        property="name"
221        datatype="string"
222        title="Name"
223        sortable="true" 
224        filterable="true"
225        exportable="true"
226        show="always" 
227      />
228      <tbl:columndef 
229        id="type"
230        property="type"
231        datatype="int"
232        enumeration="<%=types%>"
233        title="Type"
234        sortable="true" 
235        filterable="true"
236        exportable="true"
237      />
238      <tbl:columndef 
239        id="parser"
240        property="parser"
241        datatype="int"
242        enumeration="<%=parsers%>"
243        title="Parser"
244        sortable="true" 
245        filterable="true"
246        exportable="true"
247      />
248      <tbl:columndef 
249        id="rawDataType"
250        property="rawDataType"
251        datatype="string"
252        enumeration="<%=rawEnumeration%>"
253        title="Raw data type"
254        sortable="true" 
255        filterable="true"
256        exportable="true"
257      />
258      <tbl:columndef 
259        id="channels"
260        property="channels"
261        datatype="int"
262        title="Channels"
263        sortable="true" 
264        filterable="true"
265        exportable="true"
266      />
267      <tbl:columndef 
268        id="formulas"
269        property="formulas"
270        datatype="string"
271        title="Formulas"
272        sortable="false" 
273        filterable="false"
274        exportable="true"
275      />
276      <tbl:columndef 
277        id="useColors"
278        property="coloring.usingColors"
279        datatype="boolean"
280        title="Use colors"
281        sortable="true" 
282        filterable="true"
283        exportable="false"
284      />
285      <tbl:columndef 
286        id="logarithmic"
287        property="coloring.logarithmic"
288        datatype="boolean"
289        title="Logarithmic"
290        sortable="true" 
291        filterable="true"
292        exportable="false"
293      />
294      <tbl:columndef 
295        id="minValue"
296        property="coloring.minValue"
297        datatype="float"
298        title="Min value"
299        sortable="true" 
300        filterable="true"
301        exportable="false"
302      />
303      <tbl:columndef 
304        id="midValue"
305        property="coloring.midValue"
306        datatype="float"
307        title="Mid value"
308        sortable="true" 
309        filterable="true"
310        exportable="false"
311      />
312      <tbl:columndef 
313        id="maxValue"
314        property="coloring.maxValue"
315        datatype="float"
316        title="Max value"
317        sortable="true" 
318        filterable="true"
319        exportable="false"
320      />
321      <tbl:columndef 
322        id="owner"
323        property="owner.name"
324        datatype="string"
325        title="Owner"
326        sortable="true" 
327        filterable="true"
328        exportable="true"
329      />
330      <tbl:columndef 
331        id="description"
332        property="description"
333        datatype="string"
334        title="Description" 
335        sortable="true" 
336        filterable="true" 
337        exportable="true"
338      />
339      <tbl:columndef
340        id="permission"
341        title="Permission"
342      />
343      <tbl:toolbar
344        visible="<%=mode.hasToolbar()%>"
345        >
346        <tbl:button 
347          disabled="<%=createPermission ? false : true%>" 
348          image="<%=createPermission ? "new.gif" : "new_disabled.gif"%>" 
349          onclick="newItem()" 
350          title="New&hellip;" 
351          tooltip="<%=createPermission ? "Create new formula" : "You do not have permission to create formulas"%>" 
352        />
353        <tbl:button 
354          image="delete.gif"
355          onclick="deleteItems()" 
356          title="Delete" 
357          tooltip="Delete the selected items" 
358        />
359        <tbl:button 
360          image="restore.gif"
361          onclick="restoreItems()" 
362          title="Restore" 
363          tooltip="Restore the selected (deleted) items"
364        />
365        <tbl:button 
366          image="share.gif"
367          onclick="shareItems()" 
368          title="Share&hellip;" 
369          tooltip="Share the selected items"
370        />
371        <tbl:button 
372          image="take_ownership.png"
373          onclick="takeOwnership()" 
374          title="Take ownership&hellip;"
375          tooltip="Take ownership of the selected items"
376        />
377        <tbl:button 
378          image="columns.gif" 
379          onclick="configureColumns()" 
380          title="Columns&hellip;" 
381          tooltip="Show, hide and re-order columns" 
382        />
383        <tbl:button 
384          image="import.gif" 
385          onclick="runPlugin('ImportItems')" 
386          title="Import&hellip;" 
387          tooltip="Import data" 
388          visible="<%=pluginCount.containsKey(Plugin.MainType.IMPORT)%>"
389        />
390        <tbl:button 
391          image="export.gif" 
392          onclick="runPlugin('ExportItems')" 
393          title="Export&hellip;" 
394          tooltip="Export data" 
395          visible="<%=pluginCount.containsKey(Plugin.MainType.EXPORT)%>"
396        />
397        <tbl:button 
398          image="runplugin.gif" 
399          onclick="runPlugin('RunListPlugin')" 
400          title="Run plugin&hellip;" 
401          tooltip="Run a plugin" 
402          visible="<%=pluginCount.containsKey(Plugin.MainType.OTHER)%>"
403        />
404      </tbl:toolbar>
405      <tbl:navigator
406        page="<%=cc.getPage()%>" 
407        rowsperpage="<%=cc.getRowsPerPage()%>" 
408        totalrows="<%=formulas == null ? 0 : formulas.getTotalCount()%>" 
409        visible="<%=mode.hasNavigator()%>"
410      />
411      <tbl:data>
412        <tbl:columns>
413        <tbl:presetselector 
414          clazz="columnheader"
415          colspan="3"
416          onchange="presetOnChange()"
417        />
418        </tbl:columns>
419
420        <tr>
421          <tbl:header 
422            clazz="index"
423            >&nbsp;</tbl:header>
424          <tbl:header 
425            clazz="check" 
426            visible="<%=mode.hasCheck()%>"
427            ><base:icon 
428              image="check_uncheck.gif" 
429              tooltip="Check/uncheck all" 
430              onclick="Forms.checkUncheck(document.forms[formId])" style="align: left;"
431            /></tbl:header>
432          <tbl:header 
433            clazz="check" 
434            visible="<%=mode.hasRadio()%>"
435            >&nbsp;</tbl:header>
436          <tbl:header 
437            clazz="icons" 
438            visible="<%=mode.hasIcons()%>"
439            >&nbsp;</tbl:header>
440          <tbl:propertyfilter />
441        </tr>
442         
443          <tbl:rows>
444          <%
445          int index = cc.getPage()*cc.getRowsPerPage();
446          int selectedItemId = cc.getId();
447          if (formulas != null)
448          {
449            while (formulas.hasNext())
450            {
451              Formula item = formulas.next();
452              RawDataType rawDataType = item.getRawDataType();
453              List<String> expressions = item.getFormulas();
454              int itemId = item.getId();
455              String openSharePopup = "shareItem("+itemId+")";
456              boolean sharePermission = item.hasPermission(Permission.SET_PERMISSION);
457              boolean writePermission = item.hasPermission(Permission.WRITE);
458              String tooltip = mode.isSelectionMode() ?
459                  "Select this item" : "View this item" + (writePermission ? " (use CTRL, ALT or SHIFT to edit)" : "");
460              String name = HTML.encodeTags(item.getName());
461              index++;
462              numListed++;
463              %>
464              <tbl:row>
465                <tbl:header 
466                  clazz="index"
467                  ><%=index%></tbl:header>
468                <tbl:header 
469                  clazz="check" 
470                  visible="<%=mode.hasCheck()%>"
471                  ><input 
472                    type="checkbox" 
473                    name="<%=itemId%>" 
474                    value="<%=itemId%>" 
475                    title="<%=name%>" 
476                    <%=cc.getSelected().contains(itemId) ? "checked" : ""%> 
477                  ></tbl:header>
478                <tbl:header 
479                  clazz="check" 
480                  visible="<%=mode.hasRadio()%>"
481                  ><input 
482                    type="radio" 
483                    name="item_id" 
484                    value="<%=itemId%>" 
485                    title="<%=name%>" 
486                    <%=selectedItemId == itemId ? "checked" : ""%>
487                  ></tbl:header>
488                <tbl:header 
489                  clazz="icons" 
490                  visible="<%=mode.hasIcons()%>"
491                  ><base:icon 
492                    image="deleted.gif" 
493                    tooltip="This item has been scheduled for deletion" 
494                    visible="<%=item.isRemoved()%>"
495                  /><base:icon 
496                    image="<%=sharePermission ? "shared.gif" : "shared_disabled.gif"%>" 
497                    onclick="<%=sharePermission ? openSharePopup : null%>"
498                    tooltip="This item is shared to other users, groups and/or projects" 
499                    visible="<%=item.isShared()%>"
500                  />&nbsp;</tbl:header>
501                <tbl:cell column="name"><div class="link" 
502                  onclick="itemOnClick(<%=writePermission ? "event" : null%>, <%=itemId%>)" 
503                  title="<%=tooltip%>"><%=name%></div></tbl:cell>
504                <tbl:cell column="type"><%=item.getFormulaType().toString()%></tbl:cell>
505                <tbl:cell column="parser"><%=item.getParser().toString()%></tbl:cell>
506                <tbl:cell column="rawDataType"><%=rawDataType == null ? "<i>- none -</i>" : HTML.encodeTags(rawDataType.getName())%></tbl:cell>
507                <tbl:cell column="channels"><%=item.getChannels()%></tbl:cell>
508                <tbl:cell column="formulas">
509                <%
510                for (int i = 0; i < expressions.size(); ++i)
511                {
512                  %>
513                  <%=(i+1) + ": " + HTML.encodeTags(expressions.get(i))%><br>
514                  <%
515                }
516                %>
517                </tbl:cell>
518                <tbl:cell column="owner"
519                  ><base:propertyvalue 
520                    item="<%=item%>" 
521                    property="owner"
522                    enableEditLink="<%=mode.hasEditLink()%>" 
523                    enablePropertyLink="<%=mode.hasPropertyLink()%>"
524                  /></tbl:cell>
525                <tbl:cell column="useColors"><%=item.getColoring().isUsingColors() ? "yes" : "no"%></tbl:cell>
526                <tbl:cell column="logarithmic"><%=item.getColoring().isLogarithmic() ? "yes" : "no"%></tbl:cell>
527                <tbl:cell column="minValue"><%=Values.formatNumber(item.getColoring().getMinValue(), 2)%></tbl:cell>
528                <tbl:cell column="midValue"><%=Values.formatNumber(item.getColoring().getMidValue(), 2)%></tbl:cell>
529                <tbl:cell column="maxValue"><%=Values.formatNumber(item.getColoring().getMaxValue(), 2)%></tbl:cell>
530                <tbl:cell column="description"><%=HTML.encodeTags(item.getDescription())%></tbl:cell>
531                <tbl:cell column="permission"><%=PermissionUtil.getShortPermissions(item)%></tbl:cell>
532              </tbl:row>
533              <%
534              }
535            }
536          %>
537          </tbl:rows>
538      </tbl:data>
539      <%
540      if (numListed == 0)
541      {
542        %>
543        <tbl:panel><%=formulas == null || formulas.getTotalCount() == 0 ? "No formulas were found" : "No formulas on this page. Please select another page!" %></tbl:panel>
544        <%
545      }
546      else
547      {
548        %>
549        <tbl:navigator
550          page="<%=cc.getPage()%>" 
551          rowsperpage="<%=cc.getRowsPerPage()%>" 
552          totalrows="<%=formulas == null ? 0 : formulas.getTotalCount()%>" 
553          visible="<%=mode.hasNavigator()%>"
554          locked="true"
555        />
556        <%
557      }
558      %>
559    </tbl:table>
560    <base:buttongroup align="center" clazz="fixedatbottom">
561      <base:button onclick="returnSelected();" title="Ok" visible="<%=mode.hasOkButton()%>" />
562      <base:button onclick="window.close();" title="Cancel" visible="<%=mode.hasCancelButton()%>" />
563      <base:button onclick="window.close();" title="Close" visible="<%=mode.hasCloseButton()%>" />
564    </base:buttongroup>
565    <br><br><br>
566  </base:body>
567  </base:page>
568  <%
569}
570finally
571{
572  if (formulas != null) formulas.close();
573  if (dc != null) dc.close();
574}
575%>
Note: See TracBrowser for help on using the repository browser.