Project

General

Profile

« Previous | Next » 

Revision 27d50e46

Added by Serghei Mihai over 10 years ago

scripts file renamed

View differences:

calebasse/personnes/templates/personnes/base.html
4 4
{% block title %}{{ block.super }} - Gestion des personnes {% endblock %}
5 5
{% block extrascripts %}
6 6
{{ block.super }}
7
    <script src="{{ STATIC_URL }}js/calebasse.personnes.js"></script>
7
    <script src="{{ STATIC_URL }}js/calebasse.absences.js"></script>
8 8
{% endblock %}
9 9

  
10 10
{% block header %}
calebasse/static/js/calebasse.absences.js
1
function action(worker, on, action, selector, original_color, highlight_color, params, on_success) {
2
    var url = '';
3
    if(on) {
4
        url = '/cmpp/personnes/gestion/' + worker + '/holidays/' + on + '/' + action + '/';
5
        $(selector).attr('style', 'background: ' + highlight_color);
6
    } else {
7
        url = '/cmpp/personnes/gestion/' + worker + '/holidays/' + action;
8
    }
9
    $("#holiday-dlg").load(url,
10
                           function() {
11
                               $(this).dialog({title: params.title,
12
                                               width: params.width,
13
                                               buttons: [{text: params.button_close,
14
                                                          click: function() {
15
                                                              $(this).dialog('close');
16
                                                              $(selector).attr('style', original_color);
17
                                                          }},{text: params.button_confirm,
18
                                                              click: function(){
19
                                                                  $.ajax({url: url,
20
                                                                          type: 'post',
21
                                                                          data: $('#holiday-dlg form').serialize()
22
                                                                         }).done(on_success)
23
                                                              }}]});
24
                           })
25
};
26

  
27
function add_holiday(worker) {
28
    params = {'title': 'Ajouter une absence', 'button_close': 'Fermer',
29
              'button_confirm': 'Ajouter', 'width': '550px'};
30

  
31
    on_success = function(response) {
32
        try {
33
            $.parseJSON(response);
34
            if(!response.err) {
35
                var result = response.content;
36
                var id = response.id;
37
                var li = $("<li id='" + id + "'></li>");
38
                var ul = $('<ul></ul>');
39
                $.each(result, function(i, e) {
40
                    var item = $('<li class="' + e[0] + '">' + e[1] + '</li>');
41
                    ul.append(item);
42
                });
43
                var button_edit = $('<button class="icon-edit" data-action="edit" data-id="' + id + '"></button>');
44
                var button_delete = $('<button class="icon-remove" data-action="delete" data-id="' + id + '"></button>');
45
                var actions = $('<li class="actions"></li>');
46
                actions.append(button_edit, button_delete);
47
                ul.append(actions);
48
                li.append(ul);
49
                $("#holidays").append(li);
50
                $("#holiday-dlg").dialog("close");
51
            }
52
        } catch(e) {
53
            $('#holiday-dlg form').html(response);
54
        }
55

  
56
    };
57
    action(worker, null, 'ajouter', null, null, null, params, on_success);
58
};
59

  
60
function delete_holiday(worker, holiday) {
61
    var selector = '#' + holiday + ' ul';
62
    var initial_color = $(selector).attr('style');
63
    var params = {'title': 'Supprimer une absence',
64
                  'button_close': 'Non', 'button_confirm': 'Oui',
65
                  'width': '450px'}
66

  
67
    on_success = function(response) {
68
        if(!response.err) {
69
            $('#' +  holiday).remove();
70
            $(selector).attr('style', initial_color);
71
            $("#holiday-dlg").dialog("close");
72
        }
73
    };
74
    action(worker, holiday, 'supprimer', selector, initial_color, '#f8b0b0', params, on_success);
75
};
76

  
77
function edit_holiday(worker, holiday) {
78
    var selector = '#' + holiday + ' ul';
79
    var initial_color = $(selector).attr('style');
80
    params = {'title': 'Éditer une absence',
81
              'button_close': 'Fermer', 'button_confirm': 'Mettre à jour',
82
              'width': '550px'}
83

  
84
    on_success = function(response) {
85
        try {
86
            $.parseJSON(response);
87
            if(!response.err) {
88
                $.each(response.content, function(i, e) {
89
                    $('#holidays #' + holiday + ' li.' + e[0]).html(e[1]);
90
                });
91
                $(selector).attr('style', initial_color);
92
                $("#holiday-dlg").dialog("close");
93
            }
94
        } catch(e) {
95
            console.log(e);
96
            $('#holiday-dlg form').html(response);
97
        }
98

  
99
    }
100
    action(worker, holiday, 'editer', selector, initial_color,  '#af7', params, on_success);
101
};
calebasse/static/js/calebasse.personnes.js
1
function action(worker, on, action, selector, original_color, highlight_color, params, on_success) {
2
    var url = '';
3
    if(on) {
4
        url = '/cmpp/personnes/gestion/' + worker + '/holidays/' + on + '/' + action + '/';
5
        $(selector).attr('style', 'background: ' + highlight_color);
6
    } else {
7
        url = '/cmpp/personnes/gestion/' + worker + '/holidays/' + action;
8
    }
9
    $("#holiday-dlg").load(url,
10
                           function() {
11
                               $(this).dialog({title: params.title,
12
                                               width: params.width,
13
                                               buttons: [{text: params.button_close,
14
                                                          click: function() {
15
                                                              $(this).dialog('close');
16
                                                              $(selector).attr('style', original_color);
17
                                                          }},{text: params.button_confirm,
18
                                                              click: function(){
19
                                                                  $.ajax({url: url,
20
                                                                          type: 'post',
21
                                                                          data: $('#holiday-dlg form').serialize()
22
                                                                         }).done(on_success)
23
                                                              }}]});
24
                           })
25
};
26

  
27
function add_holiday(worker) {
28
    params = {'title': 'Ajouter une absence', 'button_close': 'Fermer',
29
              'button_confirm': 'Ajouter', 'width': '550px'};
30

  
31
    on_success = function(response) {
32
        try {
33
            $.parseJSON(response);
34
            if(!response.err) {
35
                var result = response.content;
36
                var id = response.id;
37
                var li = $("<li id='" + id + "'></li>");
38
                var ul = $('<ul></ul>');
39
                $.each(result, function(i, e) {
40
                    var item = $('<li class="' + e[0] + '">' + e[1] + '</li>');
41
                    ul.append(item);
42
                });
43
                var button_edit = $('<button class="icon-edit" data-action="edit" data-id="' + id + '"></button>');
44
                var button_delete = $('<button class="icon-remove" data-action="delete" data-id="' + id + '"></button>');
45
                var actions = $('<li class="actions"></li>');
46
                actions.append(button_edit, button_delete);
47
                ul.append(actions);
48
                li.append(ul);
49
                $("#holidays").append(li);
50
                $("#holiday-dlg").dialog("close");
51
            }
52
        } catch(e) {
53
            $('#holiday-dlg form').html(response);
54
        }
55

  
56
    };
57
    action(worker, null, 'ajouter', null, null, null, params, on_success);
58
};
59

  
60
function delete_holiday(worker, holiday) {
61
    var selector = '#' + holiday + ' ul';
62
    var initial_color = $(selector).attr('style');
63
    var params = {'title': 'Supprimer une absence',
64
                  'button_close': 'Non', 'button_confirm': 'Oui',
65
                  'width': '450px'}
66

  
67
    on_success = function(response) {
68
        if(!response.err) {
69
            $('#' +  holiday).remove();
70
            $(selector).attr('style', initial_color);
71
            $("#holiday-dlg").dialog("close");
72
        }
73
    };
74
    action(worker, holiday, 'supprimer', selector, initial_color, '#f8b0b0', params, on_success);
75
};
76

  
77
function edit_holiday(worker, holiday) {
78
    var selector = '#' + holiday + ' ul';
79
    var initial_color = $(selector).attr('style');
80
    params = {'title': 'Éditer une absence',
81
              'button_close': 'Fermer', 'button_confirm': 'Mettre à jour',
82
              'width': '550px'}
83

  
84
    on_success = function(response) {
85
        try {
86
            $.parseJSON(response);
87
            if(!response.err) {
88
                $.each(response.content, function(i, e) {
89
                    $('#holidays #' + holiday + ' li.' + e[0]).html(e[1]);
90
                });
91
                $(selector).attr('style', initial_color);
92
                $("#holiday-dlg").dialog("close");
93
            }
94
        } catch(e) {
95
            console.log(e);
96
            $('#holiday-dlg form').html(response);
97
        }
98

  
99
    }
100
    action(worker, holiday, 'editer', selector, initial_color,  '#af7', params, on_success);
101
};

Also available in: Unified diff