Contacts: The proper DOM wasn't loaded after import and thumbnails weren't being updated.

This commit is contained in:
Thomas Tanghus 2012-05-14 10:12:36 +02:00
parent 6d37f9b951
commit 40f91d9f7c
1 changed files with 79 additions and 62 deletions

View File

@ -203,21 +203,13 @@ Contacts={
data:undefined,
update:function(id) {
var newid;
if(id == undefined) {
if(!id) {
newid = $('#contacts li:first-child').data('id');
} else {
newid = id;
}
// Make sure proper DOM is loaded.
if(!$('#card')) {
$.getJSON(OC.filePath('contacts', 'ajax', 'loadcard.php'),{},function(jsondata){
if(jsondata.status == 'success'){
$('#rightcontent').html(jsondata.data.page);
} else {
OC.dialogs.alert(jsondata.data.message, t('contacts', 'Error'));
}
});
}
var localLoadContact = function(id) {
if($('#contacts li').length > 0) {
$('#leftcontent li[data-id="'+newid+'"]').addClass('active');
$.getJSON(OC.filePath('contacts', 'ajax', 'contactdetails.php'),{'id':newid},function(jsondata){
@ -227,7 +219,23 @@ Contacts={
OC.dialogs.alert(jsondata.data.message, t('contacts', 'Error'));
}
});
} else if($('#contacts li').length == 0) {
}
}
// Make sure proper DOM is loaded.
if(!$('#card')[0]) {
$.getJSON(OC.filePath('contacts', 'ajax', 'loadcard.php'),{},function(jsondata){
if(jsondata.status == 'success'){
$('#rightcontent').html(jsondata.data.page).ready(function() {
Contacts.UI.loadHandlers();
localLoadContact(id);
});
} else {
OC.dialogs.alert(jsondata.data.message, t('contacts', 'Error'));
}
});
}
else if($('#contacts li').length == 0) {
// load intro page
$.getJSON(OC.filePath('contacts', 'ajax', 'loadintro.php'),{},function(jsondata){
if(jsondata.status == 'success'){
@ -253,17 +261,7 @@ Contacts={
return false;
},
add:function(n, fn, aid, isnew){ // add a new contact
var card = $('#card')[0];
//if(!card) {
$.getJSON(OC.filePath('contacts', 'ajax', 'loadcard.php'),{},function(jsondata){
if(jsondata.status == 'success'){
$('#rightcontent').html(jsondata.data.page);
Contacts.UI.loadHandlers();
} else{
OC.dialogs.alert(jsondata.data.message, t('contacts', 'Error'));
}
});
//}
var localAddcontact = function(n, fn, aid, isnew) {
$.post(OC.filePath('contacts', 'ajax', 'addcontact.php'), { n: n, fn: fn, aid: aid, isnew: isnew },
function(jsondata) {
if (jsondata.status == 'success'){
@ -285,15 +283,10 @@ Contacts={
if(!added) {
$('#leftcontent ul').append(item);
}
if(isnew) { // add some default properties
Contacts.UI.Card.addProperty('EMAIL');
Contacts.UI.Card.addProperty('TEL');
//Contacts.UI.Card.addProperty('NICKNAME');
//Contacts.UI.Card.addProperty('ORG');
//Contacts.UI.Card.addProperty('CATEGORIES');
$('#fn').focus();
//$('#fn').val('');
}
}
else{
@ -302,13 +295,28 @@ Contacts={
});
$('#contact_identity').show();
$('#actionbar').show();
// TODO: Add to contacts list.
}
else{
OC.dialogs.alert(jsondata.data.message, t('contacts', 'Error'));
//alert(jsondata.data.message);
}
});
}
var card = $('#card')[0];
if(!card) {
$.getJSON(OC.filePath('contacts', 'ajax', 'loadcard.php'),{},function(jsondata){
if(jsondata.status == 'success'){
$('#rightcontent').html(jsondata.data.page).ready(function() {
Contacts.UI.loadHandlers();
localAddcontact(n, fn, aid, isnew);
});
} else{
OC.dialogs.alert(jsondata.data.message, t('contacts', 'Error'));
}
});
} else {
localAddcontact(n, fn, aid, isnew);
}
},
doDelete:function() {
$('#contacts_deletecard').tipsy('hide');
@ -1455,6 +1463,15 @@ Contacts={
OC.dialogs.alert(jsondata.data.message, t('contacts', 'Error'));
}
});
setTimeout(function() {
$('#contacts li').unbind('inview');
$('#contacts li').bind('inview', function(event, isInView, visiblePartX, visiblePartY) {
if (isInView) {
if (!$(this).attr('style')) {
$(this).css('background','url('+OC.filePath('contacts', '', 'thumbnail.php')+'?id='+$(this).data('id')+') no-repeat');
}
}
})}, 500);
setTimeout(Contacts.UI.Contacts.lazyupdate, 500);
},
// Add thumbnails to the contact list as they become visible in the viewport.