|
1 |
{% load combo %}
|
|
2 |
<h2>Appels{% if callee %} (ligne {{callee}}){% endif %}</h2>
|
|
3 |
|
|
4 |
<div id="calls" data-calls="{{ json|as_json }}">
|
|
5 |
{% if json %} {# callee has been set #}
|
|
6 |
<strong>Appel en cours</strong>
|
|
7 |
{% for call in json.data.current %}
|
|
8 |
{% if forloop.first %}
|
|
9 |
<script>
|
|
10 |
$(function() {
|
|
11 |
var $search = $('.combo-search-input');
|
|
12 |
if (! $search.is(':focus')) {
|
|
13 |
$search.val('{{ call.caller }}').trigger('change');
|
|
14 |
}
|
|
15 |
});
|
|
16 |
</script>
|
|
17 |
{% endif %}
|
|
18 |
<div class="caller" data-caller="{{ call.caller }}">
|
|
19 |
{{call.start|parse_datetime|date:"H\hi"}} : {{ call.caller }}
|
|
20 |
</div>
|
|
21 |
{% empty %}
|
|
22 |
<div>Pas d'appel en cours</div>
|
|
23 |
{% endfor %}
|
|
24 |
|
|
25 |
{% for call in json.data.past|slice:":10" %}
|
|
26 |
{% if forloop.first %}<strong>Appels précédents</strong>{% endif %}
|
|
27 |
<div class="caller" data-caller="{{ call.caller }}">
|
|
28 |
{{call.start|parse_datetime|date:"H\hi"}} : {{ call.caller }}
|
|
29 |
</div>
|
|
30 |
{% endfor %}
|
|
31 |
{% endif %}
|
|
32 |
</div>
|
|
33 |
|
|
34 |
<div>
|
|
35 |
<form>
|
|
36 |
{% if not callee %}
|
|
37 |
<div class="infonotice">
|
|
38 |
Indiquer le numéro de ligne à suivre.
|
|
39 |
</div>
|
|
40 |
{% endif %}
|
|
41 |
<input {% if callee %}type="hidden"{% else %}type="text"{% endif %} name="callee" value="{{ callee }}">
|
|
42 |
{% if not callee %}<button>✓</button>{% endif %}
|
|
43 |
</form>
|
|
44 |
{% if callee %}<button class="release-line">Ne plus suivre la ligne {{callee}}</button>{% endif %}
|
|
45 |
</div>
|
|
46 |
|
|
47 |
<script>
|
|
48 |
$(function() {
|
|
49 |
$('div.caller').on('click', function(event) {
|
|
50 |
var $search = $('.combo-search-input');
|
|
51 |
$search.val($(event.target).data('caller')).trigger('change');
|
|
52 |
});
|
|
53 |
var $cell = $('.configjsoncell.phone-calls');
|
|
54 |
{% if not callee %}
|
|
55 |
var callee = window.localStorage.publik_phone_callee;
|
|
56 |
if (callee) {
|
|
57 |
window.history.replaceState({}, "", "?callee=" + callee);
|
|
58 |
combo_load_cell($cell);
|
|
59 |
}
|
|
60 |
{% else %}
|
|
61 |
window.localStorage.publik_phone_callee = "{{ callee }}";
|
|
62 |
if (window.location.search != "?callee={{ callee }}") {
|
|
63 |
window.history.replaceState({}, "", "?callee={{ callee }}");
|
|
64 |
}
|
|
65 |
var current_calls = $cell.find('#calls').data('calls');
|
|
66 |
function get_caller(calls) {
|
|
67 |
if (calls && calls.data && calls.data.current && calls.data.current.length) return calls.data.current[0].caller;
|
|
68 |
return null;
|
|
69 |
}
|
|
70 |
function refresh_calls() {
|
|
71 |
$.ajax({url: $cell.data('ajax-cell-url') + '?callee={{ callee }}',
|
|
72 |
type: 'POST',
|
|
73 |
data: {'action': 'refresh'},
|
|
74 |
success: function(data) {
|
|
75 |
new_content = $('<div>' + data + '</div>');
|
|
76 |
var new_calls = $(new_content).find('#calls').data('calls');
|
|
77 |
var new_caller = get_caller(new_calls);
|
|
78 |
if (get_caller(current_calls) != new_caller) {
|
|
79 |
current_calls = new_calls;
|
|
80 |
$('#calls').replaceWith($(new_content).find('#calls'));
|
|
81 |
if (new_caller) {
|
|
82 |
var $search = $('.combo-search-input');
|
|
83 |
if (! $search.is(':focus')) {
|
|
84 |
$search.val(new_caller).trigger('change');
|
|
85 |
}
|
|
86 |
}
|
|
87 |
}
|
|
88 |
}
|
|
89 |
});
|
|
90 |
}
|
|
91 |
setInterval(refresh_calls, 2500);
|
|
92 |
$('button.release-line').on('click', function() {
|
|
93 |
window.localStorage.publik_phone_callee = "";
|
|
94 |
window.history.replaceState({}, "", "?callee=");
|
|
95 |
combo_load_cell($cell);
|
|
96 |
return false;
|
|
97 |
});
|
|
98 |
{% endif %}
|
|
99 |
});
|
|
100 |
</script>
|
0 |
|
-
|