Implemented ability to add a customer, and fixed the problem with flagging of the primary contact.
git-svn-id: file:///svn-source/pmgr/branches/invoice_receipt_20090629/site@220 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -6,6 +6,7 @@ class CustomersController extends AppController {
|
||||
array('name' => 'Current', 'url' => array('controller' => 'customers', 'action' => 'current')),
|
||||
array('name' => 'Past', 'url' => array('controller' => 'customers', 'action' => 'past')),
|
||||
array('name' => 'All', 'url' => array('controller' => 'customers', 'action' => 'all')),
|
||||
array('name' => 'Add Tenant', 'url' => array('controller' => 'customers', 'action' => 'add')),
|
||||
);
|
||||
|
||||
//var $components = array('RequestHandler');
|
||||
@@ -286,6 +287,9 @@ class CustomersController extends AppController {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->data['Customer']['primary_contact_id']
|
||||
= $this->data['Contact'][$this->data['Customer']['primary_contact_entry']]['id'];
|
||||
|
||||
$this->Customer->create();
|
||||
if (!$this->Customer->save($this->data, false)) {
|
||||
pr("CUSTOMER SAVE FAILED");
|
||||
@@ -367,6 +371,7 @@ class CustomersController extends AppController {
|
||||
*/
|
||||
|
||||
function add() {
|
||||
$this->edit();
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
|
||||
@@ -159,7 +159,8 @@ class Customer extends AppModel {
|
||||
('contain' => array
|
||||
(// Models
|
||||
'Contact' =>
|
||||
array(// Models
|
||||
array('order' => array('Contact.display_name'),
|
||||
// Models
|
||||
'ContactPhone',
|
||||
'ContactEmail',
|
||||
'ContactAddress',
|
||||
|
||||
@@ -15,7 +15,7 @@ $this->varstore = compact('contactTypes', 'contacts');
|
||||
* Javascript
|
||||
*/
|
||||
|
||||
function customerContactDiv($obj, $values = null) {
|
||||
function customerContactDiv($obj, $values = null, $primary = false) {
|
||||
|
||||
$div =
|
||||
// BEGIN type-div
|
||||
@@ -67,12 +67,31 @@ function customerContactDiv($obj, $values = null) {
|
||||
// BEGIN contact-div
|
||||
'<div id="contact-%{id}-contact-div"' . "\n" .
|
||||
|
||||
/* '<INPUT TYPE="radio" ' . "\n" . */
|
||||
/* ' NAME="data[Customer][primary_contact_entry]"' . "\n" . */
|
||||
/* ' CLASS="contact-primary" ' . "\n" . */
|
||||
/* ' ID="contact-primary-%{id}"' . "\n" . */
|
||||
/* ' VALUE="%{id}"' . "\n" . */
|
||||
/* //($primary ? ' CHECKED' . "\n" : "(\$(#contact-entry-id).val() == 1 ? ' CHECKED' : '')") . */
|
||||
/* ($primary ? ' CHECKED' . "\n" : '' ) . */
|
||||
/* ' />' . "\n" . */
|
||||
/* ' <LABEL FOR="contact-primary-%{id}">Primary Contact</LABEL>' . "\n" . */
|
||||
|
||||
$obj->element
|
||||
('form_table',
|
||||
array('class' => "item contact entry",
|
||||
'field_prefix' => 'Contact.%{id}.ContactsCustomer',
|
||||
'fields' => array
|
||||
(
|
||||
'Customer.primary_contact_entry' => array
|
||||
('name' => 'Primary Contact',
|
||||
'no_prefix' => true,
|
||||
'opts' => array
|
||||
('type' => 'radio',
|
||||
'options' => array('%{id}' => false),
|
||||
'value' => ($primary ? '%{id}' : 'bogus-value-to-suppress-hidden-input'),
|
||||
)),
|
||||
|
||||
'type' => array
|
||||
('opts' => array
|
||||
('options' => $obj->varstore['contactTypes'],
|
||||
@@ -171,7 +190,8 @@ function customerContactTypeDiv($obj, $stype, $values = null) {
|
||||
|
||||
function addContact(flash) {
|
||||
addDiv('contact-entry-id', 'contact', 'contacts', flash, <?php
|
||||
echo FormatHelper::phpVarToJavascript(customerContactDiv($this),
|
||||
echo FormatHelper::phpVarToJavascript
|
||||
(customerContactDiv($this),
|
||||
null,
|
||||
' ');
|
||||
?>
|
||||
@@ -185,14 +205,26 @@ function customerContactTypeDiv($obj, $stype, $values = null) {
|
||||
|
||||
<?php foreach ($this->data['Contact'] AS $contact): ?>
|
||||
addDiv('contact-entry-id', 'contact', 'contacts', false, <?php
|
||||
echo FormatHelper::phpVarToJavascript(customerContactDiv($this,
|
||||
$contact
|
||||
echo FormatHelper::phpVarToJavascript
|
||||
(customerContactDiv($this,
|
||||
$contact,
|
||||
$contact['id'] == $this->data['Customer']['primary_contact_id']
|
||||
),
|
||||
null,
|
||||
' ');
|
||||
?>
|
||||
);
|
||||
<?php endforeach; ?>
|
||||
|
||||
if ($("#contact-entry-id").val() == 1) {
|
||||
addDiv('contact-entry-id', 'contact', 'contacts', false, <?php
|
||||
echo FormatHelper::phpVarToJavascript
|
||||
(customerContactDiv($this, null, true),
|
||||
null,
|
||||
' ');
|
||||
?>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function switchContactSource(id, source) {
|
||||
|
||||
@@ -16,7 +16,7 @@ foreach ($fields AS $field => $config) {
|
||||
if (!isset($config['opts']))
|
||||
$config['opts'] = null;
|
||||
|
||||
if (isset($field_prefix))
|
||||
if (isset($field_prefix) && !isset($config['no_prefix']))
|
||||
$field = $field_prefix . '.' . $field;
|
||||
|
||||
$config['opts']['label'] = false;
|
||||
|
||||
Reference in New Issue
Block a user