implement timeout dialog
authorDobrica Pavlinusic <dpavlin@rot13.org>
Fri, 29 Aug 2014 14:26:06 +0000 (16:26 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Fri, 29 Aug 2014 14:26:06 +0000 (16:26 +0200)
examples/selfcheck.html
examples/selfcheck.js

index 6bdde5f..979ca02 100644 (file)
@@ -49,6 +49,20 @@ input[type=button] {
        height: 5em;
 }
 
+#timeout {
+       display: none;
+       position: absolute;
+       top: 50%;
+       left: 50%;
+       margin-left: -10em;
+       margin-top: -5em;
+       width: 20em;
+       height: 10em;
+       background: #ff8;
+       padding: 2em;
+       border: 0.5em solid #f00;
+}
+
 </style>
 <script type="text/javascript" src="/examples/selfcheck.js"></script>
 </head>
@@ -61,6 +75,12 @@ RFID reader not found or driver program not started.
 
 <h1>Knjižnica Filozofskog fakulteta</h1>
 
+<div id="timeout">
+Timeout in <span id="tick">99</span> seconds.
+<input type=button value="continue" onClick="start_timeout();">
+</div>
+
+
 <div class="page" id="start">
 
 <!--
index 189bfa5..ec6ee52 100644 (file)
@@ -17,6 +17,16 @@ var state;
 var scan_timeout;
 var pending_jsonp = 0;
 
+// timeout warning dialog
+var tick_timeout = 25; // s
+var tick_warning = 10; // s
+var tick = 0;
+
+function start_timeout() {
+       $('#timeout').hide();
+       tick = Math.round( tick_timeout * ( 1000 / tag_rescan ) );
+}
+
 function change_page(new_state) {
        if ( state != new_state ) {
 
@@ -65,6 +75,12 @@ function change_page(new_state) {
                                location.reload();
                        },error_timeout);
                }
+
+               if ( state == 'circulation' || state == 'borrower_info' ) {
+                       start_timeout();
+               } else {
+                       tick = 0; // timeout disabled
+               }
        }
 }
 
@@ -125,6 +141,18 @@ function scan_tags() {
                $.getJSON("/scan?callback=?", got_visible_tags);
        }
 
+       if ( tick > 0 ) {
+               if ( tick < tick_warning * ( 1000 / tag_rescan ) ) {
+                       $('#tick').html( Math.round( tick * tag_rescan / 1000 ) );
+                       $('#timeout').show();
+               }
+               tick--;
+               if ( tick == 0 ) {
+                       $('#timeout').hide();
+                       change_page('end');
+               }
+       }
+
        scan_timeout = window.setTimeout(function(){
                scan_tags();
        },tag_rescan);  // re-scan every 200ms
@@ -202,6 +230,7 @@ function circulation( barcode, sid ) {
                        $('#books_count').html( $('ul#books > li').length );
                        console.debug( book_barcodes );
                        pending_jsonp--;
+                       start_timeout(); // reset timeout
                }).fail( function() {
                        change_page('error');
                        pending_jsonp--;