Project

General

Profile

« Previous | Next » 

Revision 27a7d79c

Added by Benjamin Dauvergne over 12 years ago

conserve selected participants when navigating the agenda

View differences:

calebasse/agenda/templates/agenda/index.html
2 2
{% load url from future %}
3 3
{% block extrascripts %}
4 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
        // var selected = $('#tabs').tabs('option', 'selected');
33
        // var length = $('#tabs').tabs('length');
34
        // alert($('.tabs').index($target.filter('.tabs')));
35
        if ($target.is(':visible')) {
36
          //$target.click();
37
        }
38
      }
5 39
  $(function() {
6 40
    $('#tabs').tabs();
7 41

  
8 42
    $('div.agenda > div').accordion({active: false, autoHeight: false});
9 43

  
10 44
    $('.person-item').on('click', function() {
11
      $(this).toggleClass('active');
12
      var $target = $($(this).data('target'));
13
      $target.toggle();
14
      // var selected = $('#tabs').tabs('option', 'selected');
15
      // var length = $('#tabs').tabs('length');
16
      // alert($('.tabs').index($target.filter('.tabs')));
17
      if ($target.is(':visible')) {
18
        $target.click();
19
      }
45
      toggle_worker(this);
46
    });
47
    // select all anchors
48
    $.each(extract_anchor(), function (i, anchor) {
49
      $('#'+anchor.substr(1)).each(function (i, worker_selector) { toggle_worker(worker_selector); });
20 50
    });
21 51

  
22 52
    /* Gestion du filtre sur les utilisateurs */
......
35 65
      }
36 66

  
37 67
		});
38
		$('#agenda-date').datepicker();
68
    $('#agenda-date').datepicker({
69
      dateFormat: "DD d MM yy",
70
      onClose: function(dateText, inst) {
71
        console.log('close');
72
      }
73
    });
74
    $('#agenda-date').on('change', function () {
75
      window.location.href=replace_anchor('../' + $(this).datepicker('getDate').toISOString().substr(0,10), make_anchor());
76
    });
39 77
		$('.date').datepicker({showOn: 'button'});
40 78
		$('#add-intervenant-btn').click(function() {
41 79
			var text = $(this).prev().val();
......
94 132
     <dt>{{ workers_type.type }}</dt>
95 133
     <dd><ul>
96 134
       {% for worker in workers_type.workers %}
97
       <li class="person-item" data-target=".worker-{{worker.id}}.agenda">{{ worker.display_name }}</li>
135
       <li id="selector-worker-{{worker.id}}" class="person-item" data-target=".worker-{{worker.id}}.agenda">{{ worker.display_name }} <span title="cliquer pour déselectionner">(-)</span></li>
98 136
       {% endfor %}
99 137
     </ul></dd>
100 138
     {% endfor %}

Also available in: Unified diff