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