Subversion Repositories ALCASAR

Rev

Go to most recent revision | Details | Last modification | View Log

Rev Author Line No. Line
2565 lucas.echa 1
let radiusDays = ['Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su'];
2
 
3
function scheduleToRadius(serialized) {
4
    let radiusPeriod = [];
5
    for(let day in serialized) {
6
        if(radiusDays[day].length > 0) {
7
            for(let period of serialized[day]) {
8
                radiusPeriod.push(
9
                    radiusDays[day] + (period[0] + "-" + period[1]).replace(/:/g, '')
10
                );
11
            }
12
        }
13
    }
14
 
15
    return radiusPeriod.join(',');
16
}
17
 
18
function addPeriodToArray(array, index, hours) {
19
    array[index].push([
20
        hours[0].substr(0,2) + ':' + hours[0].substr(2,4),
21
        hours[1].substr(0,2) + ':' + hours[1].substr(2,4)
22
    ]);
23
}
24
 
25
function radiusToSchedule(radiusAttr) {
26
    let res = [[], [], [], [], [], [], []];
27
 
28
    if(radiusAttr.length === 0) {
29
        return res;
30
    }
31
 
32
    radiusAttr = radiusAttr.split(',');
33
 
34
 
35
    for(let period of radiusAttr) {
36
        day = radiusDays.indexOf(period.substr(0, 2));
37
 
38
        hours = period.substr(2).split('-');
39
 
40
        if(hours.length !== 2) continue;
41
 
42
        if(day === -1) {
43
            if(period.substr(0, 2) === 'Wk') {
44
                for (let i = 0; i < 5; ++i) {
45
                    addPeriodToArray(res, i, hours);
46
                }
47
            } else if(period.substr(0, 3) === 'Any') {
48
                hours = period.substr(3).split('-');
49
 
50
                for (let i = 0; i < 7; ++i) {
51
                    addPeriodToArray(res, i, hours);
52
                }
53
            }
54
        } else {
55
            addPeriodToArray(res, day, hours);
56
        }
57
    }
58
 
59
    return res;
60
 
61
}
62
 
63
(function ($) {
64
    let schedule = $("#login-time-schedule");
65
 
66
    $("#login-time-dialog").dialog({
67
        autoOpen: false,
68
        height: $(window).height() > 650 ? 650 : $(window).height(),
69
        width: $(window).width() > 700 ? 700 : $(window).width(),
70
        modal: true
71
    });
72
 
73
    $("#login-time-calendar").click((e) => {
74
        e.preventDefault();
75
 
76
        let scheduleArray = radiusToSchedule($("#Login-Time").val());
77
 
78
        schedule.data('artsy.dayScheduleSelector').deserialize(scheduleArray);
79
 
80
        $("#login-time-dialog").dialog("open");
81
    });
82
 
83
    schedule.dayScheduleSelector({
84
        interval: 60,
85
        startTime: '00:00',
86
        endTime: '24:00',
87
        stringDays: ['Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi', 'Dimanche']
88
    });
89
    schedule.on('selected.artsy.dayScheduleSelector', function (e, selected) {
90
        let days = schedule.data('artsy.dayScheduleSelector').serialize();
91
        $("#Login-Time").val(scheduleToRadius(days));
92
    });
93
})($);