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);
$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();
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;
}
},
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']);
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'){
*/
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.
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':
$('#emails').show();
}
Contacts.UI.Card.addMail();
+ Contacts.UI.showHideContactInfo();
break;
case 'TEL':
//console.log('phones: '+$('#phonelist>li').length);
$('#phones').show();
}
Contacts.UI.Card.addPhone();
+ Contacts.UI.showHideContactInfo();
break;
case 'ADR':
//console.log('addresses: '+$('#addressdisplay>dl').length);
$('#addresses').show();
}
Contacts.UI.Card.editAddress('new', true);
+ Contacts.UI.showHideContactInfo();
break;
case 'NICKNAME':
case 'ORG':
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);
} 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);
}
},
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){
}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() {
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];
$('#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'));
}
if(isnew) {
container.remove();
}
+ Contacts.UI.showHideContactInfo();
}
},
close : function(event, ui) {
if(isnew) {
container.remove();
}
+ Contacts.UI.showHideContactInfo();
}/*,
open : function(event, ui) {
// load 'ADR' property - maybe :-P
});
/**
- * 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){
<?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">
<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']; ?>" / -->
<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">
</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">
</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">
</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>