summaryrefslogtreecommitdiff
path: root/StoneIsland/platforms/ios/www/js/lib/account/AccountView.js
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2015-11-24 20:57:41 -0500
committerJules Laplace <jules@okfoc.us>2015-11-24 20:57:41 -0500
commit612561818f907f0f9988247c82ec158ba4494986 (patch)
tree8bbc773dad7a6364cbdb8aed2ef4cab04854f49a /StoneIsland/platforms/ios/www/js/lib/account/AccountView.js
parentd548a7d02ce6349ca9a820b6824e4374b759812b (diff)
build
Diffstat (limited to 'StoneIsland/platforms/ios/www/js/lib/account/AccountView.js')
-rw-r--r--StoneIsland/platforms/ios/www/js/lib/account/AccountView.js70
1 files changed, 70 insertions, 0 deletions
diff --git a/StoneIsland/platforms/ios/www/js/lib/account/AccountView.js b/StoneIsland/platforms/ios/www/js/lib/account/AccountView.js
new file mode 100644
index 00000000..cbd9a9c6
--- /dev/null
+++ b/StoneIsland/platforms/ios/www/js/lib/account/AccountView.js
@@ -0,0 +1,70 @@
+var AccountView = View.extend({
+
+ initialize: function(){
+ },
+
+ connect: function(cb){
+ auth.init(this.ready.bind(this, cb))
+ },
+
+ ready: function(cb){
+ if (auth.logged_in()) {
+ this.logged_in(cb)
+ }
+ else {
+ this.logged_out(cb)
+ }
+ },
+
+ populateAddresses: function(data){
+ console.log("populate addresses:", data)
+ if (! data.AddressBook) {
+ console.log("no addresses")
+ return
+ }
+ // console.log(data.AddressBook)
+ data.AddressBook.addressBookItem.forEach(function(item){
+ if (item.isDefault) {
+ // populate app.shipping.address
+ }
+ else if (item.isBillingDefault) {
+ // populate app.billing.address
+ }
+ })
+ },
+
+ logged_in: function(cb){
+ sdk.address.list({
+ success: this.populateAddresses.bind(this)
+ })
+ $("#nav .login").hide()
+ $("#nav .account, #nav .logout").show()
+ if (app.last_view && app.last_view != app.login && app.last_view != app.signin && app.last_view != app.logout) {
+ app.view && app.view.hide && app.view.hide()
+ app.view = app.last_view
+ app.view.show()
+ }
+ else {
+ cb && cb()
+ }
+ if ( ! auth.has_cart() ) {
+ auth.create_cart(auth.add_deferred_product_to_cart)
+ }
+ else {
+ if (auth.deferred_product) {
+ auth.add_deferred_product_to_cart()
+ }
+ else {
+ app.cart.load()
+ }
+ }
+ },
+
+ logged_out: function(cb){
+ $("#nav .login").show()
+ $("#nav .account, #nav .logout").hide()
+ $("#nav").removeClass("account")
+ cb && cb()
+ },
+
+})