|
1 |
{% extends "qommon/forms/widget.html" %}
|
|
2 |
{% block widget-control %}
|
|
3 |
<select style="display: none" id="form_{{widget.name}}" name="{{widget.name}}"
|
|
4 |
{% for attr in widget.attrs.items %}{{attr.0}}="{{attr.1}}"{% endfor %}>
|
|
5 |
{% for option in widget.get_options %}
|
|
6 |
<option{% for attr in option.attrs.items %} {{attr.0}}="{{attr.1}}"{% endfor %}>{{ option.description }}</option>
|
|
7 |
{% empty %}
|
|
8 |
{% if widget.separate_hint or not widget.hint %}
|
|
9 |
<option value="">---</option>
|
|
10 |
{% endif %}
|
|
11 |
{% endfor %}
|
|
12 |
</select>
|
|
13 |
<div id="form_{{widget.name}}_table" class="meetings_table">
|
|
14 |
</div>
|
|
15 |
<style>
|
|
16 |
div.meetings_table {
|
|
17 |
margin-top: 1ex;
|
|
18 |
display: flex;
|
|
19 |
width: 100%;
|
|
20 |
}
|
|
21 |
|
|
22 |
div.meetings_table > div {
|
|
23 |
flex: 0 1 auto;
|
|
24 |
width: 20%;
|
|
25 |
text-align: center;
|
|
26 |
display: none;
|
|
27 |
}
|
|
28 |
|
|
29 |
div.meetings_table div span {
|
|
30 |
display: block;
|
|
31 |
cursor: pointer;
|
|
32 |
padding: 0.3ex 0;
|
|
33 |
}
|
|
34 |
|
|
35 |
div.meetings_table div span.disabled {
|
|
36 |
opacity: 0.3;
|
|
37 |
}
|
|
38 |
|
|
39 |
div.meetings_table div span.disabled {
|
|
40 |
}
|
|
41 |
|
|
42 |
div.meetings_table div.head {
|
|
43 |
padding-bottom: 1ex;
|
|
44 |
}
|
|
45 |
</style>
|
|
46 |
<script>
|
|
47 |
$(function() {
|
|
48 |
var options = $('#form_{{widget.name}} option');
|
|
49 |
var current_date = null;
|
|
50 |
var current_day_div = null;
|
|
51 |
var current_offset = 0;
|
|
52 |
var nb_days = 0;
|
|
53 |
|
|
54 |
for (var i=0; i<options.length; i++) {
|
|
55 |
var option_date = $(options[i]).attr('value').split(':')[1].split('-', 3).join('-');
|
|
56 |
if (option_date !== current_date) {
|
|
57 |
var day_label = $(options[i]).text().split(' ', 3).join(' ');
|
|
58 |
nb_days += 1;
|
|
59 |
current_day_div = $('<div><div class="head">' + day_label + '</div></div>');
|
|
60 |
current_day_div.appendTo($('#form_{{widget.name}}_table'));
|
|
61 |
current_date = option_date;
|
|
62 |
}
|
|
63 |
var day_time = $(options[i]).text().split(' ')[3];
|
|
64 |
var option_span = $('<span class="selectable" data-idx="' + i + '">' + day_time + '</span>').appendTo(current_day_div);
|
|
65 |
if ($(options[i]).attr('disabled')) {
|
|
66 |
$(option_span).addClass('disabled').removeClass('selectable');
|
|
67 |
}
|
|
68 |
if ($(options[i]).attr('selected')) {
|
|
69 |
current_offset = nb_days - 1;
|
|
70 |
$(option_span).addClass('on');
|
|
71 |
}
|
|
72 |
}
|
|
73 |
var go_prev = $('<button class="prev"><</button>');
|
|
74 |
var go_next = $('<button class="next">></button>');
|
|
75 |
go_prev.prependTo($('#form_{{widget.name}}_table'));
|
|
76 |
go_next.appendTo($('#form_{{widget.name}}_table'));
|
|
77 |
go_prev.on('click', function() {
|
|
78 |
current_offset = Math.max(0, current_offset-1);
|
|
79 |
display(current_offset);
|
|
80 |
return false;
|
|
81 |
});
|
|
82 |
go_next.on('click', function() {
|
|
83 |
current_offset = Math.min(current_offset+1, Math.max(0, nb_days-5));
|
|
84 |
display(current_offset);
|
|
85 |
return false;
|
|
86 |
});
|
|
87 |
|
|
88 |
function display(offset) {
|
|
89 |
$('#form_{{widget.name}}_table > div').each(function(idx, elem) {
|
|
90 |
if (idx >= offset && idx < offset+5) {
|
|
91 |
$(elem).show();
|
|
92 |
} else {
|
|
93 |
$(elem).hide();
|
|
94 |
}
|
|
95 |
});
|
|
96 |
current_offset = offset;
|
|
97 |
}
|
|
98 |
display(current_offset);
|
|
99 |
$('#form_{{widget.name}}_table span.selectable').on('click', function() {
|
|
100 |
$('#form_{{widget.name}}_table span').removeClass('on');
|
|
101 |
$(this).addClass('on');
|
|
102 |
$('#form_{{widget.name}}').val($(options[$(this).data('idx')]).attr('value'));
|
|
103 |
});
|
|
104 |
});
|
|
105 |
</script>
|
|
106 |
{% endblock %}
|
0 |
|
-
|