mirror of
https://github.com/owncloudarchive/contacts.git
synced 2024-12-01 13:24:10 +01:00
now a little less in template - more in ajax controller
This commit is contained in:
parent
9eaf64b6d0
commit
d621126f11
@ -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 )));
|
||||
|
@ -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();
|
||||
|
@ -4,7 +4,6 @@
|
||||
var lang = '<?php echo OCP\Config::getUserValue(OCP\USER::getUser(), 'core', 'lang', 'en'); ?>';
|
||||
</script>
|
||||
<div id="leftcontent">
|
||||
<?php echo $this->inc("part.contacts"); ?>
|
||||
</div>
|
||||
<div id="bottomcontrols">
|
||||
<form>
|
||||
|
@ -1,39 +1,22 @@
|
||||
<?php
|
||||
// get the names of the addressbooks
|
||||
$addressbook_names = OC_Contacts_Addressbook::all(OCP\USER::getUser());
|
||||
$contacts = array();
|
||||
|
||||
// sort the contacts by addressbookid
|
||||
foreach( $_['contacts'] as $contact ):
|
||||
if(is_null($contacts[$contact['addressbookid']])) {
|
||||
$contacts[$contact['addressbookid']] = array();
|
||||
}
|
||||
$contacts[$contact['addressbookid']][] = $contact;
|
||||
endforeach;
|
||||
|
||||
// print them out sorted by addressbook-name
|
||||
for($i=0; $i<count($addressbook_names); $i++) {
|
||||
// a little ugly doing it this way but dunno how to do it else :)
|
||||
if(!(is_null($contacts[$addressbook_names[$i]['id']]))) { // look if we got contacts from this adressbook
|
||||
echo '<h3 class="addressbookname">'.$addressbook_names[$i]['displayname'].'</h3>';
|
||||
echo '<div>
|
||||
<ul class="contacts">';
|
||||
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 '<h3 class="addressbookname">'.$category.'</h3>';
|
||||
echo '<div>';
|
||||
echo '<ul class="contacts">';
|
||||
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 '<li role="button" book-id="'.$contact['addressbookid'].'" data-id="'.$contact['id'].'"><a href="index.php?id='.$contact['id'].'">'.htmlspecialchars($display).'</a></li>';
|
||||
|
||||
endforeach;
|
||||
echo '</ul></div>';
|
||||
}
|
||||
}
|
||||
}
|
||||
echo '<li role="button" book-id="'.$contact['addressbookid'].'" data-id="'.$contact['id'].'"><a href="index.php?id='.$contact['id'].'">'.htmlspecialchars($display).'</a></li>';
|
||||
endforeach;
|
||||
echo '</ul>';
|
||||
echo '</div>';
|
||||
endforeach;
|
||||
?>
|
||||
<script language="Javascript">
|
||||
$(document).ready(function() {
|
||||
|
Loading…
Reference in New Issue
Block a user