Blame view

frontend/web/js/artbox_basket.js 2.22 KB
cc658b4c   Yarik   Big commit
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
  var ArtboxBasket = (function () {
      function ArtboxBasket() {
          this.init(true, true);
      }
      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');
          });
      };
      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);
          });
      };
      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);
          });
      };
      ArtboxBasket.prototype.updateModal = function (modal, cart_html, show) {
          if (show === void 0) { show = false; }
          var modalBox = $('#modal_form-2');
          modalBox.html(modal);
          if (cart_html) {
              this.updateCart(cart_html);
          }
      };
      ArtboxBasket.prototype.updateCart = function (cart_html) {
          var cart = $('.question-form ');
          cart.html(cart_html);
      };
      Object.defineProperty(ArtboxBasket.prototype, "count", {
          get: function () {
              return Object.keys(this._items).length;
          },
          enumerable: true,
          configurable: true
      });
      return ArtboxBasket;
  }());
  //# sourceMappingURL=artbox_basket.js.map