PageSourceSearch

https://elamed.com/local/templates/.default/components/bitrix/sale.basket.basket/.default/js/action-pool.js

js elamed.com collected 2026-09-24 10:13:12 UTC 7,420 bytes, 261 lines download raw bytes

1;(function () {
2  'use strict';
3
4  BX.namespace('BX.Sale.BasketActionPool');
5
6  BX.Sale.BasketActionPool = function (component) {
7    this.component = component;
8
9    this.requestProcessing = false;
10    this.updateTimer = null;
11
12    this.isBasketRefreshed = this.component.params.DEFERRED_REFRESH !== 'Y';
13    this.needFullRecalculation = this.component.params.DEFERRED_REFRESH === 'Y';
14
15    this.pool = {};
16    this.lastActualPool = {};
17
18    this.approvedAction = ['QUANTITY', 'DELETE', 'RESTORE', 'DELAY', 'OFFER', 'MERGE_OFFER'];
19
20    this.switchTimer();
21  };
22
23  BX.Sale.BasketActionPool.prototype.setRefreshStatus = function (status) {
24    this.isBasketRefreshed = !!status;
25  };
26
27  BX.Sale.BasketActionPool.prototype.getRefreshStatus = function () {
28    return this.isBasketRefreshed;
29  };
30
31  BX.Sale.BasketActionPool.prototype.isItemInPool = function (itemId) {
32    return !!this.pool[itemId];
33  };
34
35  BX.Sale.BasketActionPool.prototype.clearLastActualQuantityPool = function (itemId) {
36    this.lastActualPool[itemId] && delete this.lastActualPool[itemId].QUANTITY;
37  };
38
39  BX.Sale.BasketActionPool.prototype.checkItemPoolBefore = function (itemId) {
40    if (!itemId)
41      return;
42
43    this.pool[itemId] = this.pool[itemId] || {};
44  };
45
46  BX.Sale.BasketActionPool.prototype.checkItemPoolAfter = function (itemId) {
47    if (!itemId || !this.pool[itemId])
48      return;
49
50    if (Object.keys(this.pool[itemId]).length === 0) {
51      delete this.pool[itemId];
52    }
53  };
54
55  BX.Sale.BasketActionPool.prototype.addCoupon = function (coupon) {
56    this.pool.COUPON = coupon;
57
58    this.switchTimer();
59  };
60
61  BX.Sale.BasketActionPool.prototype.removeCoupon = function (coupon) {
62    this.checkItemPoolBefore('REMOVE_COUPON');
63
64    this.pool.REMOVE_COUPON[coupon] = coupon;
65
66    this.switchTimer();
67  };
68
69  BX.Sale.BasketActionPool.prototype.changeQuantity = function (itemId, quantity, oldQuantity) {
70    this.checkItemPoolBefore(itemId);
71    ;
72    if (
73      (this.lastActualPool[itemId] && this.lastActualPool[itemId].QUANTITY !== quantity)
74      || (!this.lastActualPool[itemId] && quantity !== oldQuantity)
75    ) {
76      this.pool[itemId].QUANTITY = quantity;
77    } else {
78      this.pool[itemId] && delete this.pool[itemId].QUANTITY;
79    }
80
81    this.checkItemPoolAfter(itemId);
82    this.switchTimer();
83  };
84
85  BX.Sale.BasketActionPool.prototype.deleteItem = function (itemId) {
86    this.checkItemPoolBefore(itemId);
87
88    if (this.pool[itemId].RESTORE) {
89      delete this.pool[itemId].RESTORE;
90    } else {
91      this.pool[itemId].DELETE = 'Y';
92    }
93
94    this.checkItemPoolAfter(itemId);
95    this.switchTimer();
96  };
97
98  BX.Sale.BasketActionPool.prototype.restoreItem = function (itemId, itemData) {
99    this.checkItemPoolBefore(itemId);
100
101    if (this.pool[itemId].DELETE === 'Y') {
102      delete this.pool[itemId].DELETE;
103    } else {
104      this.pool[itemId].RESTORE = itemData;
105    }
106
107    this.checkItemPoolAfter(itemId);
108    this.switchTimer();
109  };
110
111  BX.Sale.BasketActionPool.prototype.addDelayed = function (itemId) {
112    this.checkItemPoolBefore(itemId);
113
114    this.pool[itemId].DELAY = 'Y';
115
116    this.checkItemPoolAfter(itemId);
117    this.switchTimer();
118  };
119
120  BX.Sale.BasketActionPool.prototype.removeDelayed = function (itemId) {
121    this.checkItemPoolBefore(itemId);
122
123    this.pool[itemId].DELAY = 'N';
124
125    this.checkItemPoolAfter(itemId);
126    this.switchTimer();
127  };
128
129  BX.Sale.BasketActionPool.prototype.changeSku = function (itemId, props, oldProps) {
130    if (JSON.stringify(props) !== JSON.stringify(oldProps)) {
131      this.checkItemPoolBefore(itemId);
132      this.pool[itemId].OFFER = props;
133    } else {
134      this.pool[itemId] && delete this.pool[itemId].OFFER;
135      this.checkItemPoolAfter(itemId);
136    }
137
138    this.switchTimer();
139  };
140
141  BX.Sale.BasketActionPool.prototype.mergeSku = function (itemId) {
142    this.checkItemPoolBefore(itemId);
143    this.pool[itemId].MERGE_OFFER = 'Y';
144
145    this.switchTimer();
146  };
147
148  BX.Sale.BasketActionPool.prototype.switchTimer = function () {
149    clearTimeout(this.updateTimer);
150
151    if (this.isProcessing()) {
152      return;
153    }
154
155    if (this.isPoolEmpty()) {
156      this.component.editPostponedBasketItems();
157      this.component.fireCustomEvents();
158    }
159
160    if (!this.isPoolEmpty()) {
161      this.updateTimer = setTimeout(BX.proxy(this.trySendPool, this), 300);
162    } else if (!this.getRefreshStatus()) {
163      this.trySendPool();
164    }
165  };
166
167  BX.Sale.BasketActionPool.prototype.trySendPool = function () {
168    if (this.isPoolEmpty() && this.getRefreshStatus()) {
169      return;
170    }
171
172    this.doProcessing(true);
173
174    if (!this.isPoolEmpty()) {
175      this.component.sendRequest('recalculateAjax', {
176        basket: this.getPoolData()
177      });
178
179      this.lastActualPool = this.pool;
180      this.pool = {};
181    } else if (!this.getRefreshStatus()) {
182      this.component.sendRequest('refreshAjax', {
183        fullRecalculation: this.needFullRecalculation ? 'Y' : 'N'
184      });
185      this.needFullRecalculation = false;
186    }
187  };
188
189  BX.Sale.BasketActionPool.prototype.getPoolData = function () {
190    var poolData = {},
191      currentPool = this.pool;
192
193    if (currentPool.COUPON) {
194      poolData.coupon = currentPool.COUPON;
195      delete currentPool.COUPON;
196    }
197
198    if (currentPool.REMOVE_COUPON) {
199      poolData.delete_coupon = currentPool.REMOVE_COUPON;
200      delete currentPool.REMOVE_COUPON;
201    }
202    let newAlmag01Quantity = 0;
203    let almag01OnPage = null;
204    for (var id in currentPool) {
205      let currentItem = document.querySelector(`.js-basket-item[data-id="${id}"]`);
206      if (currentItem) {
207        if (currentItem.dataset.productId == 981 || currentItem.dataset.productId == 983) {
208          let items = document.querySelectorAll('.js-basket-item');
209          if (currentPool[id]['QUANTITY']) {
210            newAlmag01Quantity += parseInt(currentPool[id]['QUANTITY'], 10);
211          }
212          if (items) {
213            items.forEach(item => {
214              if (item.dataset.productId != currentItem.dataset.productId)
215                if (item.dataset.productId == 981 || item.dataset.productId == 983) {
216                  if (item.querySelector('.basket-item__input').value) {
217                    newAlmag01Quantity += parseInt(item.querySelector('.basket-item__input').value, 10);
218                  }
219                }
220              if (item.dataset.productId == 43476) {
221                almag01OnPage = item.dataset.id;
222              }
223            });
224          }
225        }
226      }
227    }
228    if (almag01OnPage) {
229      currentPool[almag01OnPage] = {'QUANTITY': newAlmag01Quantity};
230    }
231    for (var id in currentPool) {
232      if (currentPool.hasOwnProperty(id)) {
233        for (var action in currentPool[id]) {
234          if (currentPool[id].hasOwnProperty(action) && BX.util.in_array(action, this.approvedAction)) {
235            poolData[action + '_' + id] = currentPool[id][action];
236          }
237        }
238      }
239    }
240
241    return poolData;
242  };
243
244  BX.Sale.BasketActionPool.prototype.isPoolEmpty = function () {
245    return Object.keys(this.pool).length === 0;
246  };
247
248  BX.Sale.BasketActionPool.prototype.doProcessing = function (state) {
249    this.requestProcessing = state === true;
250
251    if (this.requestProcessing) {
252      this.component.startLoader();
253    } else {
254      this.component.endLoader();
255    }
256  };
257
258  BX.Sale.BasketActionPool.prototype.isProcessing = function () {
259    return this.requestProcessing === true;
260  };
261})();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.