Project

General

Profile

« Previous | Next » 

Revision 2fcd3fce

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

agenda: cleaning occurrence deleting

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

  
30 30
        var $target = $($(worker_selector).data('target'));
31 31
        $target.toggle();
32 32
        if ($target.is(':visible')) {
33
          $target.click();
33
            $target.click();
34 34
        }
35
      }
36
      function delete_appointment(id, title)  {
37
          var r=confirm("Etes-vous sûr de vouloir supprimer le rendez-vous "+ title + " ?");
38
          if (r == true)
39
          {
40
              $.ajax({
41
                  url: '/api/occurrence/' + id + '/',
42
                  type: 'DELETE',
43
                  success: function(data) {
44
                      window.location.reload(true);
45
                  }
46
              });
47
          }
48
      }
49
  $(function() {
50
    $('#tabs').tabs();
35
    }
36
    $(function() {
37
        $('#tabs').tabs();
51 38

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

  
54
    $('.person-item').on('click', function() {
55
      toggle_worker(this);
56
    });
57
    // select all anchors
58
    $.each(extract_anchor(), function (i, anchor) {
59
      $('#'+anchor.substr(1)).each(function (i, worker_selector) { toggle_worker(worker_selector); });
60
    });
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
        });
61 48

  
62
    $('.textedit').on('keydown', function() {
63
        $('button', this).removeAttr("disabled");
64
    });
65
    $('.textedit button').on('click', function() {
66
        var textarea = $(this).prev();
67
        var span = textarea.prev()
68
        var btn = $(this)
69
        $.ajax({
70
            url: '/api/event/' + $(this).data("event-id") + '/?format=json',
71
            type: 'PATCH',
72
            contentType: 'application/json',
73
            data: '{"description": "' + textarea.val() + '"}',
74
            success: function(data) {
75
                btn.attr('disabled', 'disabled');
76
                span.html('Commentaire modifiée avec succès');
77
            }
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('');
78 69
        });
79
    });
80
    $('.appointment').on('click', function() {
81
        $('.textedit span', this).html('');
82
    });
83 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
        });
84 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
            }
85 101

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

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

Also available in: Unified diff