Blame view

frontend/web/js/artbox_basket.js 2.56 KB
4428da8c   Yarik   Almost all databa...
1
  var ArtboxBasket = (function() {
cc658b4c   Yarik   Big commit
2
3
4
      function ArtboxBasket() {
          this.init(true, true);
      }
4428da8c   Yarik   Almost all databa...
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
  
      Object.defineProperty(
          ArtboxBasket.prototype, "items", {
              get: function() {
                  return this._items;
              },
              enumerable: true,
              configurable: true
          }
      );
      ArtboxBasket.prototype.init = function(update_modal, update_cart) {
          $.get(
              '/basket', function(data) {
                  this._items = data.basket;
                  if (update_modal) {
                      this.updateModal(data.modal, false);
                  }
                  if (update_cart) {
                      this.updateCart(data.cart);
                  }
              }.bind(this), 'json'
          )
           .fail(
               function() {
                   console.error('Basket cannot be init');
               }
           );
cc658b4c   Yarik   Big commit
32
      };
4428da8c   Yarik   Almost all databa...
33
34
35
36
37
38
39
40
41
42
43
44
45
      ArtboxBasket.prototype.add = function(product_variant_id) {
          $.post(
              '/basket/add?product_variant_id=' + product_variant_id, function(data) {
                  this._items = data.basket;
                  this.updateModal(data.modal, data.cart, true);
                  showForm();
              }.bind(this), 'json'
          )
           .fail(
               function(xhr, status, error) {
                   console.error(error);
               }
           );
cc658b4c   Yarik   Big commit
46
      };
4428da8c   Yarik   Almost all databa...
47
48
49
50
51
52
53
54
55
56
57
58
59
      ArtboxBasket.prototype.remove = function(product_variant_id) {
          $.post(
              '/basket/remove?product_variant_id=' + product_variant_id, function(data) {
                  this._items = data.basket;
                  this.updateCart(data.cart);
                  // this.updateModal(data.modal, data.cart, true);
              }.bind(this), 'json'
          )
           .fail(
               function(xhr, status, error) {
                   console.error(error);
               }
           );
cc658b4c   Yarik   Big commit
60
      };
4428da8c   Yarik   Almost all databa...
61
62
63
64
      ArtboxBasket.prototype.updateModal = function(modal, cart_html, show) {
          if (show === void 0) {
              show = false;
          }
cc658b4c   Yarik   Big commit
65
66
67
68
69
70
          var modalBox = $('#modal_form-2');
          modalBox.html(modal);
          if (cart_html) {
              this.updateCart(cart_html);
          }
      };
4428da8c   Yarik   Almost all databa...
71
      ArtboxBasket.prototype.updateCart = function(cart_html) {
cc658b4c   Yarik   Big commit
72
73
74
          var cart = $('.question-form ');
          cart.html(cart_html);
      };
4428da8c   Yarik   Almost all databa...
75
76
77
78
79
80
81
82
83
      Object.defineProperty(
          ArtboxBasket.prototype, "count", {
              get: function() {
                  return Object.keys(this._items).length;
              },
              enumerable: true,
              configurable: true
          }
      );
cc658b4c   Yarik   Big commit
84
85
86
      return ArtboxBasket;
  }());
  //# sourceMappingURL=artbox_basket.js.map