source: trunk/www/admin/mimetypes/list_mimetypes.jsp @ 7943

Last change on this file since 7943 was 7943, checked in by Nicklas Nordborg, 2 years ago

Merged BASE 3.18.1 to the trunk.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 14.5 KB
Line 
1<%-- $Id: list_mimetypes.jsp 7943 2021-05-04 12:23:19Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg, Martin Svensson
4  Copyright (C) 2007 Johan Enell
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  @author Nicklas
24  @version 2.0
25--%>
26<%@ page pageEncoding="UTF-8" session="false"
27  import="net.sf.basedb.core.SessionControl"
28  import="net.sf.basedb.core.DbControl"
29  import="net.sf.basedb.core.Item"
30  import="net.sf.basedb.core.MimeType"
31  import="net.sf.basedb.core.ItemSubtype"
32  import="net.sf.basedb.core.ItemQuery"
33  import="net.sf.basedb.core.Include"
34  import="net.sf.basedb.core.ItemResultIterator"
35  import="net.sf.basedb.core.ItemResultList"
36  import="net.sf.basedb.core.ItemContext"
37  import="net.sf.basedb.core.Permission"
38  import="net.sf.basedb.core.PluginDefinition"
39  import="net.sf.basedb.core.query.Orders"
40  import="net.sf.basedb.core.query.Hql"
41  import="net.sf.basedb.core.plugin.GuiContext"
42  import="net.sf.basedb.core.plugin.Plugin"
43  import="net.sf.basedb.util.Enumeration"
44  import="net.sf.basedb.clients.web.Base"
45  import="net.sf.basedb.clients.web.PermissionUtil"
46  import="net.sf.basedb.clients.web.ModeInfo"
47  import="net.sf.basedb.clients.web.util.HTML"
48  import="net.sf.basedb.util.Values"
49  import="net.sf.basedb.util.formatter.Formatter"
50  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
51  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
52  import="net.sf.basedb.clients.web.extensions.JspContext"
53  import="net.sf.basedb.clients.web.extensions.renderer.PrefixSuffixRenderer"
54  import="net.sf.basedb.clients.web.extensions.toolbar.ButtonAction" 
55  import="net.sf.basedb.clients.web.extensions.toolbar.ToolbarUtil"
56  import="net.sf.basedb.clients.web.extensions.list.ListColumnAction"
57  import="net.sf.basedb.clients.web.extensions.list.ListColumnUtil"
58  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
59  import="java.util.Date"
60  import="java.util.List"
61  import="java.util.Map"
62%>
63<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
64<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
65<%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %>
66<%!
67  private static final Item itemType = Item.MIMETYPE;
68  private static final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.LIST);
69%>
70<%
71final SessionControl sc = Base.getExistingSessionControl(pageContext, Permission.DENIED, itemType);
72final String ID = sc.getId();
73final boolean createPermission = sc.hasPermission(Permission.CREATE, itemType);
74final boolean writePermission = sc.hasPermission(Permission.WRITE, itemType);
75final boolean deletePermission = sc.hasPermission(Permission.DELETE, itemType);
76final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
77
78final ModeInfo mode = ModeInfo.get(request.getParameter("mode"));
79final String callback = request.getParameter("callback");
80final String title = mode.generateTitle("MIME type", "MIME types");
81final DbControl dc = sc.newDbControl();
82ItemResultIterator<MimeType> mimeTypes = null;
83try
84{
85  Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc);
86
87  // Get all file types
88  final ItemQuery<ItemSubtype> typeQuery = ItemSubtype.getQuery(Item.FILE);
89  typeQuery.order(Orders.asc(Hql.property("name")));
90  typeQuery.setCacheResult(true);
91
92  Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext);
93  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, guiContext, null);
94  try
95  {
96    final ItemQuery<MimeType> query = Base.getConfiguredQuery(dc, cc, jspContext, true, MimeType.getQuery(), mode);
97    mimeTypes = query.iterate(dc);
98  }
99  catch (Throwable t)
100  {
101    cc.setMessage(t.getMessage());
102  }
103  int numListed = 0;
104  ExtensionsInvoker<ButtonAction> invoker = ToolbarUtil.useExtensions(jspContext);
105  ExtensionsInvoker<ListColumnAction<MimeType,?>> columnsInvoker = ListColumnUtil.useExtensions(jspContext);
106  %>
107  <base:page title="<%=title==null ? "MIME types" : title%>" type="<%=mode.getPageType()%>" id="list-page">
108  <base:head scripts="table.js,~mimetypes.js" styles="table.css,toolbar.css">
109    <ext:scripts context="<%=jspContext%>" />
110    <ext:stylesheets context="<%=jspContext%>" />
111  </base:head>
112 
113  <base:body>
114    <h1><%=title==null ? "MIME types" : title%></h1>
115    <div class="content">
116    <tbl:table 
117      id="mimeTypes" 
118      columns="<%=cc.getSetting("columns")%>"
119      sortby="<%=cc.getSortProperty()%>" 
120      direction="<%=cc.getSortDirection()%>"
121      action="index.jsp"
122      sc="<%=sc%>"
123      item="<%=itemType%>"
124      filterrows="<%=cc.getFilterRows()%>"
125      subclass="fulltable"
126      stickyheaders="name"
127      >
128      <tbl:hidden 
129        name="mode" 
130        value="<%=mode.getName()%>" 
131      />
132      <tbl:hidden 
133        name="callback" 
134        value="<%=callback%>" 
135        skip="<%=callback == null%>" 
136      />
137      <tbl:columndef 
138        id="extension"
139        clazz="uniquecol"
140        property="extension"
141        datatype="string"
142        title="File extension"
143        sortable="true"
144        filterable="true"
145        exportable="true"
146        show="always"
147      />
148      <tbl:columndef 
149        id="name"
150        property="name"
151        datatype="string"
152        title="MIME type"
153        sortable="true" 
154        filterable="true"
155        exportable="true"
156        show="always" 
157      />
158      <tbl:columndef 
159        id="id"
160        clazz="uniquecol"
161        property="id"
162        datatype="int"
163        title="ID"
164        sortable="true"
165        filterable="true"
166        exportable="true"
167      />
168      <tbl:columndef 
169        id="entryDate"
170        property="entryDate"
171        datatype="date"
172        title="Registered"
173        sortable="true" 
174        filterable="true"
175        exportable="true"
176        formatter="<%=dateFormatter%>"
177      />
178      <%
179      Enumeration<String, String> fileTypes = new Enumeration<String, String>();
180      fileTypes.add("", "- none -");
181      for (ItemSubtype ft : typeQuery.list(dc))
182      {
183        fileTypes.add(Integer.toString(ft.getId()), ft.getName());
184      }
185      %>
186      <tbl:columndef 
187        id="fileType"
188        property="fileType"
189        sortproperty="fileType.name"
190        exportproperty="fileType.name:string"
191        datatype="int"
192        enumeration="<%=fileTypes%>"
193        title="File type"
194        sortable="true" 
195        filterable="true"
196        exportable="true"
197      />
198      <tbl:columndef 
199        id="autoCompress"
200        property="autoCompress"
201        datatype="boolean"
202        title="Auto compress"
203        sortable="true" 
204        filterable="true"
205        exportable="true"
206      />
207      <tbl:columndef 
208        id="description"
209        property="description"
210        datatype="string"
211        title="Description" 
212        sortable="true" 
213        filterable="true" 
214        exportable="true"
215      />
216      <tbl:columndef 
217        id="xt-columns" 
218        extensions="<%=columnsInvoker%>" 
219        jspcontext="<%=jspContext%>" 
220      />
221      <div class="panelgroup bg-filled-50 bottomborder">
222        <tbl:toolbar
223          subclass="bottomborder"
224          visible="<%=mode.hasToolbar()%>"
225          >
226          <tbl:button 
227            id="btnNewItem"
228            disabled="<%=!createPermission%>" 
229            image="new.png" 
230            title="New&hellip;" 
231            tooltip="<%=createPermission ? "Create new MIME type" : "You do not have permission to create MIME types"%>" 
232          />
233          <tbl:button 
234            id="btnDeleteItems"
235            disabled="<%=!deletePermission%>" 
236            image="delete.png" 
237            title="Delete" 
238            tooltip="<%=deletePermission ? "Delete the selected items" : "You do not have permission to delete MIME types" %>" 
239          />
240          <tbl:button 
241            id="btnRestoreItems"
242            disabled="<%=!writePermission%>" 
243            image="restore.png" 
244            title="Restore" 
245            tooltip="<%=writePermission ? "Restore the selected (deleted) items" : "You do not have permission to edit MIME types" %>" 
246          />
247          <tbl:button 
248            id="btnColumns"
249            image="columns.png" 
250            title="Columns&hellip;" 
251            tooltip="Show, hide and re-order columns" 
252          />
253          <tbl:button 
254            id="btnImport"
255            data-plugin-type="IMPORT"
256            image="import.png" 
257            title="Import&hellip;" 
258            tooltip="Import data" 
259            visible="<%=pluginCount.containsKey(Plugin.MainType.IMPORT)%>"
260          />
261          <tbl:button 
262            id="btnExport"
263            data-plugin-type="EXPORT"
264            image="export.png" 
265            title="Export&hellip;" 
266            tooltip="Export data" 
267            visible="<%=pluginCount.containsKey(Plugin.MainType.EXPORT)%>"
268          />
269          <tbl:button 
270            id="btnRunPlugin"
271            data-plugin-type="OTHER"
272            image="runplugin.png" 
273            title="Run plugin&hellip;" 
274            tooltip="Run a plugin" 
275            visible="<%=pluginCount.containsKey(Plugin.MainType.OTHER)%>"
276          />
277          <ext:render extensions="<%=invoker%>" context="<%=jspContext%>" 
278            wrapper="<%=new PrefixSuffixRenderer<ButtonAction>(jspContext, "<td>", "</td>") %>"/>
279        </tbl:toolbar>
280        <tbl:panel>
281          <tbl:presetselector />
282          <tbl:navigator
283            page="<%=cc.getPage()%>" 
284            rowsperpage="<%=cc.getRowsPerPage()%>" 
285            totalrows="<%=mimeTypes == null ? 0 : mimeTypes.getTotalCount()%>" 
286            visible="<%=mode.hasNavigator()%>"
287          />
288        </tbl:panel>
289      </div>
290      <tbl:data>
291        <tbl:headers>
292          <tbl:headerrow>
293            <tbl:header clazz="row-index bg-filled-100" />
294            <tbl:columnheaders />
295          </tbl:headerrow>
296          <%
297          int numFilters = cc.getNumPropertyFilters();
298          int numRows = cc.getFilterRows();
299          for (int filterNo = 0; filterNo < numRows; filterNo++)
300          {
301            boolean lastRow = filterNo == numRows-1;
302            %>
303            <tbl:headerrow>
304              <tbl:header subclass="row-index bg-filled-100">
305                <div class="index-<%=mode.getName()%>">
306                  <div class="index"></div>
307                  <div class="check">
308                    <base:icon 
309                      subclass="link table-check"
310                      image="check_uncheck.png" 
311                      tooltip="Toggle all (use CTRL, ALT or SHIFT to check/uncheck)" 
312                      visible="<%=lastRow && mode.hasCheck()%>"
313                    />
314                  </div>
315                  <div class="icons">
316                    <base:icon
317                      subclass="link table-filter-row-action"
318                      image="add.png"
319                      tooltip="Add extra filter row"
320                      visible="<%=lastRow%>"
321                    /><base:icon
322                      subclass="link table-filter-row-action"
323                      image="remove.png"
324                      tooltip="Remove this filter row"
325                      visible="<%=numRows > 1 || numFilters > 0 %>"
326                      data-remove-row="<%=filterNo%>"
327                    />
328                  </div>
329                </div>
330              </tbl:header>
331              <tbl:propertyfilter row="<%=filterNo%>" />
332            </tbl:headerrow>
333            <%
334          }
335          %>
336          <tbl:columnsubtitles />
337        </tbl:headers>
338        <tbl:rows>
339          <%
340          if (cc.getMessage() != null)
341          {
342            %>
343            <tbl:panel subclass="bg-filled-50">
344              <div class="messagecontainer error"><%=cc.getMessage()%></div>
345            </tbl:panel>
346            <%
347            cc.setMessage(null);
348          }
349          int index = cc.getPage()*cc.getRowsPerPage();
350          int selectedItemId = cc.getId();
351          if (mimeTypes != null)
352          {           
353            while (mimeTypes.hasNext())
354            {
355              MimeType item = mimeTypes.next();
356              int itemId = item.getId();
357              String name = HTML.encodeTags(item.getName());
358              String tooltip = mode.isSelectionMode() ? 
359                  "Select this item" : "View this item" + (writePermission ? " (use CTRL, ALT or SHIFT to edit)" : "");
360             
361              index++;
362              numListed++;
363              %>
364              <tbl:row>
365                <tbl:header clazz="row-index bg-filled-100">
366                  <div class="index-<%=mode.getName()%>">
367                    <div class="index <%=index>999?"index-smaller":""%>"><%=index%></div>
368                    <div class="check">
369                      <base:input
370                        type="checkbox" 
371                        name="<%=itemId%>" 
372                        value="<%=itemId%>" 
373                        title="<%=name%>" 
374                        checked="<%=cc.getSelected().contains(itemId)%>"
375                        visible="<%=mode.hasCheck()%>"
376                      />
377                      <base:input 
378                        type="radio" 
379                        name="item_id" 
380                        value="<%=itemId%>" 
381                        title="<%=name%>" 
382                        checked="<%=selectedItemId == itemId%>"
383                        visible="<%=mode.hasRadio()%>"
384                      />
385                    </div>
386                    <div class="icons">
387                      <base:icon 
388                        image="deleted.png"
389                        id="<%="delete."+itemId %>"
390                        subclass="<%=deletePermission ? "table-delete-item" : "disabled" %>"
391                        data-item-id="<%=itemId%>"
392                        tooltip="This item has been scheduled for deletion" 
393                        visible="<%=item.isRemoved()%>"
394                      />
395                    </div>
396                  </div>
397                </tbl:header>
398                <tbl:cell column="extension"><div 
399                  class="link table-item"
400                  data-item-id="<%=itemId%>"
401                  data-no-edit="<%=writePermission ? 0 : 1 %>" 
402                  tabindex="0"
403                  title="<%=tooltip%>"><%=HTML.encodeTags(item.getExtension())%></div></tbl:cell>
404                <tbl:cell column="name"><%=name%></tbl:cell>
405                <tbl:cell column="id"><%=item.getId()%></tbl:cell>
406                <tbl:cell column="entryDate" value="<%=item.getEntryDate()%>" />
407                <tbl:cell column="fileType"
408                  ><base:propertyvalue 
409                    item="<%=item%>" 
410                    property="fileType"
411                    enableEditLink="<%=mode.hasEditLink()%>" 
412                    enablePropertyLink="<%=mode.hasPropertyLink()%>"
413                  /></tbl:cell>
414                <tbl:cell column="autoCompress"><%=item.getAutoCompress() ? "yes" : "no"%></tbl:cell>
415                <tbl:cell column="description"><%=HTML.encodeTags(item.getDescription())%></tbl:cell>
416                <tbl:xt-cells dc="<%=dc%>" item="<%=item%>">
417                  <tbl:cell column="xt-columns" />
418                </tbl:xt-cells>
419              </tbl:row>
420              <%
421              }
422            }
423          if (numListed == 0)
424          {
425            %>
426            <tbl:panel subclass="bg-filled-50">
427              <div class="messagecontainer note">
428              <%=mimeTypes == null || mimeTypes.getTotalCount() == 0 ? "No MIME types were found" : "No MIME types on this page. Please select another page!" %>
429              </div>
430            </tbl:panel>
431            <%
432          }
433          %>
434        </tbl:rows>
435      </tbl:data>
436    </tbl:table>
437    </div>
438   
439    <base:buttongroup subclass="dialogbuttons">
440      <base:button id="btnOk" title="Ok" visible="<%=mode.hasOkButton()%>" />
441      <base:button id="close" title="Cancel" visible="<%=mode.hasCancelButton()%>" />
442      <base:button id="close" title="Close" visible="<%=mode.hasCloseButton()%>" />
443    </base:buttongroup>
444   
445  </base:body>
446  </base:page>
447  <%
448}
449finally
450{
451  if (mimeTypes != null) mimeTypes.close();
452  if (dc != null) dc.close();
453}
454%>
Note: See TracBrowser for help on using the repository browser.