contacts: automatically select the contact being displayed (#9499)

This commit is contained in:
Frédéric Péters 2016-01-05 11:27:46 +01:00
parent fba6552232
commit eebdd89011
2 changed files with 26 additions and 8 deletions

View File

@ -1,7 +1,7 @@
{% load i18n %}
<div class="contact">
<input type="hidden" id="current-selected-user" name="current-selected-user" value="{{user_id}}"/>
<h3>{{user_display_name}} <button class="save {% if is_pinned_user %}pinned{% endif %}"></button></h3>
<h3>{{user_display_name}}</h3>
{% if user_var_address or user_var_city %}
<p>{{user_var_address}} / {{user_var_zipcode}} {{user_var_city}}</p>
{% endif %}

View File

@ -61,7 +61,6 @@ $(function() {
dataType: 'html',
success: function(data) {
$('div.contacts h3').effect('highlight');
$('div.contacts button.save').addClass('pinned');
},
error: function(error) { console.log(':/', error); }
});
@ -122,12 +121,6 @@ $(function() {
var formdef_reference = $('#id_formdef_reference').val();
var source_type = $('div.source div[data-source-type]').data('source-type');
var source_pk = $('div.source .active[data-source-pk]').data('source-pk');
if ($('div.contacts button.save').length &&
$('div.contacts button.save.pinned').length == 0) {
if (confirm("Transmettre alors que le contact n'est pas sélectionné ?") != true) {
return false;
}
}
$.ajax({url: $(this).data('action-url'),
data: {formdef_reference: formdef_reference,
source_type: source_type,
@ -217,6 +210,20 @@ $(function() {
new_zone.find('div.contact').empty();
$(zone).find('> div').replaceWith(new_zone);
if (new_zone.find('div.contact').length) {
/* unselect contact */
$.ajax({url: $('.cell.contacts').data('zone-url'),
data: {user_id: null,
source_type: source_type,
source_pk: source_pk},
method: 'POST',
dataType: 'html',
success: function(data) {
},
error: function(error) { console.log(':/', error); }
});
}
$(zone).find('select').select2();
$(zone).removeClass('has-contact-displayed');
$(zone).removeClass('has-page-displayed');
@ -276,6 +283,17 @@ $(function() {
success: function(data) {
$('.contacts .contact').replaceWith(data);
$('.contacts').addClass('has-contact-displayed');
var selected_user_id = $('#current-selected-user').val();
$.ajax({url: $('.cell.contacts').data('zone-url'),
data: {user_id: selected_user_id,
source_type: source_type,
source_pk: source_pk},
method: 'POST',
dataType: 'html',
success: function(data) {
},
error: function(error) { console.log(':/', error); }
});
},
error: function(error) { console.log(':(', error); }
});