551 |
11 May 05 |
nicklas |
1 |
<%-- $Id$ |
551 |
11 May 05 |
nicklas |
2 |
------------------------------------------------------------------ |
3675 |
16 Aug 07 |
jari |
Copyright (C) 2005 Nicklas Nordborg |
5425 |
23 Sep 10 |
nicklas |
Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg, Martin Svensson |
551 |
11 May 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/ |
551 |
11 May 05 |
nicklas |
8 |
|
551 |
11 May 05 |
nicklas |
9 |
BASE is free software; you can redistribute it and/or |
551 |
11 May 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 |
551 |
11 May 05 |
nicklas |
12 |
of the License, or (at your option) any later version. |
551 |
11 May 05 |
nicklas |
13 |
|
551 |
11 May 05 |
nicklas |
14 |
BASE is distributed in the hope that it will be useful, |
551 |
11 May 05 |
nicklas |
15 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
551 |
11 May 05 |
nicklas |
16 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
551 |
11 May 05 |
nicklas |
17 |
GNU General Public License for more details. |
551 |
11 May 05 |
nicklas |
18 |
|
551 |
11 May 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/>. |
551 |
11 May 05 |
nicklas |
21 |
------------------------------------------------------------------ |
551 |
11 May 05 |
nicklas |
22 |
|
551 |
11 May 05 |
nicklas |
23 |
|
551 |
11 May 05 |
nicklas |
24 |
@author Nicklas |
551 |
11 May 05 |
nicklas |
25 |
@version 2.0 |
551 |
11 May 05 |
nicklas |
26 |
--%> |
5426 |
24 Sep 10 |
nicklas |
27 |
<%@ page pageEncoding="UTF-8" session="false" |
551 |
11 May 05 |
nicklas |
28 |
import="net.sf.basedb.core.SessionControl" |
551 |
11 May 05 |
nicklas |
29 |
import="net.sf.basedb.core.DbControl" |
2015 |
17 Feb 06 |
nicklas |
30 |
import="net.sf.basedb.core.Item" |
551 |
11 May 05 |
nicklas |
31 |
import="net.sf.basedb.core.SystemItems" |
2015 |
17 Feb 06 |
nicklas |
32 |
import="net.sf.basedb.core.ItemContext" |
551 |
11 May 05 |
nicklas |
33 |
import="net.sf.basedb.core.Permission" |
551 |
11 May 05 |
nicklas |
34 |
import="net.sf.basedb.core.Quota" |
551 |
11 May 05 |
nicklas |
35 |
import="net.sf.basedb.core.QuotaType" |
2015 |
17 Feb 06 |
nicklas |
36 |
import="net.sf.basedb.core.Location" |
1418 |
07 Oct 05 |
nicklas |
37 |
import="net.sf.basedb.core.ItemQuery" |
1418 |
07 Oct 05 |
nicklas |
38 |
import="net.sf.basedb.core.ItemResultList" |
551 |
11 May 05 |
nicklas |
39 |
import="net.sf.basedb.core.query.Restrictions" |
551 |
11 May 05 |
nicklas |
40 |
import="net.sf.basedb.core.query.Expressions" |
551 |
11 May 05 |
nicklas |
41 |
import="net.sf.basedb.core.query.Orders" |
1418 |
07 Oct 05 |
nicklas |
42 |
import="net.sf.basedb.core.query.Hql" |
2015 |
17 Feb 06 |
nicklas |
43 |
import="net.sf.basedb.core.PermissionDeniedException" |
551 |
11 May 05 |
nicklas |
44 |
import="net.sf.basedb.clients.web.Base" |
551 |
11 May 05 |
nicklas |
45 |
import="net.sf.basedb.clients.web.util.HTML" |
2753 |
20 Oct 06 |
nicklas |
46 |
import="net.sf.basedb.util.Values" |
5506 |
19 Nov 10 |
nicklas |
47 |
import="net.sf.basedb.core.plugin.GuiContext" |
5506 |
19 Nov 10 |
nicklas |
48 |
import="net.sf.basedb.clients.web.extensions.ExtensionsControl" |
5506 |
19 Nov 10 |
nicklas |
49 |
import="net.sf.basedb.clients.web.extensions.JspContext" |
5506 |
19 Nov 10 |
nicklas |
50 |
import="net.sf.basedb.clients.web.extensions.edit.EditUtil" |
7604 |
25 Feb 19 |
nicklas |
51 |
import="net.sf.basedb.clients.web.extensions.tabcontrol.TabAction" |
5506 |
19 Nov 10 |
nicklas |
52 |
import="net.sf.basedb.util.extensions.ExtensionsInvoker" |
551 |
11 May 05 |
nicklas |
53 |
%> |
551 |
11 May 05 |
nicklas |
54 |
<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> |
551 |
11 May 05 |
nicklas |
55 |
<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %> |
6147 |
21 Sep 12 |
nicklas |
56 |
<%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %> |
551 |
11 May 05 |
nicklas |
57 |
<%! |
2015 |
17 Feb 06 |
nicklas |
58 |
private String getQuotaInput(Quota quota, QuotaType type, Location location) |
551 |
11 May 05 |
nicklas |
59 |
{ |
2015 |
17 Feb 06 |
nicklas |
60 |
long bytes = quota == null ? Quota.UNDEFINED : quota.getQuotaValue(type, location); |
551 |
11 May 05 |
nicklas |
61 |
String fBytes = ""; |
551 |
11 May 05 |
nicklas |
62 |
String clazz = "text"; |
551 |
11 May 05 |
nicklas |
63 |
if (bytes == Quota.UNLIMITED) |
551 |
11 May 05 |
nicklas |
64 |
{ |
551 |
11 May 05 |
nicklas |
65 |
fBytes = "unlimited"; |
551 |
11 May 05 |
nicklas |
66 |
clazz += " disabled"; |
551 |
11 May 05 |
nicklas |
67 |
} |
551 |
11 May 05 |
nicklas |
68 |
else if (bytes >= 0) |
551 |
11 May 05 |
nicklas |
69 |
{ |
551 |
11 May 05 |
nicklas |
70 |
fBytes = Values.formatBytes(bytes); |
551 |
11 May 05 |
nicklas |
71 |
} |
551 |
11 May 05 |
nicklas |
72 |
boolean required = type.getId() == SystemItems.getId(QuotaType.TOTAL) && location == Location.PRIMARY; |
551 |
11 May 05 |
nicklas |
73 |
if (required) clazz += " required"; |
551 |
11 May 05 |
nicklas |
74 |
|
551 |
11 May 05 |
nicklas |
75 |
StringBuilder sb = new StringBuilder(); |
2015 |
17 Feb 06 |
nicklas |
76 |
sb.append("<input type=\"text\" class=\"").append(clazz).append("\""); |
5921 |
10 Jan 12 |
nicklas |
77 |
sb.append(" maxlength=\"16\" style=\"width: 16em;\""); |
6305 |
09 Aug 13 |
nicklas |
78 |
sb.append(" name=\"").append(location.name()).append(":").append(type.getId()).append("\""); |
551 |
11 May 05 |
nicklas |
79 |
sb.append(" value=\"").append(fBytes).append("\""); |
551 |
11 May 05 |
nicklas |
80 |
sb.append(">"); |
6305 |
09 Aug 13 |
nicklas |
81 |
sb.append("<input type=\"checkbox\" class=\"auto-init\" data-auto-init=\"unlimited-quota\" value=\"1\""); |
6305 |
09 Aug 13 |
nicklas |
82 |
sb.append(" name=\"unlimited:").append(location.name()).append(":").append(type.getId()).append("\""); |
551 |
11 May 05 |
nicklas |
83 |
sb.append(bytes==Quota.UNLIMITED ? " checked" : ""); |
551 |
11 May 05 |
nicklas |
84 |
sb.append(" title=\"Unlimited quota\">\n"); |
551 |
11 May 05 |
nicklas |
85 |
return sb.toString(); |
551 |
11 May 05 |
nicklas |
86 |
} |
551 |
11 May 05 |
nicklas |
87 |
%> |
551 |
11 May 05 |
nicklas |
88 |
<% |
2015 |
17 Feb 06 |
nicklas |
89 |
final Item itemType = Item.QUOTA; |
2015 |
17 Feb 06 |
nicklas |
90 |
final SessionControl sc = Base.getExistingSessionControl(pageContext, true); |
2015 |
17 Feb 06 |
nicklas |
91 |
final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null); |
2015 |
17 Feb 06 |
nicklas |
92 |
final int itemId = cc.getId(); |
551 |
11 May 05 |
nicklas |
93 |
final String ID = sc.getId(); |
551 |
11 May 05 |
nicklas |
94 |
final float scale = Base.getScale(sc); |
7954 |
12 May 21 |
nicklas |
95 |
final DbControl dc = sc.newDbControl(":Edit "+itemType); |
551 |
11 May 05 |
nicklas |
96 |
try |
551 |
11 May 05 |
nicklas |
97 |
{ |
551 |
11 May 05 |
nicklas |
98 |
String title = null; |
551 |
11 May 05 |
nicklas |
99 |
Quota quota = null; |
2015 |
17 Feb 06 |
nicklas |
100 |
|
2015 |
17 Feb 06 |
nicklas |
101 |
if (itemId == 0) |
551 |
11 May 05 |
nicklas |
102 |
{ |
551 |
11 May 05 |
nicklas |
103 |
title = "Create quota"; |
2015 |
17 Feb 06 |
nicklas |
104 |
cc.removeObject("item"); |
551 |
11 May 05 |
nicklas |
105 |
} |
551 |
11 May 05 |
nicklas |
106 |
else |
551 |
11 May 05 |
nicklas |
107 |
{ |
2015 |
17 Feb 06 |
nicklas |
108 |
quota = Quota.getById(dc, itemId); |
6305 |
09 Aug 13 |
nicklas |
109 |
quota.checkPermission(Permission.WRITE); |
2015 |
17 Feb 06 |
nicklas |
110 |
cc.setObject("item", quota); |
551 |
11 May 05 |
nicklas |
111 |
title = "Edit quota -- " + HTML.encodeTags(quota.getName()); |
551 |
11 May 05 |
nicklas |
112 |
} |
2015 |
17 Feb 06 |
nicklas |
113 |
|
551 |
11 May 05 |
nicklas |
114 |
final QuotaType total = QuotaType.getById(dc, SystemItems.getId(QuotaType.TOTAL)); |
551 |
11 May 05 |
nicklas |
115 |
|
551 |
11 May 05 |
nicklas |
116 |
// Query to retrieve quota types |
1418 |
07 Oct 05 |
nicklas |
117 |
final ItemQuery<QuotaType> quotaTypeQuery = QuotaType.getQuery(); |
1418 |
07 Oct 05 |
nicklas |
118 |
quotaTypeQuery.order(Orders.asc(Hql.property("id"))); |
1418 |
07 Oct 05 |
nicklas |
119 |
quotaTypeQuery.restrict( |
551 |
11 May 05 |
nicklas |
120 |
Restrictions.neq( |
1418 |
07 Oct 05 |
nicklas |
121 |
Hql.property("id"), |
1418 |
07 Oct 05 |
nicklas |
122 |
Hql.entity(total) |
551 |
11 May 05 |
nicklas |
123 |
) |
551 |
11 May 05 |
nicklas |
124 |
); |
959 |
19 Jul 05 |
nicklas |
125 |
quotaTypeQuery.setCacheResult(true); |
551 |
11 May 05 |
nicklas |
126 |
|
5506 |
19 Nov 10 |
nicklas |
127 |
JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.item(itemType), quota); |
7604 |
25 Feb 19 |
nicklas |
128 |
ExtensionsInvoker<TabAction> invoker = EditUtil.useEditExtensions(jspContext); |
551 |
11 May 05 |
nicklas |
129 |
%> |
6305 |
09 Aug 13 |
nicklas |
130 |
<base:page type="popup" title="<%=title%>" id="edit-page"> |
6305 |
09 Aug 13 |
nicklas |
131 |
<base:head scripts="tabcontrol-2.js,~quota.js" styles="tabcontrol.css"> |
5506 |
19 Nov 10 |
nicklas |
132 |
<ext:scripts context="<%=jspContext%>" /> |
5506 |
19 Nov 10 |
nicklas |
133 |
<ext:stylesheets context="<%=jspContext%>" /> |
551 |
11 May 05 |
nicklas |
134 |
</base:head> |
6305 |
09 Aug 13 |
nicklas |
135 |
<base:body> |
5921 |
10 Jan 12 |
nicklas |
136 |
<h1><%=title%> <base:help tabcontrol="settings" /></h1> |
6162 |
10 Oct 12 |
nicklas |
137 |
<form action="index.jsp?ID=<%=ID%>" method="post" name="quota"> |
2015 |
17 Feb 06 |
nicklas |
138 |
<input type="hidden" name="cmd" value="UpdateItem"> |
2015 |
17 Feb 06 |
nicklas |
139 |
|
6305 |
09 Aug 13 |
nicklas |
140 |
<div id="page-data" class="datacontainer" |
6305 |
09 Aug 13 |
nicklas |
141 |
data-total-quota-id="<%=total.getId()%>" |
6305 |
09 Aug 13 |
nicklas |
142 |
></div> |
6305 |
09 Aug 13 |
nicklas |
143 |
|
5921 |
10 Jan 12 |
nicklas |
144 |
<t:tabcontrol id="settings" |
5921 |
10 Jan 12 |
nicklas |
145 |
subclass="content dialogtabcontrol" |
5506 |
19 Nov 10 |
nicklas |
146 |
position="bottom" remember="<%=quota != null%>" |
5506 |
19 Nov 10 |
nicklas |
147 |
extensions="<%=invoker%>"> |
6305 |
09 Aug 13 |
nicklas |
148 |
<t:tab id="info" title="Quota" helpid="quota.edit"> |
5921 |
10 Jan 12 |
nicklas |
149 |
<table class="fullform input100 smaller"> |
551 |
11 May 05 |
nicklas |
150 |
<tr> |
5921 |
10 Jan 12 |
nicklas |
151 |
<th>Name</th> |
6305 |
09 Aug 13 |
nicklas |
152 |
<td colspan="2"><input class="text required auto-init" data-auto-init="<%=quota == null ? "focus-select" : "focus" %>" |
6305 |
09 Aug 13 |
nicklas |
153 |
type="text" name="name" |
2015 |
17 Feb 06 |
nicklas |
154 |
value="<%=HTML.encodeTags(quota == null ? Values.getString(cc.getPropertyValue("name"), "New quota") : quota.getName())%>" |
5921 |
10 Jan 12 |
nicklas |
155 |
maxlength="<%=Quota.MAX_NAME_LENGTH%>"></td> |
5921 |
10 Jan 12 |
nicklas |
156 |
<td></td> |
551 |
11 May 05 |
nicklas |
157 |
</tr> |
551 |
11 May 05 |
nicklas |
158 |
<tr> |
5921 |
10 Jan 12 |
nicklas |
159 |
<th></th> |
551 |
11 May 05 |
nicklas |
160 |
<td><b>Primary location</b></td> |
5921 |
10 Jan 12 |
nicklas |
161 |
<td></td> |
551 |
11 May 05 |
nicklas |
162 |
</tr> |
551 |
11 May 05 |
nicklas |
163 |
<tr> |
6621 |
24 Nov 14 |
nicklas |
164 |
<th>Total quota</th> |
2015 |
17 Feb 06 |
nicklas |
165 |
<td><%=getQuotaInput(quota, total, Location.PRIMARY)%></td> |
5921 |
10 Jan 12 |
nicklas |
166 |
<td></td> |
551 |
11 May 05 |
nicklas |
167 |
</tr> |
551 |
11 May 05 |
nicklas |
168 |
<% |
2015 |
17 Feb 06 |
nicklas |
169 |
ItemResultList<QuotaType> quotaTypes = quotaTypeQuery.list(dc); |
959 |
19 Jul 05 |
nicklas |
170 |
for (QuotaType current : quotaTypes) |
551 |
11 May 05 |
nicklas |
171 |
{ |
551 |
11 May 05 |
nicklas |
172 |
%> |
551 |
11 May 05 |
nicklas |
173 |
<tr> |
5921 |
10 Jan 12 |
nicklas |
174 |
<th class="subprompt"><%=HTML.encodeTags(current.getName())%></th> |
5921 |
10 Jan 12 |
nicklas |
175 |
<td><%=getQuotaInput(quota, current, Location.PRIMARY)%></td> |
5921 |
10 Jan 12 |
nicklas |
176 |
<td></td> |
551 |
11 May 05 |
nicklas |
177 |
</tr> |
551 |
11 May 05 |
nicklas |
178 |
<% |
551 |
11 May 05 |
nicklas |
179 |
} |
551 |
11 May 05 |
nicklas |
180 |
%> |
551 |
11 May 05 |
nicklas |
181 |
<tr> |
5921 |
10 Jan 12 |
nicklas |
182 |
<th class="subprompt"></th> |
551 |
11 May 05 |
nicklas |
183 |
<td colspan="3"> |
5921 |
10 Jan 12 |
nicklas |
184 |
<div class="messagecontainer help" style="margin: 0.5em 0px 0.5em 0px;"> |
551 |
11 May 05 |
nicklas |
185 |
The individual quota values doesn't have to sum up to the total value. |
551 |
11 May 05 |
nicklas |
186 |
The most restrictive value is always used. |
551 |
11 May 05 |
nicklas |
187 |
You can use the following units (case-insensitive): |
551 |
11 May 05 |
nicklas |
188 |
<ul> |
551 |
11 May 05 |
nicklas |
189 |
<li><b>Gb</b> or <b>G</b> for gigabyte values (<code>1.5 Gb</code>) |
551 |
11 May 05 |
nicklas |
190 |
<li><b>Mb</b> or <b>M</b> for megabyte values (<code>10M</code>) |
551 |
11 May 05 |
nicklas |
191 |
<li><b>Kb</b> or <b>K</b> for kilobyte values (<code>800k</code>) |
551 |
11 May 05 |
nicklas |
192 |
<li><b>bytes</b> or <b>b</b> for byte values (<code>50 bytes</code>) |
551 |
11 May 05 |
nicklas |
193 |
</ul> |
5921 |
10 Jan 12 |
nicklas |
194 |
</div> |
551 |
11 May 05 |
nicklas |
195 |
</td> |
551 |
11 May 05 |
nicklas |
196 |
</tr> |
5921 |
10 Jan 12 |
nicklas |
197 |
<tr class="dynamic"> |
5921 |
10 Jan 12 |
nicklas |
198 |
<th>Description</th> |
5921 |
10 Jan 12 |
nicklas |
199 |
<td colspan="2"> |
6217 |
14 Dec 12 |
nicklas |
200 |
<textarea class="text" rows="6" name="description" id="description" |
5921 |
10 Jan 12 |
nicklas |
201 |
><%=HTML.encodeTags(quota == null ? cc.getPropertyValue("description") : quota.getDescription())%></textarea> |
5921 |
10 Jan 12 |
nicklas |
202 |
</td> |
5921 |
10 Jan 12 |
nicklas |
203 |
<td style="width: 20px;"> |
6215 |
13 Dec 12 |
nicklas |
204 |
<base:zoom textarea="description" title="Description" /> |
5921 |
10 Jan 12 |
nicklas |
205 |
</td> |
5921 |
10 Jan 12 |
nicklas |
206 |
</tr> |
551 |
11 May 05 |
nicklas |
207 |
</table> |
551 |
11 May 05 |
nicklas |
208 |
</t:tab> |
5921 |
10 Jan 12 |
nicklas |
209 |
</t:tabcontrol> |
5921 |
10 Jan 12 |
nicklas |
210 |
</form> |
2015 |
17 Feb 06 |
nicklas |
211 |
|
5921 |
10 Jan 12 |
nicklas |
212 |
<div class="legend"> |
5946 |
03 Feb 12 |
nicklas |
213 |
<base:icon image="required.png" />= required information |
5921 |
10 Jan 12 |
nicklas |
214 |
</div> |
2015 |
17 Feb 06 |
nicklas |
215 |
|
5921 |
10 Jan 12 |
nicklas |
216 |
<base:buttongroup subclass="dialogbuttons"> |
6305 |
09 Aug 13 |
nicklas |
217 |
<base:button id="btnSave" title="Save" /> |
6305 |
09 Aug 13 |
nicklas |
218 |
<base:button id="close" title="Cancel" /> |
5921 |
10 Jan 12 |
nicklas |
219 |
</base:buttongroup> |
551 |
11 May 05 |
nicklas |
220 |
</base:body> |
551 |
11 May 05 |
nicklas |
221 |
</base:page> |
551 |
11 May 05 |
nicklas |
222 |
<% |
551 |
11 May 05 |
nicklas |
223 |
} |
551 |
11 May 05 |
nicklas |
224 |
finally |
551 |
11 May 05 |
nicklas |
225 |
{ |
551 |
11 May 05 |
nicklas |
226 |
if (dc != null) dc.close(); |
551 |
11 May 05 |
nicklas |
227 |
} |
551 |
11 May 05 |
nicklas |
228 |
%> |