UI fixes in contact editor and address book dialog.

Error checking in ajax methods.
Localize menu entry.
This commit is contained in:
Thomas Tanghus 2012-01-19 16:04:39 +01:00
parent dc942d6f3e
commit 5bd117dd6d
7 changed files with 58 additions and 27 deletions

View File

@ -35,7 +35,7 @@ $name = $_POST['name'];
$value = $_POST['value']; $value = $_POST['value'];
if(!is_array($value)){ if(!is_array($value)){
$value = trim($value); $value = trim($value);
if(!$value && in_array($name, array('TEL', 'EMAIL', 'ORG'))) { if(!$value && in_array($name, array('TEL', 'EMAIL', 'ORG', 'BDAY', 'NICKNAME'))) {
OC_JSON::error(array('data' => array('message' => $l->t('Cannot add empty property.')))); OC_JSON::error(array('data' => array('message' => $l->t('Cannot add empty property.'))));
exit(); exit();
} }
@ -72,6 +72,7 @@ foreach ($parameters as $key=>$element) {
$vcard->children[$line]->parameters[] = new Sabre_VObject_Parameter($key,$element); $vcard->children[$line]->parameters[] = new Sabre_VObject_Parameter($key,$element);
} }
} }
$checksum = md5($vcard->children[$line]->serialize());
if(!OC_Contacts_VCard::edit($id,$vcard->serialize())) { if(!OC_Contacts_VCard::edit($id,$vcard->serialize())) {
OC_JSON::error(array('data' => array('message' => $l->t('Error adding contact property.')))); OC_JSON::error(array('data' => array('message' => $l->t('Error adding contact property.'))));
@ -88,4 +89,4 @@ $tmpl->assign('phone_types',$phone_types);
$tmpl->assign('property',OC_Contacts_VCard::structureProperty($property,$line)); $tmpl->assign('property',OC_Contacts_VCard::structureProperty($property,$line));
$page = $tmpl->fetchPage(); $page = $tmpl->fetchPage();
OC_JSON::success(array('data' => array( 'page' => $page ))); OC_JSON::success(array('data' => array( 'checksum' => $checksum, 'page' => $page )));

View File

@ -28,6 +28,7 @@ OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('contacts'); OC_JSON::checkAppEnabled('contacts');
$id = $_GET['id']; $id = $_GET['id'];
$new = isset($_GET['new']) ? true : false;
$vcard = OC_Contacts_App::getContactVCard( $id ); $vcard = OC_Contacts_App::getContactVCard( $id );
OC_Contacts_App::renderDetails($id, $vcard); OC_Contacts_App::renderDetails($id, $vcard, $new);

View File

@ -95,4 +95,4 @@ $tmpl->assign('phone_types',$phone_types);
$tmpl->assign('property',OC_Contacts_VCard::structureProperty($vcard->children[$line],$line)); $tmpl->assign('property',OC_Contacts_VCard::structureProperty($vcard->children[$line],$line));
$page = $tmpl->fetchPage(); $page = $tmpl->fetchPage();
OC_JSON::success(array('data' => array( 'page' => $page, 'line' => $line, 'oldchecksum' => $_POST['checksum'] ))); OC_JSON::success(array('data' => array( 'page' => $page, 'line' => $line, 'checksum' => $checksum, 'oldchecksum' => $_POST['checksum'] )));

View File

@ -18,16 +18,26 @@ class OC_Contacts_App{
* @param int $id of contact * @param int $id of contact
* @param Sabre_VObject_Component $vcard to render * @param Sabre_VObject_Component $vcard to render
*/ */
public static function renderDetails($id, $vcard){ public static function renderDetails($id, $vcard, $new=false){
$property_types = self::getAddPropertyOptions(); $property_types = self::getAddPropertyOptions();
$adr_types = self::getTypesOfProperty('ADR'); $adr_types = self::getTypesOfProperty('ADR');
$phone_types = self::getTypesOfProperty('TEL'); $phone_types = self::getTypesOfProperty('TEL');
$upload_max_filesize = OC_Helper::computerFileSize(ini_get('upload_max_filesize'));
$post_max_size = OC_Helper::computerFileSize(ini_get('post_max_size'));
$maxUploadFilesize = min($upload_max_filesize, $post_max_size);
$freeSpace=OC_Filesystem::free_space('/');
$freeSpace=max($freeSpace,0);
$maxUploadFilesize = min($maxUploadFilesize ,$freeSpace);
$details = OC_Contacts_VCard::structureContact($vcard); $details = OC_Contacts_VCard::structureContact($vcard);
$name = $details['FN'][0]['value']; $name = $details['FN'][0]['value'];
$tmpl = new OC_Template('contacts','part.details'); $t = $new ? 'part.contact' : 'part.details';
$tmpl = new OC_Template('contacts',$t);
$tmpl->assign('details',$details); $tmpl->assign('details',$details);
$tmpl->assign('id',$id); $tmpl->assign('id',$id);
$tmpl->assign( 'uploadMaxFilesize', $maxUploadFilesize);
$tmpl->assign( 'uploadMaxHumanFilesize', OC_Helper::humanFileSize($maxUploadFilesize));
$tmpl->assign('property_types',$property_types); $tmpl->assign('property_types',$property_types);
$tmpl->assign('adr_types',$adr_types); $tmpl->assign('adr_types',$adr_types);
$tmpl->assign('phone_types',$phone_types); $tmpl->assign('phone_types',$phone_types);

View File

@ -26,7 +26,9 @@ OC_Util::checkLoggedIn();
OC_Util::checkAppEnabled('contacts'); OC_Util::checkAppEnabled('contacts');
$id = $_GET['id']; $id = $_GET['id'];
if(isset($GET['refresh'])) {
header("Cache-Control: no-cache, no-store, must-revalidate");
}
$l10n = new OC_L10N('contacts'); $l10n = new OC_L10N('contacts');
$card = OC_Contacts_VCard::find( $id ); $card = OC_Contacts_VCard::find( $id );
@ -42,12 +44,15 @@ if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){
} }
$content = OC_VObject::parse($card['carddata']); $content = OC_VObject::parse($card['carddata']);
$image = new OC_Image();
// invalid vcard // invalid vcard
if( is_null($content)){ if( is_null($content)){
echo $l10n->t('This card is not RFC compatible.'); $image->loadFromFile('img/person_large.png');
header('Content-Type: '.$image->mimeType());
$image();
//echo $l10n->t('This card is not RFC compatible.');
exit(); exit();
} } else {
// Photo :-) // Photo :-)
foreach($content->children as $child){ foreach($content->children as $child){
if($child->name == 'PHOTO'){ if($child->name == 'PHOTO'){
@ -57,13 +62,27 @@ foreach($content->children as $child){
$mime = $parameter->value; $mime = $parameter->value;
} }
} }
$photo = base64_decode($child->value); if($image->loadFromBase64($child->value)) {
header('Content-Type: '.$mime); header('Content-Type: '.$mime);
header('Content-Length: ' . strlen($photo)); $image();
echo $photo;
exit(); exit();
} else {
$image->loadFromFile('img/person_large.png');
header('Content-Type: '.$image->mimeType());
$image();
}
//$photo = base64_decode($child->value);
//header('Content-Type: '.$mime);
//header('Content-Length: ' . strlen($photo));
//echo $photo;
//exit();
} }
} }
}
$image->loadFromFile('img/person_large.png');
header('Content-Type: '.$image->mimeType());
$image();
/*
// Logo :-/ // Logo :-/
foreach($content->children as $child){ foreach($content->children as $child){
if($child->name == 'PHOTO'){ if($child->name == 'PHOTO'){
@ -80,6 +99,6 @@ foreach($content->children as $child){
exit(); exit();
} }
} }
*/
// Not found :-( // Not found :-(
echo $l10n->t('This card does not contain a photo.'); //echo $l10n->t('This card does not contain a photo.');

View File

@ -94,7 +94,7 @@
</dd> </dd>
<dt> <dt>
<label class="label" for="adr_zipcode"><?php echo $l->t('Zipcode'); ?></label> <label class="label" for="adr_zipcode"><?php echo $l->t('Zipcode'); ?></label>
</dtl> </dt>
<dd> <dd>
<input type="text" id="adr_zipcode" name="value[ADR][5]" value=""> <input type="text" id="adr_zipcode" name="value[ADR][5]" value="">
</dd> </dd>

View File

@ -12,8 +12,8 @@ for($i = 0; $i < count($option_addressbooks); $i++){
} }
?> ?>
<tr> <tr>
<td colspan="5"> <td colspan="5" style="padding: 0.5em;">
<a href="#" onclick="Contacts.UI.Addressbooks.newAddressbook(this);"><?php echo $l->t('New Address Book') ?></a> <a class="button" href="#" onclick="Contacts.UI.Addressbooks.newAddressbook(this);"><?php echo $l->t('New Address Book') ?></a>
</td> </td>
</tr> </tr>
<tr> <tr>