affiche plus d'informations sur les contacts dans les champs de recherche

This commit is contained in:
Romain Guerrero 2016-02-10 13:56:37 +01:00
parent 8b188ec670
commit 0accc714c7
4 changed files with 88 additions and 1 deletions

View file

@ -62,15 +62,36 @@
<script>
jQuery(document).ready(function()
{
<?php
if (RASPISMS_SETTINGS_EXTENDED_CONTACTS_INFOS) {
$magicSuggestRenderer = "(data['contacts_infos.civility']!=null ? (data['contacts_infos.civility']==1 ? 'M. ' : 'Mme ') : '')";
$magicSuggestRenderer .= " + data['contacts.name']";
$magicSuggestRenderer .= " + (data['contacts_infos.birthday']!=null ? ' (' + age(data['contacts_infos.birthday']) + ' ans)' : '')";
} else {
$magicSuggestRenderer = "data['name']";
}
?>
// Affiche plus d'infos que le nom du contact si on est en mode infos contacts
jQuery('.add-contacts').each(function()
{
jQuery(this).magicSuggest({
data: '<?php echo $this->generateUrl('contacts', 'jsonGetContacts'); ?>',
valueField: '<?php echo RASPISMS_SETTINGS_EXTENDED_CONTACTS_INFOS ? 'contacts.' : ''; ?>id',
displayField: '<?php echo RASPISMS_SETTINGS_EXTENDED_CONTACTS_INFOS ? 'contacts.' : ''; ?>name',
name: 'contacts[]'
name: 'contacts[]',
allowFreeEntries: false, // évite que l'utilisateur ne saisisse autre chose qu'un contact de la liste
renderer: function(data) {
return <?php echo $magicSuggestRenderer; ?>;
}
});
});
function age(birthday)
{
birthday = new Date(birthday);
return new Number((new Date().getTime() - birthday.getTime()) / 31536000000).toFixed(0);
}
});
</script>
<?php