Fixed broken "Add new" contact.

Possible fix for cards with missing 'FN' property added through DAV.
Misc. UI cleanups.
This commit is contained in:
Thomas Tanghus 2012-02-06 14:18:40 +01:00
parent 23396721e4
commit 4db661ba9d
7 changed files with 85 additions and 46 deletions

View File

@ -24,11 +24,11 @@
require_once('../../../lib/base.php');
function bailOut($msg) {
OC_JSON::error(array('data' => array('message' => $msg)));
OC_Log::write('contacts','ajax/saveproperty.php: '.$msg, OC_Log::DEBUG);
OC_Log::write('contacts','ajax/addcontact.php: '.$msg, OC_Log::DEBUG);
exit();
}
function debug($msg) {
OC_Log::write('contacts','ajax/saveproperty.php: '.$msg, OC_Log::DEBUG);
OC_Log::write('contacts','ajax/addcontact.php: '.$msg, OC_Log::DEBUG);
}
foreach ($_POST as $key=>$element) {
debug('_POST: '.$key.'=>'.$element);
@ -44,11 +44,13 @@ $addressbook = OC_Contacts_App::getAddressbook( $aid );
$fn = trim($_POST['fn']);
$n = trim($_POST['n']);
debug('N: '.$n);
debug('FN: '.$fn);
$vcard = new OC_VObject('VCARD');
$vcard->setUID();
$vcard->setString('N',$n);
$vcard->setString('FN',$fn);
$vcard->setString('N',$n);
$id = OC_Contacts_VCard::add($aid,$vcard->serialize());
if(!$id) {

View File

@ -9,14 +9,23 @@
require_once('../../../lib/base.php');
OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('contacts');
function bailOut($msg) {
OC_JSON::error(array('data' => array('message' => $msg)));
OC_Log::write('contacts','ajax/editname.php: '.$msg, OC_Log::DEBUG);
exit();
}
function debug($msg) {
OC_Log::write('contacts','ajax/editname.php: '.$msg, OC_Log::DEBUG);
}
foreach ($_GET as $key=>$element) {
debug('_GET: '.$key.'=>'.$element);
}
$tmpl = new OC_TEMPLATE("contacts", "part.edit_name_dialog");
$id = $_GET['id'];
if($id) {
$vcard = OC_Contacts_App::getContactVCard($id);
$name = array('', '', '', '', '');
if($vcard->__isset('N')) {
$property = $vcard->__get('N');

View File

@ -24,11 +24,11 @@
require_once('../../../lib/base.php');
function bailOut($msg) {
OC_JSON::error(array('data' => array('message' => $msg)));
OC_Log::write('contacts','ajax/saveproperty.php: '.$msg, OC_Log::DEBUG);
OC_Log::write('contacts','ajax/newcontact.php: '.$msg, OC_Log::DEBUG);
exit();
}
function debug($msg) {
OC_Log::write('contacts','ajax/saveproperty.php: '.$msg, OC_Log::DEBUG);
OC_Log::write('contacts','ajax/newcontact.php: '.$msg, OC_Log::DEBUG);
}
foreach ($_POST as $key=>$element) {
debug('_POST: '.$key.'=>'.$element);
@ -47,10 +47,14 @@ $maxUploadFilesize = min($upload_max_filesize, $post_max_size);
$freeSpace=OC_Filesystem::free_space('/');
$freeSpace=max($freeSpace,0);
$maxUploadFilesize = min($maxUploadFilesize ,$freeSpace);
$adr_types = OC_Contacts_App::getTypesOfProperty('ADR');
$phone_types = OC_Contacts_App::getTypesOfProperty('TEL');
$tmpl = new OC_Template('contacts','part.contact');
$tmpl->assign('uploadMaxFilesize', $maxUploadFilesize);
$tmpl->assign('uploadMaxHumanFilesize', OC_Helper::humanFileSize($maxUploadFilesize));
$tmpl->assign('adr_types',$adr_types);
$tmpl->assign('phone_types',$phone_types);
$tmpl->assign('addressbooks',$addressbooks);
$tmpl->assign('id','');
$page = $tmpl->fetchPage();

View File

@ -16,7 +16,7 @@
#contacts_propertymenu li:hover { background-color: #1d2d44; }
#contacts_propertymenu li a:hover { color: #fff }
#actionbar { height: 30px; width: 200px; position: fixed; right: 0px; top: 75px; margin: 0 0 0 0; padding: 0 0 0 0;}
#card { /*max-width: 70em;*/ border: thin solid lightgray; display: block; }
#card { /*max-width: 70em; border: thin solid lightgray; display: block;*/ }
#firstrun { /*border: thin solid lightgray;*/ width: 80%; margin: 5em auto auto auto; text-align: center; font-weight:bold; font-size:1.5em; color:#777;}
#firstrun #selections { /*border: thin solid lightgray;*/ font-size:0.8em; width: 100%; margin: 2em auto auto auto; clear: both; }

View File

@ -67,25 +67,34 @@ Contacts={
propertyTypeFor:function(obj) {
return $(obj).parents('.propertycontainer').first().data('element');
},
showHideContactInfo:function() {
var show = ($('#emaillist li[class*="propertycontainer"]').length > 0 || $('#phonelist li[class*="propertycontainer"]').length > 0 || $('#addressdisplay dl[class*="propertycontainer"]').length > 0);
console.log('showHideContactInfo: ' + show);
if(show) {
$('#contact_communication').show();
} else {
$('#contact_communication').hide();
}
},
checkListFor:function(obj) {
var type = $(obj).parents('.propertycontainer').first().data('element');
console.log('checkListFor: ' + type);
switch (type) {
case 'EMAIL':
console.log('emails: '+$('#emaillist>li').length);
if($('#emaillist>li').length == 1) {
if($('#emaillist li[class*="propertycontainer"]').length == 0) {
$('#emails').hide();
}
break;
case 'TEL':
console.log('phones: '+$('#phonelist>li').length);
if($('#phonelist>li').length == 1) {
if($('#phonelist li[class*="propertycontainer"]').length == 0) {
$('#phones').hide();
}
break;
case 'ADR':
console.log('addresses: '+$('#addressdisplay>dl').length);
if($('#addressdisplay>dl').length == 1) {
if($('#addressdisplay dl[class*="propertycontainer"]').length == 0) {
$('#addresses').hide();
}
break;
@ -317,7 +326,7 @@ Contacts={
}
},
populateNameFields:function() {
this.fn = ''; this.fullname = ''; this.givname = ''; this.famname = ''; this.addname = ''; this.honpre = ''; this.honsuf = ''
this.fn = ''; this.fullname = ''; this.givname = ''; this.famname = ''; this.addname = ''; this.honpre = ''; this.honsuf = '';
var full = '';
var narray = undefined;
//console.log('splitting: ' + this.data.N[0]['value']);
@ -366,6 +375,8 @@ Contacts={
editNew:function(){ // add a new contact
//Contacts.UI.notImplemented();
//return false;
this.id = ''; this.fn = ''; this.fullname = ''; this.givname = ''; this.famname = ''; this.addname = ''; this.honpre = ''; this.honsuf = '';
$.getJSON('ajax/newcontact.php',{},function(jsondata){
if(jsondata.status == 'success'){
@ -394,7 +405,31 @@ Contacts={
*/
if (jsondata.status == 'success'){
$('#rightcontent').data('id',jsondata.data.id);
id = jsondata.data.id;
var id = jsondata.data.id;
$.getJSON('ajax/contactdetails.php',{'id':id},function(jsondata){
if(jsondata.status == 'success'){
Contacts.UI.loadHandlers();
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(thumbnail.php?id='+jsondata.data.id+') no-repeat scroll 0% 0% transparent;">'+Contacts.UI.Card.fn+'</a></li>';
var added = false;
$('#leftcontent ul li').each(function(){
if ($(this).text().toLowerCase() > Contacts.UI.Card.fn.toLowerCase()) {
$(this).before(item).fadeIn('fast');
added = true;
return false;
}
});
if(!added) {
$('#leftcontent ul').append(item);
}
}
else{
Contacts.UI.messageBox(t('contacts', 'Error'), jsondata.data.message);
//alert(jsondata.data.message);
}
});
$('#contact_identity').show();
$('#actionbar').show();
// TODO: Add to contacts list.
@ -466,7 +501,8 @@ Contacts={
console.log('addProperty:' + type);
switch (type) {
case 'PHOTO':
$('#contacts_propertymenu a[data-type="PHOTO"]').parent().hide();
$('#contacts_propertymenu a[data-type="'+type+'"]').parent().hide();
this.loadPhoto();
$('#file_upload_form').show();
break;
case 'EMAIL':
@ -475,6 +511,7 @@ Contacts={
$('#emails').show();
}
Contacts.UI.Card.addMail();
Contacts.UI.showHideContactInfo();
break;
case 'TEL':
//console.log('phones: '+$('#phonelist>li').length);
@ -482,6 +519,7 @@ Contacts={
$('#phones').show();
}
Contacts.UI.Card.addPhone();
Contacts.UI.showHideContactInfo();
break;
case 'ADR':
//console.log('addresses: '+$('#addressdisplay>dl').length);
@ -489,6 +527,7 @@ Contacts={
$('#addresses').show();
}
Contacts.UI.Card.editAddress('new', true);
Contacts.UI.showHideContactInfo();
break;
case 'NICKNAME':
case 'ORG':
@ -509,6 +548,7 @@ Contacts={
if(jsondata.status == 'success'){
if(type == 'list') {
Contacts.UI.propertyContainerFor(obj).remove();
Contacts.UI.showHideContactInfo();
Contacts.UI.checkListFor(obj);
} else if(type == 'single') {
var proptype = Contacts.UI.propertyTypeFor(obj);
@ -529,6 +569,7 @@ Contacts={
} else { // Property hasn't been saved so there's nothing to delete.
if(type == 'list') {
Contacts.UI.propertyContainerFor(obj).remove();
Contacts.UI.showHideContactInfo();
Contacts.UI.checkListFor(obj);
} else if(type == 'single') {
var proptype = Contacts.UI.propertyTypeFor(obj);
@ -542,7 +583,8 @@ Contacts={
}
},
editName:function(){
console.log('editName, id: ' + this.id);
console.log('editName, id: ' + (this.id == ''));
var isnew = (this.id == '');
//console.log('editName');
/* Initialize the name edit dialog */
if($('#edit_name_dialog').dialog('isOpen') == true){
@ -550,9 +592,9 @@ Contacts={
}else{ // TODO: If id=='' call addcontact.php (or whatever name) instead and reload view with id.
$('#dialog_holder').load(OC.filePath('contacts', 'ajax', 'editname.php')+'?id='+this.id, function(){
$('#edit_name_dialog' ).dialog({
modal: (this.id == '' && true || false),
closeOnEscape: (this.id == '' && false || true),
title: (this.id == '' && t('contacts', 'Add contact') || t('contacts', 'Edit name')),
modal: (isnew && true || false),
closeOnEscape: (isnew == '' && false || true),
title: (isnew && t('contacts', 'Add contact') || t('contacts', 'Edit name')),
height: 'auto', width: 'auto',
buttons: {
'Ok':function() {
@ -576,7 +618,7 @@ Contacts={
saveName:function(dlg){
console.log('saveName, id: ' + this.id);
// TODO: Check if new, get address book id and call Contacts.UI.Card.add()
var n = new Array($(dlg).find('#fam').val(),$(dlg).find('#giv').val(),$(dlg).find('#add').val(),$(dlg).find('#pre').val(),$(dlg).find('#suf').val());
var n = new Array($(dlg).find('#fam').val().strip_tags(),$(dlg).find('#giv').val().strip_tags(),$(dlg).find('#add').val().strip_tags(),$(dlg).find('#pre').val().strip_tags(),$(dlg).find('#suf').val().strip_tags());
this.famname = n[0];
this.givname = n[1];
this.addname = n[2];
@ -602,7 +644,7 @@ Contacts={
$('#fn').val(0);
if(this.id == '') {
var aid = $(dlg).find('#aid').val();
Contacts.UI.Card.add(n, $('#short').text(), aid);
Contacts.UI.Card.add(n.join(';'), $('#short').text(), aid);
} else {
Contacts.UI.Card.saveProperty($('#n'));
}
@ -704,6 +746,7 @@ Contacts={
if(isnew) {
container.remove();
}
Contacts.UI.showHideContactInfo();
}
},
close : function(event, ui) {
@ -712,6 +755,7 @@ Contacts={
if(isnew) {
container.remove();
}
Contacts.UI.showHideContactInfo();
}/*,
open : function(event, ui) {
// load 'ADR' property - maybe :-P
@ -1119,7 +1163,7 @@ $(document).ready(function(){
});
/**
* Add and insert a new contact into the list.
* Add and insert a new contact into the list. NOTE: Deprecated
*/
$('#contacts_addcardform input[type="submit"]').live('click',function(){
$.post('ajax/addcontact.php',$('#contact_identity').serialize(),function(jsondata){

View File

@ -177,7 +177,7 @@ class OC_Contacts_VCard{
} else {
$fn = 'Unknown';
}
$card->addProperty('EMAIL', $email);
$card->addProperty('FN', $fn);
$data = $card->serialize();
}

View File

@ -1,21 +1,6 @@
<?php
$l=new OC_L10N('contacts');
$id = isset($_['id']) ? $_['id'] : '';
$card = array();
$card['id'] = $id;
$card['FN'] = (array_key_exists('FN',$_['details'])) ? $_['details']['FN'][0] : null;
$card['N'] = (array_key_exists('N',$_['details'])) ? $_['details']['N'][0] : array('', '', '', '', '');
$card['ORG'] = (array_key_exists('ORG',$_['details'])) ? $_['details']['ORG'][0] : null;
$card['PHOTO'] = (array_key_exists('PHOTO',$_['details'])) ? $_['details']['PHOTO'][0] : null;
$card['BDAY'] = (array_key_exists('BDAY',$_['details'])) ? $_['details']['BDAY'][0] : null;
if($card['BDAY']) {
$bday = new DateTime($card['BDAY']['value']);
$card['BDAY']['value'] = $bday->format('d-m-Y');
}
$card['NICKNAME'] = (array_key_exists('NICKNAME',$_['details'])) ? $_['details']['NICKNAME'][0] : null;
$card['EMAIL'] = (array_key_exists('EMAIL',$_['details'])) ? $_['details']['EMAIL'] : array();
$card['TEL'] = (array_key_exists('TEL',$_['details'])) ? $_['details']['TEL'] : array();
$card['ADR'] = (array_key_exists('ADR',$_['details'])) ? $_['details']['ADR'] : array();
?>
<div id="card">
<div id="actionbar">
@ -35,7 +20,7 @@ $card['ADR'] = (array_key_exists('ADR',$_['details'])) ? $_['details']['ADR'] :
<div class="contactsection">
<form <?php echo (is_null($card['PHOTO'])?'style="display:none;"':''); ?> id="file_upload_form" action="ajax/uploadphoto.php" method="post" enctype="multipart/form-data" target="file_upload_target">
<form style="display:none;" id="file_upload_form" action="ajax/uploadphoto.php" method="post" enctype="multipart/form-data" target="file_upload_target">
<fieldset id="photo" class="formfloat">
<div id="contacts_details_photo_wrapper" title="<?php echo $l->t('Click or drop to upload picture'); ?> (max <?php echo $_['uploadMaxHumanFilesize']; ?>)">
<!-- img style="padding: 1em;" id="contacts_details_photo" alt="Profile picture" src="photo.php?id=<?php echo $_['id']; ?>" / -->
@ -80,7 +65,7 @@ $card['ADR'] = (array_key_exists('ADR',$_['details'])) ? $_['details']['ADR'] :
<form id="contact_communication" method="post" style="display: none;">
<div class="contactsection">
<!-- email addresses -->
<div id="emails" <?php echo (count($card['EMAIL'])>0?'':'style="display:none;"'); ?>>
<div id="emails" style="display:none;">
<fieldset class="contactpart">
<legend><?php echo $l->t('Email'); ?></legend>
<ul id="emaillist" class="propertylist">
@ -100,7 +85,7 @@ $card['ADR'] = (array_key_exists('ADR',$_['details'])) ? $_['details']['ADR'] :
</div> <!-- email addresses-->
<!-- Phone numbers -->
<div id="phones" <?php echo (count($card['TEL'])>0?'':'style="display:none;"'); ?>>
<div id="phones" style="display:none;">
<fieldset class="contactpart">
<legend><?php echo $l->t('Phone'); ?></legend>
<ul id="phonelist" class="propertylist">
@ -126,7 +111,7 @@ $card['ADR'] = (array_key_exists('ADR',$_['details'])) ? $_['details']['ADR'] :
</div> <!-- Phone numbers -->
<!-- Addresses -->
<div id="addresses" <?php echo (count($card['ADR'])>0?'':'style="display:none;"'); ?>>
<div id="addresses" style="display:none;">
<fieldset class="contactpart">
<legend><?php echo $l->t('Address'); ?></legend>
<div id="addressdisplay">
@ -178,11 +163,6 @@ $card['ADR'] = (array_key_exists('ADR',$_['details'])) ? $_['details']['ADR'] :
</div>
</form>
</div>
<div class="delimiter"></div>
<pre>
<?php /*print_r($card);*/ ?>
</pre>
<!-- div class="updatebar"><input type="button" value="Update" /></div -->
<div id="edit_photo_dialog" title="Edit photo">
<div id="edit_photo_dialog_img"></div>
</div>