]> source.dussan.org Git - nextcloud-server.git/commitdiff
Contacts: refactor rendering of part.details template
authorBart Visscher <bartv@thisnet.nl>
Mon, 5 Dec 2011 20:51:25 +0000 (21:51 +0100)
committerBart Visscher <bartv@thisnet.nl>
Wed, 7 Dec 2011 19:40:58 +0000 (20:40 +0100)
apps/contacts/ajax/addcard.php
apps/contacts/ajax/getdetails.php
apps/contacts/ajax/setproperty.php
apps/contacts/ajax/showaddcard.php
apps/contacts/ajax/showsetproperty.php
apps/contacts/appinfo/app.php
apps/contacts/index.php
apps/contacts/lib/app.php [new file with mode: 0644]
apps/contacts/lib/vcard.php

index 8d192641dbdf1c5ec6e761b2948746dce775901e..9a52b26ed596f928dd6f6950ba79cb8a8eb0d356 100644 (file)
 // 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);
index eb1f20ee75e4d5f7e8fa884cfbfdf4d22807b8ee..e480bce4cb49044c1d4c14f937ed245bb3e6cb70 100644 (file)
 // 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);
index 2edfa5b452f1964c102690dcde6ca7e74a0f9550..e636cc5c1bdf4ddf1d1fc88212e4f4c1a6b210a5 100644 (file)
@@ -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');
index 98367758fd4dbae358130b02a18b2783daa23e06..a2a9398bde51b74b2b32aa1bae2f6263a636bada 100644 (file)
 // 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');
index 1cf6541780902dbd9e599084ea7d2d90c3438ec1..30d0f5d817c61e19b5b262c2f7c248ad35a64621 100644 (file)
@@ -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);
index fc7b3769c537834c0f9dbcce6ec2b6379cca6a69..524cc640bc9f9aa32cc3674300fb7cd52c5fb65f 100644 (file)
@@ -1,5 +1,6 @@
 <?php
 
+OC::$CLASSPATH['OC_Contacts_App'] = 'apps/contacts/lib/app.php';
 OC::$CLASSPATH['OC_Contacts_Addressbook'] = 'apps/contacts/lib/addressbook.php';
 OC::$CLASSPATH['OC_Contacts_VCard'] = 'apps/contacts/lib/vcard.php';
 OC::$CLASSPATH['OC_Contacts_Hooks'] = 'apps/contacts/lib/hooks.php';
index 744b69023312d211206c04448b8d37ee12bd7ad4..0a847f5a672fd7e36f9949e4851c682809bf7894 100644 (file)
@@ -75,9 +75,8 @@ if( !is_null($id) || count($contacts)){
        $details = OC_Contacts_VCard::structureContact($vcard);
 }
 
-$l10n = new OC_L10N('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');
 
 // Process the template
 $tmpl = new OC_Template( 'contacts', 'index', 'user' );
diff --git a/apps/contacts/lib/app.php b/apps/contacts/lib/app.php
new file mode 100644 (file)
index 0000000..327ee6f
--- /dev/null
@@ -0,0 +1,74 @@
+<?php
+/**
+ * Copyright (c) 2011 Bart Visscher bartv@thisnet.nl
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+/**
+ * This class manages our app actions
+ */
+OC_Contacts_App::$l10n = new OC_L10N('contacts');
+class OC_Contacts_App{
+       public static $l10n;
+
+       /**
+       * Render templates/part.details to json output
+       * @param int $id of contact
+       * @param Sabre_VObject_Component $vcard to render
+       */
+       public static function renderDetails($id, $vcard){
+               $property_types = self::getAddPropertyOptions(self::$l10n);
+               $adr_types = self::getTypesOfProperty(self::$l10n, 'ADR');
+               $phone_types = self::getTypesOfProperty(self::$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('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'),
+                       );
+               }
+       }
+}
index 8836431ddbb1ec116f00d8c0a9bad3c80276b935..a573f40f7d91d9e80e5ecd48858b80810da812b9 100644 (file)
@@ -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'),
-                       );
-               }
-       }
 }