PageSourceSearch

https://aeroscreen.ru/bitrix/templates/concept_phoenix_s1/componen…/sale.order.ajax/basket_order/script.js

js aeroscreen.ru collected 2026-10-08 23:51:11 UTC 11,294 bytes, 444 lines download raw bytes

1BX.saleOrderAjax = { // bad solution, actually, a singleton at the page
2
3	BXCallAllowed: false,
4
5	options: {},
6	indexCache: {},
7	controls: {},
8
9	modes: {},
10	properties: {},
11
12	// called once, on component load
13	init: function(options)
14	{
15		var ctx = this;
16		this.options = options;
17
18		window.submitFormProxy = BX.proxy(function(){
19			ctx.submitFormProxy.apply(ctx, arguments);
20		}, this);
21
22		BX(function(){
23			ctx.initDeferredControl();
24		});
25		BX(function(){
26			ctx.BXCallAllowed = true; // unlock form refresher
27		});
28
29		this.controls.scope = BX('bx-soa-order');
30
31		// user presses "add location" when he cannot find location in popup mode
32		BX.bindDelegate(this.controls.scope, 'click', {className: '-bx-popup-set-mode-add-loc'}, function(){
33
34			var input = BX.create('input', {
35				attrs: {
36					type: 'hidden',
37					name: 'PERMANENT_MODE_STEPS',
38					value: '1'
39				}
40			});
41
42			BX.prepend(input, BX('bx-soa-order'));
43
44			ctx.BXCallAllowed = false;
45			BX.Sale.OrderAjaxComponent.sendRequest();
46		});
47	},
48
49	cleanUp: function(){
50
51		for(var k in this.properties)
52		{
53			if (this.properties.hasOwnProperty(k))
54			{
55				if(typeof this.properties[k].input != 'undefined')
56				{
57					BX.unbindAll(this.properties[k].input);
58					this.properties[k].input = null;
59				}
60
61				if(typeof this.properties[k].control != 'undefined')
62					BX.unbindAll(this.properties[k].control);
63			}
64		}
65
66		this.properties = {};
67	},
68
69	addPropertyDesc: function(desc){
70		this.properties[desc.id] = desc.attributes;
71		this.properties[desc.id].id = desc.id;
72	},
73
74	// called each time form refreshes
75	initDeferredControl: function()
76	{
77		var ctx = this,
78			k,
79			row,
80			input,
81			locPropId,
82			m,
83			control,
84			code,
85			townInputFlag,
86			adapter;
87
88		// first, init all controls
89		if(typeof window.BX.locationsDeferred != 'undefined'){
90
91			this.BXCallAllowed = false;
92
93			for(k in window.BX.locationsDeferred){
94
95				window.BX.locationsDeferred[k].call(this);
96				window.BX.locationsDeferred[k] = null;
97				delete(window.BX.locationsDeferred[k]);
98
99				this.properties[k].control = window.BX.locationSelectors[k];
100				delete(window.BX.locationSelectors[k]);
101			}
102		}
103
104		for(k in this.properties){
105
106			// zip input handling
107			if(this.properties[k].isZip){
108				row = this.controls.scope.querySelector('[data-property-id-row="'+k+'"]');
109				if(BX.type.isElementNode(row)){
110
111					input = row.querySelector('input[type="text"]');
112					if(BX.type.isElementNode(input)){
113						this.properties[k].input = input;
114
115						// set value for the first "location" property met
116						locPropId = false;
117						for(m in this.properties){
118							if(this.properties[m].type == 'LOCATION'){
119								locPropId = m;
120								break;
121							}
122						}
123
124						if(locPropId !== false){
125							BX.bindDebouncedChange(input, function(value){
126
127								var zipChangedNode = BX('ZIP_PROPERTY_CHANGED');
128								zipChangedNode && (zipChangedNode.value = 'Y');
129
130								input = null;
131								row = null;
132
133								if(BX.type.isNotEmptyString(value) && /^\s*\d+\s*$/.test(value) && value.length > 3){
134
135									ctx.getLocationsByZip(value, function(locationsData){
136										ctx.properties[locPropId].control.setValueByLocationIds(locationsData);
137									}, function(){
138										try{
139											// ctx.properties[locPropId].control.clearSelected();
140										}catch(e){}
141									});
142								}
143							});
144						}
145					}
146				}
147			}
148
149			// location handling, town property, etc...
150			if(this.properties[k].type == 'LOCATION')
151			{
152
153				if(typeof this.properties[k].control != 'undefined'){
154
155					control = this.properties[k].control; // reference to sale.location.selector.*
156					code = control.getSysCode();
157
158					// we have town property (alternative location)
159					if(typeof this.properties[k].altLocationPropId != 'undefined')
160					{
161						if(code == 'sls') // for sale.location.selector.search
162						{
163							// replace default boring "nothing found" label for popup with "-bx-popup-set-mode-add-loc" inside
164							control.replaceTemplate('nothing-found', this.options.messages.notFoundPrompt);
165						}
166
167						if(code == 'slst')  // for sale.location.selector.steps
168						{
169							(function(k, control){
170
171								// control can have "select other location" option
172								control.setOption('pseudoValues', ['other']);
173
174								// insert "other location" option to popup
175								control.bindEvent('control-before-display-page', function(adapter){
176
177									control = null;
178
179									var parentValue = adapter.getParentValue();
180
181									// you can choose "other" location only if parentNode is not root and is selectable
182									if(parentValue == this.getOption('rootNodeValue') || !this.checkCanSelectItem(parentValue))
183										return;
184
185									var controlInApater = adapter.getControl();
186
187									if(typeof controlInApater.vars.cache.nodes['other'] == 'undefined')
188									{
189										controlInApater.fillCache([{
190											CODE:		'other', 
191											DISPLAY:	ctx.options.messages.otherLocation, 
192											IS_PARENT:	false,
193											VALUE:		'other'
194										}], {
195											modifyOrigin:			true,
196											modifyOriginPosition:	'prepend'
197										});
198									}
199								});
200
201								townInputFlag = BX('LOCATION_ALT_PROP_DISPLAY_MANUAL['+parseInt(k)+']');
202
203								control.bindEvent('after-select-real-value', function(){
204
205									// some location chosen
206									if(BX.type.isDomNode(townInputFlag))
207										townInputFlag.value = '0';
208								});
209								control.bindEvent('after-select-pseudo-value', function(){
210
211									// option "other location" chosen
212									if(BX.type.isDomNode(townInputFlag))
213										townInputFlag.value = '1';
214								});
215
216								// when user click at default location or call .setValueByLocation*()
217								control.bindEvent('before-set-value', function(){
218									if(BX.type.isDomNode(townInputFlag))
219										townInputFlag.value = '0';
220								});
221
222								// restore "other location" label on the last control
223								if(BX.type.isDomNode(townInputFlag) && townInputFlag.value == '1'){
224
225									// a little hack: set "other location" text display
226									adapter = control.getAdapterAtPosition(control.getStackSize() - 1);
227
228									if(typeof adapter != 'undefined' && adapter !== null)
229										adapter.setValuePair('other', ctx.options.messages.otherLocation);
230								}
231
232							})(k, control);
233						}
234					}
235				}
236			}
237		}
238
239		this.BXCallAllowed = true;
240
241		//set location initialized flag and refresh region & property actual content
242		if (BX.Sale.OrderAjaxComponent)
243			BX.Sale.OrderAjaxComponent.locationsCompletion();
244	},
245
246	checkMode: function(propId, mode){
247
248		//if(typeof this.modes[propId] == 'undefined')
249		//	this.modes[propId] = {};
250
251		//if(typeof this.modes[propId] != 'undefined' && this.modes[propId][mode])
252		//	return true;
253
254		if(mode == 'altLocationChoosen'){
255
256			if(this.checkAbility(propId, 'canHaveAltLocation')){
257
258				var input = this.getInputByPropId(this.properties[propId].altLocationPropId);
259				var altPropId = this.properties[propId].altLocationPropId;
260
261				if(input !== false && input.value.length > 0 && !input.disabled && this.properties[altPropId].valueSource != 'default'){
262
263					//this.modes[propId][mode] = true;
264					return true;
265				}
266			}
267		}
268
269		return false;
270	},
271
272	checkAbility: function(propId, ability){
273
274		if(typeof this.properties[propId] == 'undefined')
275			this.properties[propId] = {};
276
277		if(typeof this.properties[propId].abilities == 'undefined')
278			this.properties[propId].abilities = {};
279
280		if(typeof this.properties[propId].abilities != 'undefined' && this.properties[propId].abilities[ability])
281			return true;
282
283		if(ability == 'canHaveAltLocation'){
284
285			if(this.properties[propId].type == 'LOCATION'){
286
287				// try to find corresponding alternate location prop
288				if(typeof this.properties[propId].altLocationPropId != 'undefined' && typeof this.properties[this.properties[propId].altLocationPropId]){
289
290					var altLocPropId = this.properties[propId].altLocationPropId;
291
292					if(typeof this.properties[propId].control != 'undefined' && this.properties[propId].control.getSysCode() == 'slst'){
293
294						if(this.getInputByPropId(altLocPropId) !== false){
295							this.properties[propId].abilities[ability] = true;
296							return true;
297						}
298					}
299				}
300			}
301
302		}
303
304		return false;
305	},
306
307	getInputByPropId: function(propId){
308		if(typeof this.properties[propId].input != 'undefined')
309			return this.properties[propId].input;
310
311		var row = this.getRowByPropId(propId);
312		if(BX.type.isElementNode(row)){
313			var input = row.querySelector('input[type="text"]');
314			if(BX.type.isElementNode(input)){
315				this.properties[propId].input = input;
316				return input;
317			}
318		}
319
320		return false;
321	},
322
323	getRowByPropId: function(propId){
324
325		if(typeof this.properties[propId].row != 'undefined')
326			return this.properties[propId].row;
327
328		var row = this.controls.scope.querySelector('[data-property-id-row="'+propId+'"]');
329		if(BX.type.isElementNode(row)){
330			this.properties[propId].row = row;
331			return row;
332		}
333
334		return false;
335	},
336
337	getAltLocPropByRealLocProp: function(propId){
338		if(typeof this.properties[propId].altLocationPropId != 'undefined')
339			return this.properties[this.properties[propId].altLocationPropId];
340
341		return false;
342	},
343
344	toggleProperty: function(propId, way, dontModifyRow){
345
346		var prop = this.properties[propId];
347
348		if(typeof prop.row == 'undefined')
349			prop.row = this.getRowByPropId(propId);
350
351		if(typeof prop.input == 'undefined')
352			prop.input = this.getInputByPropId(propId);
353
354		if(!way){
355			if(!dontModifyRow)
356				BX.hide(prop.row);
357			prop.input.disabled = true;
358		}else{
359			if(!dontModifyRow)
360				BX.show(prop.row);
361			prop.input.disabled = false;
362		}
363	},
364
365	submitFormProxy: function(item, control)
366	{
367		var propId = false;
368		for(var k in this.properties){
369			if(typeof this.properties[k].control != 'undefined' && this.properties[k].control == control){
370				propId = k;
371				break;
372			}
373		}
374
375		// turning LOCATION_ALT_PROP_DISPLAY_MANUAL on\off
376
377		if(item != 'other'){
378
379			if(this.BXCallAllowed){
380
381				this.BXCallAllowed = false;
382				setTimeout(function(){BX.Sale.OrderAjaxComponent.sendRequest()}, 20);
383			}
384
385		}
386	},
387
388	getPreviousAdapterSelectedNode: function(control, adapter){
389
390		var index = adapter.getIndex();
391		var prevAdapter = control.getAdapterAtPosition(index - 1);
392
393		if(typeof prevAdapter !== 'undefined' && prevAdapter != null){
394			var prevValue = prevAdapter.getControl().getValue();
395
396			if(typeof prevValue != 'undefined'){
397				var node = control.getNodeByValue(prevValue);
398
399				if(typeof node != 'undefined')
400					return node;
401
402				return false;
403			}
404		}
405
406		return false;
407	},
408	getLocationsByZip: function(value, successCallback, notFoundCallback)
409	{
410		if(typeof this.indexCache[value] != 'undefined')
411		{
412			successCallback.apply(this, [this.indexCache[value]]);
413			return;
414		}
415
416		var ctx = this;
417
418		BX.ajax({
419			url: this.options.source,
420			method: 'post',
421			dataType: 'json',
422			async: true,
423			processData: true,
424			emulateOnload: true,
425			start: true,
426			data: {'ACT': 'GET_LOCS_BY_ZIP', 'ZIP': value},
427			//cache: true,
428			onsuccess: function(result){
429				if(result.result)
430				{
431					ctx.indexCache[value] = result.data;
432					successCallback.apply(ctx, [result.data]);
433				}
434				else
435				{
436					notFoundCallback.call(ctx);
437				}
438			},
439			onfailure: function(type, e){
440				// on error do nothing
441			}
442		});
443	}
444};

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.