CSS cleanup, more error checking, better error messages, general cleanup.

This commit is contained in:
Thomas Tanghus 2012-01-11 03:56:53 +01:00
parent 5500041cca
commit 1a6ad816a3
10 changed files with 171 additions and 89 deletions

View File

@ -26,13 +26,21 @@ require_once('../../../lib/base.php');
// Check if we are a user // Check if we are a user
OC_JSON::checkLoggedIn(); OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('contacts'); OC_JSON::checkAppEnabled('contacts');
$l=new OC_L10N('contacts');
$id = $_POST['id']; $id = $_POST['id'];
$vcard = OC_Contacts_App::getContactVCard( $id ); $vcard = OC_Contacts_App::getContactVCard( $id );
$name = $_POST['name']; $name = $_POST['name'];
$value = $_POST['value']; $value = $_POST['value'];
$parameters = isset($_POST['parameters'])?$_POST['parameters']:array(); if(!is_array($value)){
$value = trim($value);
if(!$value && in_array($name, array('TEL', 'EMAIL'))) {
OC_JSON::error(array('data' => array('message' => $l->t('Cannot add empty property.'))));
exit();
}
}
$parameters = isset($_POST['parameters']) ? $_POST['parameters'] : array();
$property = $vcard->addProperty($name, $value); //, $parameters); $property = $vcard->addProperty($name, $value); //, $parameters);

View File

@ -8,9 +8,46 @@
#contacts_details_list { list-style:none; } #contacts_details_list { list-style:none; }
#contacts_details_list li { overflow:visible; } #contacts_details_list li { overflow:visible; }
#contacts_details_list li p.contacts_property_name { width:25%; float:left;text-align:right;padding-right:0.3em;color:#666; } #contacts_details_list li p.contacts_property_name { width:25%; float:left;text-align:right;padding-right:0.3em;color:#666; }
#contacts_details_list li p.contacts_property_data, #contacts_details_list li ul.contacts_property_data { width:72%;float:left; } #contacts_details_list li p.contacts_property_data, #contacts_details_list li ul.contacts_property_data { width:72%;float:left; clear: right; }
#contacts_setproperty_button { margin-left:25%; } #contacts_setproperty_button { margin-left:25%; }
dl.form
{
width: 100%;
float: left;
clear: right;
margin: 1em;
padding: 0;
}
.form dt
{
display: table-cell;
clear: left;
float: left;
min-width: 10em;
margin: 0;
padding-top: 0.5em;
padding-right: 1em;
font-weight: bold;
text-align:right;
vertical-align: text-bottom;
bottom: 0px;
}
.form dd
{
display: table-cell;
clear: right;
float: left;
min-width: 20em;
margin: 0;
padding: 0;
white-space: nowrap;
top: 0px;
}
.form input { position: relative; width: 20em; }
.contacts_property_data ul, ol.contacts_property_data { list-style:none; } .contacts_property_data ul, ol.contacts_property_data { list-style:none; }
.contacts_property_data li { overflow: hidden; } .contacts_property_data li { overflow: hidden; }
.contacts_property_data li label { width:20%; float:left; text-align:right;padding-right:0.3em; } .contacts_property_data li label { width:20%; float:left; text-align:right;padding-right:0.3em; }

View File

