PageSourceSearch

https://fhclm.ca/wp-content/plugins/AnWp_FormulairesDeDons/js/FormWizard/stepManager.js?ver=1.0.0

js fhclm.ca collected 2026-10-08 03:28:36 UTC 13,677 bytes, 367 lines download raw bytes

1// stepManager.js
2(function($, FW) {
3    'use strict';
4
5    FW.StepManager = (function() {
6        let FormType = DonationFormData.formType;
7        let stepsConfig;
8
9        if (FormType == "general") {
10            stepsConfig = {
11                'step-giftChoice': {
12                    next: function() {
13                        const recurrenceValue = $('#recurrence').val();
14                        if (recurrenceValue === 'one-time') {
15                            return 'step-convertToMonthly';
16                        } else if (recurrenceValue === 'monthly') {
17                            return 'step-donorInfo';
18                        } else {
19                            return 'step-donorInfo';
20                        }
21                    }
22                },
23                'step-giftChoice': {
24                    next: function() {
25                        const recurrenceValue = $('#recurrence').val();
26
27                        if (recurrenceValue === 'one-time') {
28                            const oneTimeValue = $('#one-time-amount').val();
29                            
30                            if (!oneTimeValue || oneTimeValue.trim() === '' || oneTimeValue == 0) {
31                                $('#error-one-time-value').text('Veuillez saisir un montant');
32                                return false;
33                            } else {
34                                $('#error-one-time-value').text('');
35                                return 'step-convertToMonthly';
36                            }
37                        } else if (recurrenceValue === 'monthly') {
38                            const monthlyValue = $('#monthly-amount').val();
39                            
40                            if (!monthlyValue || monthlyValue.trim() === '' || monthlyValue == 0) {
41                                $('#error-monthly-value').text('Veuillez saisir un montant');
42                                return false;
43                            } else {
44                                $('#error-monthly-value').text('');
45                                return 'step-donorInfo';
46                            }
47                        } else {
48                            return 'step-donorInfo';
49                        }
50                    }
51                },
52                'step-convertToMonthly': {
53                    next: function() {
54                        return 'step-donorInfo';
55                    }
56                },
57                'step-donorInfo': {
58                    next: function() {
59                        return 'step-payment';
60                    }
61                },
62                'step-payment': {
63                    next: null
64                }
65            };
66        }
67        if (FormType == "monthly") {
68            
69        }
70        if (FormType == "one-time") {
71            
72        }
73        if (FormType == "golf") {
74            stepsConfig = {
75                'step-golf': {
76                    next: function() {
77                        return 'step-donorInfo';
78                    }
79                },
80                'step-donorInfo': {
81                    next: function() {
82                        return 'step-payment';
83                    }
84                },
85                'step-payment': {
86                    next: null
87                }
88            };
89        }
90        if (FormType == "loto") {
91            stepsConfig = {
92                'step-loto': {
93                    next: function() {
94                        return 'step-donorInfo';
95                    }
96                },
97                'step-donorInfo': {
98                    next: function() {
99                        return 'step-payment';
100                    }
101                },
102                'step-payment': {
103                    next: null
104                }
105            };
106        }
107        if (FormType == "paulee") {
108            stepsConfig = {
109                'step-paulee': {
110                    next: function() {
111                        const pauleeTotal = parseFloat($('#product-total--paulee').val()) || 0;
112
113                        if (pauleeTotal <= 0) {
114                            $('#error-paulee-value').text('Veuillez sélectionner au moins un b
114illet');
115                            return false;
116                        }
117
118                        $('#error-paulee-value').text('');
119                        return 'step-donorInfo';
120                    }
121                },
122                'step-donorInfo': {
123                    next: function() {
124                        return 'step-payment';
125                    }
126                },
127                'step-payment': {
128                    next: null
129                }
130            };
131        }
132        if (FormType == "invoice") {
133            stepsConfig = {
134                'step-invoice': {
135                    next: function() {
136                        const invoiceAmount = parseFloat($('#invoice-amount').val()) || 0;
137                        const invoiceNumber = ($('#invoice-number').val() || '').trim();
138
139                        if (invoiceAmount <= 0) {
140                            $('#error-invoice-amount').text('Veuillez saisir un montant valide');
141                            return false;
142                        }
143
144                        $('#error-invoice-amount').text('');
145
146                        if (!invoiceNumber) {
147                            $('#invoice-number').next('.error-message').text('Ce champ est requis.').show();
148                            return false;
149                        }
150
151                        $('#invoice-number').next('.error-message').text('').hide();
152                        return 'step-donorInfo';
153                    }
154                },
155                'step-donorInfo': {
156                    next: function() {
157                        return 'step-payment';
158                    }
159                },
160                'step-payment': {
161                    next: null
162                }
163            };
164        }
165        if (FormType == "admin") {
166            
167        }
168        if (FormType == "encrypted") {
169            stepsConfig = {
170                'step-encGiftChoice': {
171                    next: function() {
172                        return 'step-encPayment';
173                    }
174                },
175                'step-encPayment': {
176                    next: null
177                }
178            };
179        }
180
181
182        let currentStepId = Object.keys(stepsConfig)[0];
183        const historyStack = [];
184
185        function init() {
186            showStep(currentStepId);
187            bindEvents();
188        }
189
190        function bindEvents() {
191            $('#nextBtn').on('click', function(e) {
192                e.preventDefault();
193                FW.ValidationManager.validateCurrentStep(goToNextStep);
194            });
195
196            $('#backBtn').on('click', function(e) {
197                e.preventDefault();
198                goToPreviousStep();
199            });
200        }
201
202        function showStep(stepId) {
203            $('.form-section .step').removeClass('step--active slide-in-right slide-in-left');
204            const direction = (historyStack.length > 0) ? 'slide-in-left' : 'slide-in-right';
205            $(`#${stepId}`).addClass('step--active').addClass(direction).one('animationend webkitAnimationEnd oAnimationEnd MSAnimationEnd', function() {
206                $(this).removeClass('slide-in-right slide-in-left');
207            });
208            updateNavigation(stepId);
209        }
210
211        function getNextStep() {
212            const step = stepsConfig[currentStepId];
213            if (step && typeof step.next === 'function') {
214                return step.next();
215            }
216            return null;
217        }
218
219        function goToStep(stepId, direction = 'forward') {
220            if (!stepId) return;
221            if (direction === 'forward') {
222                historyStack.push(currentStepId);
223            }
224            currentStepId = stepId;
225            showStep(currentStepId);
226        }
227
228        function goToNextStep() {
229            const nextStep = getNextStep();
230
231            // If nextStep is explicitly false, do nothing (i.e., block navigation)
232            if (nextStep === false) {
233                return;
234            }
235    
236            if (nextStep) {
237                goToStep(nextStep, 'forward');
238            } else {
239                submitForm();
240            }
241        }
242
243        function goToPreviousStep() {
244            const previousStep = historyStack.pop();
245            if (previousStep) {
246                goToStep(previousStep, 'backward');
247            }
248        }
249
250        function submitForm() {
251            $('#donation-form').submit();
252        }
253
254        // function submitForm() {
255        //     var recurrence = $('#recurrence').val();
256        //     if (recurrence === 'subscription') {
257        //         // Handle subscription-specific submission with Stripe SetupIntent
258        //         handleSubscriptionSubmission();
259        //     } else {
260        //         $('#donation-form').submit();
261        //     }
262        // }
263
264        // function handleSubscriptionSubmission() {
265        //     console.log('Handling subscription submission.');
266        //     var stripe = Stripe(StripeData.publishableKey);
267            
268        //     // Create a SetupIntent on the backend via AJAX using the localized URL.
269        //     $.ajax({
270        //         url: StripeData.setupIntentUrl,
271        //         method: "POST",
272        //         contentType: "application/json",
273        //         data: JSON.stringify({}),
274        //         success: function(response) {
275        //             console.log(response);
276        //             // Check that response.client_secret is present.
277        //             if (!response.client_secret) {
278        //                 alert("Erreur: client_secret non renvoyé.");
279        //                 return;
280        //             }
281        //             // Create Elements, passing the clientSecret.
282        //             var elements = stripe.elements({
283        //                 clientSecret: response.client_secret
284        //             });
285        //             // Create and mount the Payment Element.
286        //             var paymentElement = elements.create("payment");
287        //             paymentElement.mount("#payment-element");
288
289        //             // Confirm the SetupIntent with the Payment Element.
290        //             stripe.confirmSetup({
291        //                 elements: elements,
292        //                 clientSecret: response.client_secret,
293        //                 confirmParams: {
294        //                     return_url: window.location.href
295        //                 }
296        //             }).then(function(result) {
297        //                 if (result.error) {
298        //                     alert("Erreur: " + result.error.message);
299        //                 } else {
300        //                     // Append the payment method ID as a hidden input.
301        //                     $('<input>').attr({
302        //                         type: 'hidden',
303        //                         name: 'payment_method_id',
304        //                         value: result.setupIntent.payment_method
305        //                     }).appendTo('#donation-form');
306        //                     // Submit the form.
307        //                     $('#donation-form')[0].submit();
308        //                 }
309        //             });
310        //         },
311        //         error: function(xhr, status, error) {
312        //             alert("Erreur lors de la création du SetupIntent: " + error);
313        //         }
314        //     });
315        // }
316
317        function updateNavigation(stepId) {
318            let FormType = DonationFormData.formType;
319            const recurrenceValue = $('#recurrence').val();
320            const nextBtn = $('#nextBtn');
321            const backBtn = $('#backBtn');
322            const navigationSection = $('.navigation');
323            let oneTimeInput = parseFloat($('#one-time-amount').val()) || 0;
324            const consentFhclm = $('#consent-fhclm');
325
326            consentFhclm.hide();
327
328            if (!stepsConfig[stepId].next) {
329                nextBtn.text("Donnez").attr("aria-label", "Donnez").removeClass("icon--cc");
330            } else {
331                nextBtn.text("Suivant").attr("aria-label", "Suivant").removeClass("icon--cc");
332            }
333
334            if (stepId === 'step-giftChoice' && FormType === "general" && recurrenceValue === 'monthly') {
335                nextBtn.text(`Je donne chaque mois`);
336            }
337
338            if (stepId === 'step-convertToMonthly') {
339                nextBtn.html(`Je continue mon don de <span class="sync-one-time-amount">${parseFloat(oneTimeInput.toFixed(2))}</span>$`).removeClass("icon--cc");
340            }
341            if (stepId === 'step-payment') {
342                nextBtn.text('Carte de crédit').addClass("icon--cc");
343                consentFhclm.show();
344            }
345
346            if (historyStack.length === 0) {
347                backBtn.hide();
348                navigationSection.removeClass("navigation--multiple").addClass("navigation--single");
349                nextBtn.css('width', '100%');
350            } else {
351                backBtn.show().css('width', '20%');
352                navigationSection.removeClass("navigation--single").addClass("navigation--multiple");
353                nextBtn.css('width', '75%');
354            }
355        }
356
357        return {
358            init,
359            goToNextStep,
360            updateNavigation
361        };
362    })();
363
364    $(document).ready(function() {
365        FormWizard.StepManager.init();
366    });
367})(jQuery, window.FormWizard = window.FormWizard || {});

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.