aboutsummaryrefslogtreecommitdiff
path: root/resources/assets/javascripts/lib/startpage.js
blob: 15b2c591acea40aa13417ccc901dcc6cf7513cbb (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
const startpage = {
    init: function() {
        $('.start-widgetcontainer .portal-widget-list').sortable({
            handle: '.widget-header',
            connectWith: 'ul.portal-widget-list',
            start: function() {
                $(this)
                    .closest('.start-widgetcontainer')
                    .find('.portal-widget-list')
                    .addClass('ui-sortable move');
            },
            stop: function(event, ui) {
                $.get(STUDIP.ABSOLUTE_URI_STUDIP + 'dispatch.php/start/storeNewOrder', {
                    widget: $(ui.item).attr('id'),
                    position: $(ui.item).index(),
                    column: $(ui.item)
                        .parent()
                        .index()
                });
                $(this)
                    .closest('.start-widgetcontainer')
                    .find('.portal-widget-list')
                    .removeClass('move');
            }
        });
    },

    init_edit: function(perm) {
        $('.edit-widgetcontainer .portal-widget-list').sortable({
            handle: '.widget-header',
            connectWith: '.edit-widgetcontainer .portal-widget-list',
            start: function() {
                $(this)
                    .closest('.edit-widgetcontainer')
                    .find('.portal-widget-list')
                    .addClass('ui-sortable move');
            },
            stop: function() {
                // store the whole widget constellation
                var widgets = {
                    left: {},
                    right: {}
                };

                $('.edit-widgetcontainer .start-widgetcontainer .portal-widget-list:first-child > li').each(function() {
                    widgets.left[$(this).attr('id')] = $(this).index();
                });

                $('.edit-widgetcontainer .start-widgetcontainer .portal-widget-list:last-child > li').each(function() {
                    widgets.right[$(this).attr('id')] = $(this).index();
                });

                $.post(STUDIP.ABSOLUTE_URI_STUDIP + 'dispatch.php/start/update_defaults/' + perm, widgets);

                $(this)
                    .closest('.edit-widgetcontainer')
                    .find('.portal-widget-list')
                    .removeClass('move');
            }
        });
    }
};

export default startpage;