summaryrefslogtreecommitdiff
path: root/StoneIsland/www/js/lib/cart/CartSummary.js
blob: 77c40b52c2d0cdb404f7be4f37e8aa5410684f78 (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
77
78
79
80
81
82
var CartSummary = ScrollableView.extend({
  
  el: "#cart_summary",
  
  template: $("#cart_summary .template").html(),
  
  events: {
  },
  
  data: null,
  
  initialize: function(opt){
    this.parent = opt.parent
    this.$loader = this.$(".loader")
    this.$cart_body = this.$(".cart_body")
    this.$cart_empty = this.$(".cart_empty")
    this.scroller = new IScroll('#cart_summary', app.iscroll_options)
  },
  
  show: function(){
    document.body.className = "cart"
    app.cart.el.className = "summary"
    if (auth.has_cart()) {
      this.load()
    }
    else {
      this.empty()
    }
  },
  
  load: function(){
    this.$loader.show()
    sdk.cart.get_status({
      success: this.populate.bind(this),
      error: this.empty.bind(this),
    })
  },
  
  populate: function(data){
    this.data = data

    this.$loader.hide()
    app.footer.show("SHIPPING >", "CANCEL")

    console.log(data)

    app.header.set_cart_count(data.Cart.Items.length)
    console.log("HEY")
    this.parent.$itemcount.html(pluralize(data.Cart.Items.length, "ITEM", "S"))

    this.$el.removeClass("empty").addClass("full")
    this.deferScrollToTop()
  },
  
  empty: function(){
    this.$loader.hide()
    app.footer.hide()
    app.header.set_cart_count(0)
    this.parent.$itemcount.html("0 ITEMS")
    this.$el.addClass("empty").removeClass("full")
  },

  ok: function(){
    app.router.go('cart/shipping')
  },
  
  cancel: function(){
    app.router.go('intro')
  },
  
  remove_item: function(e){
    // $( e.currentTarget ).closest(".row").remove()
    sdk.cart.delete_item({
      data: {
        Code10: "",
        Size: "",
      },
    }).done(function(){
    })
  },

})