From 307409b7e2378e0cf2b2e027f691cdc0c84689fc Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Thu, 1 Nov 2012 02:01:00 +0100 Subject: [PATCH] Open contact from search without reloading app. --- js/app.js | 18 ++++++++++++------ js/contacts.js | 3 +++ js/loader.js | 9 +++++++++ lib/search.php | 5 +++-- 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/js/app.js b/js/app.js index d614033d..44f13455 100644 --- a/js/app.js +++ b/js/app.js @@ -452,10 +452,10 @@ OC.Contacts = OC.Contacts || { message: 'error in: ' + settings.url + ', '+'error: ' + xhr.responseText, }); }); - if(id) { + //if(id) { this.currentid = parseInt(id); console.log('init, id:', id); - } + //} // Holds an array of {id,name} maps this.scrollTimeoutMiliSecs = 100; this.isScrolling = false; @@ -583,6 +583,7 @@ OC.Contacts = OC.Contacts || { self.loading(self.$rightContent, false); self.Groups.loadGroups(self.numcontacts, function() { self.loading($('#leftcontent'), false); + console.log('Groups loaded, currentid', self.currentid); if(self.currentid) { self.openContact(self.currentid); } @@ -1053,14 +1054,19 @@ OC.Contacts = OC.Contacts || { }, closeContact: function(id) { if(typeof this.currentid === 'number') { - this.Contacts.findById(id).close(); - this.$contactList.show(); - this.jumpToContact(id); - delete this.currentid; + if(this.Contacts.findById(id).close()) { + this.$contactList.show(); + this.jumpToContact(id); + delete this.currentid; + } } this.$groups.find('optgroup,option:not([value="-1"])').remove(); }, openContact: function(id) { + console.log('Contacts.openContact', id); + if(this.currentid) { + this.closeContact(this.currentid); + } this.currentid = parseInt(id); this.$contactList.hide(); this.$toggleAll.hide(); diff --git a/js/contacts.js b/js/contacts.js index 8eb9b58e..c72263ea 100644 --- a/js/contacts.js +++ b/js/contacts.js @@ -255,6 +255,9 @@ OC.Contacts = OC.Contacts || {}; console.log('Contact.close', this); if(this.$fullelem) { this.$fullelem.remove(); + return true; + } else { + return false; } } diff --git a/js/loader.js b/js/loader.js index 63e3c271..ce869a70 100644 --- a/js/loader.js +++ b/js/loader.js @@ -76,6 +76,15 @@ Contacts_Import={ }); } } + +var openContact = function(id) { + if(typeof OC.Contacts !== 'undefined') { + OC.Contacts.openContact(id); + } else { + window.location.href = OC.linkTo('contacts', 'index.php') + '?id=' + id; + } +} + $(document).ready(function(){ if(typeof FileActions !== 'undefined'){ FileActions.register('text/vcard','importaddressbook', OC.PERMISSION_READ, '', Contacts_Import.importdialog); diff --git a/lib/search.php b/lib/search.php index 942a5c5b..8a5ad7a6 100644 --- a/lib/search.php +++ b/lib/search.php @@ -9,12 +9,13 @@ class SearchProvider extends \OC_Search_Provider{ return array(); } $results=array(); - $l = new OC_l10n('contacts'); + $l = new \OC_l10n('contacts'); foreach($addressbooks as $addressbook) { $vcards = VCard::all($addressbook['id']); foreach($vcards as $vcard) { if(substr_count(strtolower($vcard['fullname']), strtolower($query)) > 0) { - $link = \OCP\Util::linkTo('contacts', 'index.php').'?id='.urlencode($vcard['id']); + //$link = \OCP\Util::linkTo('contacts', 'index.php').'?id='.urlencode($vcard['id']); + $link = 'javascript:openContact(' . $vcard['id'] . ')'; $results[]=new \OC_Search_Result($vcard['fullname'], '', $link, (string)$l->t('Contact'));//$name,$text,$link,$type } }