Project

General

Profile

« Previous | Next » 

Revision 74ba9776

Added by Benjamin Dauvergne over 11 years ago

new appointment form: use a simple text entry for the duration field

the text entry is modified by the mousewheel with 15 minutes increments.
It uses the jquery mousewheel plugin.

View differences:

calebasse/actes/models.py
72 72
                patient=patient,
73 73
                act_type=act_type,
74 74
                date=start_datetime.date(),
75
                doctors=participants,
76 75
                )
76
        act_event.doctors = participants
77 77

  
78 78
        return self._set_event(act_event, participants, description,
79 79
                services = [service], start_datetime = start_datetime, end_datetime = end_datetime,
calebasse/agenda/forms.py
12 12

  
13 13
class NewAppointmentForm(forms.ModelForm):
14 14
    time = forms.TimeField(label=u'Heure de début')
15
    DURATION_CHOICES = (
16
            (45, '45 minutes'),
17
    )
18
    duration = forms.TypedChoiceField(choices=DURATION_CHOICES,
19
            coerce=int, label=u'Durée')
15
    duration = forms.CharField(label=u'Durée',
16
            help_text=u'en minutes; vous pouvez utiliser la roulette de votre souris.')
20 17

  
21 18
    participants = make_ajax_field(EventAct, 'participants', 'worker', True)
22 19
    patient = make_ajax_field(EventAct, 'patient', 'patientrecord', False)
calebasse/agenda/templates/agenda/appointment.html
15 15
   </td><td>
16 16
   <p>
17 17
   {{ form.duration.label_tag }}
18
   {{ form.duration }}
18
   {{ form.duration|add_class:"mousewheel"|attr:"data-mousewheel-increment:15" }}
19 19
   {{ form.duration.errors }}
20
   <div>
21
   {{ form.duration.help_text }}
22
   </div>
20 23
   </p>
21 24
   </td></tr>
22 25

  
calebasse/static/js/calebasse.mousewheel.js
1
$(function () {
2
  $('body').on('mousewheel', '.mousewheel', function (event, delta) {
3
    var increment = parseInt($(this).data('mousewheel-increment'));
4
    var lo = parseInt($(this).data('mousewheel-lo')) || 0;
5
    var hi = parseInt($(this).data('mousewheel-hi')) || 1000;
6
    var $this = $(this);
7
    if (delta < 0) {
8
      increment = -increment;
9
    }
10
    if ($this.is('input')) {
11
      value = $this.val();
12
    } else {
13
      value = $this.text();
14
    }
15
    try {
16
      value = parseInt(value || 0);
17
    } catch (e) {
18
      value = 0;
19
    }
20
    value += increment;
21
    if (value < lo) {
22
      value = lo;
23
    } else if (value > hi) {
24
      value = hi;
25
    }
26
    if ($this.is('input')) {
27
      $this.val(value);
28
    } else {
29
      $this.html(value);
30
    }
31
    return false;
32
  });
33
});
calebasse/static/js/jquery.mousewheel.js
1
/*! Copyright (c) 2011 Brandon Aaron (http://brandonaaron.net)
2
 * Licensed under the MIT License (LICENSE.txt).
3
 *
4
 * Thanks to: http://adomas.org/javascript-mouse-wheel/ for some pointers.
5
 * Thanks to: Mathias Bank(http://www.mathias-bank.de) for a scope bug fix.
6
 * Thanks to: Seamus Leahy for adding deltaX and deltaY
7
 *
8
 * Version: 3.0.6
9
 * 
10
 * Requires: 1.2.2+
11
 */
12

  
13
(function($) {
14

  
15
var types = ['DOMMouseScroll', 'mousewheel'];
16

  
17
if ($.event.fixHooks) {
18
    for ( var i=types.length; i; ) {
19
        $.event.fixHooks[ types[--i] ] = $.event.mouseHooks;
20
    }
21
}
22

  
23
$.event.special.mousewheel = {
24
    setup: function() {
25
        if ( this.addEventListener ) {
26
            for ( var i=types.length; i; ) {
27
                this.addEventListener( types[--i], handler, false );
28
            }
29
        } else {
30
            this.onmousewheel = handler;
31
        }
32
    },
33
    
34
    teardown: function() {
35
        if ( this.removeEventListener ) {
36
            for ( var i=types.length; i; ) {
37
                this.removeEventListener( types[--i], handler, false );
38
            }
39
        } else {
40
            this.onmousewheel = null;
41
        }
42
    }
43
};
44

  
45
$.fn.extend({
46
    mousewheel: function(fn) {
47
        return fn ? this.bind("mousewheel", fn) : this.trigger("mousewheel");
48
    },
49
    
50
    unmousewheel: function(fn) {
51
        return this.unbind("mousewheel", fn);
52
    }
53
});
54

  
55

  
56
function handler(event) {
57
    var orgEvent = event || window.event, args = [].slice.call( arguments, 1 ), delta = 0, returnValue = true, deltaX = 0, deltaY = 0;
58
    event = $.event.fix(orgEvent);
59
    event.type = "mousewheel";
60
    
61
    // Old school scrollwheel delta
62
    if ( orgEvent.wheelDelta ) { delta = orgEvent.wheelDelta/120; }
63
    if ( orgEvent.detail     ) { delta = -orgEvent.detail/3; }
64
    
65
    // New school multidimensional scroll (touchpads) deltas
66
    deltaY = delta;
67
    
68
    // Gecko
69
    if ( orgEvent.axis !== undefined && orgEvent.axis === orgEvent.HORIZONTAL_AXIS ) {
70
        deltaY = 0;
71
        deltaX = -1*delta;
72
    }
73
    
74
    // Webkit
75
    if ( orgEvent.wheelDeltaY !== undefined ) { deltaY = orgEvent.wheelDeltaY/120; }
76
    if ( orgEvent.wheelDeltaX !== undefined ) { deltaX = -1*orgEvent.wheelDeltaX/120; }
77
    
78
    // Add event and delta to the front of the arguments
79
    args.unshift(event, delta, deltaX, deltaY);
80
    
81
    return ($.event.dispatch || $.event.handle).apply(this, args);
82
}
83

  
84
})(jQuery);
calebasse/templates/calebasse/base.html
12 12
    <script src="{{ STATIC_URL }}js/jquery.form.js"></script>
13 13
    <script src="{{ STATIC_URL }}development-bundle/ui/i18n/jquery.ui.datepicker-fr.js"></script>
14 14
    <script src="{{ STATIC_URL }}js/ajax_select.js"></script>
15
    <script src="{{ STATIC_URL }}js/jquery.mousewheel.js"></script>
16
    <script src="{{ STATIC_URL }}js/calebasse.mousewheel.js"></script>
15 17
    {% block extrascripts %}
16 18
    {% endblock %}
17 19
  </head>

Also available in: Unified diff