Files
pmgr/site/views/customers/edit.ctp
abijah 689a6dc7aa Changed layout to enlarge the detail table on the edit page. Changed edit action to redirect to the view page.
git-svn-id: file:///svn-source/pmgr/branches/invoice_receipt_20090629@221 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-07-06 03:09:54 +00:00

291 lines
8.1 KiB
PHP

<?php /* -*- mode:PHP -*- */
/**********************************************************************
* Because we make use of functions here,
* we need to put our top level variables somewhere
* we can access them.
*/
$this->varstore = compact('contactTypes', 'contacts');
//pr($this->data);
/**********************************************************************
**********************************************************************
**********************************************************************
**********************************************************************
* Javascript
*/
function customerContactDiv($obj, $values = null, $primary = false) {
$div =
// BEGIN type-div
'<DIV>' . "\n" .
// BEGIN type-fieldset
'<FIELDSET CLASS="contact subset">' . "\n" .
'<LEGEND>Contact #%{id} (%{remove})</LEGEND>' . "\n" .
// BEGIN source-div
'<DIV ID="contact-%{id}-source-div">' . "\n" .
// BEGIN source-fieldset
'<FIELDSET>' . "\n" .
//'<LEGEND>Source</LEGEND>' . "\n" .
''
;
if (!isset($values)) {
foreach (array('Existing', 'New') AS $sname) {
$stype = strtolower($sname);
$div .=
'<INPUT TYPE="radio" ' . "\n" .
' NAME="data[Contact][%{id}][source]"' . "\n" .
' ONCLICK="switchContactSource(%{id}, '."'{$stype}'".')"' . "\n" .
' CLASS="contact-%{id}-source" ' . "\n" .
' ID="contact-%{id}-source-'.$stype.'"' . "\n" .
' VALUE="'.$stype.'"' . "\n" .
//' CHECKED' . "\n" .
' />' . "\n" .
' <LABEL FOR="contact-%{id}-source-'.$stype.'">'.$sname.'</LABEL>' . "\n" .
' ';
}
}
$div .= "\n";
if (isset($values)) {
$div .= customerContactTypeDiv($obj, 'show', $values);
}
else {
$div .= customerContactTypeDiv($obj, 'existing');
$div .= customerContactTypeDiv($obj, 'new');
}
$div .=
// END source-fieldset
'</FIELDSET>' . "\n" .
// END source-div
'</DIV>' . "\n" .
// 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'],
'selected' => (isset($values) ? $values['ContactsCustomer']['type'] : null),
)),
'comment' => array
('opts' => array
('value' => (isset($values) ? $values['ContactsCustomer']['comment'] : null),
)),
))) . "\n" .
// END contact-div
'</div>' . "\n" .
// END type-fieldset
'</FIELDSET>' . "\n" .
// END type-div
'</DIV>'
;
return $div;
}
function customerContactTypeDiv($obj, $stype, $values = null) {
$element = 'form_table';
$class = $stype;
if ($stype === 'existing') {
$fields = array
('id' => array('name' => 'Contact',
'opts' => array('options' => $obj->varstore['contacts'])),
);
}
elseif ($stype === 'new') {
$fields = array
('first_name' => null,
'last_name' => null,
'middle_name' => null,
'display_name' => null,
'company_name' => array('name' => 'Company'),
'id_federal' => array('name' => 'SSN'),
'id_local' => array('name' => 'ID #'),
'id_local_state' => array('name' => 'ID State'),
/* 'id_local_exp' => array('name' => 'ID Expiration', */
/* 'opts' => array('empty' => true)), */
'comment' => null,
);
}
elseif ($stype === 'show') {
$element = 'table';
$class = 'detail';
$column_class = array('field', 'value');
$rows = array(array('First Name', $values['first_name']),
//array('Middle Name', $values['middle_name']),
array('Last Name', $values['last_name']),
array('Company', $values['company_name']),
//array('SSN', $values['id_federal']),
/* array('ID', ($values['id_local'] */
/* . ($values['id_local'] */
/* ? " - ".$values['id_local_state'] */
/* : ""))), */
array('Comment', $values['comment']));
}
else {
die("\n\nInvalid stype ($stype)\n\n");
}
return
// BEGIN sourcetype-div
'<div ' . "\n" .
' class="contact-%{id}-div"' . "\n" .
' id="contact-%{id}-'.$stype.'-div"' . "\n" .
(isset($values) ? '' : ' STYLE="display:none;"' . "\n") .
'>' . "\n" .
$obj->element
($element,
array('class' => "item contact {$class}",
'field_prefix' => 'Contact.%{id}')
+ compact('rows', 'fields', 'column_class')) .
($stype === 'show'
? '<input type="hidden" name="data[Contact][%{id}][id]" value="'.$values['id'].'"/>' . "\n"
: '') .
// END sourcetype-div
'</div>' . "\n" .
'';
}
?>
<script type="text/javascript"><!--
function addContact(flash) {
addDiv('contact-entry-id', 'contact', 'contacts', flash, <?php
echo FormatHelper::phpVarToJavascript
(customerContactDiv($this),
null,
' ');
?>
);
}
// Reset the form
function resetForm() {
$('#contacts').html('');
$('#contact-entry-id').val(1);
<?php foreach ($this->data['Contact'] AS $contact): ?>
addDiv('contact-entry-id', 'contact', 'contacts', false, <?php
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) {
$(".contact-"+id+"-div")
.slideUp();
$("#contact-"+id+"-"+source+"-div")
.slideDown();
}
$(document).ready(function(){
resetForm();
});
--></script>
<?php
; // alignment
/**********************************************************************
**********************************************************************
**********************************************************************
**********************************************************************
* Customer Edit
*/
echo '<div class="customer edit">' . "\n";
echo $form->create('Customer', array('action' => 'edit')) . "\n";
echo $form->input('id') . "\n";
echo($this->element
('form_table',
array('class' => 'item customer detail',
'caption' => $this->data ? 'Edit Customer' : 'New Customer',
'fields' => array
('name' => null,
'comment' => null,
))) . "\n");
echo $form->submit('Update') . "\n";
?>
<div CLASS="dynamic-set">
<fieldset CLASS="contact superset">
<legend>Contacts</legend>
<input type="hidden" id="contact-entry-id" value="0">
<div id="contacts"></div>
<fieldset> <legend>
<a href="#" onClick="addContact(true); return false;">Add a Contact</a>
</legend> </fieldset>
</fieldset>
</div>
<?php
; // Alignment
echo $form->submit('Update') . "\n";
echo $form->submit('Cancel', array('name' => 'cancel')) . "\n";
echo $form->end() . "\n";
echo '</div>' . "\n";