Created
April 26, 2015 14:05
-
-
Save daniellowtw/6b7154ad89a1443cc233 to your computer and use it in GitHub Desktop.
Simple parse.com email collector
This file contains 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<title></title> | |
<script src="https://www.parsecdn.com/js/parse-1.4.2.min.js"></script> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> | |
</head> | |
<body> | |
<form method="get" accept-charset="utf-8" onsubmit="return false"> | |
<input type="text" id='email_field' name="email" value="Enter your email here"> | |
<input type="submit" name="" value="Submit" onclick="submitForm()"> | |
</form> | |
<div id="result"> </div> | |
<button type="" onclick="getAll()">Get all entries</button> | |
<button type="" onclick="deleteAll()">Delete all entries</button> | |
<br> | |
<textarea id="console"></textarea> | |
<script> | |
// Use my database | |
Parse.initialize("",""); | |
result_div = $('#result') | |
// Create a new row | |
function submitForm() { | |
email = $('#email_field').val(); | |
Db = Parse.Object.extend("ph2015"); | |
db_instance = new Db(); | |
db_instance.save({ | |
email: email | |
}).then(function(object) { | |
result_div.html("Success") | |
}, function(e) { | |
result_div.html("Failed") | |
}); | |
} | |
// Get all entries | |
function getAll() { | |
result_div = $('#result') | |
var query = new Parse.Query("ph2015"); | |
query.find({ | |
success: function(results) { | |
results.forEach(function(entry){ | |
result_div.html(result_div.html() + "</br> " + entry.get('email')) | |
}) | |
}, | |
error: function(error) { | |
result_div.html("Failed") | |
} | |
}); | |
} | |
// Delete all entries | |
function deleteAll(){ | |
result_div = $('#result') | |
var query = new Parse.Query("ph2015"); | |
query.find({ | |
success: function(results) { | |
results.forEach(function(entry){ | |
email = entry.get('email') | |
entry.destroy(function(s){ | |
$('#console').val($('#console').val() + "\nDeleted: " + email) | |
}) | |
}) | |
}, | |
error: function(error) { | |
result_div.html("Failed") | |
} | |
}); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment