From 41aa3f81a809fd8b585d73b518d4975d7c23ec34 Mon Sep 17 00:00:00 2001 From: abijah Date: Sun, 5 Jul 2009 18:32:54 +0000 Subject: [PATCH] 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 --- controllers/contacts_controller.php | 4 ++ views/contacts/edit.ctp | 75 ++++++++++++++++++++++------- 2 files changed, 61 insertions(+), 18 deletions(-) diff --git a/controllers/contacts_controller.php b/controllers/contacts_controller.php index 7baa3ae..84f319d 100644 --- a/controllers/contacts_controller.php +++ b/controllers/contacts_controller.php @@ -124,14 +124,18 @@ class ContactsController extends AppController { $phone_types = array_flip($this->Contact->ContactPhone->getEnumValues('type')); 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')); $method_types = array_flip($this->Contact->getEnumValues('type', 'pmgr_contacts_methods')); unset($method_types[0]); + $method_types = array_combine($method_types, $method_types); $this->set(compact('method_types')); $method_preferences = array_flip($this->Contact->getEnumValues('preference', 'pmgr_contacts_methods')); unset($method_preferences[0]); + $method_preferences = array_combine($method_preferences, $method_preferences); $this->set(compact('method_preferences')); $contact_phones = $this->Contact->ContactPhone->phoneList(); diff --git a/views/contacts/edit.ctp b/views/contacts/edit.ctp index abe33cf..c0db5d2 100644 --- a/views/contacts/edit.ctp +++ b/views/contacts/edit.ctp @@ -8,6 +8,7 @@ $this->varstore = compact('methodTypes', 'methodPreferences', 'contactPhones', 'phoneTypes'); +//pr($this->data); /********************************************************************** ********************************************************************** ********************************************************************** @@ -48,9 +49,10 @@ function contactMethodDiv($obj, $type, $legend, $values = null) { ' '; } } + $div .= "\n"; if (isset($values)) { - $div .= contactMethodTypeDiv($obj, $type, 'edit', $values); + $div .= contactMethodTypeDiv($obj, $type, 'show', $values); } else { $div .= contactMethodTypeDiv($obj, $type, 'existing'); @@ -71,9 +73,24 @@ function contactMethodDiv($obj, $type, $legend, $values = null) { array('class' => "item contact-{$type} entry", 'field_prefix' => 'Contact'.ucfirst($type).'.%{id}.Method', 'fields' => array - ('type' => array('opts' => array('options' => $obj->varstore['methodTypes'])), - 'preferences' => array('opts' => array('options' => $obj->varstore['methodPreferences'])), - 'comment' => null, + + ('type' => array + ('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" . // END method-div @@ -90,6 +107,8 @@ function contactMethodDiv($obj, $type, $legend, $values = null) { function contactMethodTypeDiv($obj, $type, $stype, $values = null) { + $element = 'form_table'; + if ($type === 'phone') { if ($stype === 'existing') { $fields = array @@ -97,14 +116,24 @@ function contactMethodTypeDiv($obj, $type, $stype, $values = null) { 'opts' => array('options' => $obj->varstore['contactPhones'])), ); } - elseif ($stype === 'new' || $stype === 'edit') { + elseif ($stype === 'new') { $fields = array ('type' => array('opts' => array('options' => $obj->varstore['phoneTypes'])), - 'phone' => null, //array('opts' => array('value' => )), + 'phone' => null, 'ext' => array('name' => "Extension"), '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 { die("Invalid stype ($stype)"); } @@ -119,13 +148,18 @@ function contactMethodTypeDiv($obj, $type, $stype, $values = null) { '' . "\n" . @@ -154,13 +188,18 @@ function contactMethodTypeDiv($obj, $type, $stype, $values = null) { $('#phones').html(''); $('#phone-entry-id').val(1); -/* data['ContactPhone'] AS $phone): ?> */ -/* addPhone(true); */ -/* var id=$("#phone-entry-id").val(); */ -/* $("#ContactPhone."+id+".phone').val(1); */ -/* $('ContactPhone.%{id}', */ - -/* */ + data['ContactPhone'] AS $phone): ?> + addDiv('phone-entry-id', 'phone', 'phones', false, + ); + } @@ -216,7 +255,7 @@ echo($this->element
- Phones + Phone Numbers