Contacts: Fix some regressions from last commit.

This commit is contained in:
Thomas Tanghus 2012-05-10 20:43:40 +02:00
parent bf93b9e98a
commit 7bc6e86969
4 changed files with 72 additions and 55 deletions

View file

@ -43,7 +43,7 @@ if(is_null($vcard)) {
$details = OC_Contacts_VCard::structureContact($vcard);
// Some Google exported files have no FN field.
if(!isset($details['FN'])) {
/*if(!isset($details['FN'])) {
$fn = '';
if(isset($details['N'])) {
$details['FN'] = array(implode(' ', $details['N'][0]['value']));
@ -52,7 +52,7 @@ if(!isset($details['FN'])) {
} else {
$details['FN'] = array('value' => OC_Contacts_App::$l10n->t('Unknown'));
}
}
}*/
// Make up for not supporting the 'N' field in earlier version.
if(!isset($details['N'])) {

View file

@ -4,10 +4,11 @@
#leftcontent { top: 3.5em !important; padding: 0; margin: 0; }
#rightcontent { top: 3.5em !important; padding-top: 5px; }
#contacts { background: #fff; width: 20em; left: 12.5em; top: 3.7em; bottom:3em; position: fixed; overflow: auto; padding: 0; margin: 0; }
#contacts li { height: 28px; display: block; margin: 0 0 0 0; padding: 0 0 0 25px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; -webkit-transition:background-color 200ms; -moz-transition:background-color 200ms; -o-transition:background-color 200ms; transition:background-color 200ms; }
#contacts li:hover { background-color: #eee }
#bottomcontrols { padding: 0; bottom:0px; height:2.8em; width: 20em; margin:0; background:#eee; border-top:1px solid #ccc; position:fixed; -moz-box-shadow: 0 -3px 3px -3px #000; -webkit-box-shadow: 0 -3px 3px -3px #000; box-shadow: 0 -3px 3px -3px #000;}
#contacts_newcontact { float: left; margin: 0.2em 0 0 1em; }
#chooseaddressbook { float: right; margin: 0.2em 1em 0 0; }
#leftcontent a { height: 23px; display: block; margin: 0 0 0 0; padding: 0 0 0 25px; }
#actionbar { height: 30px; width: 60px; position: fixed; right: 0px; top: 4em; margin: 0 0 0 0; padding: 0 0 0 0; z-index: 1000; }
#contacts_deletecard {position:relative; float:left; background:url('%webroot%/core/img/actions/delete.svg') no-repeat center; }
#contacts_downloadcard {position:relative; float:left; background:url('%webroot%/core/img/actions/download.svg') no-repeat center; }

View file

@ -118,7 +118,7 @@ Contacts={
$('#fn_select').combobox({
'id': 'fn',
'name': 'value',
'classes': ['contacts_property', 'huge', 'tip', 'float'],
'classes': ['contacts_property', 'nonempty', 'huge', 'tip', 'float'],
'attributes': {'placeholder': t('contacts', 'Enter name')},
'title': t('contacts', 'Format custom, Short name, Full name, Reverse or Reverse with comma')});
$('#bday').datepicker({
@ -150,20 +150,12 @@ Contacts={
}
] );
$('#fn').blur(function(){
if($('#fn').val() == '') {
OC.dialogs.alert(t('contacts','The name field cannot be empty. Please enter a name for this contact.'), t('contacts','Name is empty'), function() { $('#fn').focus(); });
$('#fn').focus();
return false;
}
});
// Name has changed. Update it and reorder.
$('#fn').change(function(){
var name = $('#fn').val();
var item = $('#contacts [data-id="'+Contacts.UI.Card.id+'"]').clone();
$('#contacts [data-id="'+Contacts.UI.Card.id+'"]').remove();
$(item).find('a').html(name);
$(item).html(name);
var added = false;
$('#contacts li').each(function(){
if ($(this).text().toLowerCase() > name.toLowerCase()) {
@ -177,6 +169,22 @@ Contacts={
}
});
$('#contacts_deletecard').click( function() { Contacts.UI.Card.doDelete();return false;} );
$('#contacts_deletecard').keydown( function(event) {
if(event.which == 13) {
Contacts.UI.Card.doDelete();
}
return false;
});
$('#contacts_downloadcard').click( function() { Contacts.UI.Card.doExport();return false;} );
$('#contacts_downloadcard').keydown( function(event) {
if(event.which == 13) {
Contacts.UI.Card.doExport();
}
return false;
});
$('#categories').multiple_autocomplete({source: categories});
$('#contacts_deletecard').tipsy({gravity: 'ne'});
$('#contacts_downloadcard').tipsy({gravity: 'ne'});
@ -247,7 +255,7 @@ Contacts={
},
add:function(n, fn, aid, isnew){ // add a new contact
var card = $('#card')[0];
if(!card) {
//if(!card) {
$.getJSON(OC.filePath('contacts', 'ajax', 'loadcard.php'),{},function(jsondata){
if(jsondata.status == 'success'){
$('#rightcontent').html(jsondata.data.page);
@ -256,7 +264,7 @@ Contacts={
OC.dialogs.alert(jsondata.data.message, t('contacts', 'Error'));
}
});
}
//}
$.post(OC.filePath('contacts', 'ajax', 'addcontact.php'), { n: n, fn: fn, aid: aid, isnew: isnew },
function(jsondata) {
if (jsondata.status == 'success'){
@ -266,7 +274,7 @@ Contacts={
if(jsondata.status == 'success'){
Contacts.UI.Card.loadContact(jsondata.data);
$('#leftcontent .active').removeClass('active');
var item = '<li data-id="'+jsondata.data.id+'" class="active"><a href="index.php?id='+jsondata.data.id+'" style="background: url('+OC.filePath('contacts', '', 'thumbnail.php')+'?id='+jsondata.data.id+') no-repeat scroll 0% 0% transparent;">'+Contacts.UI.Card.fn+'</a></li>';
var item = $('<li role="botton" data-id="'+jsondata.data.id+'" class="active" style="background: url('+OC.filePath('contacts', '', 'thumbnail.php')+'?id='+jsondata.data.id+') no-repeat scroll 0% 0% transparent;">'+Contacts.UI.Card.fn+'</li>');
var added = false;
$('#leftcontent ul li').each(function(){
if ($(this).text().toLowerCase() > Contacts.UI.Card.fn.toLowerCase()) {
@ -278,6 +286,7 @@ Contacts={
if(!added) {
$('#leftcontent ul').append(item);
}
if(isnew) { // add some default properties
Contacts.UI.Card.addProperty('EMAIL');
Contacts.UI.Card.addProperty('TEL');
@ -425,10 +434,23 @@ Contacts={
}
},
populateNameFields:function() {
var props = ['FN', 'N'];
// Clear all elements
$('#ident .propertycontainer').each(function(){
if(props.indexOf($(this).data('element')) > -1) {
$(this).data('checksum', '');
$(this).find('input').val('');
}
});
this.fn = ''; this.fullname = ''; this.givname = ''; this.famname = ''; this.addname = ''; this.honpre = ''; this.honsuf = '';
var full = '';
var narray = undefined;
this.fn = this.data.FN[0]['value'];
if(this.data.FN) {
this.fn = this.data.FN[0]['value'];
}
else {
this.fn = '';
}
if(this.data.N == undefined) {
narray = [this.fn,'','','','']; // Checking for non-existing 'N' property :-P
full = this.fn;
@ -468,7 +490,9 @@ Contacts={
.text(value));
});
$('#contact_identity').find('*[data-element="N"]').data('checksum', this.data.N[0]['checksum']);
$('#contact_identity').find('*[data-element="FN"]').data('checksum', this.data.FN[0]['checksum']);
if(this.data.FN) {
$('#contact_identity').find('*[data-element="FN"]').data('checksum', this.data.FN[0]['checksum']);
}
$('#contact_identity').show();
},
hasCategory:function(category) {
@ -549,7 +573,7 @@ Contacts={
q = q + '&id=' + this.id + '&name=' + name;
if(checksum != undefined && checksum != '') { // save
q = q + '&checksum=' + checksum;
//console.log('Saving: ' + q);
console.log('Saving: ' + q);
$(obj).attr('disabled', 'disabled');
$.post(OC.filePath('contacts', 'ajax', 'saveproperty.php'),q,function(jsondata){
if(jsondata.status == 'success'){
@ -567,7 +591,7 @@ Contacts={
}
},'json');
} else { // add
//console.log('Adding: ' + q);
console.log('Adding: ' + q);
$(obj).attr('disabled', 'disabled');
$.post(OC.filePath('contacts', 'ajax', 'addproperty.php'),q,function(jsondata){
if(jsondata.status == 'success'){
@ -1426,13 +1450,13 @@ Contacts={
// Add thumbnails to the contact list as they become visible in the viewport.
lazyupdate:function(){
$('#contacts li').live('inview', function(){
if (!$(this).find('a').attr('style')) {
$(this).find('a').css('background','url('+OC.filePath('contacts', '', 'thumbnail.php')+'?id='+$(this).data('id')+') no-repeat');
if (!$(this).attr('style')) {
$(this).css('background','url('+OC.filePath('contacts', '', 'thumbnail.php')+'?id='+$(this).data('id')+') no-repeat');
}
});
},
refreshThumbnail:function(id){
var item = $('#contacts [data-id="'+id+'"]').find('a');
var item = $('#contacts [data-id="'+id+'"]');
item.html(Contacts.UI.Card.fn);
item.css('background','url('+OC.filePath('contacts', '', 'thumbnail.php')+'?id='+id+'&refresh=1'+Math.random()+') no-repeat');
}
@ -1454,38 +1478,30 @@ $(document).ready(function(){
$('#contacts_newcontact').click(Contacts.UI.Card.editNew);
$('#contacts_newcontact').keydown(Contacts.UI.Card.editNew);
$('#contacts_deletecard').click( function() { Contacts.UI.Card.doDelete();return false;} );
$('#contacts_deletecard').keydown( function(event) {
if(event.which == 13) {
Contacts.UI.Card.doDelete();
}
return false;
});
$('#contacts_downloadcard').click( function() { Contacts.UI.Card.doExport();return false;} );
$('#contacts_downloadcard').keydown( function(event) {
if(event.which == 13) {
Contacts.UI.Card.doExport();
}
return false;
});
// Load a contact.
$('#leftcontent li').click(function(){
var id = $(this).data('id');
$(this).addClass('active');
var oldid = $('#rightcontent').data('id');
if(oldid != 0){
$('#leftcontent li[data-id="'+oldid+'"]').removeClass('active');
$('#contacts').keydown(function(event) {
if(event.which == 13) {
$('#contacts').click();
}
$.getJSON(OC.filePath('contacts', 'ajax', 'contactdetails.php'),{'id':id},function(jsondata){
if(jsondata.status == 'success'){
Contacts.UI.Card.loadContact(jsondata.data);
});
$('#contacts').click(function(event){
var $tgt = $(event.target);
if ($tgt.is('li')) {
var id = $($tgt).data('id');
$($tgt).addClass('active');
var oldid = $('#rightcontent').data('id');
if(oldid != 0){
$('#contacts li[data-id="'+oldid+'"]').removeClass('active');
}
else{
OC.dialogs.alert(jsondata.data.message, t('contacts', 'Error'));
}
});
$.getJSON(OC.filePath('contacts', 'ajax', 'contactdetails.php'),{'id':id},function(jsondata){
if(jsondata.status == 'success'){
Contacts.UI.Card.loadContact(jsondata.data);
}
else{
OC.dialogs.alert(jsondata.data.message, t('contacts', 'Error'));
}
});
}
return false;
});
@ -1498,9 +1514,9 @@ $(document).ready(function(){
// bottom part of element is visible
} else {
// whole part of element is visible
if (!$(this).find('a').attr('style')) {
if (!$(this).attr('style')) {
//alert($(this).data('id') + ' has background: ' + $(this).attr('style'));
$(this).find('a').css('background','url('+OC.filePath('contacts', '', 'thumbnail.php')+'?id='+$(this).data('id')+') no-repeat');
$(this).css('background','url('+OC.filePath('contacts', '', 'thumbnail.php')+'?id='+$(this).data('id')+') no-repeat');
}/* else {
alert($(this).data('id') + ' has style ' + $(this).attr('style').match('url'));
}*/

View file

@ -8,5 +8,5 @@
}
}
?>
<li book-id="<?php echo $contact['addressbookid']; ?>" data-id="<?php echo $contact['id']; ?>"><a href="index.php?id=<?php echo $contact['id']; ?>"><?php echo $display; ?></a></li>
<li role="button" book-id="<?php echo $contact['addressbookid']; ?>" data-id="<?php echo $contact['id']; ?>"><?php echo $display; ?></li>
<?php endforeach; ?>