Project

General

Profile

« Previous | Next » 

Revision 02fff58c

Added by Jérôme Schneider over 12 years ago

agenda: move js into a specific file

View differences:

calebasse/agenda/templates/agenda/index.html
1 1
{% extends "calebasse/base.html" %}
2 2
{% load url from future %}
3 3
{% block extrascripts %}
4
<script>
5
    function replace_anchor(url, anchor) {
6
        var splitted = url.split('#');
7
        return splitted[0] + '#' + encodeURI(anchor);
8
    }
9
    function extract_anchor() {
10
        if (window.location.href.indexOf('#') == -1) {
11
            return "";
12
        }
13
        var splitted = window.location.href.split('#');
14
        return decodeURI(splitted[1]).split(',');
15
    }
16
    function make_anchor() {
17
        return $.makeArray($('.person-item.active').map(function (v, i) { return '_' + $(i).attr('id'); })).join(',');
18
    }
19
    function toggle_worker(worker_selector) {
20
        $(worker_selector).toggleClass('active');
21
        // update the anchor
22
        var anchor = make_anchor();
23
        var new_uri = replace_anchor(window.location.href, anchor);
24
        console.log(new_uri);
25
        window.location.href = new_uri;
26
        $('a[href^="../"]').each(function (i, a) {
27
            $(a).attr('href', replace_anchor($(a).attr('href'), anchor));
28
        });
29

  
30
        var $target = $($(worker_selector).data('target'));
31
        $target.toggle();
32
        if ($target.is(':visible')) {
33
            $target.click();
34
        }
35
    }
36
    $(function() {
37
        $('#tabs').tabs();
38

  
39
        $('div.agenda > div').accordion({active: false, autoHeight: false});
40

  
41
        $('.person-item').on('click', function() {
42
            toggle_worker(this);
43
        });
44
        // select all anchors
45
        $.each(extract_anchor(), function (i, anchor) {
46
            $('#'+anchor.substr(1)).each(function (i, worker_selector) { toggle_worker(worker_selector); });
47
        });
48

  
49
        $('.textedit').on('keydown', function() {
50
            $('button', this).removeAttr("disabled");
51
        });
52
        $('.textedit button').on('click', function() {
53
            var textarea = $(this).prev();
54
            var span = textarea.prev()
55
            var btn = $(this)
56
            $.ajax({
57
                url: '/api/event/' + $(this).data("event-id") + '/?format=json',
58
                type: 'PATCH',
59
                contentType: 'application/json',
60
                data: '{"description": "' + textarea.val() + '"}',
61
                success: function(data) {
62
                    btn.attr('disabled', 'disabled');
63
                    span.html('Commentaire modifiée avec succès');
64
                }
65
            });
66
        });
67
        $('.appointment').on('click', function() {
68
            $('.textedit span', this).html('');
69
        });
70

  
71
        $('.remove-appointment').on('click', function() {
72
            var r = confirm("Etes-vous sûr de vouloir supprimer le rendez-vous " + $(this).data('rdv') + " ?");
73
            if (r == true)
74
            {
75
                $.ajax({
76
                    url: '/api/occurrence/' + $(this).data('occurrence-id') + '/',
77
                    type: 'DELETE',
78
                    success: function(data) {
79
                        window.location.reload(true);
80
                        return false;
81
                    }
82
                });
83
            }
84
            return false;
85
        });
86

  
87
        /* Gestion du filtre sur les utilisateurs */
88
        $('#filtre input').keyup(function() {
89
            var filtre = $(this).val();
90
            if (filtre) {
91
                $('#users li').each(function() {
92
                    if ($(this).text().match(filtre)) {
93
                        $(this).show();
94
                        } else {
95
                        $(this).hide();
96
                    }
97
                });
98
                } else {
99
                $('#users li').show();
100
            }
101

  
102
        });
103
        $('#agenda-date').datepicker({
104
            dateFormat: "DD d MM yy",
105
            onClose: function(dateText, inst) {
106
                console.log('close');
107
            }
108
        });
109
        $('#agenda-date').on('change', function () {
110
            window.location.href=replace_anchor('../' + $(this).datepicker('getDate').toISOString().substr(0,10), make_anchor());
111
        });
112
        $('.date').datepicker({showOn: 'button'});
113
        $('#add-intervenant-btn').click(function() {
114
            var text = $(this).prev().val();
115
            $('#intervenants ul').append('<li><input type="checkbox" value="' + text + '" checked="checked">' + text + '</input></li>');
116
            $(this).prev().val('').focus();
117
            return false;
118
        });
119
        $('#newrdv').click(function() {
120
            var participants = $('.person-item.active').map(function (i, v) { return $(v).data('worker-id'); });
121
            var qs = $.param({participants: $.makeArray(participants) }, true);
122
            var new_appointment_url = "{% url 'nouveau-rdv' service=service date=date %}?" + qs;
123
            $('#rdv').load(new_appointment_url,
124
            function () {
125
                function onsuccess(response, status, xhr, form) {
126
                    var parse = $(response);
127
                    if ($('.errorlist', parse).length != 0) {
128
                        $('#rdv').html(response);
129
                        $('#rdv form').ajaxForm({
130
                            success: onsuccess,
131
                        });
132
                        $('#rdv .datepicker-date').datepicker({dateFormat: 'yy-m-d', showOn: 'button'});
133
                        console.log('error');
134
                        } else {
135
                        console.log('success');
136
                        window.location.reload(true);
137
                    }
138
                }
139
                $('#rdv .datepicker-date').datepicker({dateFormat: 'yy-m-d', showOn: 'button'});
140
                $('form', this).ajaxForm({
141
                    success: onsuccess
142
                });
143
                $(this).dialog({title: 'Nouveau rendez-vous',
144
                    width: '800px',
145
                    buttons: [ { text: "Fermer",
146
                        click: function() { $(this).dialog("close"); } },
147
                    { text: "Ajouter",
148
                        click: function() { $("#rdv form").submit(); } }]});
149
            });
150
        });
151
    });
152
</script>
4
  <script src="{{ STATIC_URL }}js/calebasse.agenda.js"></script>
153 5
  <style>
154 6
    .person-item span { display: none; }
155 7
    .person-item.active span { display: inline; }

Also available in: Unified diff