Added ability to add a new contact, which also fixes the glaring omission of saving changes to contact details on the edit page (previously we were only saving contact methods, not any contact details.
git-svn-id: file:///svn-source/pmgr/branches/invoice_receipt_20090629/site@218 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -98,14 +98,35 @@ class ContactsController extends AppController {
|
|||||||
* action: edit
|
* action: edit
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function edit($id = null) {
|
function edit($id = null, $customer_id = null) {
|
||||||
if (isset($this->data)) {
|
if (isset($this->data)) {
|
||||||
|
|
||||||
if (isset($this->params['form']['cancel'])) {
|
if (isset($this->params['form']['cancel'])) {
|
||||||
$this->redirect(array('action'=>'view', $this->data['Contact']['id']));
|
if (isset($this->data['Contact']['id']))
|
||||||
|
$this->redirect(array('action'=>'view', $this->data['Contact']['id']));
|
||||||
|
/* else */
|
||||||
|
/* $this->redirect(array('controller' => 'customers', */
|
||||||
|
/* 'action'=>'add', $this->data['Customer']['id'])); */
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!$this->data['Contact']['display_name'])
|
||||||
|
$this->data['Contact']['display_name'] =
|
||||||
|
(($this->data['Contact']['first_name'] &&
|
||||||
|
$this->data['Contact']['last_name'])
|
||||||
|
? $this->data['Contact']['last_name'] . ', ' . $this->data['Contact']['first_name']
|
||||||
|
: ($this->data['Contact']['first_name']
|
||||||
|
? $this->data['Contact']['first_name']
|
||||||
|
: $this->data['Contact']['last_name']));
|
||||||
|
|
||||||
|
$this->Contact->create();
|
||||||
|
if (!$this->Contact->save($this->data, false)) {
|
||||||
|
pr("CONTACT SAVE FAILED");
|
||||||
|
$this->Session->setFlash("CONTACT SAVE FAILED", true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$this->data['Contact']['id'] = $this->Contact->id;
|
||||||
|
|
||||||
// Remove all associated ContactMethods, as it ensures
|
// Remove all associated ContactMethods, as it ensures
|
||||||
// any entries deleted by the user actually get deleted
|
// any entries deleted by the user actually get deleted
|
||||||
// in the system. We'll recreate the needed ones anyway.
|
// in the system. We'll recreate the needed ones anyway.
|
||||||
@@ -158,22 +179,27 @@ class ContactsController extends AppController {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$id) {
|
if ($id) {
|
||||||
$this->Session->setFlash(__('Invalid Item.', true));
|
$this->data = $this->Contact->find
|
||||||
$this->redirect(array('action'=>'index'));
|
('first', array
|
||||||
|
('contain' => array
|
||||||
|
(// Models
|
||||||
|
'ContactPhone',
|
||||||
|
'ContactEmail',
|
||||||
|
'ContactAddress',
|
||||||
|
'Customer'),
|
||||||
|
|
||||||
|
'conditions' => array('Contact.id' => $id),
|
||||||
|
));
|
||||||
|
|
||||||
|
$title = $this->data['Contact']['display_name'] . " : Edit";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$title = "Enter New Contact";
|
||||||
|
$this->data = array('ContactPhone' => array(),
|
||||||
|
'ContactAddress' => array(),
|
||||||
|
'ContactEmail' => array());
|
||||||
}
|
}
|
||||||
|
|
||||||
$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'));
|
$phone_types = array_flip($this->Contact->ContactPhone->getEnumValues('type'));
|
||||||
unset($phone_types[0]);
|
unset($phone_types[0]);
|
||||||
@@ -208,7 +234,20 @@ class ContactsController extends AppController {
|
|||||||
|
|
||||||
// Prepare to render.
|
// Prepare to render.
|
||||||
//pr($this->data);
|
//pr($this->data);
|
||||||
$title = $this->data['Contact']['display_name'] . " : Edit";
|
|
||||||
$this->set(compact('title'));
|
$this->set(compact('title'));
|
||||||
|
$this->render('edit');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* action: add
|
||||||
|
* - Adds a new contact
|
||||||
|
*/
|
||||||
|
|
||||||
|
function add($customer_id = null) {
|
||||||
|
$this->edit(null, $customer_id);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -230,6 +230,17 @@ class CustomersController extends AppController {
|
|||||||
$this->sidemenu_links[] =
|
$this->sidemenu_links[] =
|
||||||
array('name' => 'Operations', 'header' => true);
|
array('name' => 'Operations', 'header' => true);
|
||||||
|
|
||||||
|
$this->sidemenu_links[] =
|
||||||
|
array('name' => 'Edit',
|
||||||
|
'url' => array('action' => 'edit',
|
||||||
|
$id));
|
||||||
|
|
||||||
|
$this->sidemenu_links[] =
|
||||||
|
array('name' => 'Add Contact',
|
||||||
|
'url' => array('controller' => 'contacts',
|
||||||
|
'action' => 'add',
|
||||||
|
$id));
|
||||||
|
|
||||||
$this->sidemenu_links[] =
|
$this->sidemenu_links[] =
|
||||||
array('name' => 'Move-In',
|
array('name' => 'Move-In',
|
||||||
'url' => array('action' => 'move_in',
|
'url' => array('action' => 'move_in',
|
||||||
|
|||||||
@@ -342,13 +342,13 @@ function contactMethodTypeDiv($obj, $type, $stype, $values = null) {
|
|||||||
|
|
||||||
echo '<div class="contact edit">' . "\n";
|
echo '<div class="contact edit">' . "\n";
|
||||||
|
|
||||||
echo $form->create('Contact') . "\n";
|
echo $form->create('Contact', array('action' => 'edit')) . "\n";
|
||||||
echo $form->input('id') . "\n";
|
echo $form->input('id') . "\n";
|
||||||
|
|
||||||
echo($this->element
|
echo($this->element
|
||||||
('form_table',
|
('form_table',
|
||||||
array('class' => 'item contact detail',
|
array('class' => 'item contact detail',
|
||||||
'caption' => 'Edit Contact',
|
'caption' => $this->data ? 'Edit Contact' : 'New Contact',
|
||||||
'fields' => array
|
'fields' => array
|
||||||
('first_name' => null,
|
('first_name' => null,
|
||||||
'last_name' => null,
|
'last_name' => null,
|
||||||
@@ -364,6 +364,8 @@ echo($this->element
|
|||||||
//'' => null,
|
//'' => null,
|
||||||
//'' => '',
|
//'' => '',
|
||||||
))) . "\n");
|
))) . "\n");
|
||||||
|
|
||||||
|
echo $form->submit('Update') . "\n";
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<div CLASS="dynamic-set">
|
<div CLASS="dynamic-set">
|
||||||
|
|||||||
Reference in New Issue
Block a user