PageSourceSearch

https://www.zamnesia.de/modules/gsnippetsreviews/js/module.js?560f8f09da050aa5b6497d2740097f16

js zamnesia.de collected 2026-09-28 06:51:23 UTC 11,011 bytes, 394 lines download raw bytes

1// declare main object of module
2var ModuleName = function(sName)
3{
4	// set name
5	this.name = sName;
6
7	// set name
8	this.oldVersion = false;
9
10	// set translated js msgs
11	this.msgs = {};
12
13	// stock error array
14	this.aError = [];
15
16	// set url of admin img
17	this.sImgUrl = '';
18
19	// set this in obj context
20	var oThis = this;
21
22	/**
23	 * show() method execute show effect and assign HTML in
24	 * User: Business Tech (www.businesstech.fr) - Contact: [email protected]
25	 * @param string sId : container to show in
26	 * @param string sHtml : HTML to display
27	 * @return -
28	 */
29	this.show = function(sId, sHtml)
30	{
31		$("#" + sId).html(sHtml).css('style', 'none');
32		$("#" + sId).show('fast');
33	};
34
35	/**
36	 * hide() method execute hide effect and delete html
37	 * User: Business Tech (www.businesstech.fr) - Contact: [email protected]
38	 * @param string sId : container to hide in
39	 * @return -
40	 */
41	this.hide = function(sId)
42	{
43		$("#" + sId).hide('fast', function()
44			{
45				$("#" + sId).html('');
46			}
47		);
48	};
49
50	/**
51	 * form() method check all fields of current form and execute : XHR or submit => used for update all admin config
52	 * User: Business Tech (www.businesstech.fr) - Contact: [email protected]
53	 * @see ajax
54	 * @param string sForm : form
55	 * @param string sURI : query params used for XHR
56	 * @param string sRequestParam : param action and type in order to send with post mode
57	 * @param string sToDisplay :
58	 * @param string sToHide : force to hide specific ID
59	 * @param bool bSubmit : used only for sending main form
60	 * @param bool bFancyBox : used only for fancybox in xhr
61	 * @param string sCallback :
62	 * @param string sErrorType :
63	 * @return string : HTML returned by smarty
64	 */
65	this.form = function(sForm, sURI, sRequestParam, sToDisplay, sToHide, bSubmit, bFancyBox, sCallback, sErrorType, bFilter)
66	{
67
68
69		// set return validation
70		var aError = [];
71
72		if (bFilter) {
73			$('#bCheckReview, #sSelectAction').remove();
74			$('#sType').val('moderation');
75			$('#sAction').val('display');
76		}
77
78		// get all fields of form
79		var fields = $("#" + sForm).serializeArray();
80
81		// set counter
82		var iCounter = 0;
83
84		// set bIsError
85		var bIsError = false;
86
87		// set check review
88		var bCheckReview = false;
89		var bCheckedReview = false;
90
91		// check element form
92		jQuery.each(fields, function(i, field) {
93			bIsError = false;
94
95			switch(field.name) {
96				case oThis.name + 'DelayEmail' :
97					if (isNaN(field.value)) {
98						oThis.aError[iCounter] = oThis.msgs.delay;
99						bIsError = true;
100					}
101					break;
102				case oThis.name + 'ReviewTitle' :
103					if (field.value == '' && $('#bCheckFieldText').val() == 'true') {
104						oThis.aError[iCounter] = oThis.msgs.title;
105						bIsError = true;
106					}
107					break;
108				case oThis.name + 'ReviewComment' :
109					if (field.value == '' && $('#bCheckFieldText').val() == 'true') {
110						oThis.aError[iCounter] = oThis.msgs.description;
111						bIsError = true;
112					}
113					break;
114				case oThis.name + 'Email' :
115					if (field.value == '' && $('#' + oThis.name + 'EnableEmail :checked').val() == 'true') {
116						oThis.aError[iCounter] = oThis.msgs.email;
117						bIsError = true;
118					}
119					break;
120				case 'iRating' :
121					if (field.value == 0) {
122						oThis.aError[iCounter] = oThis.msgs.rating;
123						bIsError = true;
124					}
125					break;
126				case 'bCheckReview' :
127					bCheckReview = true;
128					break;
129				default:
130					// check if language field
131					if (field.name.indexOf('TabTitle') != -1 &&  field.value == '') {
132						var aLangId = field.name.split('_');
133						oThis.aError[iCounter] = oThis.msgs.tabTitle[aLangId[1]];
134
135						bIsError = true;
136					}
137					// check if language field for subject email
138					if (field.name.indexOf('TabEmailTitle') != -1 &&  field.value == '' && $('#' + oThis.name + 'EnableCallbackDiv :checked').val() == 'true') {
139						var aLangId = field.name.split('_');
140						oThis.aError[iCounter] = oThis.msgs.tabTitle[aLangId[1]];
141
142						bIsError = true;
143					}
144					// check if language field for sentence of FB post
145					if (field.name.indexOf('TabFBPostPhrase') != -1 &&  field.value == '' && $('#' + oThis.name + 'EnableFbPostDiv :checked').val() == 'true') {
146						var aLangId = field.name.split('_');
147						oThis.aError[iCounter] = oThis.msgs.tabTitle[aLangId[1]];
148
149						bIsError = true;
150					}
151					// check if language field for label of FB post
152					if (field.name.indexOf('TabFBPostLabel') != -1 &&  field.value == '' && $('#' + oThis.name + 'EnableFbPostDiv :checked').val() == 'true') {
153						var aLangId = field.name.split('_');
154						oThis.aError[iCounter] = oThis.msgs.tabTitle[aLangId[1]];
155
156						bIsError = true;
157					}
158					if (bCheckReview && (field.name.indexOf('CheckReview') != -1 || field.name.indexOf('CheckRating') != -1)) {
159						bCheckedReview = true;
160					}
161					break;
162			}
163
164			if ($('#' + field.name) != undefined && bIsError == true) {
165				$('#' + field.name).css('border', '1px solid red');
166				++iCounter;
167			}
168		});
169
170		if (bCheckReview && !bCheckedReview) {
171			oThis.aError[iCounter] = oThis.msgs.checkreview;
172			bIsError = true;
173		}
174
175		// use case - no errors in form
176		if (oThis.aError.length == 0) {
177			// use case - Ajax request
178			if (bSubmit == undefined || bSubmit == null || !bSubmit) {
179				// format objet of fields in string to execute Ajax request
180				var sFormParams = $.param(fields);
181
182				if (sCallback != null) {
183					switch (sCallback)  {
184						case 'updateDescSort' :
185							var sDescList = this.updateDescSort();
186
187							if (sDescList != '') {
188								sFormParams += '&' + oThis.name + 'DescList=' + sDescList;
189							}
190							break;
191						default:
192							break;
193					}
194				}
195
196				// hide current
197				this.hide(sForm);
198				
199				if (sRequestParam != null && sRequestParam != '') {
200					sFormParams = sRequestParam + '&' + sFormParams;
201				}
202
203				// execute Ajax request
204				this.ajax(sURI, sFormParams, sToDisplay, sToHide, bFancyBox);
205				
206				return true;
207			}
208			// use case - send form
209			else {
210				document.forms[sForm].submit();
211				return true;
212			}
213		}
214		// display errors
215		this.displayError(sErrorType);
216
217		return false;
218	};
219
220
221	/**
222	 * ajax() method execute XHR
223	 * User: Business Tech (www.businesstech.fr) - Contact: [email protected]
224	 * @param string sURI : query params used for XHR
225	 * @param string sParams :
226	 * @param string sToShow :
227	 * @param string sToHide :
228	 * @param bool bFancyBox : used only for fancybox in xhr
229	 * @return string : HTML returned by smarty
230	 */
231	this.ajax = function(sURI, sParams, sToShow, sToHide, bFancyBox)
232	{
233		if(bFancyBox) {
234			$.fancybox.showActivity();
235		}
236
237		sParams = 'sMode=xhr' + ((sParams == null || sParams == undefined) ? '' : '&' + sParams) ;
238
239		// configure XHR
240		$.ajax({
241			type : 'POST',
242			url : sURI,
243			data : sParams,
244			dataType : 'html',
245			success: function(data) {
246				if(bFancyBox) {
247					// update fancybox content
248					$.fancybox(data);
249					// replace query action and type
250					sParams = sParams.replace(/(sAction=)[a-zA-Z]+/, '$1' + 'display');
251					sParams = sParams.replace(/(sType=)[a-zA-Z]+/, '$1' + 'moderation');
252					// use case - update only widget list
253					if (sToShow == oThis.name + 'ModerationList') {
254						oThis.ajax('' + sURI + '', '' + sParams + '', '' + sToShow + '', '' + sToHide + '');
255					}
256				}
257				else if (sToShow != null && sToHide != null && sToHide.includes(',')) {
258					$('#' + sToHide).hide('fast');
259					$('#' + sToHide).empty();
260					oThis.show(sToShow, data);
261				}
262				else if (sToShow != null && sToHide != null) {
263					// same hide and show
264					if (sToShow == sToHide) {
265						$('#' + sToHide).hide('fast');
266						$('#' + sToHide).empty();
267						oThis.show(sToShow, data);
268					}
269					else {
270						oThis.hide(sToHide);
271						setTimeout('', 1000);
272						oThis.show(sToShow, data);
273					}
274				}
275				else if (sToShow != null) {
276					oThis.show(sToShow, data);
277				}
278				else if (sToHide != null) {
279					oThis.hide(sToHide);
280				}
281			},
282			error: function(xhr, ajaxOptions, thrownError) {
283				$("#" + oThis.name + "FormError").addClass('alert error');
284				oThis.show("#" + oThis.name + "FormError", '<h3>internal error</h3>');
285			}
286		});
287	};
288
289	/**
290	 * displayError() method display errors
291	 * User: Business Tech (www.businesstech.fr) - Contact: [email protected]
292	 * @param string sType : type of container
293	 * @return bool
294	 */
295	this.displayError = function(sType)
296	{
297		if (oThis.aError.length != 0) {
298			var sError = '<img class="pointer" src="' + oThis.sImgUrl + 'hook/cancel.png' + '" onclick="$(\'#' + oThis.name + sType + 'Error\').hide(\'' + oThis.name + sType + 'Error\');" />';
299			for (var i = 0; i < oThis.aError.length;++i) {
300				sError += '<span>' + oThis.aError[i] + '</span><br />';
301			}
302			$("#" + oThis.name + sType + "Error").html(sError).addClass('form-error');
303			$("#" + oThis.name + sType + "Error").show();
304
305			// flush errors
306			oThis.aError = [];
307
308			return false;
309		}
310	};
311
312	/**
313	 * sortDesc() method set sortable desc
314	 * User: Business Tech (www.businesstech.fr) - Contact: [email protected]
315	 * @param obj Current HTML elt
316	 * @return -
317	 */
318	this.sortDesc = function()
319	{
320		// set sortable elt
321		$( "#" + oThis.name + "SortableDesc" ).sortable();
322		$( "#" + oThis.name + "SortableDesc" ).disableSelection();
323	};
324
325	/**
326	 * updateDescSort() method verify all childnodes of des list and determine position to manage snippets desc
327	 * User: Business Tech (www.businesstech.fr) - Contact: [email protected]
328	 * @param -
329	 * @return string : HTML returned by smarty
330	 */
331	this.updateDescSort = function()
332	{
333		var sList = '';
334
335		if ($("#" + oThis.name + "SortableDesc li").length != 0) {
336			var aDescId = [];
337			$("#" + oThis.name + "SortableDesc li").each(function(i, elt)
338				{
339					aDescId[i] = elt.id;
340				}
341			);
342			sList = aDescId.toString();
343		}
344		return sList;
345	};
346
347	/**
348	 * changeSelect() method displays or hide related option form
349	 * User: Business Tech (www.businesstech.fr) - Contact: [email protected]
350	 * @param string sId : type of container
351	 * @param string sDestId
352	 * @return
353	 */
354	this.changeSelect = function(sId, sDestId)
355	{
356
357		$("#" + sId).bind($.browser.msie ? 'click' : 'change', function (event)
358		{
359			$("#" + sId + " input:checked").each(function ()
360			{
361				switch ($(this).val()) {
362					case 'true' :
363						// display option features
364						$("#" + sDestId).fadeIn('fast', function() {$("#" + sDestId).css('display', 'block')});
365						break;
366					default:
367						// hide option features
368						$("#" + sDestId).fadeOut('fast');
369						break;
370				}
371			});
372		});
373	};
374
375	/**
376	 * selectAll() method select / deselect all checkbox
377	 * User: Business Tech (www.businesstech.fr) - Contact: [email protected]
378	 * @param string sId : type of container
379	 * @param string sCible : all checkbox to process
380	 * @return
381	 */
382	this.selectAll = function(sId, sCible)
383	{
384		$("#" + sId).bind($.browser.msie ? 'click' : 'change', function (event)
385		{
386			if (this.checked == true) {
387				$(sCible).attr('checked', true);
388			}
389			else{
390				$(sCible).attr('checked', false);
391			}
392		});
393	};
394};

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.