From e53e413c6c65970adfb90d76812cb8f371a23176 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Mon, 5 Dec 2011 21:51:25 +0100 Subject: [PATCH] Contacts: refactor rendering of part.details template --- ajax/addcard.php | 20 ++--------- ajax/getdetails.php | 26 ++------------ ajax/setproperty.php | 4 +-- ajax/showaddcard.php | 6 ++-- ajax/showsetproperty.php | 4 +-- appinfo/app.php | 1 + index.php | 5 ++- lib/app.php | 74 ++++++++++++++++++++++++++++++++++++++++ lib/vcard.php | 21 ------------ 9 files changed, 88 insertions(+), 73 deletions(-) create mode 100644 lib/app.php diff --git a/ajax/addcard.php b/ajax/addcard.php index 8d192641..9a52b26e 100644 --- a/ajax/addcard.php +++ b/ajax/addcard.php @@ -23,16 +23,14 @@ // Init owncloud require_once('../../../lib/base.php'); -$aid = $_POST['id']; -$l10n = new OC_L10N('contacts'); - // Check if we are a user OC_JSON::checkLoggedIn(); OC_JSON::checkAppEnabled('contacts'); +$aid = $_POST['id']; $addressbook = OC_Contacts_Addressbook::find( $aid ); if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){ - OC_JSON::error(array('data' => array( 'message' => $l10n->t('This is not your addressbook.')))); // Same here (as with the contact error). Could this error be improved? + OC_JSON::error(array('data' => array( 'message' => OC_Contacts_App::$l10n->t('This is not your addressbook.')))); // Same here (as with the contact error). Could this error be improved? exit(); } @@ -68,16 +66,4 @@ foreach( $add as $propname){ } $id = OC_Contacts_VCard::add($aid,$vcard->serialize()); -$adr_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'ADR'); -$phone_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'TEL'); - -$details = OC_Contacts_VCard::structureContact($vcard); -$name = $details['FN'][0]['value']; -$tmpl = new OC_Template('contacts','part.details'); -$tmpl->assign('details',$details); -$tmpl->assign('id',$id); -$tmpl->assign('adr_types',$adr_types); -$tmpl->assign('phone_types',$phone_types); -$page = $tmpl->fetchPage(); - -OC_JSON::success(array('data' => array( 'id' => $id, 'name' => $name, 'page' => $page ))); +OC_Contacts_App::renderDetails($id, $vcard); diff --git a/ajax/getdetails.php b/ajax/getdetails.php index eb1f20ee..e480bce4 100644 --- a/ajax/getdetails.php +++ b/ajax/getdetails.php @@ -23,15 +23,11 @@ // Init owncloud require_once('../../../lib/base.php'); -$id = $_GET['id']; - -$l10n = new OC_L10N('contacts'); - // Check if we are a user OC_JSON::checkLoggedIn(); OC_JSON::checkAppEnabled('contacts'); - +$id = $_GET['id']; $card = OC_Contacts_VCard::find( $id ); if( $card === false ){ OC_JSON::error(array('data' => array( 'message' => $l10n->t('Contact could not be found.')))); @@ -51,22 +47,4 @@ if(is_null($vcard)){ exit(); } -$property_types = array( - 'ADR' => $l10n->t('Address'), - 'TEL' => $l10n->t('Telephone'), - 'EMAIL' => $l10n->t('Email'), - 'ORG' => $l10n->t('Organization'), -); -$adr_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'ADR'); -$phone_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'TEL'); - -$details = OC_Contacts_VCard::structureContact($vcard); -$tmpl = new OC_Template('contacts','part.details'); -$tmpl->assign('details',$details); -$tmpl->assign('id',$id); -$tmpl->assign('property_types',$property_types); -$tmpl->assign('adr_types',$adr_types); -$tmpl->assign('phone_types',$phone_types); -$page = $tmpl->fetchPage(); - -OC_JSON::success(array('data' => array( 'id' => $id, 'page' => $page ))); +OC_Contacts_App::renderDetails($id, $vcard); diff --git a/ajax/setproperty.php b/ajax/setproperty.php index 2edfa5b4..e636cc5c 100644 --- a/ajax/setproperty.php +++ b/ajax/setproperty.php @@ -104,8 +104,8 @@ $checksum = md5($vcard->children[$line]->serialize()); OC_Contacts_VCard::edit($id,$vcard->serialize()); -$adr_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'ADR'); -$phone_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'TEL'); +$adr_types = OC_Contacts_App::getTypesOfProperty($l10n, 'ADR'); +$phone_types = OC_Contacts_App::getTypesOfProperty($l10n, 'TEL'); if ($vcard->children[$line]->name == 'FN'){ $tmpl = new OC_Template('contacts','part.property.FN'); diff --git a/ajax/showaddcard.php b/ajax/showaddcard.php index 98367758..a2a9398b 100644 --- a/ajax/showaddcard.php +++ b/ajax/showaddcard.php @@ -23,14 +23,12 @@ // Init owncloud require_once('../../../lib/base.php'); -$l10n = new OC_L10N('contacts'); - // Check if we are a user OC_JSON::checkLoggedIn(); OC_JSON::checkAppEnabled('contacts'); -$adr_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'ADR'); -$phone_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'TEL'); +$adr_types = OC_Contacts_App::getTypesOfProperty(OC_Contacts_App::$l10n, 'ADR'); +$phone_types = OC_Contacts_App::getTypesOfProperty(OC_Contacts_App::$l10n, 'TEL'); $addressbooks = OC_Contacts_Addressbook::all(OC_USER::getUser()); $tmpl = new OC_Template('contacts','part.addcardform'); diff --git a/ajax/showsetproperty.php b/ajax/showsetproperty.php index 1cf65417..30d0f5d8 100644 --- a/ajax/showsetproperty.php +++ b/ajax/showsetproperty.php @@ -61,8 +61,8 @@ if(is_null($line)){ exit(); } -$adr_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'ADR'); -$phone_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'TEL'); +$adr_types = OC_Contacts_App::getTypesOfProperty($l10n, 'ADR'); +$phone_types = OC_Contacts_App::getTypesOfProperty($l10n, 'TEL'); $tmpl = new OC_Template('contacts','part.setpropertyform'); $tmpl->assign('id',$id); diff --git a/appinfo/app.php b/appinfo/app.php index fc7b3769..524cc640 100644 --- a/appinfo/app.php +++ b/appinfo/app.php @@ -1,5 +1,6 @@ assign('details',$details); + $tmpl->assign('id',$id); + $tmpl->assign('property_types',$property_types); + $tmpl->assign('adr_types',$adr_types); + $tmpl->assign('phone_types',$phone_types); + $page = $tmpl->fetchPage(); + + OC_JSON::success(array('data' => array( 'id' => $id, 'name' => $name, 'page' => $page ))); + } + + /** + * @return array of vcard prop => label + */ + public static function getAddPropertyOptions($l10n){ + return array( + 'ADR' => $l10n->t('Address'), + 'TEL' => $l10n->t('Telephone'), + 'EMAIL' => $l10n->t('Email'), + 'ORG' => $l10n->t('Organization'), + ); + } + + /** + * @return types for property $prop + */ + public static function getTypesOfProperty($l, $prop){ + switch($prop){ + case 'ADR': + return array( + 'WORK' => $l->t('Work'), + 'HOME' => $l->t('Home'), + ); + case 'TEL': + return array( + 'HOME' => $l->t('Home'), + 'CELL' => $l->t('Mobile'), + 'WORK' => $l->t('Work'), + 'TEXT' => $l->t('Text'), + 'VOICE' => $l->t('Voice'), + 'FAX' => $l->t('Fax'), + 'VIDEO' => $l->t('Video'), + 'PAGER' => $l->t('Pager'), + ); + } + } +} diff --git a/lib/vcard.php b/lib/vcard.php index 8836431d..a573f40f 100644 --- a/lib/vcard.php +++ b/lib/vcard.php @@ -301,25 +301,4 @@ class OC_Contacts_VCard{ } return $temp; } - - public static function getTypesOfProperty($l, $prop){ - switch($prop){ - case 'ADR': - return array( - 'WORK' => $l->t('Work'), - 'HOME' => $l->t('Home'), - ); - case 'TEL': - return array( - 'HOME' => $l->t('Home'), - 'CELL' => $l->t('Mobile'), - 'WORK' => $l->t('Work'), - 'TEXT' => $l->t('Text'), - 'VOICE' => $l->t('Voice'), - 'FAX' => $l->t('Fax'), - 'VIDEO' => $l->t('Video'), - 'PAGER' => $l->t('Pager'), - ); - } - } }