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 = '';
- inc("part.contacts"); ?>
diff --git a/apps/contacts/templates/part.contacts.php b/apps/contacts/templates/part.contacts.php index 1e64119c05..6c1252debc 100644 --- a/apps/contacts/templates/part.contacts.php +++ b/apps/contacts/templates/part.contacts.php @@ -1,39 +1,22 @@ '.$addressbook_names[$i]['displayname'].''; - echo '
-
    '; - foreach($contacts[$addressbook_names[$i]['id']] as $contact): - $display = trim($contact['fullname']); - - if(!$display) { - $vcard = OC_Contacts_App::getContactVCard($contact['id']); - if(!is_null($vcard)) { - $struct = OC_Contacts_VCard::structureContact($vcard); - $display = isset($struct['EMAIL'][0])?$struct['EMAIL'][0]['value']:'[UNKNOWN]'; - } +foreach($_['contacts'] as $category => $contacts): + echo '

    '.$category.'

    '; + echo '
    '; + echo '
      '; + foreach($contacts as $contact): + $display = trim($contact['fullname']); + if(!$display) { + $vcard = OC_Contacts_App::getContactVCard($contact['id']); + if(!is_null($vcard)) { + $struct = OC_Contacts_VCard::structureContact($vcard); + $display = isset($struct['EMAIL'][0])?$struct['EMAIL'][0]['value']:'[UNKNOWN]'; } - echo '
    • '.htmlspecialchars($display).'
    • '; - - endforeach; - echo '
    '; - } -} + } + echo '
  • '.htmlspecialchars($display).'
  • '; + endforeach; + echo '
'; + echo '
'; +endforeach; ?>