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