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
This commit is contained in:
@@ -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}'");
|
||||
|
||||
@@ -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'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
<?php
|
||||
class ContactPhone extends AppModel {
|
||||
|
||||
var $name = 'ContactPhone';
|
||||
var $validate = array(
|
||||
'id' => 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;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
@@ -1,21 +1,30 @@
|
||||
<?php /* -*- mode:PHP -*- */ ?>
|
||||
|
||||
/**********************************************************************
|
||||
**********************************************************************
|
||||
**********************************************************************
|
||||
**********************************************************************
|
||||
* Javascript
|
||||
*/
|
||||
|
||||
<script type="text/javascript"><!--
|
||||
|
||||
function addPhone(flash) {
|
||||
addDiv('phone-id', 'phone', 'phones', flash,
|
||||
// HTML section
|
||||
'<FIELDSET CLASS="phone subset">' +
|
||||
'<DIV>' + // BEGIN phone-div
|
||||
'<FIELDSET CLASS="phone subset">' + // BEGIN phone-fieldset
|
||||
'<LEGEND>Phone Number #%{id} (%{remove})</LEGEND>' +
|
||||
|
||||
'<DIV ID="phone-%{id}-source-div">' +
|
||||
'<FIELDSET>' +
|
||||
'<DIV ID="phone-%{id}-source-div">' + // BEGIN source-div
|
||||
'<FIELDSET>' + // BEGIN source-fieldset
|
||||
//'<LEGEND>Source</LEGEND>' +
|
||||
|
||||
'<INPUT TYPE="radio" NAME="data[ContactPhone][%{id}][source]"' +
|
||||
' ONCLICK="switchPhoneSource(%{id}, '+"'existing'"+')"' +
|
||||
' CLASS="phone-%{id}-source" ID="phone-%{id}-source-existing"' +
|
||||
' VALUE="existing" CHECKED/>' +
|
||||
//' VALUE="existing" CHECKED/>' +
|
||||
' VALUE="existing" />' +
|
||||
' <LABEL FOR="phone-%{id}-source-existing">Existing</LABEL>' +
|
||||
' ' +
|
||||
'<INPUT TYPE="radio" NAME="data[ContactPhone][%{id}][source]"' +
|
||||
@@ -24,99 +33,67 @@
|
||||
' VALUE="new"/>' +
|
||||
' <LABEL FOR="phone-%{id}-source-new">New</LABEL>' +
|
||||
|
||||
'<div id="phone-%{id}-existing-div"' + // BEGIN existing-div
|
||||
' STYLE="display:none;">' +
|
||||
<?php
|
||||
/* $sources = array(); */
|
||||
/* foreach(array('Existing', 'New') AS $name) */
|
||||
/* $sources[preg_replace("/ /", "", strtolower($name))] = $name; */
|
||||
|
||||
/* echo "'" . preg_replace("/\n/", "", */
|
||||
/* $form->radio('ContactPhone.%{id}.source', */
|
||||
/* $sources, */
|
||||
/* array('legend' => false, */
|
||||
/* 'separator'=>' '))) . "' +"; */
|
||||
echo ("'" .
|
||||
preg_replace
|
||||
("/\n/", "",
|
||||
$this->element
|
||||
('form_table',
|
||||
array('class' => 'item contact-phone existing',
|
||||
'field_prefix' => 'ContactPhone.%{id}',
|
||||
'fields' => array
|
||||
('id' => array('name' => 'Phone/Ext',
|
||||
'opts' => array('options' => $contactPhones)),
|
||||
))))
|
||||
. "' +");
|
||||
?>
|
||||
'</div>' + // END existing-div
|
||||
|
||||
'<div id="phone-new">' +
|
||||
|
||||
'<div id="phone-%{id}-new-div"' + // BEGIN new-div
|
||||
' STYLE="display:none;">' +
|
||||
<?php
|
||||
/* echo "'" . preg_replace("/\n/", "", */
|
||||
/* $form->input('ContactPhone.%{id}.Method.type', */
|
||||
/* array('label' => 'Type', */
|
||||
/* 'options' => $methodTypes, */
|
||||
/* ))) . "' +"; */
|
||||
echo ("'" .
|
||||
preg_replace
|
||||
("/\n/", "",
|
||||
$this->element
|
||||
('form_table',
|
||||
array('class' => 'item contact-phone entry',
|
||||
'field_prefix' => 'ContactPhone.%{id}',
|
||||
'fields' => array
|
||||
('type' => array('opts' => array('options' => $phoneTypes)),
|
||||
'phone' => null,
|
||||
'ext' => array('name' => "Extension"),
|
||||
'comment' => null,
|
||||
))))
|
||||
. "' +");
|
||||
?>
|
||||
'</div>' +
|
||||
'<div id="phone-existing"></div>' +
|
||||
'</div>' + // END new-div
|
||||
|
||||
'</FIELDSET>' +
|
||||
'</FIELDSET>' + // END source-fieldset
|
||||
'</DIV>' + // END source-div
|
||||
|
||||
|
||||
/* foreach ($sources AS $source => $name) { */
|
||||
/* $div = '<DIV>'; */
|
||||
|
||||
/* echo "'" . preg_replace("/\n/", "", */
|
||||
/* $form->input('ContactPhone.%{id}.source', */
|
||||
/* array('label' => 'Type', */
|
||||
/* 'type' => 'radio', */
|
||||
/* 'options' => $sources, */
|
||||
/* ))) . "' +"; */
|
||||
|
||||
/* $div .= '<INPUT TYPE="radio" NAME="data[ContactPhone][%{id}][source]"'; */
|
||||
/* $div .= ' ONCLICK="switchPhoneSource(%{id}, \\\''.$source.'\\\')"'; */
|
||||
/* $div .= ' CLASS="phone-source-%{id}" ID="phone-source-'.$source.'-%{id}"'; */
|
||||
/* $div .= ' VALUE="'.$name.'" ' . ($name == 'Existing' ? 'CHECKED ' : '') . '/>'; */
|
||||
/* $div .= ' <LABEL FOR="phone-source-'.$source.'-%{id}">'.$name.'</LABEL>'; */
|
||||
/* $div .= '</DIV>'; */
|
||||
/* echo "'$div' +\n"; */
|
||||
/* } */
|
||||
|
||||
'</DIV>' +
|
||||
|
||||
//'<DIV ID="phone-method-type-div-%{id}" CLASS="input text required">' +
|
||||
'<div id="phone-%{id}-method-div"' + // BEGIN method-div
|
||||
<?php
|
||||
echo "'" . preg_replace("/\n/", "",
|
||||
$form->input('ContactPhone.%{id}.Method.type',
|
||||
array('label' => 'Type',
|
||||
'options' => $methodTypes,
|
||||
))) . "' +";
|
||||
echo ("'" .
|
||||
preg_replace
|
||||
("/\n/", "",
|
||||
$this->element
|
||||
('form_table',
|
||||
array('class' => 'item contact-method entry',
|
||||
'field_prefix' => 'ContactPhone.%{id}.Method',
|
||||
'fields' => array
|
||||
('type' => array('opts' => array('options' => $methodTypes)),
|
||||
'preferences' => array('opts' => array('options' => $methodPreferences)),
|
||||
'comment' => null,
|
||||
))))
|
||||
. "' +");
|
||||
?>
|
||||
'</div>' + // END method-div
|
||||
|
||||
<?php
|
||||
echo "'" . preg_replace("/\n/", "",
|
||||
$form->input('ContactPhone.%{id}.Method.preference',
|
||||
array('label' => 'Preference',
|
||||
'options' => $methodPreferences,
|
||||
))) . "' +";
|
||||
?>
|
||||
|
||||
<?php
|
||||
echo "'" . preg_replace("/\n/", "",
|
||||
$form->input('ContactPhone.%{id}.Method.comment',
|
||||
array('label' => 'Comment',
|
||||
))) . "' +";
|
||||
?>
|
||||
|
||||
//'</DIV>' +
|
||||
|
||||
<?php
|
||||
/* '<DIV ID="phone-method-comment-div-%{id}" CLASS="input text required">' + */
|
||||
/* ' <LABEL FOR="phone-method-comment-%{id}">Comment</LABEL>' + */
|
||||
/* ' <INPUT TYPE="text" SIZE="20"' + */
|
||||
/* ' NAME="data[ContactPhone][%{id}][Method][comment]"' + */
|
||||
/* ' ID="phone-method-comment-%{id}" />' + */
|
||||
/* '</DIV>' + */
|
||||
|
||||
/* foreach ($sources AS $source => $name) { */
|
||||
/* $div = '<DIV'; */
|
||||
/* $div .= ' ID="phone-%{id}-div"'; */
|
||||
/* $div .= ' CLASS="phone-source-type-div-%{id}"'; */
|
||||
/* $div .= ' STYLE="display:none;">'; */
|
||||
/* $div .= '</DIV>'; */
|
||||
/* echo "'$div' +\n"; */
|
||||
/* } */
|
||||
?>
|
||||
|
||||
'</FIELDSET>'
|
||||
'</FIELDSET>' + // END phone-fieldset
|
||||
'</DIV>' // END phone-div
|
||||
);
|
||||
|
||||
}
|
||||
@@ -129,8 +106,29 @@
|
||||
}
|
||||
|
||||
// Reset the form
|
||||
function switchPhoneSource(id, source) {
|
||||
//alert("Switch id:"+id+" source:"+source);
|
||||
function switchPhoneSource(id, source) {
|
||||
<?php
|
||||
// REVISIT <AP>: 20090704
|
||||
// For reasons I don't yet understand, slideUp is NOT working for
|
||||
// new-div. It works fine for existing-div, and show/hide work
|
||||
// for both divs. I'll defer figuring this out until later.
|
||||
?>
|
||||
|
||||
if (source == 'new') {
|
||||
$("#phone-"+id+"-existing-div")
|
||||
.hide();
|
||||
//.slideUp();
|
||||
$("#phone-"+id+"-new-div")
|
||||
.show();
|
||||
//.slideDown();
|
||||
} else {
|
||||
$("#phone-"+id+"-new-div")
|
||||
.hide();
|
||||
//.slideUp();
|
||||
$("#phone-"+id+"-existing-div")
|
||||
.show();
|
||||
//.slideDown();
|
||||
}
|
||||
}
|
||||
|
||||
$(document).ready(function(){
|
||||
@@ -142,71 +140,54 @@
|
||||
<?php
|
||||
; // alignment
|
||||
|
||||
echo '<div class="contact edit">' . "\n";
|
||||
|
||||
/**********************************************************************
|
||||
**********************************************************************
|
||||
**********************************************************************
|
||||
**********************************************************************
|
||||
* Contact Detail Main Section
|
||||
* Contact Edit
|
||||
*/
|
||||
|
||||
echo $form->create('Contact');
|
||||
echo $form->input('id');
|
||||
echo '<div class="contact edit">' . "\n";
|
||||
|
||||
$rows = array();
|
||||
foreach (array('first_name' => null,
|
||||
'last_name' => null,
|
||||
'middle_name' => null,
|
||||
'display_name' => null,
|
||||
'company_name' => 'Company',
|
||||
'id_federal' => 'SSN',
|
||||
'id_local' => 'ID #',
|
||||
'id_local_state' => 'ID State',
|
||||
//'id_local_exp' => 'ID Expires',
|
||||
'comment' => null,
|
||||
|
||||
//'' => null,
|
||||
//'' => '',
|
||||
|
||||
) AS $field => $label) {
|
||||
if (!isset($label))
|
||||
$label = implode(' ', array_map('ucfirst', explode('_', $field)));
|
||||
|
||||
$opts = array('label' => false);
|
||||
if ($field === 'id_local_exp')
|
||||
$opts['empty'] = true;
|
||||
|
||||
$rows[] = array($label, $form->input($field, $opts));
|
||||
}
|
||||
|
||||
echo $this->element('table',
|
||||
array('class' => 'item contact detail',
|
||||
'caption' => 'Edit Contact',
|
||||
'rows' => $rows,
|
||||
'column_class' => array('field', 'value')));
|
||||
|
||||
|
||||
|
||||
|
||||
/* echo $form->input('ContactAddress'); */
|
||||
/* echo $form->input('ContactPhone'); */
|
||||
/* echo $form->input('ContactEmail'); */
|
||||
/* echo $form->input('Customer'); */
|
||||
|
||||
echo $form->submit('Update') . $form->submit('Cancel');
|
||||
echo $form->end();
|
||||
echo $form->create('Contact') . "\n";
|
||||
echo $form->input('id') . "\n";
|
||||
|
||||
echo($this->element
|
||||
('form_table',
|
||||
array('class' => 'item contact detail',
|
||||
'caption' => 'Edit Contact',
|
||||
'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,
|
||||
//'' => null,
|
||||
//'' => '',
|
||||
))) . "\n");
|
||||
?>
|
||||
|
||||
<div>
|
||||
<fieldset CLASS="phone superset">
|
||||
<legend>Phones</legend>
|
||||
<input type="hidden" id="phone-id" value="0">
|
||||
<div id="phones"></div>
|
||||
<fieldset> <legend>
|
||||
<a href="#" onClick="addPhone(true); return false;">Add Another Phone</a>
|
||||
<a href="#" onClick="addPhone(true); return false;">Add a Phone Number</a>
|
||||
</legend> </fieldset>
|
||||
</fieldset>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
; // Alignment
|
||||
|
||||
echo $form->submit('Update') . "\n";
|
||||
echo $form->submit('Cancel') . "\n";
|
||||
echo $form->end() . "\n";
|
||||
echo '</div>' . "\n";
|
||||
|
||||
31
site/views/elements/form_table.ctp
Normal file
31
site/views/elements/form_table.ctp
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php /* -*- mode:PHP -*- */
|
||||
|
||||
/* form_table.ctp */
|
||||
/*
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright 2009, Abijah Perkins
|
||||
* @package pmgr
|
||||
*/
|
||||
|
||||
|
||||
$rows = array();
|
||||
foreach ($fields AS $field => $config) {
|
||||
if (!isset($config['name']))
|
||||
$config['name'] = implode(' ', array_map('ucfirst', explode('_', $field)));
|
||||
if (!isset($config['opts']))
|
||||
$config['opts'] = null;
|
||||
|
||||
if (isset($field_prefix))
|
||||
$field = $field_prefix . '.' . $field;
|
||||
|
||||
$config['opts']['label'] = false;
|
||||
$rows[] = array($config['name'],
|
||||
$form->input($field, $config['opts']));
|
||||
}
|
||||
|
||||
echo $this->element('table',
|
||||
compact('class', 'caption', 'headers',
|
||||
'rows', 'row_class', 'suppress_alternate_rows') +
|
||||
array('column_class' => array('field', 'value'),
|
||||
));
|
||||
@@ -50,17 +50,20 @@ class FormatHelper extends AppHelper {
|
||||
return self::$time->nice($datetime);
|
||||
}
|
||||
|
||||
function phone($phone) {
|
||||
function phone($phone, $ext = null) {
|
||||
if (!isset($phone))
|
||||
return null;
|
||||
|
||||
$phone = preg_replace("/\D/", "", $phone);
|
||||
if(strlen($phone) == 7)
|
||||
return preg_replace("/(\d{3})(\d{4})/", "$1-$2", $phone);
|
||||
$phone = preg_replace("/(\d{3})(\d{4})/", "$1-$2", $phone);
|
||||
elseif(strlen($phone) == 10)
|
||||
return preg_replace("/(\d{3})(\d{3})(\d{4})/", "$1-$2-$3", $phone);
|
||||
else
|
||||
return $phone;
|
||||
$phone = preg_replace("/(\d{3})(\d{3})(\d{4})/", "$1-$2-$3", $phone);
|
||||
|
||||
if ($ext)
|
||||
$phone .= ' x' . $ext;
|
||||
|
||||
return $phone;
|
||||
}
|
||||
|
||||
function comment($comment) {
|
||||
|
||||
Reference in New Issue
Block a user