aboutsummaryrefslogtreecommitdiff
path: root/resources/assets/javascripts/bootstrap/consultations.js
blob: 6897a09b087a50e1c339622b6839047a2a03a242 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { $gettext } from '../lib/gettext.js';

$(document).on('click', '.consultation-delete-check:not(.ignore)', event => {
    const form       = $(event.target).closest('form');
    const checkboxes = form.find(':checkbox[name="slot-id[]"]:checked');
    const ids        = checkboxes.map((index, element) => element.value.split('-').pop()).get();

    if (!ids.length) {
        return false;
    }

    STUDIP.api.GET('consultations/slots/bulk', {data: {ids: ids}}).done(slots => {
        let bookings = 0;
        slots.forEach(slot => bookings += slot.booking_count);
        if (bookings === 0) {
            STUDIP.Dialog.confirm($gettext('Wollen Sie diese Termine wirklich löschen?')).done(() => {
                $('<input type="hidden" name="delete" value="1"/>').appendTo(form);
                form.submit();
            });
        } else {
            $(event.target).addClass('ignore').click().removeClass('ignore');
        }
    });

    event.preventDefault();
});