phone: display current call (#8788)

This commit is contained in:
Frédéric Péters 2015-11-03 12:01:04 +01:00
parent f0512a1b4c
commit 7250357cbb
3 changed files with 61 additions and 25 deletions

View File

@ -19,14 +19,12 @@
</div>
</div>
<div id="source-mainarea">
<h1>{% trans 'Current Call:' %} <strong>01 02 03 04 05</strong></h1>
<h3>{% trans 'Past Calls' %}</h3>
<ul>
<li>16 juillet 2015 11:23:21</li>
<li>15 juillet 2015 16:36:42</li>
</ul>
<div id="source-mainarea" data-current-calls="{% url 'phone-current-calls' %}">
{% for phonecall in phonecalls %}
<div class="phonecall active" data-source-pk="{{phonecall.id}}">
<h1>{% trans 'Current Call:' %} <strong>{{phonecall.caller}}</strong></h1>
</div>
{% endfor %}
</div>
<script>

View File

@ -51,6 +51,7 @@ class PhoneZone(TemplateView):
context = super(PhoneZone, self).get_context_data(**kwargs)
context['source_type'] = ContentType.objects.get_for_model(PhoneCall)
context['phonelines'] = PhoneLine.objects.filter(users__id=self.request.user.id)
context['phonecalls'] = PhoneCall.get_current_calls(self.request.user)
return context
zone = csrf_exempt(PhoneZone.as_view())

View File

@ -1,4 +1,25 @@
$(function() {
function refresh_bottom_cells() {
var source_type = $('div.source div[data-source-type]').data('source-type');
var source_pk = $('div.source .active[data-source-pk]').data('source-pk');
$('.cell[data-zone-url]').each(function(idx, zone) {
console.log('refresh', zone);
$.ajax({url: $(zone).data('zone-url'),
data: {source_type: source_type,
source_pk: source_pk},
async: true,
dataType: 'html',
success: function(data) {
$(zone).find('> div').replaceWith(data);
$(zone).find('select').select2();
$(zone).removeClass('has-page-displayed');
$(zone).removeClass('has-contact-displayed');
},
error: function(error) { console.log(':(', error); }
});
});
}
$('[data-pdf-href]').on('click', function() {
var current_pdf = $('#pdf-viewer').data('current-pdf-href');
var new_pdf = $(this).data('pdf-href');
@ -15,26 +36,10 @@ $(function() {
$('#id_post_date').val($(this).data('post-date'));
$('#id_registered_mail_number').val($(this).data('registered-mail-number'));
$('#id_mail_number').val($(this).data('mail-number'));
var source_type = $('div.source div[data-source-type]').data('source-type');
var source_pk = $('div.source .active[data-source-pk]').data('source-pk');
$('#postit').data('url', $('#postit').data('base-url') + '?mail=' + source_pk);
$('#postit').trigger('welco:load-mail-note');
$('#postit').show();
$('.cell[data-zone-url]').each(function(idx, zone) {
$.ajax({url: $(zone).data('zone-url'),
data: {source_type: source_type,
source_pk: source_pk},
async: true,
dataType: 'html',
success: function(data) {
$(zone).find('> div').replaceWith(data);
$(zone).find('select').select2();
$(zone).removeClass('has-page-displayed');
$(zone).removeClass('has-contact-displayed');
},
error: function(error) { console.log(':(', error); }
});
});
refresh_bottom_cells();
});
$('.contacts').delegate('button.save', 'click', function() {
@ -363,4 +368,36 @@ $(function() {
});
if ($('.source-phone').length) {
var zone = $('.source-phone .source [data-zone-url]');
console.log('zone', zone);
function check_calls() {
if ($('.phonecall').length) { /* active phone call */
} else {
var current_calls_url = $('[data-current-calls]').data('current-calls');
$.ajax({url: current_calls_url,
dataType: 'json',
success: function(response) {
if (response.data.calls.length != 0) {
/* got a call */
$.ajax({url: zone.data('zone-url'),
dataType: 'html',
success: function(data) {
$(zone).parent('div').html(data);
refresh_bottom_cells();
}
});
} else {
window.setTimeout(check_calls, 1000);
}
},
error: function() {
window.setTimeout(check_calls, 1000);
}
});
}
}
window.setTimeout(check_calls, 1000);
}
});