Projet

Général

Profil

Télécharger (3,42 ko) Statistiques
| Branche: | Tag: | Révision:

calebasse / calebasse / static / js / calebasse.absences.js @ 2c6641c8

1
var path = location.pathname.split('/');
2
var service = path[1];
3
var group_url = '/' + service + '/personnes/conges/groupe/';
4
var person_url = '/' + service + '/personnes/gestion/';
5

    
6
function action(url, worker, on, action, selector, original_color, highlight_color, params, on_success) {
7
    if(on) {
8
        if(worker)
9
            url += worker + '/holidays/' + on + '/' + action + '/';
10
        else
11
            url += on + '/' + action;
12
        $(selector).attr('style', 'background: ' + highlight_color);
13
    } else {
14
        if(worker)
15
            url += worker + '/holidays/' + action;
16
        else
17
            url += action;
18
    }
19
    $("#holiday-dlg").load(url,
20
        function() {
21
          $(this).dialog({title: params.title,
22
            width: params.width,
23
          buttons: [{text: params.button_close,
24
            click: function() {
25
              $(this).dialog('close');
26
              $(selector).attr('style', original_color);
27
            }},{text: params.button_confirm,
28
              click: function(){
29
                $.ajax({url: url,
30
                  type: 'post',
31
                data: $('#holiday-dlg form').serialize(),
32
                }
33
                ).done(on_success)
34
              }}]});
35
            $('form .datepicker input').trigger('focus');
36
        })
37
};
38

    
39
function add_holiday(worker, url) {
40
    var url = url || person_url;
41
    params = {'title': 'Ajouter une absence', 'button_close': 'Fermer',
42
              'button_confirm': 'Ajouter', 'width': '550px'};
43

    
44
    on_success = function(response) {
45
        try {
46
            $.parseJSON(response);
47
            if(!response.err) {
48
                window.location = response.location;
49
            }
50
        } catch(e) {
51
            $('#holiday-dlg form').html(response);
52
        }
53
    };
54
    action(url, worker, null, 'ajouter', null, null, null, params, on_success);
55
};
56

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

    
65
    on_success = function(response) {
66
      try {
67
          $.parseJSON(response);
68
          if(!response.err) {
69
              window.location = response.location;
70
          }
71
      } catch(e) {
72
          return false;
73
      }
74
    };
75
    action(url, worker, holiday, 'supprimer', selector, initial_color,
76
           '#f8b0b0', params, on_success);
77
};
78

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

    
87
    on_success = function(response, status, xhr) {
88
        try {
89
            $.parseJSON(response);
90
            if(!response.err) {
91
                window.location = response.location;
92
            }
93
        } catch(e) {
94
            $('#holiday-dlg form').html(response);
95
        }
96
    }
97
    action(url, worker, holiday, 'editer', selector, initial_color,  '#af7', params, on_success);
98
};
99

    
100
function add_group_holiday() {
101
    add_holiday(null, group_url);
102
}
103

    
104
function edit_group_holiday(holiday) {
105
    edit_holiday(null, holiday, group_url);
106
};
107

    
108
function delete_group_holiday(holiday) {
109
    delete_holiday(null, holiday, group_url);
110
};
(1-1/21)