source: trunk/www/admin/protocols/edit_protocol.jsp @ 5767

Last change on this file since 5767 was 5767, checked in by Nicklas Nordborg, 11 years ago

Fixes #1626: Center-align text on buttons

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 12.6 KB
Line 
1<%-- $Id: edit_protocol.jsp 5767 2011-09-28 07:31:39Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2005 Nicklas Nordborg
4  Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg, Martin Svensson
5
6  This file is part of BASE - BioArray Software Environment.
7  Available at http://base.thep.lu.se/
8
9  BASE is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License
11  as published by the Free Software Foundation; either version 3
12  of the License, or (at your option) any later version.
13
14  BASE is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  GNU General Public License for more details.
18
19  You should have received a copy of the GNU General Public License
20  along with BASE. If not, see <http://www.gnu.org/licenses/>.
21  ------------------------------------------------------------------
22
23
24  @author Nicklas
25  @version 2.0
26--%>
27<%@ page pageEncoding="UTF-8" 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.ItemContext"
32  import="net.sf.basedb.core.Permission"
33  import="net.sf.basedb.core.Protocol"
34  import="net.sf.basedb.core.ItemSubtype"
35  import="net.sf.basedb.core.AnnotationType"
36  import="net.sf.basedb.core.File"
37  import="net.sf.basedb.core.SystemItems"
38  import="net.sf.basedb.core.ItemQuery"
39  import="net.sf.basedb.core.ItemResultList"
40  import="net.sf.basedb.core.Include"
41  import="net.sf.basedb.core.PermissionDeniedException"
42  import="net.sf.basedb.core.query.Orders"
43  import="net.sf.basedb.core.query.Hql"
44  import="net.sf.basedb.clients.web.Base"
45  import="net.sf.basedb.clients.web.util.HTML"
46  import="net.sf.basedb.util.Values"
47  import="net.sf.basedb.core.plugin.GuiContext"
48  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
49  import="net.sf.basedb.clients.web.extensions.JspContext"
50  import="net.sf.basedb.clients.web.extensions.edit.EditUtil"
51  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
52  import="java.util.List"
53%>
54<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
55<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
56<%
57final Item itemType = Item.PROTOCOL;
58final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
59final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
60final int itemId = cc.getId();
61final String ID = sc.getId();
62final float scale = Base.getScale(sc);
63final DbControl dc = sc.newDbControl();
64try
65{
66  String title = null;
67  Protocol protocol = null;
68  boolean readCurrentSubtype = true;
69  int currentSubtypeId = 0;
70  boolean readCurrentFile = true;
71  File currentFile = null;
72  ItemQuery<AnnotationType> parameterQuery = null;
73
74  // Load recently used items
75  List<File> recentFiles = (List<File>)cc.getRecent(dc, Item.FILE);
76
77  if (itemId == 0)
78  {
79    title = "Create protocol";
80
81    currentSubtypeId = Values.getInt(request.getParameter("subtype_id"));
82    if (currentSubtypeId == 0) 
83    {
84      int recentSubtypeId = Values.getInt(cc.getRecent(Item.ITEMSUBTYPE.name(), 0));
85      currentSubtypeId = Values.getInt(cc.getPropertyValue("itemSubtype"), recentSubtypeId);
86    }
87    cc.removeObject("item");
88  }
89  else
90  {
91    protocol = Protocol.getById(dc, itemId);
92    protocol.checkPermission(Permission.WRITE);
93   
94    parameterQuery = protocol.getParameters();
95    cc.setObject("item", protocol);
96    title = "Edit protocol -- " + HTML.encodeTags(protocol.getName());
97    try
98    {
99      ItemSubtype subtype = protocol.getItemSubtype();
100      if (subtype != null) currentSubtypeId = subtype.getId();
101    }
102    catch (PermissionDeniedException ex)
103    {
104      readCurrentSubtype = false;
105    }
106    try
107    {
108      currentFile = protocol.getFile();
109    }
110    catch (PermissionDeniedException ex)
111    {
112      readCurrentFile = false;
113    }
114  }
115 
116  // Query to retrieve protocol types
117  final ItemQuery<ItemSubtype> subtypesQuery = Base.getSubtypesQuery(itemType);
118  subtypesQuery.include(Include.ALL);
119 
120  final String clazz = "class=\"text\"";
121  final String requiredClazz = "class=\"text required\"";
122  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.item(itemType), protocol);
123  ExtensionsInvoker invoker = EditUtil.useEditExtensions(jspContext);
124  %>
125
126  <base:page type="popup" title="<%=title%>">
127  <base:head scripts="tabcontrol.js,annotations.js,linkitems.js,ajax.js,json2.js,subtypes.js" styles="tabcontrol.css">
128    <ext:scripts context="<%=jspContext%>" />
129    <ext:stylesheets context="<%=jspContext%>" />
130    <script language="JavaScript">
131    // Validate the "Protocol" tab
132    function validateProtocol()
133    {
134      var frm = document.forms['protocol'];
135      if (Main.trimString(frm.name.value) == '')
136      {
137        alert("You must enter a name");
138        frm.name.focus();
139        return false;
140      }
141      return true;
142    }
143    // Validate the "Parameters" tab
144    function validateParameters()
145    {
146      return true;
147    }
148
149    // Submit the form
150    function saveSettings()
151    {
152      var frm = document.forms['protocol'];
153      if (TabControl.validateActiveTab('settings'))
154      {
155        if (annotationsLoaded)
156        {
157          Annotations.addModifiedAnnotationsToForm(frames.annotations, frm);
158        }
159        frm.addedAnnotationTypes.value = Link.getActionIds(1, 'A').join(',');
160        frm.removedAnnotationTypes.value = Link.getActionIds(-1, 'A').join(',');
161        frm.submit();
162      }
163    }
164   
165    var annotationsLoaded = false;
166    function switchTab(tabControlId, tabId)
167    {
168      if (TabControl.setActiveTab(tabControlId, tabId))
169      {
170        if (tabId == 'annotations' && !annotationsLoaded)
171        {
172          Annotations.loadAnnotateFrame(frames.annotations, '<%=ID%>', '<%=itemType.name()%>', <%=itemId%>);
173          annotationsLoaded = true;
174        }
175      }
176    }
177   
178    function browseOnClick()
179    {
180      var frm = document.forms['protocol'];
181      var subtype = Math.abs(frm.subtype_id[frm.subtype_id.selectedIndex].value);
182      var relatedFileSubtype = ItemSubtype.getRelatedSubtype(subtype, 'FILE', <%=SystemItems.getId(File.PROTOCOL)%>);
183      var url = '../../filemanager/index.jsp?ID=<%=ID%>&cmd=SelectOne&title=Select+protocol+file&callback=setFileCallback';
184      url += '&resetTemporary=1&tmpfilter:INT:itemSubtype=' + relatedFileSubtype.id;
185      if (frm.file_id.length > 1)
186      {
187        var id = Math.abs(parseInt(frm.file_id[1].value));
188        url += '&item_id='+id;
189      }
190      Main.openPopup(url, 'SelectFile', 1000, 700);
191    }
192    function setFileCallback(id, path)
193    {
194      var frm = document.forms['protocol'];
195      var list = frm.file_id;
196      if (list.length < 2 || list[1].value == '0') // >
197      {
198        Forms.addListOption(list, 1, new Option());
199      }
200      list[1].value = id;
201      list[1].text = path;
202      list.selectedIndex = 1;
203    }
204
205    function init()
206    {
207      var frm = document.forms['protocol'];
208      <%
209      if (protocol == null)
210      {
211        %>
212        frm.name.focus();
213        frm.name.select();
214        <%
215      }
216      if (parameterQuery != null)
217      {
218        %>
219        var annotationTypes = frm.annotationTypes;
220        <%
221        parameterQuery.include(Include.ALL);
222        parameterQuery.order(Orders.asc(Hql.property("name")));
223        ItemResultList<AnnotationType> parameters = parameterQuery.list(dc);
224        for (AnnotationType at : parameters)
225        {
226          %>
227          Link.addNewItem(annotationTypes, new Item('A', <%=at.getId()%>, '<%=HTML.javaScriptEncode(at.getName())%>'));
228          <%
229        }
230      }
231      %>
232    }
233    function addAnnotationTypesOnClick()
234    {
235      var frm = document.forms['protocol'];
236      var ids = Link.getListIds(frm.annotationTypes, 'A');
237      var excludes = ids.join(',');
238      var url = '../annotationtypes/index.jsp?ID=<%=ID%>&cmd=UpdateContext&mode=selectmultiple&callback=addAnnotationTypeCallback';
239      url += '&resetTemporary=1&tmpfilter:BOOLEAN:protocolParameter=true';
240      url += "&exclude="+excludes;
241      Main.openPopup(url, 'AddAnnotationTypes', 1000, 700);
242    }
243    function addAnnotationTypeCallback(annotationTypeId, name)
244    {
245      var item = Link.getItem('A', annotationTypeId);
246      if (!item) item = new Item('A', annotationTypeId, name);
247      Link.addItem(document.forms['protocol'].annotationTypes, item);
248    }
249    function removeAnnotationTypesOnClick()
250    {
251      Link.removeSelected(document.forms['protocol'].annotationTypes);
252    }
253    </script>
254  </base:head>
255  <base:body onload="init()">
256    <p>
257    <form action="index.jsp?ID=<%=ID%>" method="post" name="protocol" onsubmit="return false;">
258    <input type="hidden" name="cmd" value="UpdateItem">
259
260    <h3 class="docked"><%=title%> <base:help tabcontrol="settings" /></h3>
261    <t:tabcontrol id="settings" contentstyle="<%="height: "+(int)(scale*370)+"px;"%>" 
262      position="bottom"  remember="<%=protocol != null%>" switch="switchTab"
263      extensions="<%=invoker%>">
264    <t:tab id="info" title="Protocol" validate="validateProtocol()" helpid="protocol.edit">
265      <table class="form" cellspacing=0>
266      <tr>
267        <td class="prompt">Name</td>
268        <td><input <%=requiredClazz%> type="text" name="name" 
269          value="<%=HTML.encodeTags(protocol == null ? Values.getString(cc.getPropertyValue("name"), "New protocol") : protocol.getName())%>" 
270          size="40" maxlength="<%=Protocol.MAX_NAME_LENGTH%>"></td>
271      </tr>
272      <tr valign="top">
273        <td class="prompt">Type</td>
274        <td colspan="2">
275          <select name="subtype_id" 
276            <%=!readCurrentSubtype ? "disabled readonly class=\"disabled selectionlist\"" : "class=\"selectionlist\""%>>
277          <%
278          if (!readCurrentSubtype)
279          {
280            %>
281            <option value="-1">- denied -
282            <%
283          }
284          else
285          {
286            %>
287            <option value="0">-none-
288            <%
289            for (ItemSubtype subtype : subtypesQuery.list(dc))
290            {
291              int id = subtype.getId();
292              if (id != currentSubtypeId && subtype.isRemoved()) continue;
293              %>
294              <option value="<%=id == currentSubtypeId && protocol != null ? -id : id%>" 
295                <%=id == currentSubtypeId ? "selected" : ""%>
296                title="<%=HTML.encodeTags(subtype.getDescription()) %>"
297                ><%=HTML.encodeTags(subtype.getName())%>
298              <%
299            }
300          }
301          %>
302          </select>
303        </td>
304      </tr>
305      <tr>
306        <td class="prompt">External ID</td>
307        <td><input <%=clazz%> type="text" name="external_id" 
308          value="<%=HTML.encodeTags(protocol == null ? Values.getString(cc.getPropertyValue("externalId"), "") : protocol.getExternalId())%>" 
309          size="40" maxlength="<%=Protocol.MAX_EXTERNAL_ID_LENGTH%>"></td>
310      </tr>
311      <tr>
312        <td class="prompt">File</td>
313        <td>
314          <base:select 
315            id="file_id"
316            clazz="selectionlist"
317            required="false"
318            current="<%=currentFile%>"
319            denied="<%=!readCurrentFile%>"
320            recent="<%=recentFiles%>"
321            newitem="<%=protocol == null%>"
322            onselect="browseOnClick()"
323          />
324        </td>
325      </tr>
326
327      <tr valign=top>
328        <td class="prompt">Description</td>
329        <td nowrap>
330          <textarea <%=clazz%> rows="4" cols="40" name="description" wrap="virtual"
331            ><%=HTML.encodeTags(protocol == null ? cc.getPropertyValue("description") : protocol.getDescription())%></textarea>
332          <a href="javascript:Main.zoom('Description', 'protocol', 'description')"
333            title="Edit in larger window"><base:icon image="zoom.gif" /></a>
334        </td>
335      </tr>
336      </table>
337      <div align=right>&nbsp;<i><base:icon image="required.gif" /> = required information</i></div>
338    </t:tab>
339   
340    <t:tab id="parameters" title="Parameters" 
341      validate="validateParameters()" helpid="protocol.edit.parameters">
342    <table class="form" cellspacing=0>
343   
344    <tr valign="top">
345      <td><b>Annotation types</b>
346        <table border="0" cellspacing="0" cellpadding="0">
347        <tr valign="top">
348        <td>
349          <select name="annotationTypes" size="10" multiple style="width: 20em;">
350          </select>
351          <input type="hidden" name="addedAnnotationTypes" value="">
352          <input type="hidden" name="removedAnnotationTypes" value="">
353        </td>
354        <td>
355          <table border="0">
356          <tr><td width="150"><base:button 
357            clazz="leftaligned buttonclass"
358            onclick="addAnnotationTypesOnClick()" 
359            title="Add annotation types&hellip;" 
360            tooltip="Add annotation types"
361            /></td></tr>
362          <tr><td width="150"><base:button 
363            clazz="leftaligned buttonclass"
364            onclick="removeAnnotationTypesOnClick()" 
365            title="Remove" 
366            tooltip="Remove the selected annotation types"
367          /></td></tr>
368          </table>
369        </td>
370        </tr>
371        </table>
372      </td>
373    </tr>
374    </table>
375    </t:tab>
376   
377    <t:tab id="annotations" title="Annotations" 
378      helpid="annotations.edit" tooltip="Enter values for annotations">
379      <iframe name="annotations" id="idAnnotations" src="../../common/annotations/wait.jsp" 
380        width="100%"  height="<%=(int)(scale*370)%>" frameborder=0 vspace=0 hspace=0
381        marginwidth=0 marginheight=0 scrolling="auto" style="overflow: visible"></iframe>
382    </t:tab>
383   
384    </t:tabcontrol>
385
386    <table align="center">
387    <tr>
388      <td width="50%"><base:button onclick="saveSettings()" title="Save" /></td>
389      <td width="50%"><base:button onclick="window.close()" title="Cancel" /></td>
390    </tr>
391    </table>
392    </form>
393  </base:body>
394  </base:page>
395  <%
396}
397finally
398{
399  if (dc != null) dc.close();
400}
401%>
Note: See TracBrowser for help on using the repository browser.