mirror of
https://github.com/owncloudarchive/contacts.git
synced 2024-11-29 11:24:11 +01:00
Contacts: refactor rendering of part.details template
This commit is contained in:
parent
9ab66b5e9b
commit
e53e413c6c
@ -23,16 +23,14 @@
|
|||||||
// Init owncloud
|
// Init owncloud
|
||||||
require_once('../../../lib/base.php');
|
require_once('../../../lib/base.php');
|
||||||
|
|
||||||
$aid = $_POST['id'];
|
|
||||||
$l10n = new OC_L10N('contacts');
|
|
||||||
|
|
||||||
// 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');
|
||||||
|
|
||||||
|
$aid = $_POST['id'];
|
||||||
$addressbook = OC_Contacts_Addressbook::find( $aid );
|
$addressbook = OC_Contacts_Addressbook::find( $aid );
|
||||||
if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){
|
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();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,16 +66,4 @@ foreach( $add as $propname){
|
|||||||
}
|
}
|
||||||
$id = OC_Contacts_VCard::add($aid,$vcard->serialize());
|
$id = OC_Contacts_VCard::add($aid,$vcard->serialize());
|
||||||
|
|
||||||
$adr_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'ADR');
|
OC_Contacts_App::renderDetails($id, $vcard);
|
||||||
$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 )));
|
|
||||||
|
@ -23,15 +23,11 @@
|
|||||||
// Init owncloud
|
// Init owncloud
|
||||||
require_once('../../../lib/base.php');
|
require_once('../../../lib/base.php');
|
||||||
|
|
||||||
$id = $_GET['id'];
|
|
||||||
|
|
||||||
$l10n = new OC_L10N('contacts');
|
|
||||||
|
|
||||||
// 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');
|
||||||
|
|
||||||
|
$id = $_GET['id'];
|
||||||
$card = OC_Contacts_VCard::find( $id );
|
$card = OC_Contacts_VCard::find( $id );
|
||||||
if( $card === false ){
|
if( $card === false ){
|
||||||
OC_JSON::error(array('data' => array( 'message' => $l10n->t('Contact could not be found.'))));
|
OC_JSON::error(array('data' => array( 'message' => $l10n->t('Contact could not be found.'))));
|
||||||
@ -51,22 +47,4 @@ if(is_null($vcard)){
|
|||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
$property_types = array(
|
OC_Contacts_App::renderDetails($id, $vcard);
|
||||||
'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 )));
|
|
||||||
|
@ -104,8 +104,8 @@ $checksum = md5($vcard->children[$line]->serialize());
|
|||||||
|
|
||||||
OC_Contacts_VCard::edit($id,$vcard->serialize());
|
OC_Contacts_VCard::edit($id,$vcard->serialize());
|
||||||
|
|
||||||
$adr_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'ADR');
|
$adr_types = OC_Contacts_App::getTypesOfProperty($l10n, 'ADR');
|
||||||
$phone_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'TEL');
|
$phone_types = OC_Contacts_App::getTypesOfProperty($l10n, 'TEL');
|
||||||
|
|
||||||
if ($vcard->children[$line]->name == 'FN'){
|
if ($vcard->children[$line]->name == 'FN'){
|
||||||
$tmpl = new OC_Template('contacts','part.property.FN');
|
$tmpl = new OC_Template('contacts','part.property.FN');
|
||||||
|
@ -23,14 +23,12 @@
|
|||||||
// Init owncloud
|
// Init owncloud
|
||||||
require_once('../../../lib/base.php');
|
require_once('../../../lib/base.php');
|
||||||
|
|
||||||
$l10n = new OC_L10N('contacts');
|
|
||||||
|
|
||||||
// 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');
|
||||||
|
|
||||||
$adr_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'ADR');
|
$adr_types = OC_Contacts_App::getTypesOfProperty(OC_Contacts_App::$l10n, 'ADR');
|
||||||
$phone_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'TEL');
|
$phone_types = OC_Contacts_App::getTypesOfProperty(OC_Contacts_App::$l10n, 'TEL');
|
||||||
|
|
||||||
$addressbooks = OC_Contacts_Addressbook::all(OC_USER::getUser());
|
$addressbooks = OC_Contacts_Addressbook::all(OC_USER::getUser());
|
||||||
$tmpl = new OC_Template('contacts','part.addcardform');
|
$tmpl = new OC_Template('contacts','part.addcardform');
|
||||||
|
@ -61,8 +61,8 @@ if(is_null($line)){
|
|||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
$adr_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'ADR');
|
$adr_types = OC_Contacts_App::getTypesOfProperty($l10n, 'ADR');
|
||||||
$phone_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'TEL');
|
$phone_types = OC_Contacts_App::getTypesOfProperty($l10n, 'TEL');
|
||||||
|
|
||||||
$tmpl = new OC_Template('contacts','part.setpropertyform');
|
$tmpl = new OC_Template('contacts','part.setpropertyform');
|
||||||
$tmpl->assign('id',$id);
|
$tmpl->assign('id',$id);
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
<?php
|
<?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_Addressbook'] = 'apps/contacts/lib/addressbook.php';
|
||||||
OC::$CLASSPATH['OC_Contacts_VCard'] = 'apps/contacts/lib/vcard.php';
|
OC::$CLASSPATH['OC_Contacts_VCard'] = 'apps/contacts/lib/vcard.php';
|
||||||
OC::$CLASSPATH['OC_Contacts_Hooks'] = 'apps/contacts/lib/hooks.php';
|
OC::$CLASSPATH['OC_Contacts_Hooks'] = 'apps/contacts/lib/hooks.php';
|
||||||
|
@ -75,9 +75,8 @@ if( !is_null($id) || count($contacts)){
|
|||||||
$details = OC_Contacts_VCard::structureContact($vcard);
|
$details = OC_Contacts_VCard::structureContact($vcard);
|
||||||
}
|
}
|
||||||
|
|
||||||
$l10n = new OC_L10N('contacts');
|
$adr_types = OC_Contacts_App::getTypesOfProperty(OC_Contacts_App::$l10n, 'ADR');
|
||||||
$adr_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'ADR');
|
$phone_types = OC_Contacts_App::getTypesOfProperty(OC_Contacts_App::$l10n, 'TEL');
|
||||||
$phone_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'TEL');
|
|
||||||
|
|
||||||
// Process the template
|
// Process the template
|
||||||
$tmpl = new OC_Template( 'contacts', 'index', 'user' );
|
$tmpl = new OC_Template( 'contacts', 'index', 'user' );
|
||||||
|
74
lib/app.php
Normal file
74
lib/app.php
Normal file
@ -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'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -301,25 +301,4 @@ class OC_Contacts_VCard{
|
|||||||
}
|
}
|
||||||
return $temp;
|
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'),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user