www/admin/mimetypes/edit_mimetype.jsp

Code
Comments
Other
Rev Date Author Line
700 01 Jun 05 nicklas 1 <%-- $Id$
700 01 Jun 05 nicklas 2   ------------------------------------------------------------------
3675 16 Aug 07 jari 3   Copyright (C) 2005 Nicklas Nordborg
5425 23 Sep 10 nicklas 4   Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg, Martin Svensson
700 01 Jun 05 nicklas 5
2304 22 May 06 jari 6   This file is part of BASE - BioArray Software Environment.
2304 22 May 06 jari 7   Available at http://base.thep.lu.se/
700 01 Jun 05 nicklas 8
700 01 Jun 05 nicklas 9   BASE is free software; you can redistribute it and/or
700 01 Jun 05 nicklas 10   modify it under the terms of the GNU General Public License
4476 05 Sep 08 jari 11   as published by the Free Software Foundation; either version 3
700 01 Jun 05 nicklas 12   of the License, or (at your option) any later version.
700 01 Jun 05 nicklas 13
700 01 Jun 05 nicklas 14   BASE is distributed in the hope that it will be useful,
700 01 Jun 05 nicklas 15   but WITHOUT ANY WARRANTY; without even the implied warranty of
700 01 Jun 05 nicklas 16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
700 01 Jun 05 nicklas 17   GNU General Public License for more details.
700 01 Jun 05 nicklas 18
700 01 Jun 05 nicklas 19   You should have received a copy of the GNU General Public License
4510 11 Sep 08 jari 20   along with BASE. If not, see <http://www.gnu.org/licenses/>.
700 01 Jun 05 nicklas 21   ------------------------------------------------------------------
700 01 Jun 05 nicklas 22
700 01 Jun 05 nicklas 23
700 01 Jun 05 nicklas 24   @author Nicklas
700 01 Jun 05 nicklas 25   @version 2.0
700 01 Jun 05 nicklas 26 --%>
5426 24 Sep 10 nicklas 27 <%@ page pageEncoding="UTF-8" session="false"
3719 12 Sep 07 nicklas 28   import="net.sf.basedb.core.Application"
700 01 Jun 05 nicklas 29   import="net.sf.basedb.core.SessionControl"
700 01 Jun 05 nicklas 30   import="net.sf.basedb.core.DbControl"
700 01 Jun 05 nicklas 31   import="net.sf.basedb.core.Item"
2012 17 Feb 06 nicklas 32   import="net.sf.basedb.core.ItemContext"
700 01 Jun 05 nicklas 33   import="net.sf.basedb.core.Permission"
700 01 Jun 05 nicklas 34   import="net.sf.basedb.core.MimeType"
5630 13 May 11 nicklas 35   import="net.sf.basedb.core.ItemSubtype"
2691 03 Oct 06 nicklas 36   import="net.sf.basedb.core.ItemQuery"
2691 03 Oct 06 nicklas 37   import="net.sf.basedb.core.ItemResultList"
2691 03 Oct 06 nicklas 38   import="net.sf.basedb.core.query.Hql"
2691 03 Oct 06 nicklas 39   import="net.sf.basedb.core.query.Orders"
2012 17 Feb 06 nicklas 40   import="net.sf.basedb.core.PermissionDeniedException"
700 01 Jun 05 nicklas 41   import="net.sf.basedb.clients.web.Base"
700 01 Jun 05 nicklas 42   import="net.sf.basedb.clients.web.util.HTML"
2753 20 Oct 06 nicklas 43   import="net.sf.basedb.util.Values"
5510 19 Nov 10 nicklas 44   import="net.sf.basedb.core.plugin.GuiContext"
5510 19 Nov 10 nicklas 45   import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
5510 19 Nov 10 nicklas 46   import="net.sf.basedb.clients.web.extensions.JspContext"
5510 19 Nov 10 nicklas 47   import="net.sf.basedb.clients.web.extensions.edit.EditUtil"
7604 25 Feb 19 nicklas 48   import="net.sf.basedb.clients.web.extensions.tabcontrol.TabAction"
5510 19 Nov 10 nicklas 49   import="net.sf.basedb.util.extensions.ExtensionsInvoker"
700 01 Jun 05 nicklas 50 %>
700 01 Jun 05 nicklas 51 <%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
700 01 Jun 05 nicklas 52 <%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
6149 25 Sep 12 nicklas 53 <%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %>
700 01 Jun 05 nicklas 54 <%
2012 17 Feb 06 nicklas 55 final Item itemType = Item.MIMETYPE;
2012 17 Feb 06 nicklas 56 final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
2012 17 Feb 06 nicklas 57 final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
2012 17 Feb 06 nicklas 58 final int itemId = cc.getId();
700 01 Jun 05 nicklas 59 final String ID = sc.getId();
700 01 Jun 05 nicklas 60 final float scale = Base.getScale(sc);
7954 12 May 21 nicklas 61 final DbControl dc = sc.newDbControl(":Edit "+itemType);
700 01 Jun 05 nicklas 62 try
700 01 Jun 05 nicklas 63 {
700 01 Jun 05 nicklas 64   String title = null;
700 01 Jun 05 nicklas 65   MimeType mimeType = null;
2691 03 Oct 06 nicklas 66   boolean readCurrentFileType = true;
2691 03 Oct 06 nicklas 67   int currentFileTypeId = 0;
3719 12 Sep 07 nicklas 68   boolean autoCompress = false;
2012 17 Feb 06 nicklas 69
2012 17 Feb 06 nicklas 70   if (itemId == 0)
700 01 Jun 05 nicklas 71   {
2012 17 Feb 06 nicklas 72     title = "Create mime type";
2012 17 Feb 06 nicklas 73     cc.removeObject("item");
2691 03 Oct 06 nicklas 74     currentFileTypeId = Values.getInt(cc.getPropertyValue("fileType"), 0);
2691 03 Oct 06 nicklas 75     if (currentFileTypeId == 0)
2691 03 Oct 06 nicklas 76     {
5630 13 May 11 nicklas 77       currentFileTypeId = Values.getInt(cc.getRecent(Item.ITEMSUBTYPE.name(), 0), 0);
2691 03 Oct 06 nicklas 78     }
3719 12 Sep 07 nicklas 79     autoCompress = Values.getBoolean(cc.getPropertyValue("autoCompress"), autoCompress);
700 01 Jun 05 nicklas 80   }
700 01 Jun 05 nicklas 81   else
700 01 Jun 05 nicklas 82   {
2012 17 Feb 06 nicklas 83     mimeType = MimeType.getById(dc, itemId);
6305 09 Aug 13 nicklas 84     mimeType.checkPermission(Permission.WRITE);
2012 17 Feb 06 nicklas 85     cc.setObject("item", mimeType);
2012 17 Feb 06 nicklas 86     title = "Edit MIME type -- " + HTML.encodeTags(mimeType.getName() + " (" + mimeType.getExtension() + ")");
3719 12 Sep 07 nicklas 87     autoCompress = mimeType.getAutoCompress();
2691 03 Oct 06 nicklas 88     try
2691 03 Oct 06 nicklas 89     {
5630 13 May 11 nicklas 90       ItemSubtype ft = mimeType.getFileType();
2691 03 Oct 06 nicklas 91       if (ft != null) currentFileTypeId = ft.getId();
2691 03 Oct 06 nicklas 92     }
2691 03 Oct 06 nicklas 93     catch (PermissionDeniedException ex)
2691 03 Oct 06 nicklas 94     {
2691 03 Oct 06 nicklas 95       readCurrentFileType = false;
2691 03 Oct 06 nicklas 96     }
700 01 Jun 05 nicklas 97   }
700 01 Jun 05 nicklas 98   
2691 03 Oct 06 nicklas 99   // Query to retrieve file types
5630 13 May 11 nicklas 100   final ItemQuery<ItemSubtype> fileTypeQuery = ItemSubtype.getQuery(Item.FILE);
2691 03 Oct 06 nicklas 101   fileTypeQuery.order(Orders.asc(Hql.property("name")));
2691 03 Oct 06 nicklas 102   fileTypeQuery.setCacheResult(true);
2691 03 Oct 06 nicklas 103   
5510 19 Nov 10 nicklas 104   JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.item(itemType), mimeType);
7604 25 Feb 19 nicklas 105   ExtensionsInvoker<TabAction> invoker = EditUtil.useEditExtensions(jspContext);
700 01 Jun 05 nicklas 106   %>
6305 09 Aug 13 nicklas 107   <base:page type="popup" title="<%=title%>" id="edit-page">
6305 09 Aug 13 nicklas 108   <base:head scripts="tabcontrol-2.js,~mimetypes.js" styles="tabcontrol.css">
5510 19 Nov 10 nicklas 109     <ext:scripts context="<%=jspContext%>" />
5510 19 Nov 10 nicklas 110     <ext:stylesheets context="<%=jspContext%>" />
700 01 Jun 05 nicklas 111   </base:head>
6305 09 Aug 13 nicklas 112   <base:body>
5922 11 Jan 12 nicklas 113     <h1><%=title%> <base:help tabcontrol="settings" /></h1>
6162 10 Oct 12 nicklas 114     <form action="index.jsp?ID=<%=ID%>" method="post" name="mimeType">
2012 17 Feb 06 nicklas 115     <input type="hidden" name="cmd" value="UpdateItem">
2012 17 Feb 06 nicklas 116
5922 11 Jan 12 nicklas 117     <t:tabcontrol id="settings" 
5922 11 Jan 12 nicklas 118       subclass="content dialogtabcontrol"
5510 19 Nov 10 nicklas 119       position="bottom" remember="<%=mimeType != null%>"
5510 19 Nov 10 nicklas 120       extensions="<%=invoker%>">
6305 09 Aug 13 nicklas 121     <t:tab id="info" title="MIME type" helpid="mimetype.edit">
5922 11 Jan 12 nicklas 122       <table class="fullform input100 smaller">
700 01 Jun 05 nicklas 123       <tr>
5922 11 Jan 12 nicklas 124         <th>File extension</th>
6305 09 Aug 13 nicklas 125         <td><input class="text required auto-init" data-auto-init="<%=mimeType == null ? "focus-select" : "focus" %>"
6305 09 Aug 13 nicklas 126           type="text" name="extension" style="width: 10em;"
2012 17 Feb 06 nicklas 127           value="<%=HTML.encodeTags(mimeType == null ? cc.getPropertyValue("extension") : mimeType.getExtension())%>" 
5922 11 Jan 12 nicklas 128           maxlength="<%=MimeType.MAX_NAME_LENGTH%>"></td>
5922 11 Jan 12 nicklas 129         <td></td>
700 01 Jun 05 nicklas 130       </tr>
700 01 Jun 05 nicklas 131       <tr>
5922 11 Jan 12 nicklas 132         <th>MIME type</th>
6217 14 Dec 12 nicklas 133         <td><input class="text required" type="text" name="name" 
2012 17 Feb 06 nicklas 134           value="<%=HTML.encodeTags(mimeType == null ? Values.getString(cc.getPropertyValue("name"), "New MIME type") : mimeType.getName())%>" 
5922 11 Jan 12 nicklas 135           maxlength="<%=MimeType.MAX_NAME_LENGTH%>"></td>
5922 11 Jan 12 nicklas 136         <td></td>
700 01 Jun 05 nicklas 137       </tr>
5922 11 Jan 12 nicklas 138       <tr>
5922 11 Jan 12 nicklas 139         <th>File type</th>
5922 11 Jan 12 nicklas 140         <td>
5922 11 Jan 12 nicklas 141           <select name="filetype_id" <%=!readCurrentFileType ? "disabled readonly class=\"disabled\"" : "class=\"selectionlist\""%>>
2691 03 Oct 06 nicklas 142           <%
2691 03 Oct 06 nicklas 143           if (!readCurrentFileType)
2691 03 Oct 06 nicklas 144           {
2691 03 Oct 06 nicklas 145             %>
2691 03 Oct 06 nicklas 146             <option value="-1">- denied -
2691 03 Oct 06 nicklas 147             <%
2691 03 Oct 06 nicklas 148           }
2691 03 Oct 06 nicklas 149           else
2691 03 Oct 06 nicklas 150           {
2691 03 Oct 06 nicklas 151             %>
2691 03 Oct 06 nicklas 152             <option value="0">- none -
2691 03 Oct 06 nicklas 153             <%
5630 13 May 11 nicklas 154             ItemResultList<ItemSubtype> fileTypes = fileTypeQuery.list(dc);
5630 13 May 11 nicklas 155             for (ItemSubtype fileType : fileTypes)
2691 03 Oct 06 nicklas 156             {
2691 03 Oct 06 nicklas 157               int id = fileType.getId();
2691 03 Oct 06 nicklas 158               %>
2691 03 Oct 06 nicklas 159               <option 
2691 03 Oct 06 nicklas 160                 value="<%=mimeType != null && id == currentFileTypeId ? -id : id%>" 
2691 03 Oct 06 nicklas 161                 <%=id == currentFileTypeId ? "selected" : ""%>
2691 03 Oct 06 nicklas 162                 ><%=HTML.encodeTags(fileType.getName())%>
2691 03 Oct 06 nicklas 163               <%
2691 03 Oct 06 nicklas 164             }
2691 03 Oct 06 nicklas 165           }
2691 03 Oct 06 nicklas 166           %>
2691 03 Oct 06 nicklas 167           </select>
2691 03 Oct 06 nicklas 168         </td>
5922 11 Jan 12 nicklas 169         <td></td>
2691 03 Oct 06 nicklas 170       </tr>
3719 12 Sep 07 nicklas 171       <tr>
5922 11 Jan 12 nicklas 172         <th>Auto compress</th>
3719 12 Sep 07 nicklas 173         <td>
5812 17 Oct 11 nicklas 174           <input type="radio" name="autoCompress" id="autoCompressNo" value="0" 
5812 17 Oct 11 nicklas 175             <%=!autoCompress ? "checked" : ""%>><label for="autoCompressNo">no</label>
5812 17 Oct 11 nicklas 176           <input type="radio" name="autoCompress" id="autoCompressYes" value="1" 
5812 17 Oct 11 nicklas 177             <%=autoCompress ? "checked" : ""%>><label for="autoCompressYes">yes</label>
5922 11 Jan 12 nicklas 178         <td></td>
5922 11 Jan 12 nicklas 179       </tr>
5922 11 Jan 12 nicklas 180       <%
5922 11 Jan 12 nicklas 181       if (!Application.autoCompressionEnabled())
5922 11 Jan 12 nicklas 182       {
5922 11 Jan 12 nicklas 183         %>
5922 11 Jan 12 nicklas 184         <tr>
5922 11 Jan 12 nicklas 185           <th class="subprompt"></th>
5922 11 Jan 12 nicklas 186           <td>
5922 11 Jan 12 nicklas 187             <div class="messagecontainer help" style="margin: 0.5em;">
3719 12 Sep 07 nicklas 188               Auto-compression has been disabled in <code>base.config</code>
5922 11 Jan 12 nicklas 189             </div>
5922 11 Jan 12 nicklas 190           </td>
5922 11 Jan 12 nicklas 191           <td></td>
5922 11 Jan 12 nicklas 192         </tr>  
5922 11 Jan 12 nicklas 193         <%
5922 11 Jan 12 nicklas 194       }
5922 11 Jan 12 nicklas 195       %>
5922 11 Jan 12 nicklas 196       <tr class="dynamic">
5922 11 Jan 12 nicklas 197         <th>Description</th>
5922 11 Jan 12 nicklas 198         <td>
6217 14 Dec 12 nicklas 199           <textarea class="text" rows="6" name="description" id="description"
2012 17 Feb 06 nicklas 200             ><%=HTML.encodeTags(mimeType == null ? cc.getPropertyValue("description") : mimeType.getDescription())%></textarea>
700 01 Jun 05 nicklas 201         </td>
5922 11 Jan 12 nicklas 202         <td style="width: 20px;">
6215 13 Dec 12 nicklas 203           <base:zoom textarea="description" title="Description" />
5922 11 Jan 12 nicklas 204         </td>
700 01 Jun 05 nicklas 205       </tr>
700 01 Jun 05 nicklas 206       </table>
700 01 Jun 05 nicklas 207     </t:tab>
700 01 Jun 05 nicklas 208     </t:tabcontrol>
5922 11 Jan 12 nicklas 209     </form>
5922 11 Jan 12 nicklas 210     
5922 11 Jan 12 nicklas 211     <div class="legend">
5946 03 Feb 12 nicklas 212       <base:icon image="required.png" />= required information
5922 11 Jan 12 nicklas 213     </div>
700 01 Jun 05 nicklas 214
5922 11 Jan 12 nicklas 215     <base:buttongroup subclass="dialogbuttons">
6305 09 Aug 13 nicklas 216       <base:button id="btnSave" title="Save" />
6305 09 Aug 13 nicklas 217       <base:button id="close" title="Cancel" />
5922 11 Jan 12 nicklas 218     </base:buttongroup>
700 01 Jun 05 nicklas 219   </base:body>
700 01 Jun 05 nicklas 220   </base:page>
700 01 Jun 05 nicklas 221   <%
700 01 Jun 05 nicklas 222 }
700 01 Jun 05 nicklas 223 finally
700 01 Jun 05 nicklas 224 {
700 01 Jun 05 nicklas 225   if (dc != null) dc.close();
700 01 Jun 05 nicklas 226 }
700 01 Jun 05 nicklas 227 %>