Skip to content

Commit

Permalink
Merged everything
Browse files Browse the repository at this point in the history
  • Loading branch information
haubey committed Jul 19, 2011
2 parents 6098319 + a190aca commit 5374292
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 69 deletions.
Binary file added assets/www/.DS_Store
Binary file not shown.
16 changes: 13 additions & 3 deletions assets/www/index.html
@@ -1,3 +1,6 @@
<!--
TODO: Add footers (they will probbably be some form of icony nav bar)
-->
<!DOCTYPE HTML>
<html>
<head>
Expand All @@ -15,8 +18,8 @@
<!-- Jquery Mobile -->
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.1.min.js"></script>
<script src="http://ajax.microsoft.com/ajax/jquery.templates/beta1/jquery.tmpl.min.js"></script>
<script type = "text/javascript" charset="utf-8" src = "http://code.jquery.com/mobile/1.0a4/jquery.mobile-1.0a4.js"></script>
<link rel = "stylesheet" href = "http://code.jquery.com/mobile/1.0a4/jquery.mobile-1.0a4.css" />
<script type = "text/javascript" charset="utf-8" src = "http://code.jquery.com/mobile/1.0a4.1/jquery.mobile-1.0a4.1.js"></script>
<link rel = "stylesheet" href = "http://code.jquery.com/mobile/1.0a4.1/jquery.mobile-1.0a4.1.css" />
<!-- Application logic -->
<script type = "text/javascript" charset="utf-8" src = "script/index.js"></script>
<link rel = "stylesheet" href = "css/main.css" />
Expand Down Expand Up @@ -64,7 +67,7 @@ <h3 style="width:75%">${na}</h3>
<div data-role = "header"><h1>Error</h1></div>
<div data-role = "content">
<p id = "errorMsg"></p>
<div data-role = "button" id = "errorClose_btn" data-icon = "check">Ok</div>
<a href = "#" data-role = "button" id = "errorClose_btn" data-icon = "check" data-rel = "back">Ok</a>
</div>
</div>
<div data-role = "page" id = "createAccount">
Expand Down Expand Up @@ -125,6 +128,7 @@ <h3 style="width:75%">${na}</h3>
<div data-role = "button" id = "createAddress_btn" data-icon = "check">Create</div>
</div>
</div>

<div id="restDetails" data-role="page">
<div data-role="header"><h1 id="restName"></h1></div>
<div data-role="content">
Expand All @@ -148,6 +152,12 @@ <h3>Restaurant Information</h3>
</fieldset>
</div>
</div>
<div data-role = "page" id = "selectAddress">
<div data-role = "header"><h1>Select Address</h1></div>
<div data-role = "content">
<ul data-role = "listview" id = "addressList">

</ul>
</div>
</div>
</body>
Expand Down
69 changes: 39 additions & 30 deletions assets/www/script/Ordrin.js
Expand Up @@ -31,7 +31,7 @@ Ordrin = {
},


