1 | <%@ page |
---|
2 | pageEncoding="UTF-8" |
---|
3 | session="false" |
---|
4 | import="net.sf.basedb.core.Application" |
---|
5 | import="net.sf.basedb.core.User" |
---|
6 | import="net.sf.basedb.core.DbControl" |
---|
7 | import="net.sf.basedb.core.SessionControl" |
---|
8 | import="net.sf.basedb.core.Item" |
---|
9 | import="net.sf.basedb.core.ItemContext" |
---|
10 | import="net.sf.basedb.core.Directory" |
---|
11 | import="net.sf.basedb.clients.web.Base" |
---|
12 | import="net.sf.basedb.clients.web.util.HTML" |
---|
13 | import="net.sf.basedb.util.Values" |
---|
14 | import="java.util.List" |
---|
15 | %> |
---|
16 | <%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> |
---|
17 | <%@ taglib prefix="p" uri="/WEB-INF/path.tld" %> |
---|
18 | <% |
---|
19 | final SessionControl sc = Base.getExistingSessionControl(request, true); |
---|
20 | final String ID = sc.getId(); |
---|
21 | final float scale = Base.getScale(sc); |
---|
22 | DbControl dc = null; |
---|
23 | try |
---|
24 | { |
---|
25 | dc = sc.newDbControl(); |
---|
26 | final User user = User.getById(dc, sc.getLoggedInUserId()); |
---|
27 | final ItemContext cc = sc.getCurrentContext(Item.DIRECTORY); |
---|
28 | final List<Directory> recentDirectories = (List<Directory>)cc.getRecent(dc, Item.DIRECTORY, "reggie"); |
---|
29 | Directory currentDirectory = null; |
---|
30 | try |
---|
31 | { |
---|
32 | if (cc.getId() != 0) currentDirectory = Directory.getById(dc, cc.getId()); |
---|
33 | } |
---|
34 | catch (Exception ex) |
---|
35 | {} |
---|
36 | //final List<Directory> recentDirectories = Directory.getQuery().list(dc); |
---|
37 | %> |
---|
38 | <base:page type="default" > |
---|
39 | <base:head scripts="ajax.js" styles="path.css"> |
---|
40 | <link rel="stylesheet" type="text/css" href="reggie.css"> |
---|
41 | <script language="JavaScript" src="reggie.js" type="text/javascript" charset="UTF-8"></script> |
---|
42 | |
---|
43 | <script language="JavaScript"> |
---|
44 | |
---|
45 | var debug = false; |
---|
46 | var currentStep = 1; |
---|
47 | |
---|
48 | function init() |
---|
49 | { |
---|
50 | var frm = document.forms['reggie']; |
---|
51 | } |
---|
52 | |
---|
53 | function step1IsValid() |
---|
54 | { |
---|
55 | var frm = document.forms['reggie']; |
---|
56 | var list = frm.directoryId; |
---|
57 | if (list.selectedIndex < 0 || list[list.selectedIndex].value == '0') |
---|
58 | { |
---|
59 | setInputStatus('directory', 'Required', 'invalid'); |
---|
60 | return false; |
---|
61 | } |
---|
62 | setInputStatus('directory', '', 'valid'); |
---|
63 | return true; |
---|
64 | } |
---|
65 | |
---|
66 | function selectDirectoryOnClick() |
---|
67 | { |
---|
68 | if (currentStep != 1) return; |
---|
69 | var frm = document.forms['reggie']; |
---|
70 | if (frm.directoryId.disabled) return; |
---|
71 | var url = '../../filemanager/directories/index.jsp?ID=<%=ID%>&mode=selectonedirectory&callback=setDirectoryCallback'; |
---|
72 | if (frm.directoryId.length > 0) |
---|
73 | { |
---|
74 | var id = Math.abs(parseInt(frm.directoryId[0].value)); |
---|
75 | url += '&directory_id='+id; |
---|
76 | } |
---|
77 | Main.openPopup(url, 'SelectDirectory', 350, 500); |
---|
78 | } |
---|
79 | function setDirectoryCallback(id, name) |
---|
80 | { |
---|
81 | var frm = document.forms['reggie']; |
---|
82 | var list = frm.directoryId; |
---|
83 | if (list.length < 1 || list[0].value == '0') // > |
---|
84 | { |
---|
85 | Forms.addListOption(list, 0, new Option()); |
---|
86 | } |
---|
87 | list[0].value = id; |
---|
88 | list[0].text = name; |
---|
89 | list.selectedIndex = 0; |
---|
90 | } |
---|
91 | |
---|
92 | function goProcess() |
---|
93 | { |
---|
94 | if (!step1IsValid()) return; |
---|
95 | |
---|
96 | Main.hide('gocancel'); |
---|
97 | Main.hide('goprocess'); |
---|
98 | |
---|
99 | var frm = document.forms['reggie']; |
---|
100 | |
---|
101 | frm.directoryId.disabled = true; |
---|
102 | frm.pattern.disabled = true; |
---|
103 | Main.addClass(document.getElementById('directoryId'), 'disabled'); |
---|
104 | |
---|
105 | var directoryId = frm.directoryId.value; |
---|
106 | var pattern = frm.pattern.value; |
---|
107 | var request = Ajax.getXmlHttpRequest(); |
---|
108 | var url = 'ReferralForm.servlet?ID=<%=ID%>&cmd=ScanDirectory'; |
---|
109 | url += '&directoryId=' + directoryId; |
---|
110 | url += '&pattern=' + encodeURIComponent(pattern); |
---|
111 | request.open("GET", url, false); |
---|
112 | request.send(null); |
---|
113 | |
---|
114 | if (debug) Main.debug(request.responseText); |
---|
115 | var response = JSON.parse(request.responseText); |
---|
116 | if (response.status != 'ok') |
---|
117 | { |
---|
118 | setFatalError(response.message); |
---|
119 | return false; |
---|
120 | } |
---|
121 | |
---|
122 | currentStep = 2; |
---|
123 | var files = response.files; |
---|
124 | |
---|
125 | setInnerHTML('step2.title', 'Processed ' + files.length + ' file(s)'); |
---|
126 | |
---|
127 | var numAlreadyLinked = 0; |
---|
128 | var numLinkedNow = 0; |
---|
129 | var numNotLinked = 0; |
---|
130 | |
---|
131 | var htmlAlreadyLinked = ''; |
---|
132 | var htmlLinkedNow = ''; |
---|
133 | var htmlNotLinked = ''; |
---|
134 | |
---|
135 | // Collect information |
---|
136 | for (var i = 0; i < files.length; i++) |
---|
137 | { |
---|
138 | var file = files[i]; |
---|
139 | |
---|
140 | if (file.link) |
---|
141 | { |
---|
142 | numAlreadyLinked++; |
---|
143 | htmlAlreadyLinked += '<tr><td class="file">'+file.name+'</td><td>Link existed to case '+file.caseInfo.name+'</td>\n'; |
---|
144 | } |
---|
145 | else if (file.caseInfo) |
---|
146 | { |
---|
147 | numLinkedNow++; |
---|
148 | htmlLinkedNow += '<tr><td class="file">'+file.name+'</td><td>Link created to case '+file.caseInfo.name+'</td>\n'; |
---|
149 | } |
---|
150 | else |
---|
151 | { |
---|
152 | numNotLinked++; |
---|
153 | htmlNotLinked += '<tr><td class="file">'+file.name+'</td><td>'+file.message+'</td>\n'; |
---|
154 | } |
---|
155 | |
---|
156 | var html = '<table class="linktable">'; |
---|
157 | if (numAlreadyLinked > 0) |
---|
158 | { |
---|
159 | html += '<tr><td colspan="2" class="summary" onclick="showHide(\'alreadyLinked\')" title="Click to show/hide details">'; |
---|
160 | html += '<img src="../../images/show_section.gif" id="alreadyLinkedImg">'; |
---|
161 | html += numAlreadyLinked + ' file(s) was already linked to a case</td></tr>\n'; |
---|
162 | html += '<tbody id="alreadyLinked" style="display: none;">' + htmlAlreadyLinked + "</tbody>"; |
---|
163 | } |
---|
164 | if (numLinkedNow > 0) |
---|
165 | { |
---|
166 | html += '<tr><td colspan="2" class="summary" onclick="showHide(\'linkCreated\')" title="Click to show/hide details">'; |
---|
167 | html += '<img src="../../images/hide_section.gif" id="linkCreatedImg">'; |
---|
168 | html += numLinkedNow + ' file(s) linked to a case</td></tr>\n'; |
---|
169 | html += '<tbody id="linkCreated">' + htmlLinkedNow + "</tbody>"; |
---|
170 | } |
---|
171 | if (numNotLinked > 0) |
---|
172 | { |
---|
173 | html += '<tr><td colspan="2" class="summary" onclick="showHide(\'notLinked\')" title="Click to show/hide details">'; |
---|
174 | html += '<img src="../../images/hide_section.gif" id="notLinkedImg">'; |
---|
175 | html += numNotLinked + ' file(s) could not be linked</td></tr>\n'; |
---|
176 | html += '<tbody id="notLinked">' + htmlNotLinked + "</tbody>"; |
---|
177 | } |
---|
178 | |
---|
179 | setInnerHTML('filesProcessed', html); |
---|
180 | } |
---|
181 | Main.show('filesSection'); |
---|
182 | Main.show('gorestart'); |
---|
183 | } |
---|
184 | |
---|
185 | function showHide(sectionId) |
---|
186 | { |
---|
187 | Main.showHide(sectionId); |
---|
188 | var img = document.getElementById(sectionId + 'Img'); |
---|
189 | img.src = img.src.indexOf('show') > 0 ? '../../images/hide_section.gif' : '../../images/show_section.gif'; |
---|
190 | } |
---|
191 | </script> |
---|
192 | <style> |
---|
193 | .stepfields select |
---|
194 | { |
---|
195 | width: 15em; |
---|
196 | } |
---|
197 | |
---|
198 | .disabled .buttonclass_inner |
---|
199 | { |
---|
200 | color: #666666; |
---|
201 | } |
---|
202 | |
---|
203 | .disabled .buttonclass_hover |
---|
204 | { |
---|
205 | color: #666666; |
---|
206 | background: #E0E0E0; |
---|
207 | cursor: default; |
---|
208 | } |
---|
209 | |
---|
210 | .linktable |
---|
211 | { |
---|
212 | width: 100%; |
---|
213 | } |
---|
214 | |
---|
215 | .linktable .summary |
---|
216 | { |
---|
217 | font-weight: bold; |
---|
218 | color: #333377; |
---|
219 | border-bottom: 1px solid #999999; |
---|
220 | cursor: pointer; |
---|
221 | } |
---|
222 | |
---|
223 | .linktable .file |
---|
224 | { |
---|
225 | padding-left: 12px; |
---|
226 | width: 120px; |
---|
227 | } |
---|
228 | </style> |
---|
229 | </base:head> |
---|
230 | <base:body onload="init()"> |
---|
231 | |
---|
232 | <p:path style="margin-top: 20px; margin-bottom: 10px;"> |
---|
233 | <p:pathelement title="Reggie" href="<%="index.jsp?ID="+ID%>" /> |
---|
234 | <p:pathelement title="Referral form registration" /> |
---|
235 | </p:path> |
---|
236 | |
---|
237 | <% |
---|
238 | if (sc.getActiveProjectId() == 0) |
---|
239 | { |
---|
240 | %> |
---|
241 | <base:note type="warning" style="width: 800px; margin-left: 20px; margin-bottom: 20px; margin-right: 0px; font-weight: bold; color: #cc0000;"> |
---|
242 | No project has been selected. You may proceed with the registration but |
---|
243 | created items will not be shared. |
---|
244 | </base:note> |
---|
245 | <% |
---|
246 | } |
---|
247 | %> |
---|
248 | |
---|
249 | <form name="reggie" onsubmit="return false;"> |
---|
250 | |
---|
251 | <!-- 1. Dirtory with files + filename pattern --> |
---|
252 | <table border="0" cellspacing="0" cellpadding="0" class="stepform"> |
---|
253 | <tr> |
---|
254 | <td rowspan="3" class="stepno">1</td> |
---|
255 | <td class="steptitle">Select directory and filename pattern</td> |
---|
256 | </tr> |
---|
257 | <tr> |
---|
258 | <td class="stepfields"> |
---|
259 | <table border="0" cellspacing="0" cellpadding="0" width="100%"> |
---|
260 | <tr valign="top"> |
---|
261 | <td class="prompt">Directory</td> |
---|
262 | <td class="input"> |
---|
263 | <base:select |
---|
264 | id="directoryId" |
---|
265 | clazz="selectionlist" |
---|
266 | current="<%=currentDirectory%>" |
---|
267 | required="true" |
---|
268 | recent="<%=recentDirectories%>" |
---|
269 | newitem="true" |
---|
270 | onselect="selectDirectoryOnClick()" |
---|
271 | /> |
---|
272 | </td> |
---|
273 | <td class="status" id="directory.status"></td> |
---|
274 | <td class="help"><span id="directory.message" class="message" style="display: none;"></span> |
---|
275 | The directory containing scanned referral forms. Sub-directories are not searched.</td> |
---|
276 | </tr> |
---|
277 | <tr> |
---|
278 | <td class="prompt">Filename pattern</td> |
---|
279 | <td class="input"><input type="text" name="pattern" |
---|
280 | size="18" maxlength="12" value="%.pdf"></td> |
---|
281 | <td class="status" id="pattern.status"></td> |
---|
282 | <td class="help"><span id="pattern.message" class="message" style="display: none;"></span>Use % as wildcard. If empty all files will be used.</td> |
---|
283 | </tr> |
---|
284 | </table> |
---|
285 | </td> |
---|
286 | </tr> |
---|
287 | </table> |
---|
288 | |
---|
289 | <div id="filesSection" style="display: none;"> |
---|
290 | <p> |
---|
291 | <table border="0" cellspacing="0" cellpadding="0" class="stepform"> |
---|
292 | <tr> |
---|
293 | <td rowspan="2" class="stepno">2</td> |
---|
294 | <td class="steptitle" id="step2.title">Processed x files</td> |
---|
295 | </tr> |
---|
296 | <tr> |
---|
297 | <td class="stepfields" id="filesProcessed"> |
---|
298 | |
---|
299 | </td> |
---|
300 | </tr> |
---|
301 | </table> |
---|
302 | </div> |
---|
303 | |
---|
304 | <div class="error" id="errorMessage" style="display: none; width: 800px; margin-left: 20px; margin-bottom: 0px;"></div> |
---|
305 | |
---|
306 | <div id="done" class="success" style="display: none; width: 800px; margin-left: 20px; margin-top: 20px;"></div> |
---|
307 | |
---|
308 | <table style="margin-left: 20px; margin-top: 10px;" class="navigation"> |
---|
309 | <tr> |
---|
310 | <td><base:button id="gocancel" title="Cancel" onclick="goRestart(false)" style="display: none;"/></td> |
---|
311 | <td><base:button id="goprocess" title="Process" image="gonext.gif" onclick="goProcess()" |
---|
312 | tooltip="Process the files in the selected directory"/></td> |
---|
313 | <td><base:button id="gorestart" title="Restart" image="goback.gif" onclick="goRestart(true)" style="display: none;"/></td> |
---|
314 | <td id="gonext.message" class="message"></td> |
---|
315 | </tr> |
---|
316 | </table> |
---|
317 | </form> |
---|
318 | |
---|
319 | </base:body> |
---|
320 | </base:page> |
---|
321 | <% |
---|
322 | } |
---|
323 | finally |
---|
324 | { |
---|
325 | if (dc != null) dc.close(); |
---|
326 | } |
---|
327 | %> |
---|