Created
January 24, 2014 05:58
-
-
Save rominirani/8592675 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Famous Quotes</title> | |
</head> | |
<body> | |
<form action="javascript:void(0);"> | |
<h2>List Quotes</h2> | |
<div><input id="listQuote" type="submit" value="List Quotes"></div> | |
</form> | |
<div id="listQuotesResult"></div> | |
<form action="javascript:void(0);"> | |
<h2>Insert New Quote</h2> | |
<div><input id="txtAuthorName" placeholder="Author name here"></input></div> | |
<div><input id="txtMessage" placeholder="Quote text here"></input></div> | |
<div><input id="insertQuote" type="submit" value="Insert Quote"></div> | |
</form> | |
<form action="javascript:void(0);"> | |
<h2>Update Quote</h2> | |
<div><input id="editQuoteID" placeholder="Quote ID value"></input></div> | |
<div><input id="editAuthorName" placeholder="Author name here"></input></div> | |
<div><input id="editMessage" placeholder="Quote text here"></input></div> | |
<div><input id="updateQuote" type="submit" value="Update Quote"></div> | |
</form> | |
<form action="javascript:void(0);"> | |
<h2>Delete Quote</h2> | |
<div><input id="quoteID" placeholder="Quote ID value"></input></div> | |
<div><input id="deleteQuote" type="submit" value="Delete Quote"></div> | |
</form> | |
<script type="text/javascript"> | |
function init() { | |
//Parameters are APIName,APIVersion,CallBack function,API Root | |
gapi.client.load('quoteendpoint', 'v1', null, 'http://localhost:8888/_ah/api'); | |
document.getElementById('listQuote').onclick = function() { | |
listQuotes(); | |
} | |
document.getElementById('insertQuote').onclick = function() { | |
insertQuote(); | |
} | |
document.getElementById('updateQuote').onclick = function() { | |
updateQuote(); | |
} | |
document.getElementById('deleteQuote').onclick = function() { | |
deleteQuote(); | |
} | |
} | |
//List Quotes function that will execute the listQuote call | |
function listQuotes() { | |
gapi.client.quoteendpoint.listQuote().execute(function(resp) { | |
if (!resp.code) { | |
resp.items = resp.items || []; | |
var result = ""; | |
for (var i=0;i<resp.items.length;i++) { | |
result = result+ resp.items[i].message + "..." + "<b>" + resp.items[i].author + "</b>" + "[" + resp.items[i].id + "]" + "<br/>"; | |
} | |
document.getElementById('listQuotesResult').innerHTML = result; | |
} | |
}); | |
} | |
//Insert Quote function | |
function insertQuote() { | |
//Validate the entries | |
var _AuthorName = document.getElementById('txtAuthorName').value; | |
var _Message = document.getElementById('txtMessage').value; | |
//Build the Request Object | |
var requestData = {}; | |
requestData.author = _AuthorName; | |
requestData.message = _Message; | |
gapi.client.quoteendpoint.insertQuote(requestData).execute(function(resp) { | |
if (!resp.code) { | |
//Just logging to console now, you can do your check here/display message | |
console.log(resp.id + ":" + resp.author + ":" + resp.message); | |
} | |
}); | |
} | |
//Update Quote function | |
function updateQuote() { | |
//Validate the entries | |
var _ID = document.getElementById("editQuoteID").value; | |
var _AuthorName = document.getElementById('editAuthorName').value; | |
var _Message = document.getElementById('editMessage').value; | |
//Build the Request Object | |
var requestData = {}; | |
requestData.id = _ID; | |
requestData.author = _AuthorName; | |
requestData.message = _Message; | |
gapi.client.quoteendpoint.updateQuote(requestData).execute(function(resp) { | |
if (!resp.code) { | |
//Just logging to console now, you can do your check here/display message | |
console.log(resp.id + ":" + resp.author + ":" + resp.message); | |
} | |
}); | |
} | |
//Delete Quote function | |
function deleteQuote() { | |
//Validate the entries | |
var _ID = document.getElementById('quoteID').value; | |
//Build the Request Object | |
var requestData = {}; | |
requestData.id = _ID; | |
console.log(requestData); | |
gapi.client.quoteendpoint.removeQuote(requestData).execute(function(resp) { | |
//Just logging to console now, you can do your check here/display message | |
console.log(resp); | |
}); | |
} | |
</script> | |
<script src="https://apis.google.com/js/client.js?onload=init"></script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment