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

Last change on this file since 1335 was 1335, checked in by Nicklas Nordborg, 12 years ago

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

The functionality is more or less in place. Just need some more polishing up in the gui and error handling.

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