summaryrefslogtreecommitdiff
path: root/StoneIsland/platforms/ios/www/js/lib/account/AccountView.js
blob: cbd9a9c6fc9693fcd87cd003b9d9dbccfe887e96 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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()
  },

})