summaryrefslogtreecommitdiffstats
path: root/apps/contacts
diff options
context:
space:
mode:
authorStephan Bergemann <st.bergemann@htw-berlin.de>2012-06-17 02:29:35 +0200
committerThomas Tanghus <thomas@tanghus.net>2012-06-17 20:25:32 +0200
commit92e35bd843890eabeb582c5b616354324f332e85 (patch)
tree75ef31aa9e2810ae3afc61312bd197de86168d3c /apps/contacts
parent7f485d1b2058a1af2f82555939df3d6c306047a3 (diff)
downloadnextcloud-server-92e35bd843890eabeb582c5b616354324f332e85.tar.gz
nextcloud-server-92e35bd843890eabeb582c5b616354324f332e85.zip
now a little less in template - more in ajax controller
Diffstat (limited to 'apps/contacts')
-rw-r--r--apps/contacts/ajax/contacts.php28
-rw-r--r--apps/contacts/js/contacts.js3
-rw-r--r--apps/contacts/templates/index.php1
-rw-r--r--apps/contacts/templates/part.contacts.php51
4 files changed, 45 insertions, 38 deletions
diff --git a/apps/contacts/ajax/contacts.php b/apps/contacts/ajax/contacts.php
index dbc9be5ca56..1edc35709e6 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 1c5139117d9..925dbafe467 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 82619601c2b..74dcf5149d9 100644
--- a/apps/contacts/templates/index.php
+++ b/apps/contacts/templates/index.php
@@ -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>
diff --git a/apps/contacts/templates/part.contacts.php b/apps/contacts/templates/part.contacts.php
index 1e64119c055..6c1252debce 100644
--- a/apps/contacts/templates/part.contacts.php
+++ b/apps/contacts/templates/part.contacts.php
@@ -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() {