Skip to content

Instantly share code, notes, and snippets.

@cfjedimaster
Created December 27, 2012 17:36
<!doctype html>
<html>
<head>
<meta name="viewport" content="width=device-width">
<script type="text/javascript" src="jquery-1.8.3.js"></script>
<script type="text/javascript" src="parse.js"></script>
<script>
var NoteObject;
var db;
function errorCB(e) {
console.log("DB Error");
console.dir(e);
}
function online() {
return navigator.onLine;
}
$(document).ready(function() {
db = window.openDatabase("notedb", "1.0", "Note Database", 200000);
db.transaction(createDB, errorCB);
function createDB(trans) {
trans.executeSql("create table if not exists notedb(id INTEGER PRIMARY KEY,body,title)");
console.log('um');
}
$("#querytodb").on("click", function(e) {
Parse.initialize("k2Spg4ids1PrJ8yXmJzc0Cin8S7cOy5ULfIoBaSq", "n3cl1DBR9qIPdzpSOveQ6WRsUpH0dstTWMiaz3E2");
NoteObject = Parse.Object.extend("note");
var querytodb = new Parse.Query(NoteObject);
console.log("Parse data from Parse.com");
querytodb.find({
success: function(results) {
console.log("Storing to WebSQL");
/*
for(var i=0, len=results.length; i<len; i++) {
var result = results[i];
console.dir(result.attributes);
db.transaction(function(trans) {
console.log('entering ',result.attributes.body,result.attributes.title);
trans.executeSql("insert into notedb(body,title) values(?,?)", [result.attributes.body, result.attributes.title]);
}, errorCB,function() { console.log('success')});
}*/
results.forEach(function(result) {
console.dir(result.attributes);
db.transaction(function(trans) {
console.log('entering ',result.attributes.body,result.attributes.title);
trans.executeSql("insert into notedb(body,title) values(?,?)", [result.attributes.body, result.attributes.title]);
}, errorCB,function() { console.log('success')});
})
console.log("Success");
$("#loadingGraphic").hide();
},
error: function(error) {
alert("Error: " + error.code + " " + error.message);
}
});
});
});
</script>
<style>
body {
margin-left: 25px;
margin-right: 25px;
font-family: arial;
}
input {
width: 100%;
height: 25px;
}
</style>
</head>
<body>
<h2>Save Locally</h2>
<input type="submit" id="querytodb" value="Query to Local">
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment