summaryrefslogtreecommitdiff
path: root/StoneIsland/www/js/lib/cart/CartView.js
blob: e1ee355d7a46c4111238f931324945d00255255f (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
var CartView = View.extend({
  el: "#cart",

  events: {
    "click .summary_step": "show_summary",
    "click .shipping_step": "show_shipping",
    "click .payment_step": "show_payment",
  },

  initialize: function () {
    this.summary = new CartSummary({ parent: this });
    this.payment = new CartPayment({ parent: this });
    this.shipping = new CartShipping({ parent: this });
    this.confirm = new CartConfirm({ parent: this });
    this.thanks = new CartThanks({ parent: this });
    this.error = new CartError({ parent: this });

    this.$steps = this.$(".steps");
    this.$full_msg = this.$(".full_msg");
    this.$empty_msg = this.$(".empty_msg");
    this.$itemcount = this.$(".itemcount");
  },

  load: function () {
    app.curtain.show("loading");
    sdk.cart.get_status({
      success: function (data) {
        this.summary.data = data;
        this.summary.updateCounts();
        app.curtain.hide("loading");
      }.bind(this),
      error: function (data) {
        console.log(data);
        auth.clear_cart();
        app.curtain.hide("loading");
      },
    });
  },

  show: function () {
    if (!navigator.onLine) {
      app.closed.showElement();
      app.closed.setMessage("PLEASE GO ONLINE TO<br>VIEW YOUR CART.", "");
      return;
    }
    document.body.className = "cart";
    this.show_summary();
  },

  show_summary: function () {
    this.summary.show();
  },

  show_shipping: function () {
    this.shipping.show();
  },

  show_payment: function () {
    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();
    }
  },
});