PageSourceSearch

https://torens-auto.com/local/templates/torensnew/components/bitri…/torens/js/action-pool.js?16565007105918

js torens-auto.com collected 2026-09-26 04:24:24 UTC 5,918 bytes, 286 lines download raw bytes

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

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.