_apiRequest: function(api, request, func, params) {
_apiRequest: function(api, request, func, errorFunc, params) {
var paramsURL = ""; // params strung into URL
var userAuth = 0; // whether or not user authentication is required for request (sets header with proxy, adds to query string with JSONP)
var outForm = []; // form data
Expand All @@ -46,7 +46,7 @@ Ordrin = {
}

// string together all params for either submission
for (var i = 3; i < arguments.length; i++) {
for (var i = 4; i < arguments.length; i++) {
if (!/[=]/.test(arguments[i])) {
paramsURL = paramsURL + "/" + arguments[i];
} else {
Expand Down Expand Up @@ -79,7 +79,16 @@ Ordrin = {

// feed data into callback function
if (api != "o" && func) {
this._xmlhttp.onreadystatechange = function() { if (this.readyState==4 && this.status==200) { func(this.responseText); console.log("response: " + this.responseText);} };
this._xmlhttp.onreadystatechange = function() {
if (this.readyState == 4){
if (this.status == 200){
func(this.responseText);
console.log("response: " + this.responseText);
}else{
errorFunc(this.status);
}
}
};
}

// set developer key header
Expand All @@ -91,7 +100,7 @@ Ordrin = {
this._xmlhttp.setRequestHeader("X-NAAMA-AUTHENTICATION", 'username="' + Ordrin.u.currEmail + '", response="' + hashcode + '", version="1"');
}
this._xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

// send out the submission (with form data if present)
if (outForm) {
this._xmlhttp.send(outForm);
Expand Down Expand Up @@ -153,17 +162,17 @@ Ordrin = {

// Restaurant API
r: {
deliveryList: function(dTime, addr, func) {
deliveryList: function(dTime, addr, func, errorFunc) {
if (!(dTime instanceof Date)) { Ordrin._errs.push("Ordrin.r.deliveryList - argument type - date argument provided must be provided as Date object (standard Javascript object)"); }
if (!(addr instanceof Address)) { Ordrin._errs.push("Ordrin.r.deliveryList - argument type - address provided must be provided as Address object (included in Ordrin JS API)"); }
for (var i=0;i<3;i++) {
if (arguments[i] == "" || arguments[i] == null || typeof arguments[i] === "undefined") { Ordrin._errs.push("Ordrin.r.deliveryList - validation - all arguments required; no null values allowed (arguments: Date object, Address object, callback function)"); }
}
addr.validate();

Ordrin._apiRequest("r", "dl", func, dTime._convertForAPI(), addr._convertForAPI());
Ordrin._apiRequest("r", "dl", func, errorFunc, dTime._convertForAPI(), addr._convertForAPI());
},
deliveryCheck: function(restID, dTime, addr, func) {
deliveryCheck: function(restID, dTime, addr, func, errorFunc) {
if (!(dTime instanceof Date)) { Ordrin._errs.push("Ordrin.r.deliveryCheck - argument type - date provided must be provided as Date object (standard JS object)"); }
if (!(addr instanceof Address)) { Ordrin._errs.push("Ordrin.r.deliveryCheck - argument type - address provided must be provided as Address object (included in Ordrin JS API)"); }
if (!Ordrin.checkNums.test(restID)) { Ordrin._errs.push("Ordrin.r.deliveryCheck - validation - restaurant ID must be provided and numerical"); }
Expand All @@ -172,9 +181,9 @@ Ordrin = {
}
addr.validate();

Ordrin._apiRequest("r", "dc", func, restID, dTime._convertForAPI(), addr._convertForAPI());
Ordrin._apiRequest("r", "dc", func, errorFunc, restID, dTime._convertForAPI(), addr._convertForAPI());
},
deliveryFee: function(restID, subtotal, tip, dTime, addr, func) {
deliveryFee: function(restID, subtotal, tip, dTime, addr, func, errorFunc) {
if (!(dTime instanceof Date)) { Ordrin._errs.push("Ordrin.r.deliveryFee - argument type - date provided must be provided as Date object (standard JS object)"); }
if (!(addr instanceof Address)) { Ordrin._errs.push("Ordrin.r.deliveryFee - argument type - address provided must be provided as Address object (included in Ordrin JS API)"); }
if (!(subtotal instanceof Money)) { Ordrin._errs.push("Ordrin.r.deliveryFee - argument type - subtotal must be provided as Money object (included in Ordrin JS API)"); }
Expand All @@ -186,15 +195,15 @@ Ordrin = {
addr.validate();

console.log(Ordrin._errs);
Ordrin._apiRequest("r", "fee", func, restID, subtotal._convertForAPI(), tip._convertForAPI(), dTime._convertForAPI(), addr._convertForAPI());
Ordrin._apiRequest("r", "fee", func, errorFunc, restID, subtotal._convertForAPI(), tip._convertForAPI(), dTime._convertForAPI(), addr._convertForAPI());
},
details: function(restaurantID, func) {
details: function(restaurantID, func, errorFunc) {
if (!Ordrin.checkNums.test(restaurantID)) { Ordrin._errs.push("Ordrin.r.details - validation - restaurant ID must be provided and numerical"); }
for (var i=0;i<2;i++) {
if (arguments[i] == "" || arguments[i] == null || typeof arguments[i] === "undefined") { Ordrin._errs.push("Ordrin.r.details - validation - all arguments required for function; no null values allowed (restaurant ID and callback function)"); }
}

Ordrin._apiRequest("r", "rd", func, restaurantID);
Ordrin._apiRequest("r", "rd", func, errorFunc, restaurantID);
}
},

Expand Down Expand Up @@ -356,13 +365,13 @@ Ordrin = {
currEmail: "",
currPass: "",

makeAcct: function(email, password, firstName, lastName, func) {
makeAcct: function(email, password, firstName, lastName, func, errorFunc) {
for (var i=0;i<5;i++) {
if (arguments[i] == "" || arguments[i] == null || typeof arguments[i] === "undefined") { Ordrin._errs.push("Ordrin.u.makeAcct - validation - all arguments required for function; no null values allowed (arguments: email, password, first name, last name, and callback function)"); }
}
if (!Ordrin.checkEmail(email)) { Ordrin._errs.push("Ordrin.u.makeAcct - validation - email (improperly formatted)"); }

Ordrin._apiRequest("uP", "u", func, email, "first_name=" + firstName, "last_name=" + lastName, "password=" + password); // password needs to be SHA encoded in later versions
Ordrin._apiRequest("uP", "u", func, errorFunc, email, "first_name=" + firstName, "last_name=" + lastName, "password=" + password); // password needs to be SHA encoded in later versions
},
setCurrAcct: function(email, password) {
for (var i=0;i<2;i++) {
Expand All @@ -373,17 +382,17 @@ Ordrin = {
this.currEmail = email;
this.currPass = password;
},
getAcct: function(func) {
getAcct: function(func, errorFunc) {
for (var i=0;i<1;i++) {
if (arguments[i] == "" || arguments[i] == null || typeof arguments[i] === "undefined") { Ordrin._errs.push("Ordrin.u.getAcct - validation - all arguments required for function; no null values allowed (callback function)"); }
}

Ordrin._apiRequest("uG", "u", func, this.currEmail);
Ordrin._apiRequest("uG", "u", func, errorFunc, this.currEmail);
},
getAddress: function(nickname, func) {
getAddress: function(nickname, func, errorFunc) {
if (typeof arguments === "undefined") { Ordrin._errs.push("Ordrin.u.getAddress - validation - no arguments provided; no null values allowed (need nickname to grab a particular address or blank ('') to grab all in first argument, callback function in second)"); }

if (nickname) { Ordrin._apiRequest("uG", "u", func, this.currEmail, "addrs", nickname); } else { Ordrin._apiRequest("uG", "u", func, this.currEmail, "addrs"); }
if (nickname) { Ordrin._apiRequest("uG", "u", func, errorFunc, this.currEmail, "addrs", nickname); } else { Ordrin._apiRequest("uG", "u", func, errorFunc, this.currEmail, "addrs"); }
},
updateAddress: function(addr, func) {
if (!(addr instanceof Address)) { Ordrin._errs.push("Ordrin.u.updateAddress - argument type - address provided must be provided as Address object (included in Ordrin JS API)"); }
Expand All @@ -392,21 +401,21 @@ Ordrin = {
}

addr.validate();
Ordrin._apiRequest("uPu", "u", func, this.currEmail, "addrs", addr.nick, "addr=" + addr.street, "addr2=" + addr.street2, "city=" + addr.city, "state=" + addr.state, "zip=" + addr.zip, "phone=" + addr.phone);
Ordrin._apiRequest("uPu", "u", func, errorFunc, this.currEmail, "addrs", addr.nick, "addr=" + addr.street, "addr2=" + addr.street2, "city=" + addr.city, "state=" + addr.state, "zip=" + addr.zip, "phone=" + addr.phone);
},
deleteAddress: function(nickname, func) {
for (var i=0;i<2;i++) {
if (arguments[i] == "" || arguments[i] == null || typeof arguments[i] === "undefined") { Ordrin._errs.push("Ordrin.u.deleteAddress - validation - all arguments required for function; no null values allowed "); }
}

Ordrin._apiRequest("uD", "u", func, this.currEmail, "addrs", nickname);
Ordrin._apiRequest("uD", "u", func, errorFunc, this.currEmail, "addrs", nickname);
},
getCard: function(nickname, func) {
getCard: function(nickname, func, errorFunc) {
if (typeof arguments === "undefined") { Ordrin._errs.push("Ordrin.u.getCard - validation - no arguments provided; no null values allowed (need nickname to grab a particular card or blank ('') to grab all in first argument, callback function in second)"); }

if (nickname) { Ordrin._apiRequest("uG", "u", func, this.currEmail, "ccs", nickname); } else { Ordrin._apiRequest("uG", "u", func, this.currEmail, "ccs"); }
if (nickname) { Ordrin._apiRequest("uG", "u", func, errorFunc, this.currEmail, "ccs", nickname); } else { Ordrin._apiRequest("uG", "u", func, errorFunc, this.currEmail, "ccs"); }
},
updateCard: function(nickname, name, number, cvc, expiryMonth, expiryYear, addr, func) {
updateCard: function(nickname, name, number, cvc, expiryMonth, expiryYear, addr, func, errorFunc) {
if (!Ordrin.checkCC(number)) { Ordrin._errs.push("Ordrin.o.updateCard - validation - credit card number (invalid)"); }
if (!Ordrin.checkNums(cvc)) { Ordrin._errs.push("Ordrin.o.updateCard - validation - credit card security code (invalid)"); }
if (!(addr instanceof Address)) { Ordrin._errs.push("Ordrin.u.updateCard - argument type - address provided must be provided as Address object (included in Ordrin JS API)"); }
Expand All @@ -415,26 +424,26 @@ Ordrin = {
}
addr.validate();

Ordrin._apiRequest("uPu", "u", func, this.currEmail, "ccs", nickname, "name=" + name, "number=" + number, "cvc=" + cvc, "expiry_month=" + expiryMonth, "expiry_year=" + expiryYear, "bill_addr=" + addr.street, "bill_addr2=" + addr.street2, "bill_city=" + addr.city, "bill_state=" + addr.state, "bill_zip=" + addr.zip);
Ordrin._apiRequest("uPu", "u", func, errorFunc, this.currEmail, "ccs", nickname, "name=" + name, "number=" + number, "cvc=" + cvc, "expiry_month=" + expiryMonth, "expiry_year=" + expiryYear, "bill_addr=" + addr.street, "bill_addr2=" + addr.street2, "bill_city=" + addr.city, "bill_state=" + addr.state, "bill_zip=" + addr.zip);
},
deleteCard: function(nickname, func) {
deleteCard: function(nickname, func, errorFunc) {
for (var i=0;i<2;i++) {
if (arguments[i] == "" || arguments[i] == null || typeof arguments[i] === "undefined") { Ordrin._errs.push("Ordrin.u.deleteCard - validation - all arguments required for function (no blank, null, or undefined values allowed)"); }
}

Ordrin._apiRequest("uD", "u", func, this.currEmail, "ccs", nickname);
Ordrin._apiRequest("uD", "u", func, errorFunc, this.currEmail, "ccs", nickname);
},
orderHistory: function(orderID, func) {
orderHistory: function(orderID, func, errorFunc) {
if (typeof arguments === "undefined") { Ordrin._errs.push("Ordrin.u.orderHistory - validation - no arguments provided (need order ID for particular order or blank ('') to grab all in first argument, callback in second)"); }

if (orderID) { Ordrin._apiRequest("uG", "u", func, this.currEmail, "order", orderID); } else { Ordrin._apiRequest("uG", "u", func, this.currEmail, "orders"); }
if (orderID) { Ordrin._apiRequest("uG", "u", func, errorFunc, this.currEmail, "order", orderID); } else { Ordrin._apiRequest("uG", "u", func, errorFunc, this.currEmail, "orders"); }
},
updatePassword: function(password, func) {
updatePassword: function(password, func, errorFunc) {
for (var i=0;i<2;i++) {
if (arguments[i] == "" || arguments[i] == null || typeof arguments[i] === "undefined") { Ordrin._errs.push("Ordrin.u.updatePassword - validation - all arguments required for function (no blank, null, or undefined values allowed"); }
}

Ordrin._apiRequest("uPu", "u", func, this.currEmail, "password", "password=" + ordrin_SHA256(password));
Ordrin._apiRequest("uPu", "u", func, errorFunc, this.currEmail, "password", "password=" + ordrin_SHA256(password));
this.currPass = password;
}
}
Expand Down

0 comments on commit 5374292

Please sign in to comment.