Subversion Repositories ALCASAR

Rev

Rev 2565 | Details | Compare with Previous | 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
 
2626 lucas.echa 18
function addPeriodToArray(array, day, hours) {
19
    array[radiusDays.indexOf(day)].push([
2565 lucas.echa 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) {
2626 lucas.echa 36
        hours = /[0-9]{4}-[0-9]{4}$/.exec(period);
2565 lucas.echa 37
 
2626 lucas.echa 38
        if(hours === null) {
39
            hours = "0000-2400";
40
        } else {
41
            hours = hours[0]
42
        }
2565 lucas.echa 43
 
2626 lucas.echa 44
        hours = hours.split('-');
2565 lucas.echa 45
 
2626 lucas.echa 46
 
47
        days = /^[a-zA-Z]{2,3}(?:-[a-zA-Z]{2})?/.exec(period);
48
 
49
        if(days === null) {
50
            continue;
51
        } else {
52
            days = days[0].split('-');
53
            if(days.length > 1) {
54
                dBegin = radiusDays.indexOf(days[0]);
55
                dEnd = radiusDays.indexOf(days[1]);
56
 
57
                if(dBegin === -1 || dEnd === -1 || dBegin > dEnd) {
58
                    continue;
2565 lucas.echa 59
                }
60
 
2626 lucas.echa 61
                days = radiusDays.slice(dBegin, dEnd + 1);
2565 lucas.echa 62
            }
2626 lucas.echa 63
        }
64
 
65
        if(hours.length !== 2) continue;
66
 
67
        if(days[0] === 'Wk') {
68
            for (let i = 0; i < 5; ++i) {
69
                addPeriodToArray(res, radiusDays[i], hours);
70
            }
71
        } else if(days[0] === 'Any' || days[0] == 'Al') {
72
            for (day of radiusDays) {
73
                addPeriodToArray(res, day, hours);
74
            }
2565 lucas.echa 75
        } else {
2626 lucas.echa 76
            for(day of days) {
77
                addPeriodToArray(res, day, hours);
78
            }
2565 lucas.echa 79
        }
80
    }
81
 
82
    return res;
83
}
84
 
85
(function ($) {
86
    let schedule = $("#login-time-schedule");
87
 
88
    $("#login-time-dialog").dialog({
89
        autoOpen: false,
90
        height: $(window).height() > 650 ? 650 : $(window).height(),
91
        width: $(window).width() > 700 ? 700 : $(window).width(),
92
        modal: true
93
    });
94
 
95
    $("#login-time-calendar").click((e) => {
96
        e.preventDefault();
97
 
98
        let scheduleArray = radiusToSchedule($("#Login-Time").val());
99
 
100
        schedule.data('artsy.dayScheduleSelector').deserialize(scheduleArray);
101
 
102
        $("#login-time-dialog").dialog("open");
103
    });
104
 
105
    schedule.dayScheduleSelector({
106
        interval: 60,
107
        startTime: '00:00',
108
        endTime: '24:00',
109
        stringDays: ['Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi', 'Dimanche']
110
    });
111
    schedule.on('selected.artsy.dayScheduleSelector', function (e, selected) {
112
        let days = schedule.data('artsy.dayScheduleSelector').serialize();
113
        $("#Login-Time").val(scheduleToRadius(days));
114
    });
115
})($);