Implemented edit functionality for customer. Like with contacts, the interface leaves much to be desired, since it's limited in functionality. Namely, you can add a contact, but you can't add contact methods (phone/mail/email). Also, it doesn't use jqGrid to present the selection choices, and so the user is stuck with the fields we've chosen to display, as well as the sort order we've chosen. Enhancement is possible someday, but for now, it gets the job done.
git-svn-id: file:///svn-source/pmgr/branches/invoice_receipt_20090629@219 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
256
site/views/customers/edit.ctp
Normal file
256
site/views/customers/edit.ctp
Normal file
@@ -0,0 +1,256 @@
|
||||
<?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) {
|
||||
|
||||
$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" .
|
||||
|
||||
$obj->element
|
||||
('form_table',
|
||||
array('class' => "item contact entry",
|
||||
'field_prefix' => 'Contact.%{id}.ContactsCustomer',
|
||||
'fields' => array
|
||||
(
|
||||
'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';
|
||||
|
||||
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';
|
||||
$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 {$stype}",
|
||||
'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
|
||||
),
|
||||
null,
|
||||
' ');
|
||||
?>
|
||||
);
|
||||
<?php endforeach; ?>
|
||||
}
|
||||
|
||||
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";
|
||||
Reference in New Issue
Block a user