-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
102 lines (95 loc) · 2.87 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
$('#content').css('display', 'none');
function calcolaMese(meseStr) {
if (meseStr == "A")
return "gennaio";
else if (meseStr == "B")
return "febbraio";
else if (meseStr == "C")
return "marzo";
else if (meseStr == "D")
return "aprile";
else if (meseStr == "E")
return "maggio";
else if (meseStr == "H")
return "giugno";
else if (meseStr == "L")
return "luglio";
else if (meseStr == "M")
return "agosto";
else if (meseStr == "P")
return "settembre";
else if (meseStr == "R")
return "ottobre";
else if (meseStr == "S")
return "novembre";
else if (meseStr == "T")
return "dicembre";
}
// The web page fetch information from an XML file with AJAX
function loadDoc(mioCodice) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
calcolaComune(this, mioCodice);
}
};
xhttp.open("GET", "catasto.xml", true);
xhttp.send();
}
function calcolaComune(xml, mioCodice) {
var xmlDoc = xml.responseXML;
var x = xmlDoc.getElementsByTagName("ENTRY");
var i;
for (i = 0; i < x.length; i++) {
var codice = x[i].getElementsByTagName("CODICE")[0].childNodes[0].nodeValue;
if (codice == mioCodice) {
var comune = x[i].getElementsByTagName("COMUNE")[0].childNodes[0].nodeValue;
var provincia = x[i].getElementsByTagName("PROVINCIA")[0].childNodes[0].nodeValue;
$('#luogo').html("Luogo di nascita: " + comune + " (" + provincia + ")");
}
}
}
var app = {
scan: function() {
$('#content').css('display', 'none');
cordova.plugins.barcodeScanner.scan(
function (result) {
if (result.cancelled == true) {
alert("Scansione cancellata!");
} else {
var resultStr = result.text;
if (resultStr.length != 16) {
alert("Nessun codice fiscale trovato!");
} else {
$('#text').html(resultStr);
// elaborazione luogo:
loadDoc(resultStr.substr(11,4));
// elaborazione sesso e data:
var giorno = parseInt(resultStr.substr(9,2));
if (giorno > 40) {
$('#sesso').html("Sesso: femminile");
giorno = giorno - 40;
} else {
$('#sesso').html("Sesso: maschile");
}
var meseStr = resultStr.substr(8,1);
var mese = calcolaMese(meseStr);
var anno = "19" + resultStr.substr(6,2);
$('#data').html("Data di nascita: " + giorno + " " + mese + " " + anno);
}
$('#content').css('display', 'block');
}
},
function (error) {
alert("Scansione fallita: " + error);
},
{
showTorchButton : true,
prompt : "Posiziona il codice a barre all'interno dell'area di scansione",
resultDisplayDuration: 0,
formats : "CODE_39",
orientation : "portrait"
}
);
}
};