PageSourceSearch

https://mallettcars.com/wp-content/plugins/service-booking-manager…/mpwpb_user_dashboard.js?ver=1791305836

js mallettcars.com collected 2026-10-06 18:08:31 UTC 14,137 bytes, 388 lines download raw bytes

1jQuery(document).ready(function($) {
2    'use strict';
3    
4    // Cancel booking
5    $('.mpwpb-cancel-btn').on('click', function(e) {
6        e.preventDefault();
7        
8        const bookingId = $(this).data('id');
9        
10        if (confirm(mpwpb_dashboard.cancel_confirm)) {
11            $.ajax({
12                type: 'POST',
13                url: mpwpb_dashboard.ajaxurl,
14                data: {
15                    action: 'mpwpb_cancel_booking',
16                    booking_id: bookingId,
17                    nonce: mpwpb_dashboard.nonce
18                },
19                beforeSend: function() {
20                    // Show loading state
21                    $(e.target).prop('disabled', true).text('Processing...');
22                },
23                success: function(response) {
24                    if (response.success) {
25                        // Show success message and reload page
26                        alert(response.data.message);
27                        window.location.reload();
28                    } else {
29                        // Show error message
30                        alert(response.data.message);
31                        $(e.target).prop('disabled', false).text('Cancel');
32                    }
33                },
34                error: function() {
35                    // Show error message
36                    alert('An error occurred. Please try again.');
37                    $(e.target).prop('disabled', false).text('Cancel');
38                }
39            });
40        }
41    });
42    
43    // Reschedule booking - open modal
44    $('.mpwpb-reschedule-btn').on('click', function(e) {
45        e.preventDefault();
46        
47        const bookingId = $(this).data('id');
48        const serviceId = $(this).data('service');
49        
50        // Set values in the form
51        $('#booking_id').val(bookingId);
52        $('#service_id').val(serviceId);
53        
54        // Clear previous options
55        $('#new_date').html('<option value="">Select Date</option>');
56        $('#new_time').html('<option value="">Select Time</option>');
57        
58        // Get available dates
59        $.ajax({
60            type: 'POST',
61            url: mpwpb_dashboard.ajaxurl,
62            data: {
63                action: 'mpwpb_get_available_dates',
64                service_id: serviceId,
65                nonce: mpwpb_dashboard.nonce
66            },
67            beforeSend: function() {
68                $('#new_date').prop('disabled', true);
69            },
70            success: function(response) {
71                if (response.success && response.data.dates) {
72                    // Populate date dropdown
73                    $.each(response.data.dates, function(index, date) {
74                        $('#new_date').append('<option value="' + date.value + '">' + date.label + '</option>');
75                    });
76                }
77                $('#new_date').prop('disabled', false);
78            },
79            error: function() {
80                alert('Error loading available dates. Please try again.');
81                $('#new_date').prop('disabled', false);
82            }
83        });
84        
85        // Show modal
86        $('#mpwpb-reschedule-modal').css('display', 'block');
87    });
88    
89    // Close modal when clicking the X
90    $('.mpwpb-close').on('click', function() {
91        $('#mpwpb-reschedule-modal').css('display', 'none');
92    });
93    
94    // Close modal when clicking outside the content
95    $(window).on('click', function(e) {
96        if ($(e.target).is('#mpwpb-reschedule-modal')) {
97            $('#mpwpb-reschedule-modal').css('display', 'none');
98        }
99    });
100    
101    // Get time slots when date is selected
102    $('#new_date').on('change', function() {
103        const date = $(this).val();
104        const serviceId = $('#service_id').val();
105        
106        if (!date) {
107            $('#new_time').html('<option value="">Select Time</option>').prop('disabled', true);
108            return;
109        }
110        
111        // Get available time slots for the selected date
112        $.ajax({
113            type: 'POST',
114            url: mpwpb_dashboard.ajaxurl,
115            data: {
116                action: 'mpwpb_get_available_times',
117                service_id: serviceId,
118                date: date,
119                nonce: mpwpb_dashboard.nonce
120            },
121            beforeSend: function() {
122                $('#new_time').html('<option value="">Loading...</option>').prop('disabled', true);
123            },
124            success: function(response) {
125                $('#new_time').html('<option value="">Select Time</option>');
126                
127                if (response.success && response.data.times) {
128                    // Populate time dropdown
129                    $.each(response.data.times, function(index, time) {
130                        $('#new_time').append('<option value="' + time.value + '">' + time.label + '</option>');
131                    });
132                }
133                
134                $('#new_time').prop('disabled', false);
135            },
136            error: function() {
137                $('#new_time').html('<option value="">Select Time</option>').prop('disabled', false);
138                alert('Error loading available times. Please try again.');
139            }
140        });
141    });
142    
143    // Submit reschedule form
144    $('#mpwpb-reschedule-form').on('submit', function(e) {
145        e.preventDefault();
146        
147        const bookingId = $('#booking_id').val();
148        const newDate = $('#new_date').val();
149        const newTime = $('#new_time').val();
150        
151        if (!newDate || !newTime) {
152            alert('Please select both date and time.');
153            return;
154        }
155        
156        $.ajax({
157            type: 'POST',
158            url: mpwpb_dashboard.ajaxurl,
159            data: {
160                action: 'mpwpb_reschedule_booking',
161                booking_id: bookingId,
162                new_date: newDate,
163                new_time: newTime,
164                nonce: mpwpb_dashboard.nonce
165            },
166            beforeSend: function() {
167                $('.mpwpb-submit-btn').prop('disabled', true).text('Processing...');
168            },
169            success: function(response) {
170                if (response.success) {
171                    alert(response.data.message);
172                    window.location.reload();
173                } else {
174                    alert(response.data.message);
175                    $('.mpwpb-submit-btn').prop('disabled', false).text('Confirm Reschedule');
176                }
177            },
178            error: function() {
179                alert('An error occurred. Please try again.');
180                $('.mpwpb-submit-btn').prop('disabled', false).text('Confirm Reschedule');
181            }
182        });
183    });
184
185    $(document).on('click', '.mpwpb_view_selected_service_staff', function(e) {
186        e.preventDefault();
187
188        $('.mpwpb-service-staff_card').fadeOut();
189        $(this).closest('.mpwpb-service-wrapper')
190            .find('.mpwpb-service-staff_card')
191            .fadeIn();
192    });
193
194    // Profile update form
195    $('#mpwpb-profile-form').on('submit', function(e) {
196        e.preventDefault();
197        
198        // Validate password confirmation
199        const password = $('#password').val();
200        const passwordConfirm = $('#password_confirm').val();
201        
202        if (password && password !== passwordConfirm) {
203            $('#mpwpb-profile-message').removeClass('success').addClass('error').text('Passwords do not match').show();
204            return;
205        }
206        
207        // Get form data
208        const formData = $(this).serialize();
209        
210        $.ajax({
211            type: 'POST',
212            url: mpwpb_dashboard.ajaxurl,
213            data: {
214                action: 'mpwpb_update_user_profile',
215                nonce: mpwpb_dashboard.nonce,
216                ...formData
217            },
218            beforeSend: function() {
219                $('.mpwpb-submit-btn').prop('disabled', true).text('Updating...');
220                $('#mpwpb-profile-message').hide();
221            },
222            success: function(response) {
223                if (response.success) {
224                    $('#mpwpb-profile-message').removeClass('error').addClass('success').text(response.data.message).show();
225                    
226                    // Clear password fields
227                    $('#password, #password_confirm').val('');
228                } else {
229                    $('#mpwpb-profile-message').removeClass('success').addClass('error').text(response.data.message).show();
230                }
231                
232                $('.mpwpb-submit-btn').prop('disabled', false).text('Update Profile');
233            },
234            error: function() {
235                $('#mpwpb-profile-message').removeClass('success').addClass('error').text('An error occurred. Please try again.').show();
236                $('.mpwpb-submit-btn').prop('disabled', false).text('Update Profile');
237            }
238        });
239    });
240
241
242    function getAllOffDates() {
243        let dates = [];
244        $('input[name="mpwpb_off_dates[]"]').each(function() {
245            let val = $(this).val();
246            if (val) {
247                dates.push(val);
248            }
249        });
250        return dates;
251    }
252    function updateOffDaysValue() {
253        let selectedDays = [];
254        $('.groupCheckBox input[type="checkbox"]').each(function() {
255            if ($(this).is(':checked')) {
256                selectedDays.push($(this).data('checked'));
257            }
258        });
259
260        $('input[name="mpwpb_off_days"]').val(selectedDays.join(','));
261    }
262
263    $('.groupCheckBox input[type="checkbox"]').on('change', function() {
264        updateOffDaysValue();
265    });
266    updateOffDaysValue();
267
268    $(document).on('click', '#saveScheduleBtn', function(e) {
269
270        e.preventDefault();
271
272        let offDays = $('input[name="mpwpb_off_days"]').val();
273        let offDates = getAllOffDates();
274        let offDates_str = JSON.stringify( offDates );
275        // console.log( offDates_str );
276
277        var days = ['default', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'];
278        var schedule = {};
279
280        days.forEach(function(day) {
281            const start       = $(`select[name="mpwpb_${day}_start_time"]`).val();
282            const end         = $(`select[name="mpwpb_${day}_end_time"]`).val();
283            const break_start = $(`select[name="mpwpb_${day}_start_break_time"]`).val();
284            const break_end   = $(`select[name="mpwpb_${day}_end_break_time"]`).val();
285            schedule[day] = {
286                start_time: start,
287                end_time: end,
288                start_break_time: break_start || "",
289                end_break_time: break_end || ""
290            };
291        });
292        if (!schedule['default']) {
293            alert("Default time must have both Start and End time.");
294            return;
295        }
296        $.post( mpwpb_ajax_url , {
297            action: 'mpwpb_save_specific_schedule',
298            schedule: schedule,
299            offDays: offDays,
300            offDates_str: offDates_str,
301        }, function(response) {
302            if (response.success) {
303                alert('Schedule saved successfully!');
304            } else {
305                alert('Error: ' + response.data);
306            }
307        });
308
309    });
310
311    $('#mpmw_staff_add_off_date').on('click', function() {
312        $('#mpmw_staff_off_dates_wrapper').append(`
313            <div class="mpmw_staff_off_date_row">
314                <input type="date" class="mpmw_staff_off_date_input" name="mpmw_staff_off_dates[]">
315                <button type="button" class="mpmw_staff_delete_btn">🗑️</button>
316            </div>
317        `);
318    });
319
320    // Remove date row
321    $(document).on('click', '.mpmw_staff_delete_btn', function() {
322        $(this).closest('.mpmw_staff_off_date_row').remove();
323    });
324
325    // Get all selected off dates
326    function getOffDates() {
327        let offDates = [];
328        $('.mpmw_staff_off_date_input').each(function() {
329            const val = $(this).val();
330            if (val) {
331                offDates.push(val);
332            }
333        });
334        return offDates;
335    }
336
337    // Example: Get on button click
338    $('#mpmw_staff_get_dates').on('click', function() {
339        const dates = getOffDates();
340        console.log('Selected Dates:', dates);
341    });
342
343    function load_sortable_datepicker(parent, item) {
344        if(parent.find('.mp_item_insert_before').length>0){
345            jQuery(item).insertBefore(parent.find('.mp_item_insert_before').first()).promise().done(function () {
346                parent.find('.mp_sortable_area').sortable({
347                    handle: jQuery(this).find('.mpwpb_sortable_button')
348                });
349                mpwpb_load_date_picker(parent);
350            });
351        }else {
352            parent.find('.mp_item_insert').first().append(item).promise().done(function () {
353                parent.find('.mp_sortable_area').sortable({
354                    handle: jQuery(this).find('.mpwpb_sortable_button')
355                });
356                mpwpb_load_date_picker(parent);
357            });
358        }
359        return true;
360    }
361    $(document).find('.mp_sortable_area').sortable({
362        handle: $(this).find('.mpwpb_sortable_button')
363    });
364
365    $(document).on('click', '.mpwpb_item_remove', function (e) {
366        e.preventDefault();
367        if (confirm('Are You Sure , Remove this row ? \n\n 1. Ok : To Remove . \n 2. Cancel : To Cancel .')) {
368            $(this).closest('.mp_remove_area').slideUp(250).remove();
369            return true;
370        } else {
371            return false;
372        }
373    });
374
375    $(document).on('click', '.mp_add_item', function () {
376        let parent = $(this).closest('.mp_settings_area');
377        let item = $(this).next($('.mpwpb_hidden_content')).find(' .mpwpb_hidden_item').html();
378        if (!item || item === "undefined" || item === " ") {
379            item = parent.find('.mpwpb_hidden_content').first().find('.mpwpb_hidden_item').html();
380        }
381        load_sortable_datepicker(parent, item);
382        parent.find('.mp_item_insert').find('.add_mpwpb_select2').select2({});
383        return true;
384    });
385
386
387
388});

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.