If a contact wasn't loaded in the list you coulcn't access it from search result. Fixes oc-1264.

This commit is contained in:
Thomas Tanghus 2012-07-17 01:35:35 +02:00
parent f128b96ac0
commit 4de66880ed
2 changed files with 29 additions and 4 deletions

View File

@ -30,6 +30,7 @@ $id = isset($_GET['id'])?$_GET['id']:null;
if(is_null($id)) { if(is_null($id)) {
bailOut(OC_Contacts_App::$l10n->t('Missing ID')); bailOut(OC_Contacts_App::$l10n->t('Missing ID'));
} }
$card = OC_Contacts_VCard::find($id);
$vcard = OC_Contacts_App::getContactVCard( $id ); $vcard = OC_Contacts_App::getContactVCard( $id );
if(is_null($vcard)) { if(is_null($vcard)) {
bailOut(OC_Contacts_App::$l10n->t('Error parsing VCard for ID: "'.$id.'"')); bailOut(OC_Contacts_App::$l10n->t('Error parsing VCard for ID: "'.$id.'"'));
@ -50,5 +51,7 @@ if(isset($details['PHOTO'])) {
$details['PHOTO'] = false; $details['PHOTO'] = false;
} }
$details['id'] = $id; $details['id'] = $id;
$details['displayname'] = $card['fullname'];
$details['addressbookid'] = $card['addressbookid'];
OC_Contacts_App::setLastModifiedHeader($vcard); OC_Contacts_App::setLastModifiedHeader($vcard);
OCP\JSON::success(array('data' => $details)); OCP\JSON::success(array('data' => $details));

View File

@ -299,7 +299,13 @@ Contacts={
newid = parseInt($('#contacts').find('li[data-bookid="'+bookid+'"]').first().data('id')); newid = parseInt($('#contacts').find('li[data-bookid="'+bookid+'"]').first().data('id'));
} else if(parseInt(params.cid) && !parseInt(params.aid)) { } else if(parseInt(params.cid) && !parseInt(params.aid)) {
newid = parseInt(params.cid); newid = parseInt(params.cid);
bookid = parseInt($('#contacts li[data-id="'+newid+'"]').data('bookid')); var listitem = $('#contacts li[data-id="'+newid+'"]');
console.log('Is contact in list? ' + listitem.length);
if(listitem.length) {
bookid = parseInt($('#contacts li[data-id="'+newid+'"]').data('bookid'));
} else { // contact isn't in list yet.
bookid = 'unknown';
}
} else { } else {
newid = parseInt(params.cid); newid = parseInt(params.cid);
bookid = parseInt(params.aid); bookid = parseInt(params.aid);
@ -311,9 +317,14 @@ Contacts={
console.log('newid: ' + newid + ' bookid: ' +bookid); console.log('newid: ' + newid + ' bookid: ' +bookid);
var localLoadContact = function(newid, bookid) { var localLoadContact = function(newid, bookid) {
if($('.contacts li').length > 0) { if($('.contacts li').length > 0) {
$('#contacts li[data-id="'+newid+'"],#contacts h3[data-id="'+bookid+'"]').addClass('active');
$.getJSON(OC.filePath('contacts', 'ajax', 'contactdetails.php'),{'id':newid},function(jsondata){ $.getJSON(OC.filePath('contacts', 'ajax', 'contactdetails.php'),{'id':newid},function(jsondata){
if(jsondata.status == 'success'){ if(jsondata.status == 'success'){
if(bookid == 'unknown') {
bookid = jsondata.data.addressbookid;
var entry = Contacts.UI.Card.createEntry(jsondata.data);
$('#contacts ul[data-id="'+bookid+'"]').append(entry);
}
$('#contacts li[data-id="'+newid+'"],#contacts h3[data-id="'+bookid+'"]').addClass('active');
$('#contacts ul[data-id="'+bookid+'"]').slideDown(300); $('#contacts ul[data-id="'+bookid+'"]').slideDown(300);
Contacts.UI.Card.loadContact(jsondata.data, bookid); Contacts.UI.Card.loadContact(jsondata.data, bookid);
} else { } else {
@ -1549,9 +1560,10 @@ Contacts={
}); });
} }
var contactlist = $('#contacts ul[data-id="'+b+'"]'); var contactlist = $('#contacts ul[data-id="'+b+'"]');
var contacts = $('#contacts ul[data-id="'+b+'"] li');
for(var c in book.contacts) { for(var c in book.contacts) {
if(book.contacts[c].id == undefined) { continue; } if(book.contacts[c].id == undefined) { continue; }
if($('#contacts li[data-id="'+book.contacts[c]['id']+'"][data-id="'+book.contacts[c]['bookid']+'"]').length == 0) { if(!$('#contacts li[data-id="'+book.contacts[c]['id']+'"]').length) {
var contact = Contacts.UI.Card.createEntry(book.contacts[c]); var contact = Contacts.UI.Card.createEntry(book.contacts[c]);
if(c == self.batchnum-5) { if(c == self.batchnum-5) {
contact.bind('inview', function(event, isInView, visiblePartX, visiblePartY) { contact.bind('inview', function(event, isInView, visiblePartX, visiblePartY) {
@ -1564,7 +1576,17 @@ Contacts={
} }
}); });
} }
contactlist.append(contact); var added = false;
contacts.each(function(){
if ($(this).text().toLowerCase() > book.contacts[c].displayname.toLowerCase()) {
$(this).before(contact);
added = true;
return false;
}
});
if(!added) {
contactlist.append(contact);
}
} }
} }
}); });