From b3b67ab2cb679a39ca6a159100210714ddec487a Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Wed, 20 Jun 2012 21:00:07 +0200 Subject: [PATCH] More changes for updating the contacts list. --- ajax/addcontact.php | 2 +- js/contacts.js | 32 +++++++++++++++++++------------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/ajax/addcontact.php b/ajax/addcontact.php index e45072c9..12f7bb9d 100644 --- a/ajax/addcontact.php +++ b/ajax/addcontact.php @@ -47,4 +47,4 @@ if(!$id) { exit(); } -OCP\JSON::success(array('data' => array( 'id' => $id ))); +OCP\JSON::success(array('data' => array( 'id' => $id, 'aid' => $aid ))); diff --git a/js/contacts.js b/js/contacts.js index 2319334c..8ab2a3fb 100644 --- a/js/contacts.js +++ b/js/contacts.js @@ -174,7 +174,7 @@ Contacts={ // TODO: Take addressbook into account $('#fn').change(function(){ var name = $('#fn').val().strip_tags(); - var item = $('.contacts [data-id="'+Contacts.UI.Card.id+'"]'); + var item = $('.contacts li[data-id="'+Contacts.UI.Card.id+'"]'); $(item).find('a').html(name); Contacts.UI.Card.fn = name; var added = false; @@ -186,7 +186,7 @@ Contacts={ } }); if(!added) { - $('#leftcontent ul[data-id="'+Contacts.UI.Card.bookid+'"]').append(item); + $('#contacts ul[data-id="'+Contacts.UI.Card.bookid+'"]').append(item); } Contacts.UI.Contacts.scrollTo(Contacts.UI.Card.id); }); @@ -250,8 +250,10 @@ Contacts={ var newid, firstitem; if(!id) { firstitem = $('#contacts:first-child li:first-child'); - newid = firstitem.data('id'); - bookid = firstitem.data('bookid'); + if(firstitem.length > 0) { + newid = firstitem.data('id'); + bookid = firstitem.data('bookid'); + } } else { newid = id; } @@ -269,7 +271,7 @@ Contacts={ } // Make sure proper DOM is loaded. - if(!$('#card')[0]) { + if(!$('#card')[0] && newid) { $.getJSON(OC.filePath('contacts', 'ajax', 'loadcard.php'),{},function(jsondata){ if(jsondata.status == 'success'){ $('#rightcontent').html(jsondata.data.page).ready(function() { @@ -281,7 +283,7 @@ Contacts={ } }); } - else if($('.contacts li').length == 0) { + else if(!newid) { // load intro page $.getJSON(OC.filePath('contacts', 'ajax', 'loadintro.php'),{},function(jsondata){ if(jsondata.status == 'success'){ @@ -316,13 +318,14 @@ Contacts={ if (jsondata.status == 'success'){ $('#rightcontent').data('id',jsondata.data.id); var id = jsondata.data.id; + var aid = jsondata.data.aid; $.getJSON(OC.filePath('contacts', 'ajax', 'contactdetails.php'),{'id':id},function(jsondata){ if(jsondata.status == 'success'){ Contacts.UI.Card.loadContact(jsondata.data, aid); - $('#leftcontent .active').removeClass('active'); + $('#contacts .active').removeClass('active'); var item = $('
  • '+Contacts.UI.Card.fn+'
  • '); var added = false; - $('#leftcontent ul li').each(function(){ + $('#contacts ul[data-id="'+aid+'"] li').each(function(){ if ($(this).text().toLowerCase() > Contacts.UI.Card.fn.toLowerCase()) { $(this).before(item).fadeIn('fast'); added = true; @@ -330,7 +333,7 @@ Contacts={ } }); if(!added) { - $('#leftcontent ul').append(item); + $('#contacts ul[data-id="'+aid+'"]').append(item); } if(isnew) { // add some default properties Contacts.UI.Card.addProperty('EMAIL'); @@ -374,7 +377,7 @@ Contacts={ $.post(OC.filePath('contacts', 'ajax', 'deletecard.php'),{'id':Contacts.UI.Card.id},function(jsondata){ if(jsondata.status == 'success'){ var newid = '', bookid; - var curlistitem = $('#leftcontent [data-id="'+jsondata.data.id+'"]'); + var curlistitem = $('#contacts li[data-id="'+jsondata.data.id+'"]'); var newlistitem = curlistitem.prev(); if(newlistitem == undefined) { newlistitem = curlistitem.next(); @@ -1541,13 +1544,16 @@ Contacts={ }); }, refreshThumbnail:function(id){ - var item = $('.contacts [data-id="'+id+'"]').find('a'); + var item = $('.contacts li[data-id="'+id+'"]').find('a'); item.html(Contacts.UI.Card.fn); item.css('background','url('+OC.filePath('contacts', '', 'thumbnail.php')+'?id='+id+'&refresh=1'+Math.random()+') no-repeat'); }, scrollTo:function(id){ - $('.contacts').animate({ - scrollTop: $('#leftcontent li[data-id="'+id+'"]').offset().top-20}, 'slow','swing'); + var item = $('#contacts li[data-id="'+id+'"]'); + if(item) { + $('.contacts').animate({ + scrollTop: $('#contacts li[data-id="'+id+'"]').offset().top-20}, 'slow','swing'); + } } } }