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