aboutsummaryrefslogtreecommitdiff
path: root/resources/assets/javascripts/lib/statusgroups.js
blob: ea6b6bd18142dc683303d830a9a121405071ca6d (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
const Statusgroups = {
    ajax_endpoint: false,
    apply: function() {
        $('.movable tbody').sortable({
            axis: 'y',
            handle: '.dragHandle',
            helper: function(event, ui) {
                ui.children().each(function() {
                    $(this).width($(this).width());
                });
                return ui;
            },
            start: function(event, ui) {
                $(this)
                    .closest('table')
                    .addClass('nohover');
            },
            stop: function(event, ui) {
                var table = $(this).closest('table'),
                    group = table.attr('id'),
                    user = ui.item.data('userid'),
                    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: function() {
        //$('input[name="selfassign_start"]').datetimepicker();
        if (!$('input[name="selfassign"]').attr('checked')) {
            $('input[name="exclusive"]')
                .closest($('section'))
                .hide();
            $('input[name="selfassign_start"]')
                .closest($('section'))
                .hide();
            $('input[name="selfassign_end"]')
                .closest($('section'))
                .hide();
        }
        //$('input[name="selfassign_end"]').datetimepicker();
        $('input[name="selfassign"]').on('click', function() {
            $('input[name="exclusive"]')
                .closest($('section'))
                .toggle();
            $('input[name="selfassign_start"]')
                .closest($('section'))
                .toggle();
            $('input[name="selfassign_end"]')
                .closest($('section'))
                .toggle();
        });

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

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

export default Statusgroups;