@ -1,6 +1,6 @@
<?php <?php
/** /**
* Copyright (c) 2011 Georg Ehrke <ownclouddev at georgswebsite dot de> * Copyright (c) 2011-2012 Thomas Tanghus <thomas@tanghus.net>
* This file is licensed under the Affero General Public License version 3 or * This file is licensed under the Affero General Public License version 3 or
* later. * later.
* See the COPYING-README file. * See the COPYING-README file.
@ -20,9 +20,9 @@ if(isset($book)){
$cardobjects = OC_Contacts_VCard::all($book); $cardobjects = OC_Contacts_VCard::all($book);
header('Content-Type: text/directory'); header('Content-Type: text/directory');
header('Content-Disposition: inline; filename=' . str_replace(' ', '_', $addressbook['displayname']) . '.vcf'); header('Content-Disposition: inline; filename=' . str_replace(' ', '_', $addressbook['displayname']) . '.vcf');
for($i = 0;$i <= count($cardobjects); $i++){
echo $cardobjects[$i]['carddata']; foreach($cardobjects as $card) {
//echo '\r\n'; echo $card['carddata'];
} }
}elseif(isset($contact)){ }elseif(isset($contact)){
$data = OC_Contacts_App::getContactObject($contact); $data = OC_Contacts_App::getContactObject($contact);

View File

@ -60,10 +60,10 @@ if(!is_null($id)) {
// Include Style and Script // Include Style and Script
OC_Util::addScript('contacts','interface'); OC_Util::addScript('contacts','interface');
OC_Util::addStyle('contacts','styles'); OC_Util::addScript('contacts','jquery.inview');
OC_Util::addStyle('contacts','formtastic');
OC_Util::addScript('', 'jquery.multiselect'); OC_Util::addScript('', 'jquery.multiselect');
OC_Util::addStyle('', 'jquery.multiselect'); OC_Util::addStyle('contacts','styles');
//OC_Util::addStyle('contacts','formtastic');
$property_types = OC_Contacts_App::getAddPropertyOptions(); $property_types = OC_Contacts_App::getAddPropertyOptions();
$adr_types = OC_Contacts_App::getTypesOfProperty('ADR'); $adr_types = OC_Contacts_App::getTypesOfProperty('ADR');

View File

@ -29,18 +29,28 @@ Contacts={
$('#carddav_url_close').show(); $('#carddav_url_close').show();
}, },
messageBox:function(title, msg) { messageBox:function(title, msg) {
var $dialog = $('<div></div>') if($('#messagebox').dialog('isOpen') == true){
.html(msg) // NOTE: Do we ever get here?
.dialog({ $('#messagebox').dialog('moveToTop');
autoOpen: true, }else{
title: title,buttons: [ $('#dialog_holder').load(OC.filePath('contacts', 'ajax', 'messagebox.php'), function(){
$('#messagebox').dialog(
{ {
text: "Ok", autoOpen: true,
click: function() { $(this).dialog("close"); } title: title,
} buttons: [{
] text: "Ok",
} click: function() { $(this).dialog("close"); }
); }],
close: function(event, ui) {
$(this).dialog('destroy').remove();
},
open: function(event, ui) {
$('#messagebox_msg').html(msg);
}
});
});
}
}, },
Addressbooks:{ Addressbooks:{
overview:function(){ overview:function(){
@ -159,6 +169,10 @@ $(document).ready(function(){
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------
* Event handlers * Event handlers
*-----------------------------------------------------------------------*/ *-----------------------------------------------------------------------*/
/**
* Load the details view for a contact.
*/
$('#leftcontent li').live('click',function(){ $('#leftcontent li').live('click',function(){
var id = $(this).data('id'); var id = $(this).data('id');
var oldid = $('#rightcontent').data('id'); var oldid = $('#rightcontent').data('id');
@ -179,6 +193,9 @@ $(document).ready(function(){
return false; return false;
}); });
/**
* Delete currently selected contact (and clear form?)
*/
$('#contacts_deletecard').live('click',function(){ $('#contacts_deletecard').live('click',function(){
var id = $('#rightcontent').data('id'); var id = $('#rightcontent').data('id');
$.getJSON('ajax/deletecard.php',{'id':id},function(jsondata){ $.getJSON('ajax/deletecard.php',{'id':id},function(jsondata){
@ -195,6 +212,10 @@ $(document).ready(function(){
return false; return false;
}); });
/**
* Add a property to the contact.
* NOTE: Where does 'contacts_addproperty' exist?
*/
$('#contacts_addproperty').live('click',function(){ $('#contacts_addproperty').live('click',function(){
var id = $('#rightcontent').data('id'); var id = $('#rightcontent').data('id');
$.getJSON('ajax/showaddproperty.php',{'id':id},function(jsondata){ $.getJSON('ajax/showaddproperty.php',{'id':id},function(jsondata){
@ -204,12 +225,15 @@ $(document).ready(function(){
} }
else{ else{
Contacts.UI.messageBox('Error', jsondata.data.message); Contacts.UI.messageBox('Error', jsondata.data.message);
//alert(jsondata.data.message); alert('From handler: '+jsondata.data.message);
} }
}); });
return false; return false;
}); });
/**
* Change the inputs based on which type of property is selected for addition.
*/
$('#contacts_addpropertyform [name="name"]').live('change',function(){ $('#contacts_addpropertyform [name="name"]').live('change',function(){
$('#contacts_addpropertyform #contacts_addresspart').remove(); $('#contacts_addpropertyform #contacts_addresspart').remove();
$('#contacts_addpropertyform #contacts_phonepart').remove(); $('#contacts_addpropertyform #contacts_phonepart').remove();
@ -234,12 +258,14 @@ $(document).ready(function(){
} }
else{ else{
Contacts.UI.messageBox('Error', jsondata.data.message); Contacts.UI.messageBox('Error', jsondata.data.message);
//alert(jsondata.data.message);
} }
}, 'json'); }, 'json');
return false; return false;
}); });
/**
* Show the Addressbook chooser
*/
$('#chooseaddressbook').click(function(){ $('#chooseaddressbook').click(function(){
Contacts.UI.Addressbooks.overview(); Contacts.UI.Addressbooks.overview();
return false; return false;
@ -292,6 +318,10 @@ $(document).ready(function(){
}, 'json'); }, 'json');
return false; return false;
}); });
/**
* Show inputs for editing a property.
*/
$('.contacts_property [data-use="edit"]').live('click',function(){ $('.contacts_property [data-use="edit"]').live('click',function(){
var id = $('#rightcontent').data('id'); var id = $('#rightcontent').data('id');
var checksum = $(this).parents('.contacts_property').first().data('checksum'); var checksum = $(this).parents('.contacts_property').first().data('checksum');
@ -308,6 +338,9 @@ $(document).ready(function(){
return false; return false;
}); });
/**
* Save the edited property
*/
$('#contacts_setpropertyform input[type="submit"]').live('click',function(){ $('#contacts_setpropertyform input[type="submit"]').live('click',function(){
$.post('ajax/setproperty.php',$(this).parents('form').first().serialize(),function(jsondata){ $.post('ajax/setproperty.php',$(this).parents('form').first().serialize(),function(jsondata){
if(jsondata.status == 'success'){ if(jsondata.status == 'success'){

View File

@ -203,15 +203,6 @@ class OC_Contacts_Addressbook{
while( $row = $result->fetchRow()){ while( $row = $result->fetchRow()){
$addressbooks[] = $row; $addressbooks[] = $row;
} }
/*
foreach( $active as $aid ){
$stmt = OC_DB::prepare( 'SELECT * FROM *PREFIX*contacts_addressbooks WHERE id = ? ORDER BY displayname' );
$result = $stmt->execute(array($aid,));
while( $row = $result->fetchRow()){
$addressbooks[] = $row;
}
}*/
return $addressbooks; return $addressbooks;
} }
@ -240,6 +231,7 @@ class OC_Contacts_Addressbook{
unset($openaddressbooks[array_search($id, $openaddressbooks)]); unset($openaddressbooks[array_search($id, $openaddressbooks)]);
} }
} }
// NOTE: Ugly hack...
$openaddressbooks = self::cleanArray($openaddressbooks, false); $openaddressbooks = self::cleanArray($openaddressbooks, false);
sort($openaddressbooks, SORT_NUMERIC); sort($openaddressbooks, SORT_NUMERIC);
// FIXME: I alway end up with a ';' prepending when imploding the array..? // FIXME: I alway end up with a ';' prepending when imploding the array..?

View File

@ -73,6 +73,7 @@ class OC_Contacts_App{
for($i=0;$i<count($vcard->children);$i++){ for($i=0;$i<count($vcard->children);$i++){
if(md5($vcard->children[$i]->serialize()) == $checksum ){ if(md5($vcard->children[$i]->serialize()) == $checksum ){
$line = $i; $line = $i;
break;
} }
} }
if(is_null($line)){ if(is_null($line)){

View File

@ -151,6 +151,7 @@ class OC_Contacts_VCard{
foreach($card->children as $property){ foreach($card->children as $property){
if($property->name == 'FN'){ if($property->name == 'FN'){
$fn = $property->value; $fn = $property->value;
break;
} }
} }
} }
@ -178,6 +179,7 @@ class OC_Contacts_VCard{
foreach($card->children as $property){ foreach($card->children as $property){
if($property->name == 'FN'){ if($property->name == 'FN'){
$fn = $property->value; $fn = $property->value;
break;
} }
} }
} }
@ -206,6 +208,7 @@ class OC_Contacts_VCard{
foreach($card->children as $property){ foreach($card->children as $property){
if($property->name == 'FN'){ if($property->name == 'FN'){
$fn = $property->value; $fn = $property->value;
break;
} }
} }
} }

View File

@ -1,10 +1,3 @@
<?php // Include Style and Script
//OC_Util::addScript('contacts','interface'); // this line caused entry duplication, cause contacts/index.php already inlcudes it
OC_Util::addScript('contacts','jquery.inview');
OC_Util::addStyle('contacts','styles');
OC_Util::addStyle('contacts','formtastic');
?>
<script type='text/javascript'> <script type='text/javascript'>
var totalurl = '<?php echo OC_Helper::linkTo('contacts', 'carddav.php', null, true); ?>/addressbooks'; var totalurl = '<?php echo OC_Helper::linkTo('contacts', 'carddav.php', null, true); ?>/addressbooks';
</script> </script>

View File

@ -3,93 +3,108 @@
<input type="hidden" name="id" value="<?php echo $_['addressbooks'][0]['id']; ?>"> <input type="hidden" name="id" value="<?php echo $_['addressbooks'][0]['id']; ?>">
<?php else: ?> <?php else: ?>
<fieldset class="inputs"> <fieldset class="inputs">
<ol> <dl class="form">
<li class="input stringish"> <dt>
<label class="label" for="id"><?php echo $l->t('Group'); ?></label> <label class="label" for="id"><?php echo $l->t('Group'); ?></label>
</dt>
<dd>
<select name="id" size="1"> <select name="id" size="1">
<?php echo html_select_options($_['addressbooks'], null, array('value'=>'id', 'label'=>'displayname')); ?> <?php echo html_select_options($_['addressbooks'], null, array('value'=>'id', 'label'=>'displayname')); ?>
</select> </select>
</li> </dd>
</ol> </dl>
</fieldset> </fieldset>
<?php endif; ?> <?php endif; ?>
<fieldset class="inputs"> <fieldset class="inputs">
<ol> <dl class="form">
<li class="input stringish"> <dt>
<label class="label" for="fn"><?php echo $l->t('Name'); ?></label> <label class="label" for="fn"><?php echo $l->t('Name'); ?></label>
</dd>
<dd>
<input id="fn" type="text" name="fn" value=""><br> <input id="fn" type="text" name="fn" value=""><br>
</li> </dd>
<li class="input stringish"> <dt>
<label class="label" for="org"><?php echo $l->t('Organization'); ?></label> <label class="label" for="org"><?php echo $l->t('Organization'); ?></label>
</dt>
<dd>
<input id="org" type="text" name="value[ORG]" value=""> <input id="org" type="text" name="value[ORG]" value="">
</li> </dd>
</ol> </dl>
</fieldset> </fieldset>
<fieldset class="inputs"> <fieldset class="inputs">
<ol> <dl class="form">
<li class="input stringish"> <dt>
<label class="label" for="email"><?php echo $l->t('Email'); ?></label> <label class="label" for="email"><?php echo $l->t('Email'); ?></label>
</dt>
<dd>
<input id="email" type="text" name="value[EMAIL]" value=""> <input id="email" type="text" name="value[EMAIL]" value="">
</li> </dd>
<li class="input"> <dt>
<fieldset class="fragments"> <label for="tel"><?php echo $l->t('Telephone'); ?></label>
<legend class="label"> </dt>
<label for="tel"><?php echo $l->t('Telephone'); ?></label> <dd>
</legend> <input type="phone" id="tel" name="value[TEL]" value="">
<ol class="fragments-group"> <select id="TEL" name="parameters[TEL][TYPE][]" multiple="multiple">
<li class="fragment"> <?php echo html_select_options($_['phone_types'], 'CELL') ?>
<label for="tel"><?php echo $l->t('Number'); ?></label> </select>
<input type="phone" id="tel" name="value[TEL]" value=""> </dd>
</li> </dl>
<li class="fragment">
<label for="tel_type"><?php echo $l->t('Type'); ?></label>
<select id="TEL" name="parameters[TEL][TYPE][]" multiple="multiple">
<?php echo html_select_options($_['phone_types'], 'CELL') ?>
</select>
</li>
</ol>
</fieldset>
</li>
</ol>
</fieldset> </fieldset>
<fieldset class="inputs"> <fieldset class="inputs">
<legend><?php echo $l->t('Address'); ?></legend> <legend><?php echo $l->t('Address'); ?></legend>
<ol> <dl class="form">
<li class="input"> <dt>
<label class="label" for="adr_type"><?php echo $l->t('Type'); ?></label> <label class="label" for="adr_type"><?php echo $l->t('Type'); ?></label>
</dt>
<dd>
<select id="adr_type" name="parameters[ADR][TYPE]" size="1"> <select id="adr_type" name="parameters[ADR][TYPE]" size="1">
<?php echo html_select_options($_['adr_types'], 'HOME') ?> <?php echo html_select_options($_['adr_types'], 'HOME') ?>
</select> </select>
</li> </dd>
<li class="input stringish"> <dt>
<label class="label" for="adr_pobox"><?php echo $l->t('PO Box'); ?></label> <label class="label" for="adr_pobox"><?php echo $l->t('PO Box'); ?></label>
</dt>
<dd>
<input type="text" id="adr_pobox" name="value[ADR][0]" value=""> <input type="text" id="adr_pobox" name="value[ADR][0]" value="">
</li> </dd>
<li class="input stringish"> <dd>
<dt>
<label class="label" for="adr_extended"><?php echo $l->t('Extended'); ?></label> <label class="label" for="adr_extended"><?php echo $l->t('Extended'); ?></label>
</dt>
<dd>
<input type="text" id="adr_extended" name="value[ADR][1]" value=""> <input type="text" id="adr_extended" name="value[ADR][1]" value="">
</li> </dd>
<li class="input stringish"> <dt>
<label class="label" for="adr_street"><?php echo $l->t('Street'); ?></label> <label class="label" for="adr_street"><?php echo $l->t('Street'); ?></label>
</dt>
<dd>
<input type="text" id="adr_street" name="value[ADR][2]" value=""> <input type="text" id="adr_street" name="value[ADR][2]" value="">
</li> </dd>
<li class="input stringish"> <dt>
<label class="label" for="adr_city"><?php echo $l->t('City'); ?></label> <label class="label" for="adr_city"><?php echo $l->t('City'); ?></label>
</dt>
<dd>
<input type="text" id="adr_city" name="value[ADR][3]" value=""> <input type="text" id="adr_city" name="value[ADR][3]" value="">
</li> </dd>
<li class="input stringish"> <dt>
<label class="label" for="adr_region"><?php echo $l->t('Region'); ?></label> <label class="label" for="adr_region"><?php echo $l->t('Region'); ?></label>
</dt>
<dd>
<input type="text" id="adr_region" name="value[ADR][4]" value=""> <input type="text" id="adr_region" name="value[ADR][4]" value="">
</li> </dd>
<li class="input stringish"> <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>
<dd>
<input type="text" id="adr_zipcode" name="value[ADR][5]" value=""> <input type="text" id="adr_zipcode" name="value[ADR][5]" value="">
</li> </dd>
<li class="input stringish"> <dt>
<label class="label" for="adr_country"><?php echo $l->t('Country'); ?></label> <label class="label" for="adr_country"><?php echo $l->t('Country'); ?></label>
</dt>
<dd>
<input type="text" id="adr_country" name="value[ADR][6]" value=""> <input type="text" id="adr_country" name="value[ADR][6]" value="">
</li> </dd>
</ol> </dl>
</fieldset> </fieldset>
<fieldset class="buttons"> <fieldset class="buttons">
<ol> <ol>