PageSourceSearch

https://kiusamisvaba.ee/wp-content/plugins/edwiser-bridge-pro/publ…e-users-course-purchase-public.js?ver=4.2.2

js kiusamisvaba.ee collected 2026-09-24 20:53:18 UTC 16,892 bytes, 569 lines download raw bytes

1/*
2* Bulk purchase product purchase css
3*/
4(function ($) {
5	var dlgOverlyOpct  = 0.8;
6	var dlgOverlyColor = "black";
7	jQuery( document ).ready(
8		function () {
9			var div = '<div id="eb-lading-parent" class="eb-lading-parent-wrap"><div class="eb-loader-progsessing-anim"></div></div>';
10			$( "body" ).append( div );
11			div = '<div class="eb-background-div"></div>';
12
13			/**
14			 * Variable product support.
15			 */
16			$( ".single_variation_wrap" ).on(
17				"show_variation",
18				function (event, variation) {
19					// Fired when the user selects all the required dropdowns / attributes.
20					// and a final variation is selected / shown.
21
22					$( '.wdm_edwiser_bulk_purchase' ).css( 'display', 'none' );
23
24					if ($( '#bp_enable_group_purchase_' + [variation.variation_id] ).length) {
25						$( '#bp_enable_group_purchase_' + [variation.variation_id] ).show();
26					}/* else {
27					$('.wdm_edwiser_bulk_purchase').hide();
28					}*/
29
30				}
31			);
32
33			/**
34			 * Events to dismiss the responce messages on the enrolle student page.
35			 */
36			$( document ).on(
37				'click',
38				'.wdm_enroll_warning_msg_dismiss',
39				function () {
40					$( this ).parent().remove();
41					// $('.wdm_user_list').remove();
42					$( '#wdm_eb_message_divider' ).remove();
43					// $('#wdm_eb_enroll_user_page').css("border", "0px solid white");
44				}
45			);
46			$( document ).on(
47				'click',
48				'.wdm_error_msg_dismiss',
49				function () {
50					$( this ).parent().remove();
51					// $('.wdm_user_list').remove();
52					$( '#wdm_eb_message_divider' ).remove();
53					// $('#wdm_eb_enroll_user_page').css("border", "0px solid white");
54				}
55			);
56			$( document ).on(
57				'click',
58				'.wdm_success_msg_dismiss',
59				function () {
60					$( this ).parent().remove();
61					// $('.wdm_user_list').remove();
62					$( '#wdm_eb_message_divider' ).remove();
63					// $('#wdm_eb_enroll_user_page').css("border", "0px solid white");
64				}
65			);
66
67			/**
68			 * removing error msg
69		 *
70			 * @since 1.1.0
71			 */
72
73			$( document ).on(
74				'click',
75				'.wdm_success_msg_dismiss, .wdm_select_course_msg_dismiss',
76				function () {
77					$( '.wdm_select_course_msg' ).css( "display", "none" );
78					$( '#wdm_eb_message_divider' ).remove();
79				}
80			);
81
82			$( document ).on(
83				'click',
84				'.wdm_enroll_warning_msg_dismiss',
85				function () {
86					$( '.wdm_enroll_warning_message' ).css( "display", "none" );
87					$( '#wdm_eb_message_divider' ).remove();
88				}
89			);
90
91			$( document ).on(
92				'click',
93				'.wdm_success_msg_dismiss',
94				function () {
95					$( '.wdm_success_message' ).css( "display", "none" );
96					$( '#wdm_eb_message_divider' ).remove();
97				}
98			);
99
100			$( document ).on(
101				'click',
102				'.wdm_grp_update_msg_dismiss',
103				function () {
104					$( this ).parent().css( "display", "none" );
105				}
106			);
107
108			$( "body" ).append( div );
109			// Added this in the enroll students js.
110			/*$('#wdm_eb_upload_csv').hide();
111			$('#wdm_avaliable_reg').hide();
112			$('#enroll-new-user-btn-div').hide();
113			$("#wdm_associated_courses_container").hide();*/
114			var seat_limit = 0;
115
116			$( document ).on(
117				"change",
118				"#mucp-cart-group-checkbox",
119				function () {
120					if ($( this ).prop( "checked" ) == true) {
121						processGroupPurchaseCheckbox( 1 );
122					} else if ($( this ).prop( "checked" ) == false) {
123						processGroupPurchaseCheckbox( 0 );
124					}
125				}
126			);
127
128			function isItemQtyEql() {
129				var allQty = [];
130				$( '.qty' ).each(
131					function () {
132						allQty.push( $( this ).val() );
133					}
134				)
135				var max    = allQty[0];
136				for (var cnt = 1; cnt < allQty.length; cnt++) {
137					if (max != allQty[cnt]) {
138						return false;
139					}
140				}
141				return true;
142			}
143
144			/**
145			 * This will check is the bulk purchase option is present on screen
146			 * if the checkbox is present on the screen then disable the quantity box.
147			 */
148			if ($( "#wdm_edwiser_self_enroll" ).length) {
149				var ischecked = $( this ).is( ':checked' );
150				if ( ! ischecked) {
151					$( ".qty" ).prop( 'disabled', true );
152					$( ".qty" ).attr( "value", "1" );
153				} else {
154					$( ".qty" ).prop( 'disabled', false );
155				}
156			}
157
158			/**
159			 * Handle the group purchase enable disable events
160			 * If the checkbox is enabled then enable the product quantity box
161			 * Disable otherwise
162			 */
163			// add event listner for each checkbox
164			$( "input[name='wdm_edwiser_self_enroll']" ).change(
165				function () {
166					var ischecked = $( this ).is( ':checked' );
167					if ( ! ischecked) {
168						$( ".qty" ).prop( 'disabled', true );
169						$( ".qty" ).attr( "value", "1" );
170					} else {
171						$( ".qty" ).prop( 'disabled', false );
172					}
173				}
174			);
175
176			function processGroupPurchaseCheckbox(isChecked) {
177				jQuery.ajax(
178					{
179						type: 'POST',
180						url: ebbpPublic.ajax_url,
181						dataType: 'json',
182						data: {
183							action: 'check_for_different_products',
184							single_group: isChecked,
185						},
186						success: function (response) {
187							if (response.success == true) {
188								if (response.data.status) {
189									$( ".wdm-diff-prod-qty-error" ).addClass( "wdm-hide" );
190									$( ".wdm-diff-prod-qty-success" ).removeClass( "wdm-hide" );
191									$( "#wdm-diff-prod-qty-success-msg" ).html( response.data.msg );
192								} else {
193									$( ".wdm-diff-prod-qty-error" ).removeClass( "wdm-hide" );
194									$( ".wdm-diff-prod-qty-success" ).addClass( "wdm-hide" );
195									$( "#wdm-diff-prod-qty-error-msg" ).html( response.data.msg );
196								}
197							} else {
198								$( ".wdm-diff-prod-qty-error" ).removeClass( "wdm-hide" );
199								$( ".wdm-diff-prod-qty-success" ).addClass( "wdm-hide" );
200								$( "#wdm-diff-prod-qty-error-msg" ).html( response.data );
201								$( "#mucp-cart-group-checkbox" ).prop( "checked", false );
202							}
203						},
204						error: function (error) {
205							errorMsgDialog( error );
206						}
207					}
208				);
209
210			}
211
212			// v1.1.1.
213			/**
214			 * Show Error message.
215			 */
216			function errorMsgDialog(msg) {
217				var error = $( document.createElement( 'div' ) );
218				msg       = '<div class="ui-state-error ui-corner-all"><i class="dashicons dashicons-warning" aria-hidden="true"></i><p style = "margin-top:5%;">' + msg + '</p></div>';
219				error.append( msg );
220				error.dialog(
221					{
222						title: "Error",
223						autoOpen: false,
224						modal: true,
225						resizable: false,
226						dialogClass: "wdm-error-message-dialog",
227						buttons: [
228						{
229							text: ebbpPublic.ok,
230							class: 'wdm-dialog-ok-button',
231							click: function () {
232								closeDialog( this );
233							}
234						},
235						],
236						open: function (event, ui) {
237							$( ".ui-widget-overlay" ).css(
238								{
239									opacity: dlgOverlyOpct,
240									backgroundColor: dlgOverlyColor
241								}
242							);
243						},
244						create: function (event, ui) {
245							$( event.target ).parent().css( 'position', 'fixed' );
246						},
247					}
248				).dialog( "open" );
249			}
250
251			/**
252			 *  Handling change on input of Add Quantity Popup
253			 */
254			$( document ).on(
255				'keypress click input',
256				'input.add-more-quantity',
257				function (event) {
258					if (event.which == 45 || event.which == 46 || event.which == 189) {
259						event.preventDefault();
260					}
261					var grand_total = 0;
262					var quantity    = $( this ).val();
263					if (quantity == "") {
264						quantity = 0;
265					}
266					var productId       = $( this ).attr( "id" );
267					var minQuantity     = $( "#" + productId + "-min-quantity" ).html();
268					var perProductPrice = $( "#" + productId + "-per-product-price" ).html();
269					$( "#" + productId + "-total-quantity" ).html( parseInt( minQuantity ) + parseInt( quantity ) );
270					$( "#" + productId + "-total-price" ).html( parseFloat( perProductPrice ) * parseInt( quantity ) );
271					var totals = jQuery( '.wdm-quantity-total' );
272					totals.each(
273						function (index, value) {
274							grand_total += parseFloat( $( this ).html() );
275						}
276					);
277					$( '#add-quantity-total-price' ).html( grand_total );
278				}
279			);
280
281			/**
282			 * Functionality to calculate the total price per product
283			 * in the add more product/quantity popup
284			 */
285			$(document).ready(function () {
286
287				function calculateTotalPrice(targetElement, isNewProd = false) {
288					var wdmId = $(targetElement).attr('id');
289					var priceId;
290					var totalPriceId = wdmId + "-total-price";
291					var quantityElement = $("#" + wdmId);
292					var priceElement;
293					var calculate = true;
294
295					if (isNewProd) {
296						var selectedProd = wdmId + "-wdm-sele-prod";
297						if ($("#" + selectedProd).prop('checked') !== true) {
298							calculate = false;
299						}
300						priceId = wdmId + "-per-product-price";
301					} else {
302						priceId = wdmId + "-per-product-price";
303					}
304					priceElement = $("#" + priceId);
305
306					if (calculate && quantityElement.length && priceElement.length && totalPriceElement.length && !isNaN(parseFloat(quantityElement.val())) && !isNaN(parseFloat(priceElement.text()))) {
307						var quantity = parseFloat(quantityElement.val());
308						var price = parseFloat(priceElement.text());
309						totalPriceElement.html((quantity * price).toFixed(2));
310					}
311				}
312
313				// Initial calculation for existing elements
314				$('.wdm_new_qty_per_prod, .wdm_new_qty_per_new_prod').each(function () {
315					calculateTotalPrice(this, $(this).hasClass('wdm_new_qty_per_new_prod'));
316				});
317
318				// Set up Mutation Observer
319				const targetNode = document.body; // Or a more specific parent element
320				const config = {
321					subtree: true,
322					childList: true,
323					attributes: true,
324					attributeFilter: ['class']
325				};
326
327				const observer = new MutationObserver(function (mutationsList, observer) {
328					for (const mutation of mutationsList) {
329						if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {
330							mutation.addedNodes.forEach(node => {
331								if (node.classList) {
332									if (node.classList.contains('wdm_new_qty_per_prod')) {
333										calculateTotalPrice(node);
334									} else if (node.classList.contains('wdm_new_qty_per_new_prod')) {
335										calculateTotalPrice(node, true);
336									}
337								}
338								if (node.querySelectorAll) {
339									node.querySelectorAll('.wdm_new_qty_per_prod').forEach(function () {
340										calculateTotalPrice(this);
341									});
342									node.querySelectorAll('.wdm_new_qty_per_new_prod').forEach(function () {
343										calculateTotalPrice(this, true);
344									});
345								}
346							});
347						} else if (mutation.type === 'attributes' && mutation.attributeName === 'class') {
348							if (mutation.target.classList.contains('wdm_new_qty_per_prod')) {
349								calculateTotalPrice(mutation.target);
350							} else if (mutation.target.classList.contains('wdm_new_qty_per_new_prod')) {
351								calculateTotalPrice(mutation.target, true);
352							}
353						}
354					}
355				});
356				observer.observe(targetNode, config);
357
358				// Event listener for direct changes.
359				$(document).on('change', '.wdm_new_qty_per_prod, .wdm_new_qty_per_new_prod', function (event) {
360					calculateTotalPrice(this, $(this).hasClass('wdm_new_qty_per_new_prod'));
361				});
362			});
363
364			// v1.1.1.
365			/**
366			 *  Handling change on input of Add Product Popup
367			 */
368			$( document ).on(
369				'keypress click input',
370				'input.add-more-product,.wdm_selected_products',
371				function (event) {
372					if (event.which == 45 || event.which == 46 || event.which == 189) {
373						event.preventDefault();
374					}
375					var minVal      = $( this ).attr( 'min' );
376					var grand_total = 0;
377					var quantity    = $( this ).val();
378					if (quantity == "" || quantity < minVal) {
379						quantity = minVal;
380					}
381					var selectedProducts = jQuery( ".wdm_selected_products" );
382					var productId        = $( this ).attr( "id" );
383					var perProductPrice  = $( "#" + productId + "-per-product-price" ).html();
384					var total            = parseInt( perProductPrice ) * parseInt( quantity );
385					$( "#" + productId + "-total-price" ).html( total );
386					var totals = jQuery( '.wdm-product-total' );
387					totals.each(
388						function (index, value) {
389							if (jQuery( selectedProducts[index] ).is( ':checked' )) {
390								grand_total += parseInt( $( this ).html() );
391							}
392						}
393					);
394					$( '#add-product-total-price' ).html( grand_total );
395				}
396			);
397
398			$( document ).on(
399				'keypress',
400				'#add-quantity-inp',
401				function (event) {
402					if (event.which == 45 || event.which == 189) {
403						event.preventDefault();
404					}
405
406				}
407			);
408
409			function closeDialog(dialogObj) {
410				$( dialogObj ).dialog( 'destroy' );
411			}
412
413			/**
414			 * create fields for new user.
415			 */
416			jQuery( '#wdm_user_data' ).delegate(
417				'#btn_add_new',
418				'click',
419				function () {
420					var numItems = jQuery( '#wdm_enroll_fname' ).length;
421					if (numItems < seat_limit) {
422						jQuery( '.wdm_button' ).before(
423							"<ul class='wdm_new_user'>\n\
424                                        <li>\n\
425                                            <i class='dashicons dashicons-dismiss wdm_remove_user'></i>\n\
426                                        </li>\n\
427                                        <li>\n\
428                                                <label for='lbl_first_name'>" + ebbpPublic.enterFirstName + "</label>\n\
429                                            <input type=text class='txt_fname' name='firstname[]' required>\n\
430                                        </li>\n\
431                                        <li>\n\
432                                                <label class='lbl_last_name'>" + ebbpPublic.enterLastName + "</label>\n\
433                                            <input type=text class='txt_lname' name='lastname[]' required>\n\
434                                        </li>\n\
435                                        <li>\n\
436                                                <label class='lbl_email'>" + ebbpPublic.enterEmailName + "</label>\n\
437                                            <input type='email' class='txt_email' name='email[]' ' required>\n\
438                                        </li>\n\
439                                            </ul>"
440						);
441						jQuery( '#btn_enroll' ).removeAttr( 'disabled' );
442						$( this ).toggleClass( "active" );
443					}
444					if (numItems + 1 == seat_limit) {
445						jQuery( this ).attr( 'disabled', 'disabled' );
446					}
447				}
448			);
449
450			$( document ).on(
451				'click',
452				'input',
453				'.txt_fname, .txt_lname, .txt_email',
454				function (event) {
455					jQuery( this ).css( 'border', 'solid 1px #000' );
456				}
457			);
458
459			/**
460			 * Remove extra user fields.
461			 */
462			jQuery( '#enroll-user-form-csv' ).delegate(
463				'.wdm_remove_user',
464				'click',
465				function () {
466					jQuery( this ).parent().parent().remove();
467
468					if (jQuery( '.wdm_remove_user' ).length <= 0) {
469						jQuery( '#enroll-user-form-csv' ).dialog( 'close' );
470						jQuery( '#btn_enroll' ).attr( 'disabled', 'disabled' );
471					}
472					jQuery( "#btn_add_new" ).removeAttr( 'disabled' );
473
474				}
475			);
476
477			$( document ).on(
478				'click',
479				'.ebbp_course_progress',
480				function () {
481					// loader.
482					// $("body").css("cursor", "progress");
483					$( '#eb-lading-parent' ).css( 'display', 'block' );
484
485					var cohortId = $( this ).data( 'cohortid' );
486					var userId   = $( this ).data( 'userid' );
487
488					var courseProgress = {
489						resizable: false,
490						title: ebbpPublic.courseprogres,
491						autoOpen: false,
492						modal: true,
493						width: 550,
494						dialogClass: "ebbp_custom_field_dialog wdm-enroll-stud-page-dialog",
495						buttons: [
496						{
497							text: ebbpPublic.close,
498							class: "wdm-dialog-cancel-button",
499							click: function () {
500								$( this ).dialog( "close" );
501							}
502						}
503						],
504					};
505
506					$.ajax(
507						{
508							type: 'POST',
509							url: ebbpPublic.ajax_url,
510							dataType: 'json',
511							data: {
512								action: 'get_cohort_course_progress',
513								cohort_id: cohortId,
514								user_id: userId,
515								nonce: ebbpPublic.nonce_gp_mng
516							},
517							success: function (response) {
518
519								// $("body").css("cursor", "default");
520								$( '#eb-lading-parent' ).css( 'display', 'none' );
521
522								if (response.success == true) {
523
524									/*$("#add-quantity-popup").empty();
525									$("#add-quantity-popup").html(response.data);
526
527									$("#add-quantity-table").DataTable({
528									searching: false,
529									ordering: false,
530									lengthChange: false,
531									paging : false
532									});
533
534									$('#add-quantity-popup').prop('title', ebbpPublic.addQuantity);
535									$('.eb-background-div').show();
536									$("#add-quantity-popup").dialog(addQuantity).dialog("open");*/
537
538									$( response.data ).dialog( courseProgress ).dialog( "open" );
539
540								}
541								// else {
542
543								// errorMsgDialog(response.data);
544
545								// }
546								// jQuery("#eb-lading-parent").hide();
547							},
548							error: function (response) {
549
550								// $("body").css("cursor", "default");
551								$( '#eb-lading-parent' ).css( 'display', 'none' );
552
553								// errorMsgDialog(response);
554								// jQuery("#eb-lading-parent").hide();
555							}
556						}
557					);
558
559				}
560			);
561
562		}
563	);
564
565})( jQuery );
566
567/*
568 * VARIABLE PRODUCT JS
569 */

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.