Got the existing contact phone numbers to populate correctly. I've chosen to disallow editing of these numbers, since a) it's tricky to do this in place, and b) it will be too confusing at the moment to handle this on a separate page, and c) I don't want to implement a modal ajax box at the moment, and d) doing so would probably be a user error liability, since folks would choose to edit a shared number instead of adding a new one when the situation would warrant the latter.

git-svn-id: file:///svn-source/pmgr/branches/invoice_receipt_20090629/site@212 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-07-05 18:32:54 +00:00
parent bb78a85d1b
commit 41aa3f81a8
2 changed files with 61 additions and 18 deletions

View File

@@ -124,14 +124,18 @@ class ContactsController extends AppController {
$phone_types = array_flip($this->Contact->ContactPhone->getEnumValues('type')); $phone_types = array_flip($this->Contact->ContactPhone->getEnumValues('type'));
unset($phone_types[0]); unset($phone_types[0]);
//$phone_types = array_combine($phone_types, array_map('ucfirst', array_map('strtolower', $phone_types)));
$phone_types = array_combine($phone_types, $phone_types);
$this->set(compact('phone_types')); $this->set(compact('phone_types'));
$method_types = array_flip($this->Contact->getEnumValues('type', 'pmgr_contacts_methods')); $method_types = array_flip($this->Contact->getEnumValues('type', 'pmgr_contacts_methods'));
unset($method_types[0]); unset($method_types[0]);
$method_types = array_combine($method_types, $method_types);
$this->set(compact('method_types')); $this->set(compact('method_types'));
$method_preferences = array_flip($this->Contact->getEnumValues('preference', 'pmgr_contacts_methods')); $method_preferences = array_flip($this->Contact->getEnumValues('preference', 'pmgr_contacts_methods'));
unset($method_preferences[0]); unset($method_preferences[0]);
$method_preferences = array_combine($method_preferences, $method_preferences);
$this->set(compact('method_preferences')); $this->set(compact('method_preferences'));
$contact_phones = $this->Contact->ContactPhone->phoneList(); $contact_phones = $this->Contact->ContactPhone->phoneList();

View File

@@ -8,6 +8,7 @@
$this->varstore = compact('methodTypes', 'methodPreferences', $this->varstore = compact('methodTypes', 'methodPreferences',
'contactPhones', 'phoneTypes'); 'contactPhones', 'phoneTypes');
//pr($this->data);
/********************************************************************** /**********************************************************************
********************************************************************** **********************************************************************
********************************************************************** **********************************************************************
@@ -48,9 +49,10 @@ function contactMethodDiv($obj, $type, $legend, $values = null) {
' '; ' ';
} }
} }
$div .= "\n";
if (isset($values)) { if (isset($values)) {
$div .= contactMethodTypeDiv($obj, $type, 'edit', $values); $div .= contactMethodTypeDiv($obj, $type, 'show', $values);
} }
else { else {
$div .= contactMethodTypeDiv($obj, $type, 'existing'); $div .= contactMethodTypeDiv($obj, $type, 'existing');
@@ -71,9 +73,24 @@ function contactMethodDiv($obj, $type, $legend, $values = null) {
array('class' => "item contact-{$type} entry", array('class' => "item contact-{$type} entry",
'field_prefix' => 'Contact'.ucfirst($type).'.%{id}.Method', 'field_prefix' => 'Contact'.ucfirst($type).'.%{id}.Method',
'fields' => array 'fields' => array
('type' => array('opts' => array('options' => $obj->varstore['methodTypes'])),
'preferences' => array('opts' => array('options' => $obj->varstore['methodPreferences'])), ('type' => array
'comment' => null, ('opts' => array
('options' => $obj->varstore['methodTypes'],
'selected' => (isset($values) ? $values['ContactsMethod']['type'] : null),
)),
'preferences' => array
('opts' => array
('options' => $obj->varstore['methodPreferences'],
'selected' => (isset($values) ? $values['ContactsMethod']['preference'] : null),
)),
'comment' => array
('opts' => array
('value' => (isset($values) ? $values['ContactsMethod']['comment'] : null),
)),
))) . "\n" . ))) . "\n" .
// END method-div // END method-div
@@ -90,6 +107,8 @@ function contactMethodDiv($obj, $type, $legend, $values = null) {
function contactMethodTypeDiv($obj, $type, $stype, $values = null) { function contactMethodTypeDiv($obj, $type, $stype, $values = null) {
$element = 'form_table';
if ($type === 'phone') { if ($type === 'phone') {
if ($stype === 'existing') { if ($stype === 'existing') {
$fields = array $fields = array
@@ -97,14 +116,24 @@ function contactMethodTypeDiv($obj, $type, $stype, $values = null) {
'opts' => array('options' => $obj->varstore['contactPhones'])), 'opts' => array('options' => $obj->varstore['contactPhones'])),
); );
} }
elseif ($stype === 'new' || $stype === 'edit') { elseif ($stype === 'new') {
$fields = array $fields = array
('type' => array('opts' => array('options' => $obj->varstore['phoneTypes'])), ('type' => array('opts' => array('options' => $obj->varstore['phoneTypes'])),
'phone' => null, //array('opts' => array('value' => )), 'phone' => null,
'ext' => array('name' => "Extension"), 'ext' => array('name' => "Extension"),
'comment' => null, 'comment' => null,
); );
} }
elseif ($stype === 'show') {
$element = 'table';
$column_class = array('field', 'value');
$rows = array
(array('Type', $values['type']),
array('Phone', $values['phone']),
array('Extension', $values['ext']),
array('Comment', $values['comment']),
);
}
else { else {
die("Invalid stype ($stype)"); die("Invalid stype ($stype)");
} }
@@ -119,13 +148,18 @@ function contactMethodTypeDiv($obj, $type, $stype, $values = null) {
'<div ' . "\n" . '<div ' . "\n" .
' class="'.$type.'-%{id}-div"' . "\n" . ' class="'.$type.'-%{id}-div"' . "\n" .
' id="'.$type.'-%{id}-'.$stype.'-div"' . "\n" . ' id="'.$type.'-%{id}-'.$stype.'-div"' . "\n" .
' STYLE="display:none;">' . "\n" . (isset($values) ? '' : ' STYLE="display:none;"' . "\n") .
'>' . "\n" .
$obj->element $obj->element
('form_table', ($element,
array('class' => "item contact-{$type} {$stype}", array('class' => "item contact-{$type} {$stype}",
'field_prefix' => 'Contact'.ucfirst($type).'.%{id}', 'field_prefix' => 'Contact'.ucfirst($type).'.%{id}')
'fields' => $fields)) . "\n" . + compact('rows', 'fields', 'column_class')) .
($stype === 'show'
? '<input type="hidden" name="data[Contact'.ucfirst($type).'][%{id}][id]" value="'.$values['id'].'"/>' . "\n"
: '') .
// END sourcetype-div // END sourcetype-div
'</div>' . "\n" . '</div>' . "\n" .
@@ -154,13 +188,18 @@ function contactMethodTypeDiv($obj, $type, $stype, $values = null) {
$('#phones').html(''); $('#phones').html('');
$('#phone-entry-id').val(1); $('#phone-entry-id').val(1);
/* <?php foreach ($this->data['ContactPhone'] AS $phone): ?> */ <?php foreach ($this->data['ContactPhone'] AS $phone): ?>
/* addPhone(true); */ addDiv('phone-entry-id', 'phone', 'phones', false, <?php
/* var id=$("#phone-entry-id").val(); */ echo FormatHelper::phpVarToJavascript(contactMethodDiv($this,
/* $("#ContactPhone."+id+".phone').val(1); */ 'phone',
/* $('ContactPhone.%{id}', */ 'Phone Number',
$phone
/* <?php endforeach; ?> */ ),
null,
' ');
?>
);
<?php endforeach; ?>
} }
@@ -216,7 +255,7 @@ echo($this->element
<div CLASS="dynamic-set"> <div CLASS="dynamic-set">
<fieldset CLASS="phone superset"> <fieldset CLASS="phone superset">
<legend>Phones</legend> <legend>Phone Numbers</legend>
<input type="hidden" id="phone-entry-id" value="0"> <input type="hidden" id="phone-entry-id" value="0">
<div id="phones"></div> <div id="phones"></div>
<fieldset> <legend> <fieldset> <legend>