summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2015-11-25 04:08:39 -0500
committerJules Laplace <jules@okfoc.us>2015-11-25 04:08:39 -0500
commitf0c551933c5e725b980014b559d757bee99d0536 (patch)
treeba8f090c42934f3ef601eb8d0e42b4398242fc68
parente024c35a2584f5d975b3b4f8fe942bb8e35b6e47 (diff)
fix auth bugs pt 1
-rw-r--r--StoneIsland/www/css/cart.css1
-rw-r--r--StoneIsland/www/index.html18
-rw-r--r--StoneIsland/www/js/lib/account/AccountView.js2
-rw-r--r--StoneIsland/www/js/lib/auth/LogoutView.js3
-rw-r--r--StoneIsland/www/js/lib/cart/CartSummary.js18
-rw-r--r--StoneIsland/www/js/lib/cart/CartView.js14
-rw-r--r--StoneIsland/www/js/lib/nav/HeaderView.js2
-rw-r--r--StoneIsland/www/js/lib/products/ProductView.js27
-rw-r--r--StoneIsland/www/js/lib/view/Router.js (renamed from StoneIsland/www/js/vendor/view/router.js)0
-rw-r--r--StoneIsland/www/js/lib/view/Scrollable.js (renamed from StoneIsland/www/js/vendor/view/scrollable.js)0
-rw-r--r--StoneIsland/www/js/lib/view/Serializable.js (renamed from StoneIsland/www/js/vendor/view/serializable.js)0
-rw-r--r--StoneIsland/www/js/lib/view/View.js (renamed from StoneIsland/www/js/vendor/view/view.js)0
-rw-r--r--StoneIsland/www/js/sdk/auth.js14
-rw-r--r--proxy/index.js3
14 files changed, 62 insertions, 40 deletions
diff --git a/StoneIsland/www/css/cart.css b/StoneIsland/www/css/cart.css
index bc5088d5..7b0df653 100644
--- a/StoneIsland/www/css/cart.css
+++ b/StoneIsland/www/css/cart.css
@@ -51,6 +51,7 @@ border-right: 1px solid #bbb
.full .cart_body { display: block; }
.empty .cart_empty { display: block; }
+#cart h1 span { display: none }
.cart_body {
display: none;
}
diff --git a/StoneIsland/www/index.html b/StoneIsland/www/index.html
index aeb1eb61..84e21692 100644
--- a/StoneIsland/www/index.html
+++ b/StoneIsland/www/index.html
@@ -535,7 +535,14 @@
<!-- CART ================================================ -->
<div id="cart">
- <h1>YOUR CART / <span class="itemcount"></h1>
+ <h1>
+ <span class="full_msg">
+ YOUR CART / <span class="itemcount"></span>
+ </span>
+ <span class="empty_msg">
+ YOUR CART IS EMPTY
+ </span>
+ </h1>
<div class="steps">
<span class="summary_step">SUMMARY</span>
@@ -800,10 +807,6 @@
<script src="js/vendor/promise.js"></script>
<script src="js/vendor/flickity.pkgd.js"></script>
<script src="js/vendor/util.js"></script>
-<script src="js/vendor/view/view.js"></script>
-<script src="js/vendor/view/router.js"></script>
-<script src="js/vendor/view/scrollable.js"></script>
-<script src="js/vendor/view/serializable.js"></script>
<script src="js/sdk/_sdk.js"></script>
<script src="js/sdk/account.js"></script>
@@ -814,6 +817,11 @@
<script src="js/sdk/product.js"></script>
<script src="js/sdk/shipping.js"></script>
+<script src="js/lib/view/view.js"></script>
+<script src="js/lib/view/router.js"></script>
+<script src="js/lib/view/scrollable.js"></script>
+<script src="js/lib/view/serializable.js"></script>
+
<script src="js/lib/cart/CartView.js"></script>
<script src="js/lib/cart/CartPayment.js"></script>
<script src="js/lib/cart/CartShipping.js"></script>
diff --git a/StoneIsland/www/js/lib/account/AccountView.js b/StoneIsland/www/js/lib/account/AccountView.js
index cbd9a9c6..ddca9666 100644
--- a/StoneIsland/www/js/lib/account/AccountView.js
+++ b/StoneIsland/www/js/lib/account/AccountView.js
@@ -48,10 +48,12 @@ var AccountView = View.extend({
cb && cb()
}
if ( ! auth.has_cart() ) {
+ console.log("VV make cart")
auth.create_cart(auth.add_deferred_product_to_cart)
}
else {
if (auth.deferred_product) {
+ console.log("VV got def prod", auth.deferred_product)
auth.add_deferred_product_to_cart()
}
else {
diff --git a/StoneIsland/www/js/lib/auth/LogoutView.js b/StoneIsland/www/js/lib/auth/LogoutView.js
index 735c0242..481dcb8d 100644
--- a/StoneIsland/www/js/lib/auth/LogoutView.js
+++ b/StoneIsland/www/js/lib/auth/LogoutView.js
@@ -7,9 +7,10 @@ var LogoutView = View.extend({
show: function(){
document.body.className = "logout"
+ app.header.set_cart_count(0)
app.footer.hide()
+ auth.log_out()
app.account.logged_out()
- auth.clear_user()
},
}) \ No newline at end of file
diff --git a/StoneIsland/www/js/lib/cart/CartSummary.js b/StoneIsland/www/js/lib/cart/CartSummary.js
index 209e3102..05842380 100644
--- a/StoneIsland/www/js/lib/cart/CartSummary.js
+++ b/StoneIsland/www/js/lib/cart/CartSummary.js
@@ -110,21 +110,21 @@ var CartSummary = ScrollableView.extend({
.replace(/{{price}}/, as_cash(details.Item.Price.DiscountedPrice))
$el.data("price", details.Item.Price.DiscountedPrice)
$el.html(t)
- this.deferScrollToTop()
+ this.refreshScroller()
}.bind(this))
}.bind(this))
this.updateTotals()
this.el.className = "full"
- this.deferScrollToTop()
+ this.refreshScroller()
},
updateCounts: function(){
- app.header.set_cart_count(this.data.Cart.Items.length)
- this.parent.$itemcount.html(pluralize(this.data.Cart.Items.length, "ITEM", "S"))
+ app.header.set_cart_count( this.data.Cart.Items.length )
+ this.parent.setHeaderCount( this.data.Cart.Items.length )
},
-
+
updateTotals: function(){
var subtotal = this.data.Cart.Totals.TotalWithoutPromotions
var shipping_cost = this.data.Cart.DeliveryMethod.Selected.Amount.Total
@@ -140,6 +140,7 @@ var CartSummary = ScrollableView.extend({
empty: function(){
app.footer.hide()
app.header.set_cart_count(0)
+ this.parent.setHeaderCount( 0 )
this.parent.$itemcount.html("0 ITEMS")
this.el.className = "empty"
},
@@ -155,9 +156,9 @@ var CartSummary = ScrollableView.extend({
remove_item: function(e){
var $el = $( e.currentTarget ).closest(".cart_item_row")
var data = $el.data()
- data.Cart.Totals.TotalWithoutPromotions -= data.price
- data.Cart.Totals.TotalToPay -= data.price
-
+
+ this.data.Cart.Totals.TotalWithoutPromotions -= data.price
+ this.data.Cart.Totals.TotalToPay -= data.price
this.data.Cart.Items = this.data.Cart.Items.filter(function(item){
return ( item['Code10'] !== data.code || item['Size'] !== data.size)
})
@@ -165,6 +166,7 @@ var CartSummary = ScrollableView.extend({
this.updateTotals()
this.updateCounts()
$el.remove()
+ this.refreshScroller()
if (this.data.Cart.Items.length == 0) {
this.empty()
diff --git a/StoneIsland/www/js/lib/cart/CartView.js b/StoneIsland/www/js/lib/cart/CartView.js
index 8bea43dc..b57caadd 100644
--- a/StoneIsland/www/js/lib/cart/CartView.js
+++ b/StoneIsland/www/js/lib/cart/CartView.js
@@ -15,6 +15,8 @@ var CartView = View.extend({
this.confirm = new CartConfirm ({ parent: this })
this.thanks = new CartThanks ({ parent: this })
+ this.$full_msg = this.$(".full_msg")
+ this.$empty_msg = this.$(".empty_msg")
this.$itemcount = this.$(".itemcount")
},
@@ -47,4 +49,16 @@ var CartView = View.extend({
this.payment.show()
},
+ setHeaderCount: function(n){
+ if (n) {
+ this.$itemcount.html(pluralize(n, "ITEM", "S"))
+ this.$full_msg.show()
+ this.$empty_msg.hide()
+ }
+ else {
+ this.$full_msg.hide()
+ this.$empty_msg.show()
+ }
+ },
+
}) \ No newline at end of file
diff --git a/StoneIsland/www/js/lib/nav/HeaderView.js b/StoneIsland/www/js/lib/nav/HeaderView.js
index 7563be2d..f4b3f76e 100644
--- a/StoneIsland/www/js/lib/nav/HeaderView.js
+++ b/StoneIsland/www/js/lib/nav/HeaderView.js
@@ -43,7 +43,7 @@ var HeaderView = View.extend({
count: 0,
set_cart_count: function(n){
this.count = n
- this.$cart_count.html(n)
+ this.$cart_count.html(n || " ")
},
increment_cart_count: function(){
this.$cart_count.html( ++this.count )
diff --git a/StoneIsland/www/js/lib/products/ProductView.js b/StoneIsland/www/js/lib/products/ProductView.js
index c99ff0ab..bd28955f 100644
--- a/StoneIsland/www/js/lib/products/ProductView.js
+++ b/StoneIsland/www/js/lib/products/ProductView.js
@@ -205,27 +205,14 @@ var ProductView = ScrollableView.extend({
// ADD TO CART
save: function(){
- auth.deferred_product = { Size: this.size, Code10: this.code }
- if ( ! auth.logged_in() ) {
- app.router.go("account/login")
- app.last_view = app.cart
- }
- else if ( ! auth.has_cart() ) {
- auth.create_cart(function(){
- auth.add_deferred_product_to_cart(function(){
- app.router.go("cart")
- })
- })
- }
- else {
- auth.add_deferred_product_to_cart(function(){
- app.router.go("cart")
- })
- }
+ this.add_to_cart({ route: false })
},
-
// BUY NOW
cancel: function(){
+ this.add_to_cart({ route: true })
+ },
+
+ add_to_cart: function(opt){
auth.deferred_product = { Size: this.size, Code10: this.code }
if ( ! auth.logged_in() ) {
app.router.go("account/login")
@@ -240,7 +227,9 @@ var ProductView = ScrollableView.extend({
}
else {
auth.add_deferred_product_to_cart(function(){
- app.router.go("cart")
+ if (opt.route) {
+ app.router.go("cart")
+ }
})
}
},
diff --git a/StoneIsland/www/js/vendor/view/router.js b/StoneIsland/www/js/lib/view/Router.js
index a8ec331f..a8ec331f 100644
--- a/StoneIsland/www/js/vendor/view/router.js
+++ b/StoneIsland/www/js/lib/view/Router.js
diff --git a/StoneIsland/www/js/vendor/view/scrollable.js b/StoneIsland/www/js/lib/view/Scrollable.js
index 7cd96f89..7cd96f89 100644
--- a/StoneIsland/www/js/vendor/view/scrollable.js
+++ b/StoneIsland/www/js/lib/view/Scrollable.js
diff --git a/StoneIsland/www/js/vendor/view/serializable.js b/StoneIsland/www/js/lib/view/Serializable.js
index e9459229..e9459229 100644
--- a/StoneIsland/www/js/vendor/view/serializable.js
+++ b/StoneIsland/www/js/lib/view/Serializable.js
diff --git a/StoneIsland/www/js/vendor/view/view.js b/StoneIsland/www/js/lib/view/View.js
index 41638ab7..41638ab7 100644
--- a/StoneIsland/www/js/vendor/view/view.js
+++ b/StoneIsland/www/js/lib/view/View.js
diff --git a/StoneIsland/www/js/sdk/auth.js b/StoneIsland/www/js/sdk/auth.js
index 8a72dd46..87ce60ea 100644
--- a/StoneIsland/www/js/sdk/auth.js
+++ b/StoneIsland/www/js/sdk/auth.js
@@ -95,15 +95,20 @@ var auth = sdk.auth = (function(){
auth.add_deferred_product_to_cart = function(cb){
// auth.deferred_product
if (! auth.deferred_product) {
+ console.log("VV NO DEF PROD")
cb && cb()
return
}
sdk.cart.add_item({
data: auth.deferred_product,
success: function(){
- console.log("ADDED")
+ console.log("ADDED ITEM")
cb && cb()
- }
+ },
+ error: function(data){
+ console.log("ERROR ADDING ITEM", data)
+ cb && cb()
+ },
})
auth.deferred_product = null
app.header.increment_cart_count()
@@ -112,13 +117,12 @@ var auth = sdk.auth = (function(){
auth.log_out = function(){
auth.clear_user()
auth.clear_cart()
- auth.view_logged_out()
}
auth.logged_in = function(){
- return (auth.user_id !== -1) && (auth.user_id !== "undefined")
+ return (auth.user_id && auth.user_id !== -1 && auth.user_id !== "undefined")
}
auth.has_cart = function(){
- return (sdk.cart.id !== -1) && (sdk.cart.id !== "undefined")
+ return (sdk.cart.id && sdk.cart.id !== -1 && sdk.cart.id !== "undefined")
}
return auth
diff --git a/proxy/index.js b/proxy/index.js
index cac25fd1..425f97f6 100644
--- a/proxy/index.js
+++ b/proxy/index.js
@@ -8,6 +8,7 @@ var PORT = 9090
var cache = {}
var DEBUG = false
+var USE_CACHE = false
var server = http.createServer().listen(PORT, function(){
console.log('Proxy listening on: http://lvh.me:%s', PORT)
@@ -26,7 +27,7 @@ server.on('request', function (req, res){
console.log(req.method, req.url)
- if (req.method == 'GET' && req.url in cache) {
+ if (USE_CACHE && req.method == 'GET' && req.url in cache) {
res.writeHeader(200, { 'Content-type': 'application/json' })
res.end(cache[req.url])
return