aboutsummaryrefslogtreecommitdiff
path: root/resources/assets/javascripts/lib/statusgroups.js
blob: 1ed44a5d11a67a8dc323e6981085991fd1cfdfc0 (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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const Statusgroups = {
    ajax_endpoint: false,
    apply() {
        $('.movable tbody').sortable({
            axis: 'y',
            handle: '.drag-handle',
            helper(event, ui) {
                ui.children().each(function () {
                    $(this).width($(this).width());
                });
                return ui;
            },
            start() {
                $(this)
                    .closest('table')
                    .addClass('nohover');
            },
            stop(event, ui) {
                const table = $(this).closest('table');
                const group = table.attr('id');
                const user = ui.item.data('userid');
                const position = $(ui.item).prevAll().length;

                table.removeClass('nohover');

                $.ajax({
                    type: 'POST',
                    url: Statusgroups.ajax_endpoint,
                    dataType: 'html',
                    data: {group: group, user: user, pos: position},
                    async: false
                }).done(function (data) {
                    $('tbody', table).html(data);
                    Statusgroups.apply();
                });
            }
        });
    },

    initInputs() {
        $('input[name="numbering_type"]').on('click', () => {
            const type = $('input[name="numbering_type"]:checked').val();
            const disabled = parseInt(type, 10) === 2;

            $('input[name="startnumber"]')
                .prop('disabled', disabled)
                .toggle(!disabled);
        });
    }
};

export default Statusgroups;