/[RFID]/koha/koha-rfid.js
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /koha/koha-rfid.js

Parent Directory Parent Directory | Revision Log Revision Log


Revision 76 - (hide annotations)
Thu Feb 11 23:02:03 2010 UTC (14 years, 3 months ago) by dpavlin
File MIME type: application/javascript
File size: 2593 byte(s)
implement auto-submit

1 dpavlin 69
2     // XXX dpavlin: RFID support for Koha
3    
4 dpavlin 76 function barcode_on_screen(barcode) {
5     var found = 0;
6 dpavlin 72 $('table tr td a:contains(130)').each( function(i,o) {
7     var possible = $(o).text();
8     console.debug(i,o,possible, barcode);
9 dpavlin 76 if ( possible == barcode ) found++;
10     })
11     return found;
12 dpavlin 72 }
13    
14 dpavlin 76 function rfid_secure(barcode,sid,val) {
15     console.debug('rfid_secure', barcode, sid, val);
16     if ( barcode_on_screen(barcode) )
17     $.getJSON( 'http://localhost:9000/secure.js?' + sid + '=' + val + ';callback=?' )
18     }
19    
20 dpavlin 74 var rfid_reset_field = false;
21    
22 dpavlin 69 function rfid_scan(data,textStatus) {
23     // console.debug( 'rfid_scan', data, textStatus );
24    
25     var span = $('span#rfid');
26     if ( span.size() == 0 ) {
27     $('ul#i18nMenu').append('<li><span id=rfid>RFID reader found<span>');
28     span = $('span#rfid');
29     }
30    
31     if ( data.tags ) {
32     if ( data.tags.length === 1 ) {
33 dpavlin 70 var t = data.tags[0];
34 dpavlin 76 // if ( span.text() != t.content ) {
35     if ( 1 ) { // force update of security
36    
37     var url = document.location.toString();
38     var circulation = url.substr(-14,14) == 'circulation.pl';
39     var returns = url.substr(-10,10) == 'returns.pl';
40    
41 dpavlin 70 if ( t.content.substr(0,3) == '130' ) {
42 dpavlin 76
43     if ( circulation )
44     rfid_secure( t.content, t.sid, 'D7' );
45     if ( returns )
46     rfid_secure( t.content, t.sid, 'DA' );
47    
48 dpavlin 70 var color = 'blue';
49     if ( t.security.toUpperCase() == 'DA' ) color = 'red';
50     if ( t.security.toUpperCase() == 'D7' ) color = 'green';
51     span.text( t.content ).css('color', color);
52 dpavlin 72
53 dpavlin 76 if ( ! barcode_on_screen( t.content ) ) {
54     rfid_reset_field = 'barcode';
55     var i = $('input[name=barcode]:last');
56     if ( i.val() != t.content )
57     i.val( t.content )
58     .closest('form').submit();
59     }
60 dpavlin 72
61 dpavlin 69 } else {
62 dpavlin 72 span.text( t.content ).css('color', 'blue' );
63 dpavlin 76
64     if ( url.substr(-14,14) != 'circulation.pl' || $('form[name=mainform]').size() == 0 ) {
65     rfid_reset_field = 'findborrower';
66     $('input[name=findborrower]').val( t.content )
67     .parent().submit();
68     }
69 dpavlin 69 }
70     }
71     } else {
72     var error = data.tags.length + ' tags near reader: ';
73     $.each( data.tags, function(i,tag) { error += tag.content + ' '; } );
74     span.text( error ).css( 'color', 'red' );
75     }
76 dpavlin 72
77 dpavlin 69 } else {
78     span.text( 'no tags in range' ).css('color','gray');
79 dpavlin 74 if ( rfid_reset_field ) {
80     $('input[name='+rfid_reset_field+']').val( '' );
81     rfid_reset_field = false;
82     }
83 dpavlin 69 }
84    
85     window.setTimeout( function() {
86     $.getJSON("http://localhost:9000/scan?callback=?", rfid_scan);
87     }, 1000 ); // 1000ms
88     }
89    
90     $(document).ready( function() {
91     $.getJSON("http://localhost:9000/scan?callback=?", rfid_scan);
92     });

  ViewVC Help
Powered by ViewVC 1.1.26