source: extensions/net.sf.basedb.reggie/trunk/resources/refform.jsp @ 1336

Last change on this file since 1336 was 1336, checked in by Nicklas Nordborg, 11 years ago

Fixes #303: Automatic attachment of files to sample (Case) items

File size: 11.9 KB
Line 
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<%
19final SessionControl sc = Base.getExistingSessionControl(request, true);
20final String ID = sc.getId();
21final float scale = Base.getScale(sc);
22DbControl dc = null;
23try
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<script language="JavaScript">
41
42var debug = false;
43var currentStep = 1;
44
45function init()
46{
47  var frm = document.forms['reggie'];
48}
49
50function step1IsValid()
51{
52  var frm = document.forms['reggie'];
53  var list = frm.directoryId;
54  if (list.selectedIndex < 0 || list[list.selectedIndex].value == '0')
55  {
56    setInputStatus('directory', 'Required', 'invalid');
57    return false;
58  }
59  setInputStatus('directory', '', 'valid');
60  return true;
61}
62
63
64function goNextOnTab(event)
65{
66  if (event.keyCode == 9) setTimeout('goNext()', 200);
67  return true;
68}
69
70function goNextOnTabOrEnter(event)
71{
72  if (event.keyCode == 9 || event.keyCode == 13) setTimeout('goNext()', 200);
73  return true;
74}
75
76function focusOnEnter(event, inputField)
77{
78  if (event.keyCode == 13) setTimeout("document.forms['reggie']."+inputField+".focus()", 200);
79  return true;
80}
81
82
83function setInnerHTML(id, html)
84{
85  var tag = document.getElementById(id);
86  if (!tag) alert('No tag with id='+id);
87  tag.innerHTML = html;
88}
89
90function setInputStatus(prefix, message, clazz)
91{
92  var tag = document.getElementById(prefix + '.status');
93  tag.className = 'status ' + clazz;
94 
95  setInnerHTML(prefix + '.message', message);
96  if (message)
97  {
98    Main.showInline(prefix + '.message');
99  }
100  else
101  {
102    Main.hide(prefix + '.message');
103  }
104}
105
106function setFatalError(message)
107{
108  setInnerHTML('errorMessage', message);
109  Main.show('errorMessage');
110  Main.hide('gonext');
111  Main.hide('gocancel');
112  Main.show('gorestart');
113  var frm = document.forms['reggie'];
114  for (var i = 0; i < frm.elements.length; i++)
115  {
116    frm.elements[i].disabled = true; 
117  }
118
119}
120
121function goRestart(force)
122{
123  if (!force && !confirm('Cancel this registration?')) return;
124  location.href = location.href;
125}
126
127function selectDirectoryOnClick()
128{
129  if (currentStep != 1) return;
130  var frm = document.forms['reggie'];
131  var url = '../../filemanager/directories/index.jsp?ID=<%=ID%>&mode=selectonedirectory&callback=setDirectoryCallback';
132  if (frm.directoryId.length > 0)
133  {
134    var id = Math.abs(parseInt(frm.directoryId[0].value));
135    url += '&directory_id='+id;
136  }
137  Main.openPopup(url, 'SelectDirectory', 350, 500);
138}
139function setDirectoryCallback(id, name)
140{
141  var frm = document.forms['reggie'];
142  var list = frm.directoryId;
143  if (list.length < 1 || list[0].value == '0') // >
144  {
145    Forms.addListOption(list, 0, new Option());
146  }
147  list[0].value = id;
148  list[0].text = name;
149  list.selectedIndex = 0;
150}
151
152function goProcess()
153{
154  if (!step1IsValid()) return;
155
156  Main.hide('gocancel');
157  Main.hide('goprocess');
158 
159  var frm = document.forms['reggie'];
160 
161  frm.directoryId.disabled = true;
162  frm.pattern.disabled = true;
163  Main.addClass(document.getElementById('directoryId'), 'disabled');
164 
165  var directoryId = frm.directoryId.value;
166  var pattern = frm.pattern.value;
167  var request = Ajax.getXmlHttpRequest();
168  var url = 'ReferralForm.servlet?ID=<%=ID%>&cmd=ScanDirectory';
169  url += '&directoryId=' + directoryId;
170  url += '&pattern=' + encodeURIComponent(pattern);
171  request.open("GET", url, false);
172  request.send(null);
173 
174  if (debug) Main.debug(request.responseText);
175  var response = JSON.parse(request.responseText);
176  if (response.status != 'ok')
177  {
178    setFatalError(response.message);
179    return false;
180  }
181 
182  currentStep = 2;
183  var files = response.files;
184 
185  setInnerHTML('step2.title', 'Processed ' + files.length + ' file(s)');
186 
187  var numAlreadyLinked = 0;
188  var numLinkedNow = 0;
189  var numNotLinked = 0;
190 
191  var htmlAlreadyLinked = '';
192  var htmlLinkedNow = '';
193  var htmlNotLinked = '';
194 
195  // Collect information
196  for (var i = 0; i < files.length; i++)
197  {
198    var file = files[i];
199   
200    if (file.link)
201    {
202      numAlreadyLinked++;
203      htmlAlreadyLinked += '<tr><td class="file">'+file.name+'</td><td>Link existed to case '+file.caseInfo.name+'</td>\n';
204    }
205    else if (file.caseInfo)
206    {
207      numLinkedNow++;
208      htmlLinkedNow += '<tr><td class="file">'+file.name+'</td><td>Link created to case '+file.caseInfo.name+'</td>\n';
209    }
210    else
211    {
212      numNotLinked++;
213      htmlNotLinked += '<tr><td class="file">'+file.name+'</td><td>'+file.message+'</td>\n';
214    }
215   
216    var html = '<table class="linktable">';
217    if (numAlreadyLinked > 0)
218    {
219      html += '<tr><td colspan="2" class="summary" onclick="showHide(\'alreadyLinked\')" title="Click to show/hide details">';
220      html += '<img src="../../images/show_section.gif" id="alreadyLinkedImg">';
221      html += numAlreadyLinked + ' file(s) was already linked to a case</td></tr>\n';
222      html += '<tbody id="alreadyLinked" style="display: none;">' + htmlAlreadyLinked + "</tbody>";
223    }
224    if (numLinkedNow > 0)
225    {
226      html += '<tr><td colspan="2" class="summary" onclick="showHide(\'linkCreated\')" title="Click to show/hide details">';
227      html += '<img src="../../images/hide_section.gif" id="linkCreatedImg">';
228      html += numLinkedNow + ' file(s) linked to a case</td></tr>\n';
229      html += '<tbody id="linkCreated">' + htmlLinkedNow + "</tbody>";
230    }
231    if (numNotLinked > 0)
232    {
233      html += '<tr><td colspan="2" class="summary" onclick="showHide(\'notLinked\')" title="Click to show/hide details">';
234      html += '<img src="../../images/hide_section.gif" id="notLinkedImg">';
235      html += numNotLinked + ' file(s) could not be linked</td></tr>\n';
236      html += '<tbody id="notLinked">' + htmlNotLinked + "</tbody>";
237    }
238   
239    setInnerHTML('filesProcessed', html);
240  }
241  Main.show('filesSection');
242  Main.show('gorestart');
243 
244 
245}
246
247function showHide(sectionId)
248{
249  Main.showHide(sectionId);
250  var img = document.getElementById(sectionId + 'Img');
251  img.src = img.src.indexOf('show') > 0 ? '../../images/hide_section.gif' : '../../images/show_section.gif';
252}
253
254</script>
255<style>
256
257.stepform
258{
259  margin-left: 20px;
260  border: 1px solid #999999;
261  width: 800px;
262  table-layout: fixed;
263}
264
265.stepno
266{
267  width: 20px;
268  font-size: 20px;
269  font-weight: bold;
270  color: #E0E0E0;
271  background: #555577;
272  vertical-align: top;
273  text-align: center;
274}
275
276.steptitle
277{
278  width: 780px;
279  color: #333377;
280  background: #E0E0E0;
281  font-weight: bold;
282  padding: 1px 4px 1px 4px;
283  border-bottom: 1px solid #999999;
284}
285
286.nextstep
287{
288  width: 780px;
289  color: #333377;
290  background: #E0E0E0;
291  font-weight: bold;
292  padding: 1px 4px 1px 4px;
293  border-top: 1px solid #999999;
294}
295
296.stepfields
297{
298  width: 780px;
299}
300
301.stepfields .prompt
302{
303  width: 150px;
304  font-weight: bold;
305  padding: 1px 2px 1px 2px;
306}
307
308.stepfields .subprompt
309{
310  width: 150px;
311  text-align: right;
312  padding: 1px 2px 1px 2px;
313  white-space: nowrap;
314}
315
316.stepfields .input
317{
318  width: 250px;
319  padding: 1px 2px 1px 2px;
320}
321
322.stepfields .status
323{
324  width: 30px;
325  padding: 1px 2px 1px 2px;
326}
327
328.stepfields .help
329{
330  background: #e0e0e0;
331  width: 350px;
332  font-style: italic;
333  padding: 1px 2px 1px 2px;
334}
335
336.stepfields select
337{
338  width: 15em;
339}
340
341.stepfields .message, .navigation .message
342{
343  color: #cc0000;
344  font-weight: bold;
345  padding-right: 6px;
346}
347
348.status.invalid:before
349{
350  content: url('../../images/error.gif');
351}
352.status.warning:before
353{
354  content: url('../../images/warning.gif');
355}
356.status.valid:before
357{
358  content: url('../../images/ok.gif');
359}
360.success ul
361{
362  list-style-image: url('../../images/ok.gif');
363}
364
365.disabled .buttonclass_inner
366{
367  color: #666666;
368}
369
370.disabled .buttonclass_hover
371{
372  color: #666666;
373  background: #E0E0E0;
374  cursor: default;
375}
376
377.linktable
378{
379  width: 100%;
380}
381
382.linktable .summary
383{
384  font-weight: bold;
385  color: #333377;
386  border-bottom: 1px solid #999999;
387  cursor: pointer;
388}
389
390.linktable .file
391{
392  padding-left: 12px;
393  width: 120px;
394}
395
396</style>
397</base:head>
398<base:body onload="init()">
399
400  <p:path style="margin-top: 20px; margin-bottom: 10px;">
401    <p:pathelement title="Reggie" href="<%="index.jsp?ID="+ID%>" />
402    <p:pathelement title="Referral form registration" />
403  </p:path>
404
405  <%
406  if (sc.getActiveProjectId() == 0)
407  {
408    %>
409    <base:note type="warning" style="width: 800px; margin-left: 20px; margin-bottom: 20px; margin-right: 0px; font-weight: bold; color: #cc0000;">
410      No project has been selected. You may proceed with the registration but
411      created items will not be shared.
412    </base:note>
413    <%
414  }
415  %>
416
417  <form name="reggie" onsubmit="return false;">
418 
419  <!-- 1. Dirtory with files + filename pattern -->
420  <table border="0" cellspacing="0" cellpadding="0" class="stepform">
421  <tr>
422    <td rowspan="3" class="stepno">1</td>
423    <td class="steptitle">Select directory and filename pattern</td>
424  </tr>
425  <tr>
426    <td class="stepfields">
427      <table border="0" cellspacing="0" cellpadding="0" width="100%">
428      <tr valign="top">
429        <td class="prompt">Directory</td>
430        <td class="input">
431          <base:select 
432            id="directoryId"
433            clazz="selectionlist"
434            current="<%=currentDirectory%>"
435            required="true"
436            recent="<%=recentDirectories%>"
437            newitem="true"
438            onselect="selectDirectoryOnClick()"
439          />
440        </td>
441        <td class="status" id="directory.status"></td>
442        <td class="help"><span id="directory.message" class="message" style="display: none;"></span>
443          The directory containing scanned referral forms. Sub-directories are not searched.</td>
444      </tr>
445      <tr>
446        <td class="prompt">Filename pattern</td>
447        <td class="input"><input type="text" name="pattern" 
448          size="18" maxlength="12" value="%.pdf"></td>
449        <td class="status" id="pattern.status"></td>
450        <td class="help"><span id="pattern.message" class="message" style="display: none;"></span>Use % as wildcard. If empty all files will be used.</td>
451      </tr>
452      </table>
453    </td>
454  </tr>
455  </table>
456
457  <div id="filesSection" style="display: none;">
458  <p>
459  <table border="0" cellspacing="0" cellpadding="0" class="stepform">
460  <tr>
461    <td rowspan="2" class="stepno">2</td>
462    <td class="steptitle" id="step2.title">Processed x files</td>
463  </tr>
464  <tr>
465    <td class="stepfields" id="filesProcessed">
466
467    </td>
468  </tr>
469  </table>
470  </div>
471
472  <div class="error" id="errorMessage" style="display: none; width: 800px; margin-left: 20px; margin-bottom: 0px;"></div>
473
474  <div id="done" class="success" style="display: none; width: 800px; margin-left: 20px; margin-top: 20px;"></div>
475
476  <table style="margin-left: 20px; margin-top: 10px;" class="navigation">
477  <tr>
478    <td><base:button id="gocancel" title="Cancel" onclick="goRestart(false)" style="display: none;"/></td>
479    <td><base:button id="goprocess" title="Process" image="gonext.gif" onclick="goProcess()" 
480      tooltip="Process the files in the selected directory"/></td>
481    <td><base:button id="gorestart" title="Restart" image="goback.gif" onclick="goRestart(true)" style="display: none;"/></td>
482    <td id="gonext.message" class="message"></td>
483  </tr>
484  </table>
485  </form>
486 
487</base:body>
488</base:page>
489<%
490}
491finally
492{
493  if (dc != null) dc.close();
494}
495%>
Note: See TracBrowser for help on using the repository browser.