PageSourceSearch

https://www.editionspixnlove.com/modules/facebookpsconnect/views/js/module.js

js editionspixnlove.com collected 2026-10-02 06:56:05 UTC 14,884 bytes, 489 lines download raw bytes

1/*
2 * 2003-2015 Business Tech
3 *
4 *  @author    Business Tech SARL <http://www.businesstech.fr/en/contact-us>
5 *  @copyright 2003-2015 Business Tech SARL
6 */
7
8// declare main object of module
9var FpcModule = function(sName) {
10	// set name
11	this.name = sName;
12
13	// set name
14	this.oldVersion = false;
15
16	// set translated js msgs
17	this.msgs = {};
18
19	// stock error array
20	this.aError = [];
21
22	// set url of admin img
23	this.sImgUrl = '';
24
25	// set url of module's web service
26	this.sWebService = '';
27
28	// set response
29	this.response = null;
30
31	// set this in obj context
32	var oThis = this;
33
34	/*
35	 * show() method show effect and assign HTML in
36	 * User: Business Tech (www.businesstech.fr) - Contact: http://www.businesstech.fr/en/contact-us
37	 * @param string sId : container to show in
38	 * @param string sHtml : HTML to display
39	 * @return -
40	 */
41	this.show = function(sId, sHtml) {
42		$("#" + sId).html(sHtml).css('style', 'none');
43		$("#" + sId).show('fast');
44	};
45
46	/*
47	 * hide() method hide effect and delete html
48	 * User: Business Tech (www.businesstech.fr) - Contact: http://www.businesstech.fr/en/contact-us
49	 * @param string sId : container to hide in
50	 * @return -
51	 */
52	this.hide = function(sId) {
53		$("#" + sId).hide('fast', function() {
54				$("#" + sId).html('');
55			}
56		);
57	};
58
59	/*
60	 * form() method check all fields of current form and execute : XHR or submit => used for update all admin config
61	 * User: Business Tech (www.businesstech.fr) - Contact: http://www.businesstech.fr/en/contact-us
62	 * @see ajax
63	 * @param string sForm : form
64	 * @param string sURI : query params used for XHR
65	 * @param string sRequestParam : param action and type in order to send with post mode
66	 * @param string sToDisplay :
67	 * @param string sToHide : force to hide specific ID
68	 * @param bool bSubmit : used only for sending main form
69	 * @param bool bFancyBox : used only for fancybox in xhr
70	 * @param string sCallback :
71	 * @param string sErrorType :
72	 * @param string sLoadBar :
73	 * @return string : HTML returned by smarty
74	 */
75	this.form = function(sForm, sURI, sRequestParam, sToDisplay, sToHide, bSubmit, bFancyBox, sCallback, sErrorType, sLoadBar) {
76		// set loading bar
77		if (sLoadBar) {
78			$('#'+sLoadBar).show();
79		}
80
81		// set return validation
82		var aError = [];
83
84		// get all fields of form
85		var fields = $("#" + sForm).serializeArray();
86
87		// set counter
88		var iCounter = 0;
89
90		// set bIsError
91		var bIsError = false;
92
93		// check element form
94		jQuery.each(fields, function(i, field) {
95			bIsError = false;
96
97			switch(field.name) {
98				case 'id' :
99					if (field.value == '') {
100						oThis.aError[iCounter] = oThis.msgs.id;
101						bIsError = true;
102					}
103					break;
104				case 'secret' :
105					if (field.value == '') {
106						oThis.aError[iCounter] = oThis.msgs.secret;
107						bIsError = true;
108					}
109					break;
110				case 'callback' :
111					if (field.value == '') {
112						oThis.aError[iCounter] = oThis.msgs.callback;
113						bIsError = true;
114					}
115					break;
116				case 'scope' :
117					if (field.value == '') {
118						oThis.aError[iCounter] = oThis.msgs.scope;
119						bIsError = true;
120					}
121					break;
122				case 'developerKey' :
123					if (field.value == '') {
124						oThis.aError[iCounter] = oThis.msgs.developerKey;
125						bIsError = true;
126					}
127					break;
128				case 'socialEmail' :
129					if (field.value == '') {
130						oThis.aError[iCounter] = oThis.msgs.socialEmail;
131						bIsError = true;
132					}
133				case 'fbpscPrefixCode' :
134					if (field.value == '') {
135						oThis.aError[iCounter] = oThis.msgs.prefixCode;
136						bIsError = true;
137					}
138				//case 'fbpscVoucherAmount' :
139				//	if ((field.value == '' || field.value == 0) && $('#fbpscDiscountType').val() == "amount") {
140				//		console.log($('#fbpscDiscountType').val());
141				//		oThis.aError[iCounter] = oThis.msgs.voucherAmount;
142				//		bIsError = true;
143				//	}
144				//case 'fbpscVoucherPercent' :
145				//	if ((field.value == '' || field.value == 0) && $('#fbpscDiscountType').val() == "percentage" ) {
146				//		console.log($('#fbpscDiscountType').val());
147				//		oThis.aError[iCounter] = oThis.msgs.voucherPercent;
148				//		bIsError = true;
149				//	}
150				case 'fbpscApiRequestType' :
151					if (field.value == '') {
152						oThis.aError[iCounter] = oThis.msgs.apiType;
153						bIsError = true;
154					}
155					break;
156				default:
157					break;
158			}
159
160			if (($('input[name="' + field.name + '"]') != undefined || $('textarea[name="' + field.name + '"]') != undefined || $('select[name="' + field.name + '"]').length != undefined) && bIsError == true) {
161				if ($('input[name="' + field.name + '"]').length != 0) {
162					$('input[name="' + field.name + '"]').parent().addClass('has-error has-feedback');
163					$('input[name="' + field.name + '"]').append('<span class="icon-remove-sign"></span>');
164				}
165				if ($('textarea[name="' + field.name + '"]').length != 0) {
166					$('textarea[name="' + field.name + '"]').parent().addClass('has-error has-feedback');
167					$('textarea[name="' + field.name + '"]').append('<span class="icon-remove-sign"></span>');
168				}
169				if ($('select[name="' + field.name + '"]').length != 0) {
170					$('select[name="' + field.name + '"]').parent().addClass('has-error has-feedback');
171					$('select[name="' + field.name + '"]').append('<span class="icon-remove-sign"></span>');
172				}
173				++iCounter;
174			}
175		});
176
177		if (oThis.aError.length == 0 && !bIsError) {
178			// use case - Ajax request
179			if (bSubmit == undefined || bSubmit == null || !bSubmit) {
180				if (sLoadBar && sToHide != null) {
181					oThis.hide(sToHide, true);
182				}
183
184				// format object of fields in string to execute Ajax request
185				var sFormParams = $.param(fields);
186
187				if (sRequestParam != null && sRequestParam != '') {
188					sFormParams = sRequestParam + '&' + sFormParams;
189				}
190
191				// execute Ajax request
192				this.ajax(sURI, sFormParams, sToDisplay, sToHide, bFancyBox, null, sLoadBar);
193
194				return true;
195			}
196			// use case - send form
197			else {
198				// hide loading bar
199				if (sLoadBar) {
200					$('#'+sLoadBar).hide();
201				}
202				document.forms[sForm].submit();
203				return true;
204			}
205		}
206		else {
207			$('#'+sLoadBar).hide();
208		}
209		// display errors
210		this.displayError(sErrorType);
211
212		return false;
213	};
214
215	/*
216	 * ajax() method execute XHR
217	 * User: Business Tech (www.businesstech.fr) - Contact: http://www.businesstech.fr/en/contact-us
218	 * @param string sURI : query params used for XHR
219	 * @param string sParams :
220	 * @param string sToShow :
221	 * @param string sToHide :
222	 * @param bool bFancyBox : used only for fancybox in xhr
223	 * @param bool bFancyBoxActivity : used only for fancybox in xhr
224	 * @param string sLoadBar : used only for loading
225	 * @return string : HTML returned by smarty
226	 */
227this.ajax = function(sURI, sParams, sToShow, sToHide, bFancyBox, bFancyBoxActivity, sLoadBar) {
228		if(bFancyBox && bFancyBoxActivity != false) {
229			$.fancybox.showActivity();
230		}
231
232		sParams = 'sMode=xhr' + ((sParams == null || sParams == undefined) ? '' : '&' + sParams) ;
233
234		// configure XHR
235		$.ajax({
236			type : 'POST',
237			url : sURI,
238			data : sParams,
239			dataType : 'html',
240			success: function(data) {
241				// hide loading bar
242				if (sLoadBar) {
243					$('#'+sLoadBar).hide();
244				}
245				if(bFancyBox) {
246					// update fancybox content
247					$.fancybox(data);
248
249					// use case - update only widget list
250					if (sToShow == oThis.name + 'ConnectorList') {
251						oThis.ajax('' + sURI, 'sAction=display&sType=connectors', '' + sToShow + '', '' + sToHide + '');
252					}
253					// use case - update widget list and hook list
254					else if (sToShow == oThis.name + 'HookList') {
255						sToShow = sToHide = oThis.name + 'ConnectorList';
256						oThis.ajax('' + sURI + 'connectors', 'sAction=display&sType=connectors', '' + sToShow + '', '' + sToHide + '');
257						sToShow = sToHide = oThis.name + 'HookList';
258						oThis.ajax('' + sURI + 'hooks', 'sAction=display&sType=hooks', '' + sToShow + '', '' + sToHide + '');
259					}
260				}
261				else if (sToShow != null && sToHide != null) {
262					// same hide and show
263					if (sToShow == sToHide) {
264						oThis.hide('fast');
265						$('#' + sToHide).hide('fast');
266						$('#' + sToHide).empty();
267						setTimeout('', 1000);
268						oThis.show(sToShow, data);
269					}
270					else {
271						oThis.hide(sToHide);
272						setTimeout('', 1000);
273						oThis.show(sToShow, data);
274					}
275				}
276				else if (sToShow != null) {
277					oThis.show(sToShow, data);
278				}
279				else if (sToHide != null) {
280					oThis.hide(sToHide);
281				}
282				else {
283					oThis.response = data;
284				}
285			},
286			error: function(xhr, ajaxOptions, thrownError) {
287				$("#" + oThis.name + "FormError").addClass('alert error');
288				oThis.show("#" + oThis.name + "FormError", '<h3>internal error</h3>');
289			}
290		});
291	};
292
293	/*
294	 * displayError() method display errors
295	 * User: Business Tech (www.businesstech.fr) - Contact: http://www.businesstech.fr/en/contact-us
296	 * @param string sType : type of container
297	 * @return bool
298	 */
299	this.displayError = function(sType) {
300		if (oThis.aError.length != 0) {
301			var sError = '<div class="alert alert-danger"><button type="button" class="close" data-dismiss="alert">×</button><ul class="list-unstyled">';
302			for (var i = 0; i < oThis.aError.length;++i) {
303				sError += '<li>' + oThis.aError[i] + '</li>';
304			}
305			sError += '</ul></div>'
306
307			$("#" + oThis.name + sType + "Error").html(sError);
308			$("#" + oThis.name + sType + "Error").slideDown();
309
310			// flush errors
311			oThis.aError = [];
312
313			return false;
314		}
315	};
316
317	/**
318	 * changeSelect() method displays or hide related option form
319	 *
320	 * @param string sId : type of container
321	 * @param mixed mDestId
322	 * @param string sDestId2
323	 * @param string sType of second dest id
324	 * @param bool bForce
325	 * @param bool mVal
326	 */
327	this.changeSelect = function(sId, mDestId, sDestId2, sDestIdToHide, bForce, mVal) {
328		if (bForce) {
329			if (typeof mDestId == 'string') {
330				mDestId = [mDestId];
331			}
332
333			for (var i = 0; i < mDestId.length; ++i) {
334				if (mVal) {
335					$("#" + mDestId[i]).fadeIn('fast', function() {$("#" + mDestId[i]).css('display', 'block')});
336				}
337				else {
338					$("#" + mDestId[i]).fadeOut('fast');
339				}
340			}
341		}
342		else {
343			$("#" + sId).bind('change', function (event){
344				$("#" + sId + " input:checked").each(function (){
345					switch ($(this).val()) {
346						case 'true' :
347							// display option features
348							$("#" + sDestId).fadeIn('fast', function() {$("#" + sDestId).css('display', 'block')});
349							break;
350						default:
351							// hide option features
352							$("#" + sDestId).fadeOut('fast');
353
354							// set to false
355							if (sDestId2 && sDestIdToHide) {
356								$("#" + sDestId2 + " input").each(function (){
357										switch ($(this).val()) {
358											case 'false' :
359												$(this).attr('checked', 'checked');
360												// hide option features
361												$("#" + sDestIdToHide).fadeOut('fast');
362												break;
363											default:
364												$(this).attr('checked', '');
365												break;
366										}
367									}
368								);
369							}
370							break;
371					}
372				});
373			});
374		}
375	};
376
377	/**
378	 * selectAll() method select / deselect all checkbox
379	 *
380	 * @param string sId : type of container
381	 * @param string sCible : all checkbox to process
382	 */
383	this.selectAll = function(sCible, sType){
384		if (sType == 'check') {
385			$(sCible).attr('checked', true);
386		}
387		else{
388			$(sCible).attr('checked', false);
389		}
390	};
391
392	/*
393	 * updateHook() method verify all childnodes of hook list and determine position to display widget in hook
394	 * User: Business Tech (www.businesstech.fr)
395	 * @param string sURI : query params used for XHR
396	 * @param string sHookList :
397	 * @param string sToShow :
398	 * @param string sToHide :
399	 * @param bool bFancyBox : used only for fancybox in xhr
400	 * @return string : HTML returned by smarty
401	 */
402	this.updateHook = function(sURI, sHookList, sToShow, sToHide, bFancyBox) {
403		var sList = '';
404
405		if ($("#" + sHookList + " li").length != 0) {
406			var aConnectorId = [];
407			$("#" + sHookList + " li").each(function(i, elt) {
408					aConnectorId[i] = elt.id;
409				}
410			);
411			sList = aConnectorId.toString();
412		}
413		this.ajax(sURI, 'sConnectorList=' + sList, sToShow, sToHide, bFancyBox);
414	};
415
416	/*
417	 * draggableConnector() method set draggable
418	 * User: Business Tech (www.businesstech.fr)
419	 * @param obj Current HTML elt
420	 * @return -
421	 */
422	this.draggableConnector = function() {
423		// declare draggable elts
424		$("#" + oThis.name + "DraggableConnector li").draggable({
425			revert : "invalid"
426		});
427
428		// declare droppable elt - only drop elt in this tag
429		$("#" + oThis.name + "DroppableConnector ul").droppable({
430			drop : function(event, ui) {
431				// append draggable elt
432				$("#" + oThis.name + "DroppableConnector ul").append(ui.draggable);
433				// set css and deactivate drag
434				$(ui.draggable).css({position:"relative", top:"0px", left:"0px", display : "block"})
435					.draggable("disable")
436					.css({opacity : 1})
437					.addClass('fbpscsortli', 'ui-state-default');
438				// append img and click evt only in no already added img
439				var bFound = $(ui.draggable).find('img.' + oThis.name + 'Garbage');
440
441				// use case - add img and click evt in no img case
442				if (bFound.length == 0) {
443					$(ui.draggable).append('<img class="' + oThis.name + 'Garbage" src="' + oThis.sAdminImgUrl + 'delete.gif" />').bind('click', function() {
444							oThis.deleteConnector(this);
445						}
446					);
447				}
448			}
449		});
450	};
451
452	/*
453	 * sortableConnector() method set sortable Connector
454	 * User: Business Tech (www.businesstech.fr)
455	 * @param obj Current HTML elt
456	 * @return -
457	 */
458	this.sortableConnector = function() {
459		// set sortable elt
460		$( "#" + oThis.name + "Sortable" ).sortable();
461		$( "#" + oThis.name + "Sortable" ).disableSelection();
462	};
463
464	/*
465	 * deleteConnector() method delete added Connector in hook form
466	 * User: Business Tech (www.businesstech.fr)
467	 * @param obj Current HTML elt
468	 * @return -
469	 */
470	this.deleteConnector = function(oElt) {
471		$(oElt).find('img.' + oThis.name + 'Garbage').remove();
472		$("#" + oThis.name + "DraggableConnector ul").append($(oElt).removeClass('fbpscsortli').draggable('enable').draggable('option', 'revert' , 'invalid').addClass('fbpscdragli'));
473	};
474
475	/*
476	 * collect() method save the customer action and behavior
477	 * User: Business Tech (www.businesstech.fr) - Contact: http://www.businesstech.fr/en/contact-us
478	 * @param string sConnector : connector name : facebook | twitter | google | paypal
479	 * @param int iCustId : customer id
480	 * @param int iSocialId : customer social id
481	 * @param string sAction : FB action : like or want button, etc ...
482	 * @param string sType : PS object type: product or manufacturer or supplier ...
483	 * @param int iObjId : PS object ID : product or manufacturer or supplier or category ...
484	 */
485	this.collect = function(sConnector, iCustId, iSocialId, sAction, sType, iObjId) {
486		this.ajax(this.sWebService, 'sAction=clt&sType=scl&cn=' + sConnector + '&ci=' + iCustId + '&si=' + iSocialId + '&ca=' + sAction + '&ct=' + sType + '&oi=' + iObjId, null, null, null, null, null);
487	};
488
489};

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.