source: trunk/www/admin/reporterclonetemplates/edit_template.jsp @ 5885

Last change on this file since 5885 was 5885, checked in by Nicklas Nordborg, 10 years ago

References #1616: Clone reporter information to per-experiment tables in the dynamic database

Updated Experiment explorer to use cloned information when possible. Renamed ClonedProperty to ClonableProperty.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 8.8 KB
Line 
1<%-- $Id $
2  ------------------------------------------------------------------
3  Copyright (C) 2011 Nicklas Nordborg
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 3
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 BASE. If not, see <http://www.gnu.org/licenses/>.
20  ------------------------------------------------------------------
21--%>
22<%@ page pageEncoding="UTF-8" session="false"
23  import="net.sf.basedb.core.SessionControl"
24  import="net.sf.basedb.core.DbControl"
25  import="net.sf.basedb.core.Item"
26  import="net.sf.basedb.core.ItemContext"
27  import="net.sf.basedb.core.Permission"
28  import="net.sf.basedb.core.ReporterCloneTemplate"
29  import="net.sf.basedb.core.ClonableProperty"
30  import="net.sf.basedb.core.ItemQuery"
31  import="net.sf.basedb.core.ItemResultList"
32  import="net.sf.basedb.core.Include"
33  import="net.sf.basedb.core.PermissionDeniedException"
34  import="net.sf.basedb.core.query.Orders"
35  import="net.sf.basedb.core.query.Hql"
36  import="net.sf.basedb.clients.web.Base"
37  import="net.sf.basedb.clients.web.util.HTML"
38  import="net.sf.basedb.util.Values"
39  import="net.sf.basedb.core.plugin.GuiContext"
40  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
41  import="net.sf.basedb.clients.web.extensions.JspContext"
42  import="net.sf.basedb.clients.web.extensions.edit.EditUtil"
43  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
44  import="java.util.List"
45  import="java.util.Collections"
46%>
47<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
48<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
49<%
50final Item itemType = Item.REPORTERCLONETEMPLATE;
51final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
52final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
53final int itemId = cc.getId();
54final String ID = sc.getId();
55final float scale = Base.getScale(sc);
56final DbControl dc = sc.newDbControl();
57try
58{
59  String title = null;
60  ReporterCloneTemplate template = null;
61  List<ClonableProperty> clonableProperties = null;
62 
63  if (itemId == 0)
64  {
65    title = "Create reporter clone template";
66    clonableProperties = ClonableProperty.getAllMandatory();
67    cc.removeObject("item");
68  }
69  else
70  {
71    template = ReporterCloneTemplate.getById(dc, itemId);
72    template.checkPermission(Permission.WRITE);
73    clonableProperties = template.getClonableProperties();
74    cc.setObject("item", template);
75    title = "Edit reporter clone template -- " + HTML.encodeTags(template.getName());
76  }
77 
78  final String clazz = "class=\"text\"";
79  final String requiredClazz = "class=\"text required\"";
80  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.item(itemType), template);
81  ExtensionsInvoker invoker = EditUtil.useEditExtensions(jspContext);
82  %>
83
84  <base:page type="popup" title="<%=title%>">
85  <base:head scripts="tabcontrol.js" styles="tabcontrol.css">
86    <ext:scripts context="<%=jspContext%>" />
87    <ext:stylesheets context="<%=jspContext%>" />
88    <script language="JavaScript">
89    // Validate the "Template" tab
90    function validateTemplate()
91    {
92      var frm = document.forms['template'];
93      if (Main.trimString(frm.name.value) == '')
94      {
95        alert("You must enter a name");
96        frm.name.focus();
97        return false;
98      }
99      return true;
100    }
101
102    // Submit the form
103    function saveSettings()
104    {
105      var frm = document.forms['template'];
106      if (TabControl.validateActiveTab('settings'))
107      {
108        for (var i = 0; i < frm.cloned_properties.length; i++)
109        {
110          frm.cloned_properties[i].selected = true;
111        }
112        for (var i = 0; i < frm.uncloned_properties.length; i++)
113        {
114          frm.uncloned_properties[i].selected = true;
115        }
116        frm.submit();
117      }
118    } 
119
120    function init()
121    {
122      var frm = document.forms['template'];
123      <%
124      if (template == null)
125      {
126        %>
127        frm.name.focus();
128        frm.name.select();
129        <%
130      }
131      %>
132    }
133   
134    function moveBetween(list1, list2, exceptMandatory)
135    {
136      var moved = 0;
137      for(i=0; i < list1.options.length; i++) // >
138      {
139        if (list1.options[i].selected)
140        {
141          if (exceptMandatory && list1.options[i].text.indexOf('×') > 0)
142          {
143            alert(list1.options[i].text + ' is mandatory');
144          }
145          else
146          {
147            moved++;
148            list2.options[list2.options.length] = new Option(list1.options[i].text, list1.options[i].value, false, true);
149            list1.options[i] = null;
150            i--;
151          }
152        }
153      }
154    }
155    </script>
156  </base:head>
157  <base:body onload="init()">
158    <p>
159    <form action="index.jsp?ID=<%=ID%>" method="post" name="template" onsubmit="return false;">
160    <input type="hidden" name="cmd" value="UpdateItem">
161
162    <h3 class="docked"><%=title%> <base:help tabcontrol="settings" /></h3>
163    <t:tabcontrol id="settings" contentstyle="<%="height: "+(int)(scale*320)+"px;"%>" 
164      position="bottom"  remember="<%=template != null%>" switch="switchTab"
165      extensions="<%=invoker%>">
166    <t:tab id="info" title="Reporter clone template" validate="validateTemplate()" helpid="reporterclonetemplate.edit">
167      <table class="form" cellspacing=0>
168      <tr>
169        <td class="prompt">Name</td>
170        <td><input <%=requiredClazz%> type="text" name="name" 
171          value="<%=HTML.encodeTags(template == null ? Values.getString(cc.getPropertyValue("name"), "New reporter clone template") : template.getName())%>" 
172          size="40" maxlength="<%=ReporterCloneTemplate.MAX_NAME_LENGTH%>"></td>
173      </tr>
174      <tr>
175        <td class="prompt">Properties</td>
176        <td>
177          <table border="0" cellspacing="0" cellpadding="0" width="100%">
178          <tr>
179            <td width="45%">
180              <b>Cloned</b><br>
181              <select name="cloned_properties" multiple size="12" style="width: 100%;" 
182                ondblclick="moveBetween(document.forms['template'].cloned_properties, document.forms['template'].uncloned_properties, true)">
183              <%
184              for (ClonableProperty cp : clonableProperties)
185              {
186                %>
187                <option value="<%=cp.getName()%>" 
188                  style="<%=cp.isMandatory() ? "font-weight: bold;" : "" %>
189                  title="<%=HTML.encodeTags(cp.getDescription())%>"><%=HTML.encodeTags(cp.getTitle())%><%=cp.isMandatory() ? " ×" : ""%>
190                <%
191              }
192              %>
193              </select>
194            </td>
195           
196            <td style="vertical-align: middle; padding: 5px;" width="10%">
197               <br>
198              <base:button
199                onclick="moveBetween(document.forms['template'].uncloned_properties, document.forms['template'].cloned_properties)" 
200                title="<img src='../../images/move_left.gif' alt='' style='vertical-align: middle;'>" 
201                tooltip="Clone the selected uncloned properties" 
202              /><p>
203              <base:button 
204                onclick="moveBetween(document.forms['template'].cloned_properties, document.forms['template'].uncloned_properties, true)" 
205                title="<img src='../../images/move_right.gif' alt='' style='vertical-align: middle;'>" 
206                tooltip="Do not cloned the selected properties" 
207              />
208              <br>
209            </td>
210           
211            <td width="45%">
212              <b>Not cloned</b><br>
213              <select name="uncloned_properties" multiple size="12" style="width: 100%;" 
214                ondblclick="moveBetween(document.forms['template'].uncloned_properties, document.forms['template'].cloned_properties)">
215              <%
216              for (ClonableProperty cp : ClonableProperty.getAll())
217              {
218                if ((template == null && !cp.isMandatory()) || (template != null && !template.hasClonableProperty(cp.getName())))
219                {
220                  %>
221                  <option value="<%=cp.getName()%>" title="<%=HTML.encodeTags(cp.getDescription())%>"><%=HTML.encodeTags(cp.getTitle())%>
222                  <%
223                }
224              }
225              %>
226              </select>
227            </td>
228           
229          </tr>
230          </table>
231        </td>
232      </tr>
233      <tr valign=top>
234        <td class="prompt">Description</td>
235        <td nowrap>
236          <textarea <%=clazz%> rows="4" cols="40" name="description" wrap="virtual"
237            ><%=HTML.encodeTags(template == null ? cc.getPropertyValue("description") : template.getDescription())%></textarea>
238          <a href="javascript:Main.zoom('Description', 'template', 'description')"
239            title="Edit in larger window"><base:icon image="zoom.gif" /></a>
240        </td>
241      </tr>
242      </table>
243      <div align=right>&nbsp;<i><base:icon image="required.gif" /> = required information</i></div>
244    </t:tab>
245   
246    </t:tabcontrol>
247
248    <table align="center">
249    <tr>
250      <td width="50%"><base:button onclick="saveSettings()" title="Save" /></td>
251      <td width="50%"><base:button onclick="window.close()" title="Cancel" /></td>
252    </tr>
253    </table>
254    </form>
255  </base:body>
256  </base:page>
257  <%
258}
259finally
260{
261  if (dc != null) dc.close();
262}
263%>
Note: See TracBrowser for help on using the repository browser.