Created
June 25, 2012 09:40
-
-
Save dhavaln/2987658 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var db; | |
var dbpath; | |
var dbCreated = false; | |
var scroll = new iScroll('wrapper', { vScrollbar: false, hScrollbar:false, hScroll: false }); | |
var id1; | |
var email; | |
var picture; | |
var xDESC; | |
var xName; | |
var userNome; | |
var userCognome; | |
var userIndirizzo; | |
var userEmail; | |
var userNum_tel; | |
//Metodo chiamato per sapere se il device Ë pronto | |
document.addEventListener("deviceready", onDeviceReady(), false); | |
//Se il device Ë pronto, chiama il metodo "transaction" getX, | |
//se questo d‡ esito negativo | |
function onDeviceReady() { | |
db = window.openDatabase("xAsk", "1.0", "xAsk DB", 10000); | |
console.log("device pronto"); | |
db.transaction(getX, transaction_error); | |
} | |
//Metodo che mostra l'errore generato dalla transazione | |
function transaction_error(tx, error) { | |
$('#busy').hide(); | |
alert("Database Error: " + error); | |
console.log("!!!!!!!!!!errore!!!!!!!!!!!"); | |
} | |
//Metodo che esegue la query per la ricerca dei prodotti, se ha successo, chiama getX_success | |
function getX(tx) { | |
var sql = "select e.id, e.xName, e.xDESC, e.email, e.picture, count(r.id) reportCount " + | |
"from xask e left join xask r on r.supid = e.id " + | |
"group by e.id order by e.xName "; | |
console.log("query per cercare tutti i risultati"); | |
tx.executeSql(sql, [], getX_success); | |
} | |
//Metodo che indica il successo dell'esecuzione della query. | |
//Quindi, si viene rimandati alla pagina index.html | |
function getX_success(tx, results) { | |
$('#busy').hide(); | |
var len = results.rows.length; | |
for (var i=0; i<len; i++) { | |
var x = results.rows.item(i); | |
$('#xList').append('<li><a onclick=\'xgetProdReady("'+x.id+'");\' href="#">' + //?id=' + x.id + '">' + | |
'<img src="img/pics/' + x.picture + '" class="list-icon"/>' + | |
'<p class="line1">' + x.xName + '</p>' + | |
'<p class="line2">' + x.xDESC + '</p></a></li>'); | |
} | |
setTimeout(function(){ | |
scroll.refresh(); | |
},100); | |
db = null; | |
console.log("query terminata con successo"); | |
} | |
/* | |
* METODI CHIAMATI ALLA SCELTA DI UN ELEMENTO DELLA LISTA | |
*/ | |
//Metodo che apre il DB e avvia la transaction xgetProd, | |
//generando una transaction_error se da errore | |
function xgetProdReady(id) { | |
id1 = id; | |
db = window.openDatabase("xAsk", "1.0", "xAsk DB", 10000); | |
console.log("tap su un risultato, ora si visualizzaranno i dettagli"); | |
db.transaction(xgetProd, transaction_error); | |
} | |
//Metodo che fa la select dei prodotti con un determinato id | |
function xgetProd(tx) { | |
$('#busy').show(); | |
var sql = "select e.id, e.xName, e.xDESC, e.SupId, e.officePhone, e.cellPhone, e.pdfFile," + | |
"e.email, e.picture, m.xName managerFirstName, m.xDesc managerLastName, count(r.id) reportCount " + | |
"from xask e left join xask r on r.supId = e.id left join xask m on e.supid = m.id " + | |
"where e.id=:id group by e.xName order by e.xName"; | |
console.log("esegue la query con sto id:" + id1); | |
tx.executeSql(sql, [id1], xgetProdOk); | |
} | |
//Metodo che mostra i risultati della query e visualizza il prodotto scelto | |
function xgetProdOk(tx, results) { | |
console.log(" query eseguita:" + id1); | |
$("#wrapper").hide(); | |
$("#wrapper_hidden").show(); | |
$("#footer").show(); | |
$("#nav").show(); | |
$("#busy").hide(); | |
var x = results.rows.item(0); | |
email = x.email; | |
picture = x.picture; | |
xDESC = x.xDESC; | |
xName = x.xName; | |
$('#xPic').attr('src', 'img/pics/' + x.picture); | |
$('#xName').text(x.xName); | |
$('#xEmail').text(x.xDESC); | |
$('#actionList').append('<li><a href="#" onclick=\'pdf_manager("technical_guide.pdf")\'><p class="line1">Panoramica</p>' + | |
'<p class="line2">technical_guide.pdf</p><img src="img/pdf.png" class="action-icon"/></a></li>'); | |
if (x.pdfFile) { | |
$('#actionList').append('<li><a href="#" onclick=\'pdf_manager("'+x.pdfFile+'")\'><p class="line1">Scheda Tecnica</p>' + | |
'<p class="line2">'+x.pdfFile+'</p><img src="img/pdf.png" class="action-icon"/></a></li>'); | |
} | |
if (x.email) { | |
$('#azioni').append('<li><a href="#" onclick=\'send_mail("'+x.email+'");\'><img src="img/mail.png"/></a></li>'); | |
} | |
if (x.email) { | |
$('#azioni').append('<li><a href="#" onclick=\'send_mail("'+x.email+'");\'><img src="img/utente.png"/></a></li>'); | |
} | |
if (x.officePhone) { | |
$('#azioni').append('<li><a href="tel:'+x.officePhone+'"><img src="img/phone.png"/></a></li>'); | |
} | |
var sql1 = "select * from UTENTE"; | |
tx.executeSql(sql1, [], function(tx,results){ | |
var len = results.rows.length; | |
for (var i=0; i<len; i++) { | |
var x = results.rows.item(i); | |
$('#wrapper').append(x.cognome + x.nome + x.email); | |
userNome = x.nome; | |
userCognome = x.cognome; | |
userEmail = x.email; | |
userIndirizzo = x.indirizzo; | |
userNum_tel = x.num_tel; | |
} | |
db = null; | |
}); | |
setTimeout(function(){ | |
scroll.refresh(); | |
}); | |
db = null; | |
} | |
//Metodo che popola i vari campi necessari all'invio di una mail | |
function send_mail(mail) | |
{ | |
var oggetto = "Informazioni sul prodotto: " + xName; | |
var testo = "Richieste sul prodotto..... \n Descrizione: " + xDESC; | |
window.location.href="mailto:"+mail+"?subject="+oggetto+"&body="+testo; | |
// Cordova.exec(null, null, "EmailComposer", "showEmailComposer", [oggetto, testo]); | |
} | |
function pdf_manager(pdf) | |
{ | |
console.log("www/doc/"+pdf); | |
//Cordova.exec("ChildBrowserCommand.showWebPage", "file:///www/Documents/"+pdf); | |
loadChildBrowser(true, "/Documents/"+pdf); | |
} | |
function loadChildBrowser(isInternal, URL) { | |
if(isInternal){ | |
var strPath = window.location.href; | |
var path = strPath.substr(0,strPath.lastIndexOf('/')) + URL; | |
Cordova.exec("ChildBrowserCommand.showWebPage", encodeURI(path) ); | |
} | |
else{ | |
Cordova.exec("ChildBrowserCommand.showWebPage", URL ); | |
} | |
} | |
function show_mob() | |
{ | |
if($("#busy_2").is(":visible")) | |
{ | |
$("#busy_2").hide(); | |
} | |
else | |
{ | |
$("#busy_2").show(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment