1 | <%-- |
---|
2 | Copyright (C) 2011 Nicklas Nordborg |
---|
3 | |
---|
4 | This file is part of the Example Code Package for BASE. |
---|
5 | Available at http://baseplugins.thep.lu.se/ |
---|
6 | BASE main site: http://base.thep.lu.se/ |
---|
7 | |
---|
8 | This 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 | The software 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 | <%@ page |
---|
22 | pageEncoding="UTF-8" |
---|
23 | session="false" |
---|
24 | import="net.sf.basedb.core.SessionControl" |
---|
25 | import="net.sf.basedb.core.DbControl" |
---|
26 | import="net.sf.basedb.core.BasicItem" |
---|
27 | import="net.sf.basedb.core.ItemContext" |
---|
28 | import="net.sf.basedb.core.Item" |
---|
29 | import="net.sf.basedb.core.AnyToAny" |
---|
30 | import="net.sf.basedb.core.File" |
---|
31 | import="net.sf.basedb.core.ItemNotFoundException" |
---|
32 | import="net.sf.basedb.core.PermissionDeniedException" |
---|
33 | import="net.sf.basedb.clients.web.Base" |
---|
34 | import="net.sf.basedb.clients.web.util.HTML" |
---|
35 | import="net.sf.basedb.clients.web.extensions.JspContext" |
---|
36 | %> |
---|
37 | <%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> |
---|
38 | <% |
---|
39 | // Get the JspContext that was created on the main edit page |
---|
40 | final JspContext jspContext = (JspContext)request.getAttribute(JspContext.ATTRIBUTE_KEY); |
---|
41 | |
---|
42 | // The current item is found in the context. NOTE! Can be null if a new item |
---|
43 | final BasicItem item = (BasicItem)jspContext.getCurrentItem(); |
---|
44 | |
---|
45 | // Get the DbControl and SessionControl used to handle the request (do not close!) |
---|
46 | final DbControl dc = jspContext.getDbControl(); |
---|
47 | final SessionControl sc = dc.getSessionControl(); |
---|
48 | final String ID = sc.getId(); |
---|
49 | |
---|
50 | AnyToAny any = null; |
---|
51 | |
---|
52 | // Try to get the currently attached history file |
---|
53 | File currentFile = null; |
---|
54 | boolean readCurrentFile = true; |
---|
55 | if (item != null) |
---|
56 | { |
---|
57 | try |
---|
58 | { |
---|
59 | any = AnyToAny.getByName(dc, item, "history-file"); |
---|
60 | if (any != null && any.getToType() == Item.FILE) |
---|
61 | { |
---|
62 | currentFile = (File)any.getTo(); |
---|
63 | } |
---|
64 | } |
---|
65 | catch (ItemNotFoundException ex) |
---|
66 | {} // There is no file |
---|
67 | catch (PermissionDeniedException ex) |
---|
68 | { |
---|
69 | // There is a file but the user doesn't have permission to it |
---|
70 | readCurrentFile = false; |
---|
71 | } |
---|
72 | } |
---|
73 | %> |
---|
74 | <base:page type="include"> |
---|
75 | <base:head /> |
---|
76 | <base:body> |
---|
77 | <script> |
---|
78 | function browseOnClick() |
---|
79 | { |
---|
80 | var frm = document.forms[0]; |
---|
81 | var url = getRoot() + '/filemanager/index.jsp?ID=<%=ID%>'; |
---|
82 | url += '&cmd=SelectOne&title=Select+history+file'; |
---|
83 | url += '&callback=setFileCallback&resetTemporary=1'; |
---|
84 | if (frm.history_file_id.length > 1) |
---|
85 | { |
---|
86 | var id = Math.abs(parseInt(frm.history_file_id[1].value)); |
---|
87 | url += '&item_id='+id; |
---|
88 | } |
---|
89 | Main.openPopup(url, 'SelectFile', 1050, 700); |
---|
90 | } |
---|
91 | function setFileCallback(id, path) |
---|
92 | { |
---|
93 | var frm = document.forms[0]; |
---|
94 | var list = frm.history_file_id; |
---|
95 | if (list.length < 2 || list[1].value == '0') // > |
---|
96 | { |
---|
97 | Forms.addListOption(list, 1, new Option()); |
---|
98 | } |
---|
99 | list[1].value = id; |
---|
100 | list[1].text = path; |
---|
101 | list.selectedIndex = 1; |
---|
102 | } |
---|
103 | </script> |
---|
104 | <table class="fullform input100"> |
---|
105 | <tr> |
---|
106 | <th>History file</th> |
---|
107 | <td> |
---|
108 | <base:select |
---|
109 | id="history_file_id" |
---|
110 | clazz="selectionlist" |
---|
111 | required="false" |
---|
112 | current="<%=currentFile%>" |
---|
113 | denied="<%=!readCurrentFile%>" |
---|
114 | newitem="<%=item == null%>" |
---|
115 | onselect="browseOnClick()" |
---|
116 | /> |
---|
117 | </td> |
---|
118 | <td></td> |
---|
119 | </tr> |
---|
120 | <tr class="dynamic"> |
---|
121 | <th>Description</th> |
---|
122 | <td> |
---|
123 | <textarea class="text" rows="6" name="history_description" |
---|
124 | ><%=HTML.encodeTags(any == null ? "" : any.getDescription())%></textarea> |
---|
125 | </td> |
---|
126 | <td style="width: 20px;"> |
---|
127 | <base:icon image="zoom.png" |
---|
128 | onclick="Main.zoom('Description', document.forms[0].name, 'history_description')" |
---|
129 | tooltip="Edit in larger window" |
---|
130 | /> |
---|
131 | </td> |
---|
132 | </tr> |
---|
133 | </table> |
---|
134 | </base:body> |
---|
135 | </base:page> |
---|
136 | |
---|