Skip to content

Instantly share code, notes, and snippets.

@edanuff
Created July 30, 2012 23:34
Show Gist options
  • Save edanuff/3211906 to your computer and use it in GitHub Desktop.
Save edanuff/3211906 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css" />-->
<link rel="stylesheet" href="http://current.bootstrapcdn.com/bootstrap-v204/css/bootstrap-combined.min.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
<script src="../js/appSDK.js" type="text/javascript"></script>
<script type="text/javascript">
//first set the app path
client = new APIClient('ApigeeRod', 'sandbox'); //<== update this line with the org name you signed up with
$(document).ready(function () {
//bind the click event
$('#create-user').bind('click', function() {
createUser();
});
$('#get-user').bind('click', function() {
getUser('barney');
});
//function to create the user
function createUser(){
var name = $("#name").val();
var username = $("#username").val();
var email = $("#email").val();
//if (usergrid.Client.validateUser(name, username, email)) {
data = {"name": name, "username":username, "email":email}
client.runAppQuery(new QueryObj("POST", "users", data, null,
function() {
$('#new-user').hide();
$('#user-list').show();
getUser();
},
function(e) {
alert('Error - user not created: ' + e.responseText);
}
));
//}
}
//function to get the most recent user
function getUser(){
var query = {"ql":"order by created desc","limit":"1"};
client.runAppQuery(new QueryObj("GET", "users", null, query,
function(response) {
$("#userlist").html(' ');
for (count in response.entities){
var html = "{<br />";
html += '"name":' + response.entities[count].name + "<br />";
html += '"email":' + response.entities[count].email + "<br />";
html += '"username":' + response.entities[count].username + "<br />";
$("#userlist").append( "<div>" + response.entities[count].name + ' - ' + response.entities[count].email + "</div>" );
html += "<br />}";
}
$("#userlist").html(html);
},
function(e) {
alert('Error getting user: ' + e.responseText);
}
));
}
});
</script>
</head>
<body>
<div style="width: 100%; height: 60px; background-color: #41aee3;">
&nbsp;
</div>
<div id="new-user" style="width: 400px; margin: 40px auto; display: block;">
<h2>Welcome to Sandbox</h2>
<div style="padding-top: 10px;">
This is a sample signup form. Sandbox isn't a real app, but we're using it as an example web application to help
you learn how Usergrid works. What you see below is information that you, the developer of Sandbox, would like
to collect for users to register.
</div>
<div style="padding: 10px 0 10px 0;">
<strong>Get started by creating a new user.</strong>
</div>
<form name="newuser-form" id="newuser-form">
<label for="name">Full Name</label>
<input type="text" name="name" id="name" class="span4" />
<label for="username">Username</label>
<input type="text" name="username" id="username" class="span4" />
<label for="email">Email:</label>
<input type="text" name="email" id="email" class="span4" />
</form>
<a class="btn-large btn-primary" href="#" id="create-user">Create User</a>
</div>
<div id="user-list" style="width: 400px; margin: 40px auto; display: none;">
<h1>Success!</h1>
<div style="padding-top: 10px;">
You've created your first user in the Sandbox web app.
</div>
<div style="padding: 10px 0 10px 0; font-weight: bold;">
<strong>You can now return to the tutorial. In the next step, you'll check that the user you created shows up in your Usergrid database.</strong>
</div>
<div id="userlist">
User not found
</div>
<!--a class="btn-large btn-primary" href="#" id="get-user">Get User</a-->
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment