Moved the customer edit page to include address and email fields. This is largely all the work on the presentation side, now I just need to take the data and update the database.
git-svn-id: file:///svn-source/pmgr/branches/invoice_receipt_20090629/site@214 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -141,6 +141,12 @@ class ContactsController extends AppController {
|
||||
$contact_phones = $this->Contact->ContactPhone->phoneList();
|
||||
$this->set(compact('contact_phones'));
|
||||
|
||||
$contact_addresses = $this->Contact->ContactAddress->addressList();
|
||||
$this->set(compact('contact_addresses'));
|
||||
|
||||
$contact_emails = $this->Contact->ContactEmail->emailList();
|
||||
$this->set(compact('contact_emails'));
|
||||
|
||||
// Prepare to render.
|
||||
//pr($this->data);
|
||||
$title = $this->data['Contact']['display_name'] . " : Edit";
|
||||
|
||||
@@ -17,5 +17,23 @@ class ContactAddress extends AppModel {
|
||||
'conditions' => "method = 'POST'",
|
||||
)
|
||||
);
|
||||
|
||||
function addressList() {
|
||||
$results = $this->find('all',
|
||||
array('contain' => false,
|
||||
'fields' => array('id', 'address', 'city', 'state', 'postcode'),
|
||||
'order' => array('state', 'city', 'postcode', 'address')));
|
||||
|
||||
$list = array();
|
||||
foreach ($results as $key => $val) {
|
||||
$list[$val['ContactAddress']['id']]
|
||||
= preg_replace("/\n/", ", ", $val['ContactAddress']['address'])
|
||||
. ', ' . $val['ContactAddress']['city']
|
||||
. ', ' . $val['ContactAddress']['state']
|
||||
. ' ' . $val['ContactAddress']['postcode']
|
||||
;
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -2,6 +2,7 @@
|
||||
class ContactEmail extends AppModel {
|
||||
|
||||
var $name = 'ContactEmail';
|
||||
var $displayField = 'email';
|
||||
var $validate = array(
|
||||
'id' => array('numeric'),
|
||||
'email' => array('email')
|
||||
@@ -18,5 +19,9 @@ class ContactEmail extends AppModel {
|
||||
)
|
||||
);
|
||||
|
||||
function emailList() {
|
||||
return $this->find('list');
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
@@ -6,7 +6,9 @@
|
||||
* we can access them.
|
||||
*/
|
||||
$this->varstore = compact('methodTypes', 'methodPreferences',
|
||||
'contactPhones', 'phoneTypes');
|
||||
'contactPhones', 'phoneTypes',
|
||||
'contactAddresses',
|
||||
'contactEmails');
|
||||
|
||||
//pr($this->data);
|
||||
/**********************************************************************
|
||||
@@ -38,7 +40,7 @@ function contactMethodDiv($obj, $type, $legend, $values = null) {
|
||||
$stype = strtolower($sname);
|
||||
$div .=
|
||||
'<INPUT TYPE="radio" ' . "\n" .
|
||||
' NAME="data[Contact'.ucfirst($type).'][%{id}][source]"' . "\n" .
|
||||
//' NAME="data[Contact'.ucfirst($type).'][%{id}][source]"' . "\n" .
|
||||
' ONCLICK="switchMethodSource(%{id}, '."'{$type}', '{$stype}'".')"' . "\n" .
|
||||
' CLASS="'.$type.'-method-%{id}-source" ' . "\n" .
|
||||
' ID="'.$type.'-method-%{id}-source-'.$stype.'"' . "\n" .
|
||||
@@ -135,12 +137,70 @@ function contactMethodTypeDiv($obj, $type, $stype, $values = null) {
|
||||
);
|
||||
}
|
||||
else {
|
||||
die("Invalid stype ($stype)");
|
||||
die("\n\nInvalid stype ($stype)\n\n");
|
||||
}
|
||||
|
||||
}
|
||||
elseif ($type === 'address') {
|
||||
if ($stype === 'existing') {
|
||||
$fields = array
|
||||
('id' => array('name' => 'Address',
|
||||
'opts' => array('options' => $obj->varstore['contactAddresses'])),
|
||||
);
|
||||
}
|
||||
elseif ($stype === 'new') {
|
||||
$fields = array
|
||||
('address' => null,
|
||||
'city' => null,
|
||||
'state' => null,
|
||||
'postcode' => array('name' => 'Zip Code'),
|
||||
'country' => null,
|
||||
'comment' => null,
|
||||
);
|
||||
}
|
||||
elseif ($stype === 'show') {
|
||||
$element = 'table';
|
||||
$column_class = array('field', 'value');
|
||||
$rows = array
|
||||
(array('Address', preg_replace("/\n/", "<BR>", $values['address'])),
|
||||
array('City', $values['city']),
|
||||
array('State', $values['state']),
|
||||
array('Zip Code', $values['postcode']),
|
||||
array('Country', $values['country']),
|
||||
array('Comment', $values['comment']),
|
||||
);
|
||||
}
|
||||
else {
|
||||
die("Invalid type ($type)");
|
||||
die("\n\nInvalid stype ($stype)\n\n");
|
||||
}
|
||||
}
|
||||
elseif ($type === 'email') {
|
||||
/* [email] => abijah@PerkinsHouse.com */
|
||||
/* [comment] => */
|
||||
|
||||
if ($stype === 'existing') {
|
||||
$fields = array
|
||||
('id' => array('name' => 'Email',
|
||||
'opts' => array('options' => $obj->varstore['contactEmails'])),
|
||||
);
|
||||
}
|
||||
elseif ($stype === 'new') {
|
||||
$fields = array
|
||||
('email' => null,
|
||||
'comment' => null,
|
||||
);
|
||||
}
|
||||
elseif ($stype === 'show') {
|
||||
$element = 'table';
|
||||
$column_class = array('field', 'value');
|
||||
$rows = array
|
||||
(array('Email', $values['email']),
|
||||
array('Comment', $values['comment']),
|
||||
);
|
||||
}
|
||||
}
|
||||
else {
|
||||
die("\n\nInvalid type ($type)\n\n");
|
||||
}
|
||||
|
||||
return
|
||||
@@ -183,10 +243,36 @@ function contactMethodTypeDiv($obj, $type, $stype, $values = null) {
|
||||
);
|
||||
}
|
||||
|
||||
function addAddress(flash) {
|
||||
addDiv('address-entry-id', 'address', 'addresses', flash, <?php
|
||||
echo FormatHelper::phpVarToJavascript(contactMethodDiv($this,
|
||||
'address',
|
||||
'Address'),
|
||||
null,
|
||||
' ');
|
||||
?>
|
||||
);
|
||||
}
|
||||
|
||||
function addEmail(flash) {
|
||||
addDiv('email-entry-id', 'email', 'emails', flash, <?php
|
||||
echo FormatHelper::phpVarToJavascript(contactMethodDiv($this,
|
||||
'email',
|
||||
'Email Address'),
|
||||
null,
|
||||
' ');
|
||||
?>
|
||||
);
|
||||
}
|
||||
|
||||
// Reset the form
|
||||
function resetForm() {
|
||||
$('#phones').html('');
|
||||
$('#addresses').html('');
|
||||
$('#emails').html('');
|
||||
$('#phone-entry-id').val(1);
|
||||
$('#address-entry-id').val(1);
|
||||
$('#email-entry-id').val(1);
|
||||
|
||||
<?php foreach ($this->data['ContactPhone'] AS $phone): ?>
|
||||
addDiv('phone-entry-id', 'phone', 'phones', false, <?php
|
||||
@@ -201,6 +287,32 @@ function contactMethodTypeDiv($obj, $type, $stype, $values = null) {
|
||||
);
|
||||
<?php endforeach; ?>
|
||||
|
||||
<?php foreach ($this->data['ContactAddress'] AS $address): ?>
|
||||
addDiv('address-entry-id', 'address', 'addresses', false, <?php
|
||||
echo FormatHelper::phpVarToJavascript(contactMethodDiv($this,
|
||||
'address',
|
||||
'Address',
|
||||
$address
|
||||
),
|
||||
null,
|
||||
' ');
|
||||
?>
|
||||
);
|
||||
<?php endforeach; ?>
|
||||
|
||||
<?php foreach ($this->data['ContactEmail'] AS $email): ?>
|
||||
addDiv('email-entry-id', 'email', 'emails', false, <?php
|
||||
echo FormatHelper::phpVarToJavascript(contactMethodDiv($this,
|
||||
'email',
|
||||
'Email Address',
|
||||
$email
|
||||
),
|
||||
null,
|
||||
' ');
|
||||
?>
|
||||
);
|
||||
<?php endforeach; ?>
|
||||
|
||||
}
|
||||
|
||||
function switchMethodSource(id, type, source) {
|
||||
@@ -264,6 +376,28 @@ echo($this->element
|
||||
</fieldset>
|
||||
</div>
|
||||
|
||||
<div CLASS="dynamic-set">
|
||||
<fieldset CLASS="address superset">
|
||||
<legend>Mailing Addresses</legend>
|
||||
<input type="hidden" id="address-entry-id" value="0">
|
||||
<div id="addresses"></div>
|
||||
<fieldset> <legend>
|
||||
<a href="#" onClick="addAddress(true); return false;">Add a Mailing Address</a>
|
||||
</legend> </fieldset>
|
||||
</fieldset>
|
||||
</div>
|
||||
|
||||
<div CLASS="dynamic-set">
|
||||
<fieldset CLASS="email superset">
|
||||
<legend>Email Addresses</legend>
|
||||
<input type="hidden" id="email-entry-id" value="0">
|
||||
<div id="emails"></div>
|
||||
<fieldset> <legend>
|
||||
<a href="#" onClick="addEmail(true); return false;">Add an Email Address</a>
|
||||
</legend> </fieldset>
|
||||
</fieldset>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
; // Alignment
|
||||
|
||||
|
||||
@@ -215,9 +215,24 @@ form {
|
||||
width: 80%;
|
||||
}
|
||||
|
||||
div.dynamic-set {
|
||||
div.dynamic-set fieldset.superset {
|
||||
margin-top: 1.5em;
|
||||
width: 50%;
|
||||
width: 80%;
|
||||
}
|
||||
|
||||
div.dynamic-set fieldset.superset legend {
|
||||
font-size: 120%;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
div.dynamic-set fieldset.superset fieldset {
|
||||
margin-top: 0.8em;
|
||||
/* width: 90%; */
|
||||
}
|
||||
|
||||
div.dynamic-set fieldset.superset fieldset legend {
|
||||
font-size: 110%;
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
fieldset {
|
||||
|
||||
Reference in New Issue
Block a user