diff --git a/apps/contacts/ajax/addcontact.php b/apps/contacts/ajax/addcontact.php index 4bd3df54e3..c39d75eff8 100644 --- a/apps/contacts/ajax/addcontact.php +++ b/apps/contacts/ajax/addcontact.php @@ -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) { diff --git a/apps/contacts/ajax/editname.php b/apps/contacts/ajax/editname.php index 6205cc74b0..c7a7bcdeaf 100644 --- a/apps/contacts/ajax/editname.php +++ b/apps/contacts/ajax/editname.php @@ -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'); diff --git a/apps/contacts/ajax/newcontact.php b/apps/contacts/ajax/newcontact.php index 3d1a8e7453..fcfd12ca80 100644 --- a/apps/contacts/ajax/newcontact.php +++ b/apps/contacts/ajax/newcontact.php @@ -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(); diff --git a/apps/contacts/css/contacts.css b/apps/contacts/css/contacts.css index a48533f85a..d90e93f64e 100644 --- a/apps/contacts/css/contacts.css +++ b/apps/contacts/css/contacts.css @@ -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; } diff --git a/apps/contacts/js/contacts.js b/apps/contacts/js/contacts.js index b66dd6949d..40f049de3b 100644 --- a/apps/contacts/js/contacts.js +++ b/apps/contacts/js/contacts.js @@ -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 = '
  • '+Contacts.UI.Card.fn+'
  • '; + 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){ diff --git a/apps/contacts/lib/vcard.php b/apps/contacts/lib/vcard.php index aefa2c7411..eee57ec4a1 100644 --- a/apps/contacts/lib/vcard.php +++ b/apps/contacts/lib/vcard.php @@ -177,7 +177,7 @@ class OC_Contacts_VCard{ } else { $fn = 'Unknown'; } - $card->addProperty('EMAIL', $email); + $card->addProperty('FN', $fn); $data = $card->serialize(); } diff --git a/apps/contacts/templates/part.contact.php b/apps/contacts/templates/part.contact.php index 8a4faf720d..446a9b88ed 100644 --- a/apps/contacts/templates/part.contact.php +++ b/apps/contacts/templates/part.contact.php @@ -1,21 +1,6 @@ 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(); ?>
    @@ -35,7 +20,7 @@ $card['ADR'] = (array_key_exists('ADR',$_['details'])) ? $_['details']['ADR'] :
    -
    id="file_upload_form" action="ajax/uploadphoto.php" method="post" enctype="multipart/form-data" target="file_upload_target"> +
    @@ -80,7 +65,7 @@ $card['ADR'] = (array_key_exists('ADR',$_['details'])) ? $_['details']['ADR'] :
    -
    0?'':'style="display:none;"'); ?>> + -
    0?'':'style="display:none;"'); ?>> + -
    0?'':'style="display:none;"'); ?>> + -
    -
    -
    -
    -