PageSourceSearch

https://vidacristalinas.com/modules/facebookpsconnect/views/js/module.js

js vidacristalinas.com collected 2026-10-10 01:44:56 UTC 18,554 bytes, 643 lines download raw bytes

1/*
2 * 2003-2019 Business Tech
3 *
4 *  @author    Business Tech SARL
5 *  @copyright 2003-2019 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					break;
134                case 'fbpscDefaultConnectText' :
135                    if (field.value == '') {
136                        oThis.aError[iCounter] = oThis.msgs.defaultText;
137                        bIsError = true;
138                    }
139	                break;
140				case 'fbpscPrefixCode' :
141					if (field.value == '' && $('input:radio[name="fbpscEnableVoucher"]').val() == 'true') {
142						oThis.aError[iCounter] = oThis.msgs.prefixCode;
143						bIsError = true;
144					}
145					break;
146				case 'fbpscApiRequestType' :
147					if (field.value == '') {
148						oThis.aError[iCounter] = oThis.msgs.apiType;
149						bIsError = true;
150					}
151					break;
152				case 'fbpscHtmlElement' :
153					if (field.value == '') {
154						oThis.aError[iCounter] = oThis.msgs.htmlElement;
155						bIsError = true;
156					}
157					break;
158				case 'fbpscPositionName' :
159					if (field.value == '') {
160						oThis.aError[iCounter] = oThis.msgs.positionName;
161						bIsError = true;
162					}
163					break;
164				case 'sCssPaddingTop' :
165					if (field.value == '' || $.isNumeric( field.value ) == false) {
166						oThis.aError[iCounter] = oThis.msgs.padding;
167						bIsError = true;
168					}
169					break;
170				case 'sCssPaddingRight' :
171					if (field.value == '' || $.isNumeric( field.value ) == false ) {
172						oThis.aError[iCounter] = oThis.msgs.padding;
173						bIsError = true;
174					}
175					break;
176				case 'sCssPaddingBottom' :
177					if (field.value == '' || $.isNumeric( field.value ) == false ) {
178						oThis.aError[iCounter] = oThis.msgs.padding;
179						bIsError = true;
180					}
181					break;
182				case 'sCssPaddingLeft' :
183					if (field.value == '' || $.isNumeric( field.value ) == false ) {
184						oThis.aError[iCounter] = oThis.msgs.padding;
185						bIsError = true;
186					}
187					break;
188				case 'sCssMarginTop' :
189					if (field.value == '' || $.isNumeric( field.value ) == false) {
190						oThis.aError[iCounter] = oThis.msgs.margin;
191						bIsError = true;
192					}
193					break;
194				case 'sCssMarginRight' :
195					if (field.value == '' || $.isNumeric( field.value ) == false ) {
196						oThis.aError[iCounter] = oThis.msgs.margin;
197						bIsError = true;
198					}
199					break;
200				case 'sCssMarginBottom' :
201					if (field.value == '' || $.isNumeric( field.value ) == false ) {
202						oThis.aError[iCounter] = oThis.msgs.margin;
203						bIsError = true;
204					}
205					break;
206				case 'sCssMarginLeft' :
207					if (field.value == '' || $.isNumeric( field.value ) == false ) {
208						oThis.aError[iCounter] = oThis.msgs.margin;
209						bIsError = true;
210					}
211					break;
212				default:
213					break;
214			}
215
216			if (($('input[name="' + field.name + '"]') != undefined || $('textarea[name="' + field.name + '"]') != undefined || $('select[name="' + field.name + '"]').length != undefined) && bIsError == true) {
217				if ($('input[name="' + field.name + '"]').length != 0) {
218					$('input[name="' + field.name + '"]').parent().addClass('has-error has-feedback');
219					$('input[name="' + field.name + '"]').append('<span class="icon-remove-sign"></span>');
220				}
221				if ($('textarea[name="' + field.name + '"]').length != 0) {
222					$('textarea[name="' + field.name + '"]').parent().addClass('has-error has-feedback');
223					$('textarea[name="' + field.name + '"]').append('<span class="icon-remove-sign"></span>');
224				}
225				if ($('select[name="' + field.name + '"]').length != 0) {
226					$('select[name="' + field.name + '"]').parent().addClass('has-error has-feedback');
227					$('select[name="' + field.name + '"]').append('<span class="icon-remove-sign"></span>');
228				}
229				++iCounter;
230			}
231		});
232
233		if (oThis.aError.length == 0 && !bIsError) {
234			// use case - Ajax request
235			if (bSubmit == undefined || bSubmit == null || !bSubmit) {
236				if (sLoadBar && sToHide != null) {
237					oThis.hide(sToHide, true);
238				}
239
240				// format object of fields in string to execute Ajax request
241				var sFormParams = $.param(fields);
242
243				if (sRequestParam != null && sRequestParam != '') {
244					sFormParams = sRequestParam + '&' + sFormParams;
245				}
246
247				// execute Ajax request
248				this.ajax(sURI, sFormParams, sToDisplay, sToHide, bFancyBox, null, sLoadBar);
249
250				return true;
251			}
252			// use case - send form
253			else {
254				// hide loading bar
255				if (sLoadBar) {
256					$('#'+sLoadBar).hide();
257				}
258				document.forms[sForm].submit();
259				return true;
260			}
261		}
262		else {
263			$('#'+sLoadBar).hide();
264		}
265		// display errors
266		this.displayError(sErrorType);
267
268		return false;
269	};
270
271	/*
272	 * ajax() method execute XHR
273	 * User: Business Tech (www.businesstech.fr) - Contact: http://www.businesstech.fr/en/contact-us
274	 * @param string sURI : query params used for XHR
275	 * @param string sParams :
276	 * @param string sToShow :
277	 * @param string sToHide :
278	 * @param bool bFancyBox : used only for fancybox in xhr
279	 * @param bool bFancyBoxActivity : used only for fancybox in xhr
280	 * @param string sLoadBar : used only for loading
281	 * @return string : HTML returned by smarty
282	 */
283this.ajax = function(sURI, sParams, sToShow, sToHide, bFancyBox, bFancyBoxActivity, sLoadBar) {
284		if(bFancyBox && bFancyBoxActivity != false) {
285			//$.fancybox.showActivity();
286		}
287
288		sParams = 'sMode=xhr' + ((sParams == null || sParams == undefined) ? '' : '&' + sParams) ;
289
290		// configure XHR
291		$.ajax({
292			type : 'POST',
293			url : sURI,
294			data : sParams,
295			dataType : 'html',
296			success: function(data) {
297				// hide loading bar
298				if (sLoadBar) {
299					$('#'+sLoadBar).hide();
300				}
301				if(bFancyBox) {
302					// update fancybox content
303					$.fancybox(data);
304
305					// use case - update only widget list
306					if (sToShow == oThis.name + 'ConnectorList') {
307						oThis.ajax('' + sURI, 'sAction=display&sType=connectors', '' + sToShow + '', '' + sToHide + '');
308					}
309					// use case - update widget list and hook list
310					else if (sToShow == oThis.name + 'HookList') {
311						sToShow = sToHide = oThis.name + 'ConnectorList';
312						oThis.ajax('' + sURI + 'connectors', 'sAction=display&sType=connectors', '' + sToShow + '', '' + sToHide + '');
313						sToShow = sToHide = oThis.name + 'HookList';
314						oThis.ajax('' + sURI + 'hooks', 'sAction=display&sType=hooks', '' + sToShow + '', '' + sToHide + '');
315					}
316					else if (sToShow == oThis.name + 'HookAdvanced')
317					{
318						oThis.ajax('' + sURI, 'sAction=display&sType=hookAdvanced', '' + sToShow + '', '' + sToHide + '');
319					}
320					else if (sToShow == oThis.name + 'ShortCode')
321					{
322						oThis.ajax('' + sURI, 'sAction=display&sType=shortCode', '' + sToShow + '', '' + sToHide + '');
323					}
324				}
325				else if (sToShow != null && sToHide != null) {
326					// same hide and show
327					if (sToShow == sToHide) {
328						oThis.hide('fast');
329						$('#' + sToHide).hide('fast');
330						$('#' + sToHide).empty();
331						setTimeout('', 1000);
332						oThis.show(sToShow, data);
333					}
334					else {
335						oThis.hide(sToHide);
336						setTimeout('', 1000);
337						oThis.show(sToShow, data);
338					}
339				}
340				else if (sToShow != null) {
341					oThis.show(sToShow, data);
342				}
343				else if (sToHide != null) {
344					oThis.hide(sToHide);
345				}
346				else {
347					oThis.response = data;
348				}
349			},
350			error: function(xhr, ajaxOptions, thrownError) {
351				$("#" + oThis.name + "FormError").addClass('alert error');
352				oThis.show("#" + oThis.name + "FormError", '<h3>internal error</h3>');
353			}
354		});
355	};
356
357	/*
358	 * displayError() method display errors
359	 * User: Business Tech (www.businesstech.fr) - Contact: http://www.businesstech.fr/en/contact-us
360	 * @param string sType : type of container
361	 * @return bool
362	 */
363	this.displayError = function(sType) {
364		if (oThis.aError.length != 0) {
365			var sError = '<div class="alert alert-danger"><button type="button" class="close" data-dismiss="alert">×</button><ul class="list-unstyled">';
366			for (var i = 0; i < oThis.aError.length;++i) {
367				sError += '<li>' + oThis.aError[i] + '</li>';
368			}
369			sError += '</ul></div>'
370
371			$("#" + oThis.name + sType + "Error").html(sError);
372			$("#" + oThis.name + sType + "Error").slideDown();
373
374			// flush errors
375			oThis.aError = [];
376
377			return false;
378		}
379	};
380
381	/**
382	 * changeSelect() method displays or hide related option form
383	 *
384	 * @param string sId : type of container
385	 * @param mixed mDestId
386	 * @param string sDestId2
387	 * @param string sType of second dest id
388	 * @param bool bForce
389	 * @param bool mVal
390	 */
391	this.changeSelect = function(sId, mDestId, sDestId2, sDestIdToHide, bForce, mVal) {
392		if (bForce) {
393			if (typeof mDestId == 'string') {
394				mDestId = [mDestId];
395			}
396
397			for (var i = 0; i < mDestId.length; ++i) {
398				if (mVal) {
399					$("#" + mDestId[i]).fadeIn('fast', function() {$("#" + mDestId[i]).css('display', 'block')});
400				}
401				else {
402					$("#" + mDestId[i]).fadeOut('fast');
403				}
404			}
405		}
406		else {
407			$("#" + sId).bind('change', function (event){
408				$("#" + sId + " input:checked").each(function (){
409					switch ($(this).val()) {
410						case 'true' :
411							// display option features
412							$("#" + sDestId).fadeIn('fast', function() {$("#" + sDestId).css('display', 'block')});
413							break;
414						default:
415							// hide option features
416							$("#" + sDestId).fadeOut('fast');
417
418							// set to false
419							if (sDestId2 && sDestIdToHide) {
420								$("#" + sDestId2 + " input").each(function (){
421										switch ($(this).val()) {
422											case 'false' :
423												$(this).attr('checked', 'checked');
424												// hide option features
425												$("#" + sDestIdToHide).fadeOut('fast');
426												break;
427											default:
428												$(this).attr('checked', '');
429												break;
430										}
431									}
432								);
433							}
434							break;
435					}
436				});
437			});
438		}
439	};
440
441	/**
442	 * selectAll() method select / deselect all checkbox
443	 *
444	 * @param string sId : type of container
445	 * @param string sCible : all checkbox to process
446	 */
447	this.selectAll = function(sCible, sType){
448		if (sType == 'check') {
449			$(sCible).attr('checked', true);
450		}
451		else{
452			$(sCible).attr('checked', false);
453		}
454	};
455
456	/*
457	 * updateHook() method verify all childnodes of hook list and determine position to display widget in hook
458	 * User: Business Tech (www.businesstech.fr)
459	 * @param string sURI : query params used for XHR
460	 * @param string sHookList :
461	 * @param string sToShow :
462	 * @param string sToHide :
463	 * @param bool bFancyBox : used only for fancybox in xhr
464	 * @return string : HTML returned by smarty
465	 */
466	this.updateHook = function(sURI, sHookList, sToShow, sToHide, bFancyBox) {
467		var sList = '';
468
469		if ($("#" + sHookList + " li").length != 0) {
470			var aConnectorId = [];
471			$("#" + sHookList + " li").each(function(i, elt) {
472					aConnectorId[i] = elt.id;
473				}
474			);
475			sList = aConnectorId.toString();
476		}
477		this.ajax(sURI, 'sConnectorList=' + sList, sToShow, sToHide, bFancyBox);
478	};
479
480	/*
481	 * draggableConnector() method set draggable
482	 * User: Business Tech (www.businesstech.fr)
483	 * @param obj Current HTML elt
484	 * @return -
485	 */
486	this.draggableConnector = function() {
487		// declare draggable elts
488		$("#" + oThis.name + "DraggableConnector li").draggable({
489			revert : "invalid"
490		});
491
492		// declare droppable elt - only drop elt in this tag
493		$("#" + oThis.name + "DroppableConnector ul").droppable({
494			drop : function(event, ui) {
495				// append draggable elt
496				$("#" + oThis.name + "DroppableConnector ul").append(ui.draggable);
497				// set css and deactivate drag
498				$(ui.draggable).css({position:"relative", top:"0px", left:"0px", display : "block"})
499					.draggable("disable")
500					.css({opacity : 1})
501					.addClass('fbpscsortli', 'ui-state-default', 'pull-left', 'col-xs-8')
502
503				// append img and click evt only in no already added img
504				var bFound = $(ui.draggable).find('span.' + oThis.name + 'Garbage');
505
506				// use case - add img and click evt in no img case
507				if (bFound.length == 0) {
508
509					//Init html content
510					var oCurrentDragableA = $(ui.draggable).html();
511					console.log(oCurrentDragableA);
512					var oGarbage = '<span class="pull-left btn btn-default btn-mini ' + oThis.name + 'Garbage"> <i class="fa fa-trash"/></span>';
513
514					$(ui.draggable).html();
515					$(ui.draggable).html('<div class="row" id="fbpsc" ><div class="col-xs-10">' + oCurrentDragableA + '</div><div class="col-xs-2">' + oGarbage + ' </div></div>');
516					$(ui.draggable).bind('click', function() {
517							oThis.deleteConnector(this)
518						}
519					);
520				}
521			}
522		});
523	};
524
525	/*
526	 * sortableConnector() method set sortable Connector
527	 * User: Business Tech (www.businesstech.fr)
528	 * @param obj Current HTML elt
529	 * @return -
530	 */
531	this.sortableConnector = function() {
532		// set sortable elt
533		$( "#" + oThis.name + "Sortable" ).sortable();
534		$( "#" + oThis.name + "Sortable" ).disableSelection();
535	};
536
537	/*
538	 * deleteConnector() method delete added Connector in hook form
539	 * User: Business Tech (www.businesstech.fr)
540	 * @param obj Current HTML elt
541	 * @return -
542	 */
543	this.deleteConnector = function(oElt) {
544		$(oElt).find('button.' + oThis.name + 'Garbage').remove();
545		$("#" + oThis.name + "DraggableConnector ul").append($(oElt).removeClass('fbpscsortli').draggable('enable').draggable('option', 'revert' , 'invalid').addClass('fbpscdragli'));
546	};
547
548	/*
549	 * getCharts() method get the charts for connect
550	 * User: Business Tech (www.businesstech.fr) - Contact: http://www.businesstech.fr/en/contact-us
551	 * @param string sElem : Canvas element to plug the charts
552	 * @param array aData : data to manage the charts
553	 * @param array aLabel : list of label to manage
554	 * @param array aColor : color for each element of the charts
555	 * @param string sTitle : the graph title
556	 */
557	this.getCharts = function(sElem, aData, aLabel, aColor, sTitle) {
558
559		//For filter charts
560		aData = {
561			datasets: [{
562				data : aData,
563				backgroundColor: aColor
564			}],
565			// These labels appear in the legend and in the tooltips when hovering different arcs
566			labels: aLabel
567		};
568
569		var oDoughnutChart = new Chart(sElem, {
570			type: 'pie',
571			data: aData,
572			options: {
573				legend : {
574					position : 'bottom'
575				},
576				title : {
577					display : true,
578					position : 'top',
579					text: sTitle,
580					fontSize : 14
581				}
582			}
583		});
584	};
585
586
587	/*
588	 * hide() method hide effect and delete html
589	 * User: Business Tech (www.businesstech.fr) - Contact: http://www.businesstech.fr/en/contact-us
590	 * @param string sId : container to hide in
591	 * @return -
592	 */
593	this.hide = function(sId) {
594		$("#" + sId).hide('fast', function() {
595				$("#" + sId).html('');
596			}
597		);
598	};
599
600	/**
601	 * getBulkCheckBox() method get all checkbox for one element
602	 *
603	 * @param array aParams
604	 * @param json
605	 */
606	this.getBulkCheckBox = function(sFieldName)
607	{
608		var iElemId = [];
609
610		$('input:checked[name="' + sFieldName + '"]').each(function() {
611			iElemId.push($(this).val());
612		})
613
614		if (iElemId != null)
615			return iElemId;
616		else
617			return iElemId = 1;
618
619	}
620
621	/**
622	 * getContentFromSwitch() method return a cotent according to the switch value
623	 */
624	this.getContentFromSwitch = function(sIdElemOn, sElem){
625		if ($("#"+ sIdElemOn).is(':checked') == true){
626			$("#" + sElem).show();
627		}
628		else
629		{
630			$("#" + sElem).hide();
631		}
632	};
633
634	/**
635	 * getConnectors() method return visual for connectors
636	 * @param sShortCodeName
637	 */
638	this.getConnectors = function(sSelector, sShortCodeName){
639
640		this.ajax(this.sWebService, 'sAction=display&sType=shortCode&sShortCodeName=' + sShortCodeName, 'sl_connector_'+ sSelector, null, null, null, null);
641	};
642
643};

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.