From 1a6ad816a32eb9d4813b66457f8bcdc9c46e2141 Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Wed, 11 Jan 2012 03:56:53 +0100 Subject: [PATCH] CSS cleanup, more error checking, better error messages, general cleanup. --- apps/contacts/ajax/addproperty.php | 10 +- apps/contacts/css/styles.css | 39 ++++++- apps/contacts/export.php | 8 +- apps/contacts/index.php | 6 +- apps/contacts/js/interface.js | 59 +++++++--- apps/contacts/lib/addressbook.php | 10 +- apps/contacts/lib/app.php | 1 + apps/contacts/lib/vcard.php | 3 + apps/contacts/templates/index.php | 7 -- apps/contacts/templates/part.addcardform.php | 117 +++++++++++-------- 10 files changed, 171 insertions(+), 89 deletions(-) diff --git a/apps/contacts/ajax/addproperty.php b/apps/contacts/ajax/addproperty.php index 0f76add3c9..74f1c3d0e9 100644 --- a/apps/contacts/ajax/addproperty.php +++ b/apps/contacts/ajax/addproperty.php @@ -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); diff --git a/apps/contacts/css/styles.css b/apps/contacts/css/styles.css index 7b56767bab..dfc296a221 100644 --- a/apps/contacts/css/styles.css +++ b/apps/contacts/css/styles.css @@ -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; } diff --git a/apps/contacts/export.php b/apps/contacts/export.php index fd2d7da175..a1e974c962 100644 --- a/apps/contacts/export.php +++ b/apps/contacts/export.php @@ -1,6 +1,6 @@ + * Copyright (c) 2011-2012 Thomas Tanghus * 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); diff --git a/apps/contacts/index.php b/apps/contacts/index.php index 0b705e71b5..6f65ac1c60 100644 --- a/apps/contacts/index.php +++ b/apps/contacts/index.php @@ -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'); diff --git a/apps/contacts/js/interface.js b/apps/contacts/js/interface.js index 4a27073c15..9547c581c8 100644 --- a/apps/contacts/js/interface.js +++ b/apps/contacts/js/interface.js @@ -29,18 +29,28 @@ Contacts={ $('#carddav_url_close').show(); }, messageBox:function(title, msg) { - var $dialog = $('
') - .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'){ diff --git a/apps/contacts/lib/addressbook.php b/apps/contacts/lib/addressbook.php index 78792f5f94..41d488c09f 100644 --- a/apps/contacts/lib/addressbook.php +++ b/apps/contacts/lib/addressbook.php @@ -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..? diff --git a/apps/contacts/lib/app.php b/apps/contacts/lib/app.php index 79e00920a6..907ce82c76 100644 --- a/apps/contacts/lib/app.php +++ b/apps/contacts/lib/app.php @@ -73,6 +73,7 @@ class OC_Contacts_App{ for($i=0;$ichildren);$i++){ if(md5($vcard->children[$i]->serialize()) == $checksum ){ $line = $i; + break; } } if(is_null($line)){ diff --git a/apps/contacts/lib/vcard.php b/apps/contacts/lib/vcard.php index 6a248ff59e..401f962254 100644 --- a/apps/contacts/lib/vcard.php +++ b/apps/contacts/lib/vcard.php @@ -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; } } } diff --git a/apps/contacts/templates/index.php b/apps/contacts/templates/index.php index 24484231af..d548f17172 100644 --- a/apps/contacts/templates/index.php +++ b/apps/contacts/templates/index.php @@ -1,10 +1,3 @@ - - diff --git a/apps/contacts/templates/part.addcardform.php b/apps/contacts/templates/part.addcardform.php index 627053547a..510096a9e8 100644 --- a/apps/contacts/templates/part.addcardform.php +++ b/apps/contacts/templates/part.addcardform.php @@ -3,93 +3,108 @@
-
    -
  1. +
    +
    +
    +
    -
  2. -
+ +
-
    -
  1. +
    +
    + +

    -
  2. -
  3. + +
    +
    +
    -
  4. -
+ +
-
    -
  1. +
    +
    +
    +
    -
  2. -
  3. -
    - - - -
      -
    1. - - -
    2. -
    3. - - -
    4. -
    -
    -
  4. -
+ +
+ +
+
+ + +
+
t('Address'); ?> -
    -
  1. +
    +
    +
    +
    -
  2. -
  3. + +
    +
    +
    -
  4. -
  5. + +
    +
    +
    +
    -
  6. -
  7. + +
    +
    +
    -
  8. -
  9. + +
    +
    +
    -
  10. -
  11. + +
    +
    +
    -
  12. -
  13. + +
    + +
    -
  14. -
  15. + +
    +
    +
    -
  16. -
+ +