Project

General

Profile

Download (11.9 KB) Statistics
| Branch: | Tag: | Revision:

calebasse / calebasse / agenda / templates / agenda / index.html @ 2fcd3fce

1
{% extends "calebasse/base.html" %}
2
{% load url from future %}
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>
153
  <style>
154
    .person-item span { display: none; }
155
    .person-item.active span { display: inline; }
156
    #agenda-date { width: 20em; }
157
  </style>
158
{% endblock %}
159

    
160
{% block title %}{{ block.super }} - Agenda {% endblock %}
161

    
162
{% block header %}
163
  {{ block.super }}
164
  <span>Agenda - {{ service_name }}</spam>
165
{% endblock %}
166

    
167
{% block appbar %}
168
    <h2>Agenda</h2>
169
    <a href="../..">Retourner à l'accueil</a>
170
    <button>Nouvel événement (autre)</button>
171
    <button id="newrdv">Nouveau rendez-vous patient</button>
172
{% endblock %}
173

    
174
{% block beforecontent %}
175
    <div id="extra-top-links">
176
     <a href="activite-du-service">Activité du service</a>
177
178
     <a href="validation-des-actes">Validation des actes</a>
179
180
     <a href="rendez-vous-periodiques">Rendez-vous périodiques</a>
181
    </div>
182

    
183

    
184
    <div id="users">
185
    <div id="filtre">
186
     <input type="text"/>
187
    </div>
188
    <dl>
189
     {% for workers_type in workers_types %}
190
     <dt>{{ workers_type.type }}</dt>
191
     <dd><ul>
192
       {% for worker in workers_type.workers %}
193
       <li id="selector-worker-{{worker.id}}" class="person-item" data-worker-id="{{worker.id}}" data-target=".worker-{{worker.id}}.agenda">{{ worker.display_name }} <span title="cliquer pour déselectionner">(-)</span></li>
194
       {% endfor %}
195
     </ul></dd>
196
     {% endfor %}
197
   </dl>
198
 </div>
199
{% endblock %}
200

    
201
{% block content %}
202
<div class="content">
203
   <div id="datesel">
204
     <a href="../{{ previous_month|date:"SHORT_DATE_FORMAT"}}">««</a>
205
     <a href="../{{ previous_day|date:"SHORT_DATE_FORMAT"}}">«</a>
206
   <!-- <span>Jeudi 5 juillet 2012</span> -->
207
   <input id="agenda-date" value="{{ date|date:"DATE_FORMAT" }}"/>
208
   <a href="../{{ next_day|date:"SHORT_DATE_FORMAT"}}">»</a>
209
   <a href="../{{ next_month|date:"SHORT_DATE_FORMAT"}}">»»</a>
210
   </div>
211

    
212
   <table>
213
    <tbody>
214
    <tr>
215
     <td id="dispos">
216
      Disponibilités
217
      <table>
218
        {% for start_time, quaters in disponibility.items %}
219
          <tr class="hour-mark">
220
              <td rowspan="4">{{ start_time }}:00</td>
221
              {% for quater in quaters|slice:":1" %}
222
                {% for value in quater %}
223
                <td class="worker-{{ value.id }} agenda {{ value.dispo }}" style="display: none; "></td>
224
                {% endfor %}
225
              {% endfor %}
226
          </tr>
227
          {% for quater in quaters|slice:"1:4" %}
228
            <tr>
229
              {% for value in quater %}
230
                <td class="worker-{{ value.id }} agenda {{ value.dispo }}" style="display: none; "></td>
231
              {% endfor %}
232
            </tr>
233
          {% endfor %}
234
        {% endfor %}
235
      </table>
236
     </td>
237

    
238
     <td id="agendas">
239
       <div id="tabs">
240
       <ul>
241
        {% for worker_agenda in workers_agenda %}
242
           <li><a href="#tabs-worker-{{ worker_agenda.worker.id }}" class="worker-{{ worker_agenda.worker.id }} agenda" style="display: none;">{{ worker_agenda.worker.display_name }}</a></li>
243
        {% endfor %}
244
       </ul>
245
       {% for worker_agenda in workers_agenda %}
246
       <div id="tabs-worker-{{ worker_agenda.worker.id }}" class="tabs agenda worker-{{ worker_agenda.worker.id }}" style="display: none;">
247
         <a class="print" href="#">Imprimer</a>
248
         <div>
249
           {% for appointment in worker_agenda.appointments %}
250
           <h3 class="{{ appointment.type }} appointment">
251
             <span class="hour">{{ appointment.begin_hour }}</span>
252
             {% if appointment.title %} — {{ appointment.title }}  {% endif %}
253
             {% if appointment.length %} — {{ appointment.length }}m {% endif %}
254
             {% if appointment.workers_initial %} —{{ appointment.workers_initial }} {% endif %}
255
             {% if appointment.act_type %} — {{ appointment.act_type }} {% endif %}
256
             {% if appointment.room %} — {{ appointment.room }} {% endif %}
257
             <span class="right">
258
                 {% if appointment.service and appointment.service != service %}
259
                 <span class="box {{ appointment.service }}" title="{{ appointment.service }}"></span>
260
                 {% endif %}
261
                 {% if appointment.convocation_sent %}
262
                 <img title="Une convocation a été envoyée" src="{{ STATIC_URL }}images/emblem-mail.png">
263
                 {% endif %}
264
                 {% if appointment.description %}
265
                 <img title="Un commentaire existe" src="{{ STATIC_URL }}images/emblem-documents.png">
266
                 {% endif %}
267
                 {% if appointment.event_id %}
268
                 <button type="button"><img title="Editer un rendez-vous" src="{{ STATIC_URL }}images/accessories-text-editor.png"></button>
269
                 <button data-occurrence-id="{{ appointment.occurrence_id }}" data-rdv="{{ appointment.title }}"  type="button" class="remove-appointment">
270
                     <img title="Supprimer un rendez-vous" src="{{ STATIC_URL }}images/list-remove.png">
271
                 </button>
272
                 {% endif %}
273
            </span>
274
           </h3>
275

    
276
           <div>
277
             {% if appointment.type == 'free' %}<button class='booking' data-hour="{{ appointment.begin_hour }}">Prendre un rendez-vous</button> {% endif %}
278
             {% if appointment.event_id %}
279
             <div class="tabs-worker-{{ worker_agenda.worker.id }} textedit">
280
                 <span></span>
281
                 <textarea>{{ appointment.description }}</textarea>
282
                 <button disabled="disabled" data-event-id="{{ appointment.event_id }}"></button>
283
             </div>
284
             {% endif %}
285
             {% if appointment.patient_record_id %}
286
             <a href="/{{ service }}/dossiers/{{ appointment.patient_record_id }}">Dossier patient</a> -
287
             <a href="#">Prochains rendez-vous</a> -
288
             <a href="#">Convoquer patient</a>
289
             {% endif %}
290
           </div>
291
           {% endfor %}
292
         </div>
293
       </div>
294
       {% endfor %}
295

    
296
       </div>
297

    
298
       </div>
299
     </td>
300
    </tr>
301
    </tbody>
302
   </table>
303
 </div>
304

    
305

    
306
{% endblock %}
307

    
308
{% block dialogs %}
309
  <div id="rdv" style="display: none;">
310
 </div>
311
{% endblock %}
(2-2/3)