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
OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('contacts');
$l=new OC_L10N('contacts');
$id = $_POST['id'];
$vcard = OC_Contacts_App::getContactVCard( $id );
$name = $_POST['name'];
$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);

View File

@ -8,9 +8,46 @@
#contacts_details_list { list-style:none; }
#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_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%; }
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 li { overflow: hidden; }
.contacts_property_data li label { width:20%; float:left; text-align:right;padding-right:0.3em; }

View File

@ -1,6 +1,6 @@
<?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
* later.
* See the COPYING-README file.
@ -20,9 +20,9 @@ if(isset($book)){
$cardobjects = OC_Contacts_VCard::all($book);
header('Content-Type: text/directory');
header('Content-Disposition: inline; filename=' . str_replace(' ', '_', $addressbook['displayname']) . '.vcf');
for($i = 0;$i <= count($cardobjects); $i++){
echo $cardobjects[$i]['carddata'];
//echo '\r\n';
foreach($cardobjects as $card) {
echo $card['carddata'];
}
}elseif(isset($contact)){
$data = OC_Contacts_App::getContactObject($contact);

View File

@ -60,10 +60,10 @@ if(!is_null($id)) {
// Include Style and Script
OC_Util::addScript('contacts','interface');
OC_Util::addStyle('contacts','styles');
OC_Util::addStyle('contacts','formtastic');
OC_Util::addScript('contacts','jquery.inview');
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();
$adr_types = OC_Contacts_App::getTypesOfProperty('ADR');

View File

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

View File

@ -203,15 +203,6 @@ class OC_Contacts_Addressbook{
while( $row = $result->fetchRow()){
$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;
}
@ -240,6 +231,7 @@ class OC_Contacts_Addressbook{
unset($openaddressbooks[array_search($id, $openaddressbooks)]);
}
}
// NOTE: Ugly hack...
$openaddressbooks = self::cleanArray($openaddressbooks, false);
sort($openaddressbooks, SORT_NUMERIC);
// 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++){
if(md5($vcard->children[$i]->serialize()) == $checksum ){
$line = $i;
break;
}
}
if(is_null($line)){

View File

@ -151,6 +151,7 @@ class OC_Contacts_VCard{
foreach($card->children as $property){
if($property->name == 'FN'){
$fn = $property->value;
break;
}
}
}
@ -178,6 +179,7 @@ class OC_Contacts_VCard{
foreach($card->children as $property){
if($property->name == 'FN'){
$fn = $property->value;
break;
}
}
}
@ -206,6 +208,7 @@ class OC_Contacts_VCard{
foreach($card->children as $property){
if($property->name == 'FN'){
$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'>
var totalurl = '<?php echo OC_Helper::linkTo('contacts', 'carddav.php', null, true); ?>/addressbooks';
</script>

View File

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