summaryrefslogtreecommitdiff
path: root/StoneIsland/platforms/ios/www/js/lib/account/ShippingView.js
blob: b8b260ab3f3bbc0e101b5ea87250e61c7c8f8124 (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
71
72
73
74
75
76
var ShippingView = FormView.extend({
  
  el: "#shipping",

  action: sdk.address.add,
  
  events: {
  },
  
  test_data: {
    "Name":"name",
    "Surname":"surname",
    "Address":"address1\naddress2",
    "IsDefault":false,
    "IsBillingDefault":false,
    "IsOwner":false,
    "ZipCode":"88040",
    "City":"City",
    "Province":"NY",
    "Phone":"1234567890",
    "Mobile":"Mobile",
    "Mail":"Mail",
    "UserId": sdk.auth.user_id,
  },

  initialize: function(){
    this.$form = this.$("form")
    this.$msg = this.$(".msg")
    this.address = new AddressView ({ parent: this })
    this.scroller = new IScroll('#shipping', app.iscroll_options)
  },

  show: function(){
    if (! auth.logged_in()) { return app.router.go("intro") }
//    this.preload( this.data || this.test_data )
    app.footer.show("SAVE", "CANCEL")
    document.body.className = "shipping"
  },
  
  populate: function(data){
    this.data = data || this.data
    this.address.populate(data)
  },
  
  finalize: function(data){
    if (this.address.data && this.address.data.Id) {
      sdk.address.destroy({
        id: this.address.data.Id,
        success: function(){},
        error: function(){},
      })
    }

    data.IsDefault = "true" // this.$isDefault.prop("checked") ? "true" : "false"
    data.UserId = sdk.auth.user_id

    console.log(data)
    return data
  },
  
  success: function(data){
    app.curtain.show("loading")
    app.account.listAddresses(function(){
      app.curtain.hide("loading")
    })
  },
  
  error: function(data){
    console.log(data)
  },
  
  cancel: function(){
    app.router.go("intro")
  },

})