]> source.dussan.org Git - nextcloud-server.git/commitdiff
now a little less in template - more in ajax controller
authorStephan Bergemann <st.bergemann@htw-berlin.de>
Sun, 17 Jun 2012 00:29:35 +0000 (02:29 +0200)
committerThomas Tanghus <thomas@tanghus.net>
Sun, 17 Jun 2012 18:25:32 +0000 (20:25 +0200)
apps/contacts/ajax/contacts.php
apps/contacts/js/contacts.js
apps/contacts/templates/index.php
apps/contacts/templates/part.contacts.php

index dbc9be5ca565484435c1e56e9fa993c57b597c59..1edc35709e6dcef3174c77d56ead2aa729651bf3 100644 (file)
@@ -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 )));
index 1c5139117d9b4e27121f3ba31bc7fdeae9106cf1..925dbafe46775fe81b7aa9012113ac997e7df249 100644 (file)
@@ -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();
index 82619601c2b9afab7fe176e55a4ab69470275b5c..74dcf5149d96accfaad740e0bfe2b9f06d641002 100644 (file)
@@ -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>
index 1e64119c055da384f184f9020318717b9ed715f4..6c1252debce979453d3a5a5b605f108cce6db99a 100644 (file)
@@ -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() {