diff --git a/apps/contacts/ajax/contacts.php b/apps/contacts/ajax/contacts.php index dbc9be5ca5..1edc35709e 100644 --- a/apps/contacts/ajax/contacts.php +++ b/apps/contacts/ajax/contacts.php @@ -11,9 +11,33 @@ OCP\JSON::checkLoggedIn(); OCP\JSON::checkAppEnabled('contacts'); $ids = OC_Contacts_Addressbook::activeIds(OCP\USER::getUser()); -$contacts = OC_Contacts_VCard::all($ids); +$contacts_alphabet = OC_Contacts_VCard::all($ids); +$active_addressbooks = OC_Contacts_Addressbook::active(OCP\USER::getUser()); + +// Our new array for the contacts sorted by addressbook +$contacts_addressbook = array(); +foreach($contacts_alphabet as $contact): + if(is_null($contacts_addressbook[$contact['addressbookid']])) { + $contacts_addressbook[$contact['addressbookid']] = array(); + } + $contacts_addressbook[$contact['addressbookid']][] = $contact; +endforeach; + +// FIXME: this is kind of ugly - just to replace the keys of the array +// perhaps we could do some magic combine_array() instead... +foreach($contacts_addressbook as $addressbook_id => $contacts): + foreach($active_addressbooks as $addressbook): + if($addressbook_id == $addressbook['id']) { + unset($contacts_addressbook[$addressbook_id]); + $contacts_addressbook[$addressbook['displayname']] = $contacts; + } + endforeach; +endforeach; +// This one should be ok for a small amount of Addressbooks +ksort($contacts_addressbook); + $tmpl = new OCP\Template("contacts", "part.contacts"); -$tmpl->assign('contacts', $contacts, false); +$tmpl->assign('contacts', $contacts_addressbook, false); $page = $tmpl->fetchPage(); OCP\JSON::success(array('data' => array( 'page' => $page ))); diff --git a/apps/contacts/js/contacts.js b/apps/contacts/js/contacts.js index 1c5139117d..925dbafe46 100644 --- a/apps/contacts/js/contacts.js +++ b/apps/contacts/js/contacts.js @@ -1557,7 +1557,7 @@ $(document).ready(function(){ $('.contacts').click(); } }); - $('.contacts').click(function(event){ + $(document).on("click", ".contacts",function(event){ var $tgt = $(event.target); if ($tgt.is('li') || $tgt.is('a')) { var item = $tgt.is('li')?$($tgt):($tgt).parent(); @@ -1678,3 +1678,4 @@ $(document).ready(function(){ $('#contacts_propertymenu_dropdown a').click(propertyMenuItem); $('#contacts_propertymenu_dropdown a').keydown(propertyMenuItem); }); +Contacts.UI.Contacts.update(); diff --git a/apps/contacts/templates/index.php b/apps/contacts/templates/index.php index 82619601c2..74dcf5149d 100644 --- a/apps/contacts/templates/index.php +++ b/apps/contacts/templates/index.php @@ -4,7 +4,6 @@ var lang = '';