PageSourceSearch

https://cphride.dk/wp-content/plugins/bookly-responsive-appointmen…/resources/js/staff-schedule.js?ver=28.5

js cphride.dk collected 2026-10-08 07:22:52 UTC 15,363 bytes, 296 lines download raw bytes

1(function ($) {
2    var Schedule = function ($container, options) {
3        let obj = this;
4        jQuery.extend(obj.options, options);
5
6        // Loads schedule list
7        if (options.reload) {
8            $container.html('<div class="bookly-loading"></div>');
9            $.ajax({
10                type: 'POST',
11                url: ajaxurl,
12                data: $.extend({csrf_token: BooklyL10nGlobal.csrf_token}, obj.options.get_staff_schedule),
13                dataType: 'json',
14                xhrFields: {withCredentials: true},
15                crossDomain: 'withCredentials' in new XMLHttpRequest(),
16                success: function (response) {
17                    // fill in the container
18                    $container.html('');
19                    $container.append(response.data.html);
20                    $container.removeData('init');
21                    obj.options.onLoad();
22                    initContainer($container, obj);
23                }
24            });
25        } else {
26            initContainer($container, obj);
27        }
28
29        function initContainer($panel, obj) {
30            if ($panel.data('init') != true) {
31                initBooklyPopover($container);
32
33                $container.off()
34                    // Save Schedule
35                    .on('click', '#bookly-schedule-save', function (e) {
36                        e.preventDefault();
37                        let ladda = Ladda.create(this),
38                            data = {};
39                        ladda.start();
40                        $('select.bookly-js-parent-range-start, select.bookly-js-parent-range-end, input:hidden', $container).each(function () {
41                            data[this.name] = this.value;
42                        });
43                        data['location_id'] = $('#staff_location_id', $container).val();
44                        data['custom_location_settings'] = $('#custom_location_settings', $container).val();
45                        data['staff_id'] = obj.options.get_staff_schedule.staff_id;
46                        data['action'] = 'bookly_update_staff_schedule';
47                        data['csrf_token'] = BooklyL10nGlobal.csrf_token;
48                        $.post(ajaxurl, $.param(data), function () {
49                            ladda.stop();
50                            obj.options.saving({success: [obj.options.l10n.saved]});
51                        });
52                    })
53                    // Resets initial schedule values
54                    .on('click', '#bookly-schedule-reset', function (e) {
55                        e.preventDefault();
56                        var ladda = Ladda.create(this);
57                        ladda.start();
58
59                        $('.bookly-js-parent-range-start', $container).each(function () {
60                            $(this).val($(this).data('default_value'));
61                            $(this).trigger('change');
62                        });
63
64                        $('.bookly-js-parent-range-end', $container).each(function () {
65                            $(this).val($(this).data('default_value'));
66                        });
67
68                        // reset breaks
69                        $.ajax({
70                            url: ajaxurl,
71                            type: 'POST',
72                            data: {
73                                action: 'bookly_staff_cabinet_reset_breaks',
74                                breaks: $(this).data('default-breaks'),
75                                staff_cabinet: $(this).data('staff-cabinet') || 0,
76                                csrf_token: BooklyL10nGlobal.csrf_token
77                            },
78                            dataType: 'json',
79                            success: function (response) {
80                                $('[data-index]', $container).each(function () {
81                                    let $row = $(this),
82                                        index = $row.data('index'),
83                                        $list = $('.bookly-js-breaks-list', $row);
84                                    $list.html('');
85                                    if (response.data.breaks.hasOwnProperty(index)) {
86                                        response.data.breaks[index].forEac
86h(function (elem) {
87                                            var $html = $.parseHTML(elem);
88                                            initBooklyPopover($html);
89                                            $list.append($html)
90                                        });
91                                    }
92                                });
93                            },
94                            complete: function () {
95                                ladda.stop();
96                            }
97                        });
98                    })
99                    .on('click', '.bookly-js-clone-schedule a', function (e) {
100                        let from = $(this).closest('.bookly-js-range-row').find('.bookly-js-parent-range-start').val(),
101                            to = $(this).closest('.bookly-js-range-row').find('.bookly-js-parent-range-end').val();
102                        $('#bookly-schedule-container .bookly-js-parent-range-start').val(from).trigger('change');
103                        $('#bookly-schedule-container .bookly-js-parent-range-end').val(to).trigger('change');
104                    })
105                    .on('click', '.popover-body .bookly-js-save-break', function (e) {
106                        e.preventDefault();
107                        // Listener for saving break.
108                        let $button = $(this),
109                            $body = $button.closest('.popover-body'),
110                            ladda = rangeTools.ladda(this),
111                            data = $.extend({
112                                action: 'bookly_staff_schedule_handle_break',
113                                csrf_token: BooklyL10nGlobal.csrf_token,
114                                start_time: $('.bookly-js-popover-range-start', $body).val(),
115                                end_time: $('.bookly-js-popover-range-end', $body).val(),
116                            }, $button.data('submit'));
117                        let $parentRange = $('.bookly-js-range-row[data-key=' + data.ss_id + ']');
118
119                        data.working_end = $('.bookly-js-parent-range-end > option:selected', $parentRange).val();
120                        data.working_start = $('.bookly-js-parent-range-start > option:selected', $parentRange).val();
121                        $.ajax({
122                            method: 'POST',
123                            url: ajaxurl,
124                            data: data,
125                            dataType: 'json',
126                            success: function (response) {
127                                if (response.success) {
128                                    if (data.hasOwnProperty('id')) {
129                                        // Change text on button with new range value.
130                                        var $interval_button = $('button.bookly-js-break-interval', $('[data-entity-id=' + data.id + ']'));
131                                        $interval_button.html(response.data.interval);
132                                    } else {
133                                        var $html = $.parseHTML(response.data.html);
134                                        initBooklyPopover($html);
135                                        $('.bookly-js-range-row[data-key=' + data.ss_id + '] .bookly-js-breaks-list', $container)
136                                            .append($html);
137                                    }
138                                    $button.data('start', data.start_time);
139                                    $button.data('end', data.end_time);
140                                    $button.parents('.bookly-popover').booklyPopover('hide');
141                                } else {
142                                    if (response.data && response.data.message) {
143                                        obj.options.booklyAlert({error: [response.data.message]});
144                                    }
145                                }
146                            }
147                        }).always(function () {
148                            ladda.stop()
149                        });
150                    })
151                    .on('click', '.bookly-js-delete-break', function () {
152                        deleteBreak.call(this);
153                    })
154
155                    .on('change', '.bookly-js-popover-range-start', function () {
156                        let $start = $(this),
157                            $body = $start.closest('.popover-body'),
158                            $end = $('.bookly-js-popover-range-end', $body),
159                            ss_id = $('.bookly-js-save-break', $body).data('submit').ss_id,
160                            $parent = $('.bookly-js-range-row[data-key=' + ss_id + ']');
161                        rangeTools.hideInaccessibleBreaks($start, $end, $parent);
162                    })
163
164                    .on('change', '.bookly-js-parent-range-start', function () {
165                        var $parentRangeStart = $(this),
166                            $rangeRow = $parentRangeStart.parents('.bookly-js-range-row');
167                        if ($parentRangeStart.val() == '') {
168                            $rangeRow
169                                .find('.bookly-js-hide-on-off').hide().end()
170                                .find('.bookly-js-invisible-on-off').addClass('d-none');
171                        } else {
172                            $rangeRow
173                                .find('.bookly-js-hide-on-off').show().end()
174                                .find('.bookly-js-invisible-on-off').removeClass('d-none');
175                            rangeTools.hideInaccessibleEndTime($parentRangeStart, $('.bookly-js-parent-range-end', $rangeRow));
176                        }
177                    })
178                    // Change location
179                    .on('change', '#staff_location_id', function () {
180                        let get_staff_schedule = {
181                                action: obj.options.get_staff_schedule.action,
182                                staff_id: obj.options.get_staff_schedule.staff_id
183                            },
184                            staff_location_id = $('#staff_location_id', $container).val();
185                        if (staff_location_id != '') {
186                            get_staff_schedule['location_id'] = staff_location_id;
187                        }
188                        new BooklyStaffSchedule($container, {
189                            reload: true,
190                            get_staff_schedule: get_staff_schedule,
191                            l10n: options.l10n
192                        });
193                    })
194                    // Change default/custom settings for location
195                    .on('change', '#custom_location_settings', function () {
196                        if ($(this).val() == 1) {
197                            $('.bookly-js-range-row', $container).show();
198                        } else {
199                            $('.bookly-js-range-row', $container).hide();
200                        }
201                    })
202                ;
203
204                $('#custom_location_settings', $container).trigger('change');
205                $('.bookly-js-parent-range-start', $container).trigger('change');
206                $container.data('init', true);
207            }
208        }
209
210        function initBooklyPopover($panel) {
211            $('.bookly-js-toggle-popover', $panel)
212                .booklyPopover({
213                    html: true,
214                    placement: 'bottom',
215                    container: $container,
216                    template: '<div class="bookly-popover mw-100" role="tooltip"><div class="arrow"></div><div class="popover-body"></div></div>',
217                    trigger: 'manual',
218                    content: function () {
219                        let $button = $(this),
220                            $popover = $('.bookly-js-edit-break-body > div', $container).clone(),
221                            $popoverStart = $('.bookly-js-popover-range-start', $popover),
222                            $popoverEnd = $('.bookly-js-popover-range-end', $popover),
223                            $saveButton = $('.bookly-js-save-break', $popover),
224                            force_keep_values = false;
225                        if ($button.hasClass('bookly-js-break-interval')) {
226                            $popoverStart.val($button.data('start'));
227                            $popoverEnd.val($button.data('end'));
228                            force_keep_values = true;
229                            $saveButton.data('submit', {
230                                id: $button.closest('[data-entity-id]').data('entity-id'),
231                                ss_id: $button.closest('.bookly-js-range-row').data('key'),
232                            });
233                        } else {
234                            rangeTools.setPopoverRangeDefault($popoverStart, $popoverEnd, $button.closest('.bookly-js-range-row'));
235                            $saveButton.data('submit', {
236                                ss_id: $button.closest('.bookly-js-range-row').data('key'),
237                            });
238                        }
239                        rangeTools.hideInaccessibleBreaks($popoverStart, $popoverEnd, $button.closest('.bookly-js-range-row'), force_keep_values);
240                        $('.bookly-js-close', $popover).on('click', function () {
241                            $button.booklyPopover('hide');
242                        });
243
244                        return $popover;
245                    }
246                })
247                .on('click', function () {
248                    $('.bookly-js-toggle-popover').booklyPopover('hide');
249                    $(this).booklyPopover('toggle');
250                });
251        }
252
253        function deleteBreak() {
254            var $btn_group = $(this).closest('[data-entity-id]');
255            if (confirm(obj.options.l10n.areYouSure)) {
256                var ladda = Ladda.create(this);
257                ladda.start();
258                $.ajax({
259                    url: ajaxurl,
260                    type: 'POST',
261                    data: {
262                        action: 'bookly_delete_staff_schedule_break',
263                        id: $btn_group.data('entity-id'),
264                        csrf_token: BooklyL10nGlobal.csrf_token
265                    },
266                    success: function (response) {
267                        if (response.success) {
268                            $btn_group.remove();
269                        }
270                    },
271                    complete: function () {
272                        ladda.stop();
273                    }
274                });
275            }
276        }
277    };
278
279    Schedule.prototype.options = {
280        reload: false,
281        get_staff_schedule: {
282            action: 'bookly_get_staff_schedule',
283            staff_id: -1,
284        },
285        saving: function (alerts) {
286            $(document.body).trigger('staff.saving', [alerts]);
287        },
288        booklyAlert: function (alerts) {
289            booklyAlert(alerts);
290        },
291        onLoad: function () {},
292        l10n: {}
293    };
294
295    window.BooklyStaffSchedule = Schedule;
296})(jQuery);

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.