From dc850f4e8e9452f30326356429a39ee599083c19 Mon Sep 17 00:00:00 2001 From: abijah Date: Sun, 5 Jul 2009 15:01:18 +0000 Subject: [PATCH] First shot at an actual working form to enter contact information. It only handles phone numbers at the moment, and it does NOT handle existing ones. It's a decent start though, and worth checking in. Next I'll have to handle existing phone numbers, and then addresses and emails. Of course, after that, I'll have to actually save everything to the database. git-svn-id: file:///svn-source/pmgr/branches/invoice_receipt_20090629@209 97e9348a-65ac-dc4b-aefc-98561f571b83 --- site/app_model.php | 10 +- site/controllers/contacts_controller.php | 66 ++++++ site/models/contact_phone.php | 17 +- site/views/contacts/edit.ctp | 255 +++++++++++------------ site/views/elements/form_table.ctp | 31 +++ site/views/helpers/format.php | 13 +- 6 files changed, 245 insertions(+), 147 deletions(-) create mode 100644 site/views/elements/form_table.ctp diff --git a/site/app_model.php b/site/app_model.php index 0f8aa86..64c398b 100644 --- a/site/app_model.php +++ b/site/app_model.php @@ -47,13 +47,15 @@ class AppModel extends Model { * * Gets the enum values for MySQL 4 and 5 to use in selectTag() */ - function getEnumValues($columnName=null, $respectDefault=false) + function getEnumValues($columnName=null, $tableName=null) { if ($columnName==null) { return array(); } //no field specified - //Get the name of the table - $db =& ConnectionManager::getDataSource($this->useDbConfig); - $tableName = $db->fullTableName($this, false); + if (!isset($tableName)) { + //Get the name of the table + $db =& ConnectionManager::getDataSource($this->useDbConfig); + $tableName = $db->fullTableName($this, false); + } //Get the values for the specified column (database and version specific, needs testing) $result = $this->query("SHOW COLUMNS FROM {$tableName} LIKE '{$columnName}'"); diff --git a/site/controllers/contacts_controller.php b/site/controllers/contacts_controller.php index d61d64d..7baa3ae 100644 --- a/site/controllers/contacts_controller.php +++ b/site/controllers/contacts_controller.php @@ -46,6 +46,11 @@ class ContactsController extends AppController { return $order; } + function jqGridRecordLinks(&$params, &$model, &$records, $links) { + $links['Contact'] = array('id'); + return parent::jqGridRecordLinks($params, $model, $records, $links); + } + /************************************************************************** ************************************************************************** @@ -72,8 +77,69 @@ class ContactsController extends AppController { 'conditions' => array('Contact.id' => $id), )); + // Set up dynamic menu items + $this->sidemenu_links[] = + array('name' => 'Operations', 'header' => true); + + $this->sidemenu_links[] = + array('name' => 'Edit', + 'url' => array('action' => 'edit', + $id)); + // Prepare to render. $title = $contact['Contact']['display_name']; $this->set(compact('contact', 'title')); } + + + /************************************************************************** + ************************************************************************** + ************************************************************************** + * action: edit + */ + + function edit($id = null) { + if (isset($this->data)) { + pr($this->data); + $this->autoRender = false; + return; + } + + if (!$id) { + $this->Session->setFlash(__('Invalid Item.', true)); + $this->redirect(array('action'=>'index')); + } + + $this->data = $this->Contact->find + ('first', array + ('contain' => array + (// Models + 'ContactPhone', + 'ContactEmail', + 'ContactAddress', + 'Customer'), + + 'conditions' => array('Contact.id' => $id), + )); + + $phone_types = array_flip($this->Contact->ContactPhone->getEnumValues('type')); + unset($phone_types[0]); + $this->set(compact('phone_types')); + + $method_types = array_flip($this->Contact->getEnumValues('type', 'pmgr_contacts_methods')); + unset($method_types[0]); + $this->set(compact('method_types')); + + $method_preferences = array_flip($this->Contact->getEnumValues('preference', 'pmgr_contacts_methods')); + unset($method_preferences[0]); + $this->set(compact('method_preferences')); + + $contact_phones = $this->Contact->ContactPhone->phoneList(); + $this->set(compact('contact_phones')); + + // Prepare to render. + //pr($this->data); + $title = $this->data['Contact']['display_name'] . " : Edit"; + $this->set(compact('title')); + } } diff --git a/site/models/contact_phone.php b/site/models/contact_phone.php index f53b61d..012afcf 100644 --- a/site/models/contact_phone.php +++ b/site/models/contact_phone.php @@ -1,7 +1,6 @@ array('numeric'), //'type' => array('inlist'), @@ -20,5 +19,21 @@ class ContactPhone extends AppModel { ) ); + function phoneList() { + $results = $this->find('all', + array('contain' => false, + 'fields' => array('id', 'phone', 'ext'), + 'order' => array('phone', 'ext'))); + + App::Import('Helper', 'Format'); + $list = array(); + foreach ($results as $key => $val) { + $list[$val['ContactPhone']['id']] + = FormatHelper::phone($val['ContactPhone']['phone'], + $val['ContactPhone']['ext']); + } + return $list; + } + } ?> \ No newline at end of file diff --git a/site/views/contacts/edit.ctp b/site/views/contacts/edit.ctp index cee1f04..07ba1e1 100644 --- a/site/views/contacts/edit.ctp +++ b/site/views/contacts/edit.ctp @@ -1,21 +1,30 @@ +/********************************************************************** + ********************************************************************** + ********************************************************************** + ********************************************************************** + * Javascript + */ +