Menu jquery-ified. Add customer autocomplete replaced with custom dialog box

This commit is contained in:
Karl Cordes 2010-03-16 14:20:38 +11:00
parent a6873f7823
commit 625eb8e42a
9 changed files with 365 additions and 225 deletions

View file

@ -1,111 +1,113 @@
<?php <?php
class CustomersController extends AppController { class CustomersController extends AppController {
var $name = 'Customers'; var $name = 'Customers';
var $helpers = array('Html', 'Form', 'Time', 'Ajax'); var $helpers = array('Html', 'Form', 'Time', 'Ajax');
var $components = array('RequestHandler'); var $components = array('RequestHandler');
var $paginate = array(
'Customer' => array('order' => array('Customer.name' => 'asc'),
'limit' => 200
),
'Enquiry' => array('order' => array('Enquiry.id' => 'desc'))
);
function index() {
$this->Customer->recursive = 0;
$this->set('customers', $this->paginate());
$this->set('customer_categories', $this->Customer->CustomerCategory->find('all'));
/* Show only customers from a particular category name */
if(isset($this->params['named']['showonly'])) {
$this->set('customers', $this->paginate('Customer', array('Customer.customer_category_id' => $this->params['named']['showonly'])));
}
}
function view($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid Customer.', true));
$this->redirect(array('action'=>'index'));
}
$this->set('customer', $this->Customer->read(null, $id));
$this->set('addresses', $this->Customer->Address->findAllByCustomerId($id));
$this->set('enquiries', $this->paginate('Enquiry', array('Enquiry.customer_id' => $id)));
$this->set('contacts', $this->Customer->Contact->find('all', array('conditions' => array('customer_id' => $id), 'order' => 'Contact.last_name ASC')));
$statuses = $this->Customer->Enquiry->Status->find('all', array('recursive'=>0));
$status_list = array();
foreach ($statuses as $status) {
$statusid = $status['Status']['id'];
$status_list[$statusid] = $status['Status']['name'];
}
$this->set('status_list', $status_list);
$this->set('parent_industry_list', $this->Customer->Industry->find('list', array('conditions' => array('parent_id' => null))));
}
function add() {
if (!empty($this->data)) {
/* Remove all whitespace and non-digit characters from the user input */
$this->data['Customer']['abn'] = preg_replace("/\s*\D*/", "", $this->data['Customer']['abn']);
if($this->Customer->saveAll($this->data, array('validate'=>'first')) ) { var $paginate = array(
$newcustomerid = $this->Customer->id; 'Customer' => array('order' => array('Customer.name' => 'asc'),
$this->Session->setFlash(__('The Customer has been saved', true)); 'limit' => 200
$this->redirect(array('action'=>'view', 'id'=>$newcustomerid)); ),
} 'Enquiry' => array('order' => array('Enquiry.id' => 'desc'))
);
}
$this->set('customer_categories', $this->Customer->CustomerCategory->find('list'));
$this->set('states', $this->Customer->Address->State->find('list'));
//$this->set('countries', $this->Customer->Country->find('list', array('order'=>array('Country.name ASC'))));
}
function edit($id = null) { function index() {
$this->Customer->recursive = 0;
$this->set('customers', $this->paginate());
$this->set('customer_categories', $this->Customer->CustomerCategory->find('all'));
/* Show only customers from a particular category name */
if(isset($this->params['named']['showonly'])) {
$this->set('customers', $this->paginate('Customer', array('Customer.customer_category_id' => $this->params['named']['showonly'])));
}
if (!$id && empty($this->data)) { }
$this->Session->setFlash(__('Invalid Customer', true));
$this->redirect(array('action'=>'index'));
}
if (!empty($this->data)) { function view($id = null) {
/* Remove all whitespace and non-digit characters from the user input */ if (!$id) {
$this->data['Customer']['abn'] = preg_replace("/\s*\D*/", "", $this->data['Customer']['abn']); $this->Session->setFlash(__('Invalid Customer.', true));
if ($this->Customer->saveAll($this->data)) { $this->redirect(array('action'=>'index'));
$this->Session->setFlash(__('The Customer has been saved', true)); }
$id = $this->Customer->id; $this->set('customer', $this->Customer->read(null, $id));
$this->redirect(array('action'=>'view/'.$id)); $this->set('addresses', $this->Customer->Address->findAllByCustomerId($id));
} else { $this->set('enquiries', $this->paginate('Enquiry', array('Enquiry.customer_id' => $id)));
$this->Session->setFlash(__('The Customer could not be saved. Please, try again.', true)); $this->set('contacts', $this->Customer->Contact->find('all', array('conditions' => array('customer_id' => $id), 'order' => 'Contact.last_name ASC')));
$this->set('customer_categories', $this->Customer->CustomerCategory->find('list'));
$this->set('industries', $this->Customer->Industry->find('list', array('fields'=>array('Industry.id', 'Industry.name', 'ParentIndustry.name'),'recursive' => 0,
'order'=>'ParentIndustry.name ASC, Industry.name ASC')));
}
}
if (empty($this->data)) {
$this->data = $this->Customer->read(null, $id);
$this->set('customer_categories', $this->Customer->CustomerCategory->find('list'));
$this->set('industries', $this->Customer->Industry->find('list', array('fields'=>array('Industry.id', 'Industry.name', 'ParentIndustry.name'),'recursive' => 0,
'order'=>'ParentIndustry.name ASC, Industry.name ASC')));
}
}
/* Autocomplete the customer name - Used in: add.ctp */ $statuses = $this->Customer->Enquiry->Status->find('all', array('recursive'=>0));
function completeCustomer() { $status_list = array();
foreach ($statuses as $status) {
$statusid = $status['Status']['id'];
$status_list[$statusid] = $status['Status']['name'];
}
$this->set('status_list', $status_list);
$this->set('parent_industry_list', $this->Customer->Industry->find('list', array('conditions' => array('parent_id' => null))));
}
function add() {
if (!empty($this->data)) {
/* Remove all whitespace and non-digit characters from the user input */
$this->data['Customer']['abn'] = preg_replace("/\s*\D*/", "", $this->data['Customer']['abn']);
if($this->Customer->saveAll($this->data, array('validate'=>'first')) ) {
$newcustomerid = $this->Customer->id;
$this->Session->setFlash(__('The Customer has been saved', true));
$this->redirect(array('action'=>'view', 'id'=>$newcustomerid));
}
}
$this->set('customer_categories', $this->Customer->CustomerCategory->find('list'));
$this->set('states', $this->Customer->Address->State->find('list'));
//$this->set('countries', $this->Customer->Country->find('list', array('order'=>array('Country.name ASC'))));
}
function edit($id = null) {
if (!$id && empty($this->data)) {
$this->Session->setFlash(__('Invalid Customer', true));
$this->redirect(array('action'=>'index'));
}
if (!empty($this->data)) {
/* Remove all whitespace and non-digit characters from the user input */
$this->data['Customer']['abn'] = preg_replace("/\s*\D*/", "", $this->data['Customer']['abn']);
if ($this->Customer->saveAll($this->data)) {
$this->Session->setFlash(__('The Customer has been saved', true));
$id = $this->Customer->id;
$this->redirect(array('action'=>'view/'.$id));
} else {
$this->Session->setFlash(__('The Customer could not be saved. Please, try again.', true));
$this->set('customer_categories', $this->Customer->CustomerCategory->find('list'));
$this->set('industries', $this->Customer->Industry->find('list', array('fields'=>array('Industry.id', 'Industry.name', 'ParentIndustry.name'),'recursive' => 0,
'order'=>'ParentIndustry.name ASC, Industry.name ASC')));
}
}
if (empty($this->data)) {
$this->data = $this->Customer->read(null, $id);
$this->set('customer_categories', $this->Customer->CustomerCategory->find('list'));
$this->set('industries', $this->Customer->Industry->find('list', array('fields'=>array('Industry.id', 'Industry.name', 'ParentIndustry.name'),'recursive' => 0,
'order'=>'ParentIndustry.name ASC, Industry.name ASC')));
}
}
/* Autocomplete the customer name - Used in: find.ctp */
function completeCustomer() {
$query = strtolower($_GET["term"]); $query = strtolower($_GET["term"]);
//$this->set('customers_json', print_r($this->data));
if($query == null) { if($query == null) {
return; return;
} }
@ -113,12 +115,12 @@ class CustomersController extends AppController {
App::import('Core', 'Sanitize'); App::import('Core', 'Sanitize');
$query = Sanitize::clean($query); $query = Sanitize::clean($query);
$customers = $this->Customer->find('all', array( $customers = $this->Customer->find('all', array(
'conditions' => array( 'conditions' => array(
'Customer.name LIKE' => '%'.$query.'%' 'Customer.name LIKE' => '%'.$query.'%'
),'fields' => array('Customer.name'), ),'fields' => array('Customer.name'),
'order' => array('Customer.name ASC') 'order' => array('Customer.name ASC')
@ -129,55 +131,77 @@ class CustomersController extends AppController {
$custid = $customer['Customer']['id']; $custid = $customer['Customer']['id'];
$cust_list[] = array('id'=> $custid, 'label' => $customer['Customer']['name']); $cust_list[] = array('id'=> $custid, 'label' => $customer['Customer']['name']);
} }
$customers_json = json_encode($cust_list); $customers_json = json_encode($cust_list);
$this->set('customers_json', $customers_json); $this->set('customers_json', $customers_json);
$this->layout = 'ajax'; $this->layout = 'ajax';
} }
function find() {
if(!empty($this->data)) { function similarCustomers() {
$customer = $this->Customer->findByName($this->data['Customer']['name']); App::import('Core', 'Sanitize');
if(!$customer) {
$this->Session->setFlash(__('Could not find the Requested Customer. Please select one from the drop down box as you type.', true)); $query = Sanitize::clean($this->data['Customer']['name']);
}
else {
$this->redirect(array('action'=>'view/'.$customer['Customer']['id'])); $customers = $this->Customer->find('all', array(
} 'conditions' => array(
} 'Customer.name LIKE' => '%'.$query.'%'
} ),'fields' => array('Customer.name'),
'order' => array('Customer.name ASC')
function tagindustries($id = null) {
if (!$id && empty($this->data)) {
$this->Session->setFlash(__('Invalid Customer', true));
$this->redirect(array('action'=>'index')); ));
}
if(!empty($this->data)) {
if($this->Customer->saveAll($this->data)) { $this->set('customers', $customers);
$this->Session->setFlash(__('The Industry Tags have been Saved to the Customer', true)); $this->layout = 'ajax';
$this->redirect(array('action'=>'view/'.$this->data['Customer']['id'])); }
}
else { function find() {
$this->Session->setFlash(__('Something went wrong saving the Tags. Call for help!', true)); if(!empty($this->data)) {
$this->redirect(array('action'=>'index')); $customer = $this->Customer->findByName($this->data['Customer']['name']);
} if(!$customer) {
} $this->Session->setFlash(__('Could not find the Requested Customer. Please select one from the drop down box as you type.', true));
else { }
$this->set('industries', $this->Customer->Industry->find('list', array('fields'=>array('Industry.id', 'Industry.name', 'ParentIndustry.name'),'recursive' => 0, else {
'order'=>'ParentIndustry.name ASC, Industry.name ASC'))); $this->redirect(array('action'=>'view/'.$customer['Customer']['id']));
$this->data = $this->Customer->read(null, $id); }
} }
} }
function tagindustries($id = null) {
if (!$id && empty($this->data)) {
$this->Session->setFlash(__('Invalid Customer', true));
$this->redirect(array('action'=>'index'));
}
if(!empty($this->data)) {
if($this->Customer->saveAll($this->data)) {
$this->Session->setFlash(__('The Industry Tags have been Saved to the Customer', true));
$this->redirect(array('action'=>'view/'.$this->data['Customer']['id']));
}
else {
$this->Session->setFlash(__('Something went wrong saving the Tags. Call for help!', true));
$this->redirect(array('action'=>'index'));
}
}
else {
$this->set('industries', $this->Customer->Industry->find('list', array('fields'=>array('Industry.id', 'Industry.name', 'ParentIndustry.name'),'recursive' => 0,
'order'=>'ParentIndustry.name ASC, Industry.name ASC')));
$this->data = $this->Customer->read(null, $id);
}
}
} }
?> ?>

View file

@ -8,8 +8,7 @@
<?php <?php
echo $form->input('name', array('id'=>'customerName')); echo $form->input('name', array('id'=>'customerName'));
echo "<br><br><span class=\"warning\">If the Customer you are adding appears automatically, it already exists in the ".$html->link('Customers Index', array('action' => 'index')). "<br>Do Not Add Duplicates.</span>";
echo $form->input('country_name', array('default'=>'Australia')); echo $form->input('country_name', array('default'=>'Australia'));
echo $form->input('country_id', array('type'=>'hidden', 'value'=>1)); echo $form->input('country_id', array('type'=>'hidden', 'value'=>1));
@ -44,3 +43,9 @@
</ul> </ul>
</div> </div>
<div id="dialog" title="Is this customer already in the database?">
<p>Please confirm the customer you are adding is not one of these customers:</p>
<ul id="similarCustList">
</ul>
</div>

View file

@ -0,0 +1,8 @@
<?
foreach ($customers as $customer) {
echo "<li>";
echo $html->link($customer['Customer']['name'],array('controller'=>'customers', 'action'=>'view',$customer['Customer']['id']));
echo "</li>";
}
?>

View file

@ -23,6 +23,7 @@
echo $javascript->link('jquery-ui'); echo $javascript->link('jquery-ui');
echo $javascript->link('jquery.form'); echo $javascript->link('jquery.form');
echo $javascript->link('menu');
echo $scripts_for_layout; echo $scripts_for_layout;
@ -50,59 +51,58 @@
?> ?>
</div> </div>
<div id = "nav"> <div id = "navdiv">
<ul id="nav"> <ul id="nav">
<li><h3><?php echo $html->link('Enquiries', '/enquiries/index'); ?></h3> <li><?php echo $html->link('Enquiries', '/enquiries/index'); ?><ul>
<ul> <li class="last"><?php echo $html->link('Enquiry Register', '/enquiries/index'); ?></li>
<li><?php echo $html->link('Enquiry Register', '/enquiries/index'); ?></li>
</ul> </ul>
</li> </li>
<li><h3><?php echo $html->link('Customers', '/customers/index'); ?></h3> <li><?php echo $html->link('Customers', '/customers/index'); ?>
<ul> <ul>
<li><?php echo $html->link('Customer Index', '/customers/index'); ?></li> <li><?php echo $html->link('Customer Index', '/customers/index'); ?></li>
<li><?php echo $html->link('Find Customer', '/customers/find'); ?></li> <li><?php echo $html->link('Find Customer', '/customers/find'); ?></li>
<li><?php echo $html->link('Add Customer', '/customers/add'); ?></li> <li><?php echo $html->link('Add Customer', '/customers/add'); ?></li>
<li><?php echo $html->link('Industries', '/industries/index'); ?></li> <li class="last"><?php echo $html->link('Industries', '/industries/index'); ?></li>
</ul> </ul>
</li> </li>
<li><h3><?php echo $html->link('Contacts', '/contacts/index'); ?></h3> <li><?php echo $html->link('Contacts', '/contacts/index'); ?>
<ul> <ul>
<li><?php echo $html->link('Contact Index', '/contacts/index'); ?></li> <li><?php echo $html->link('Contact Index', '/contacts/index'); ?></li>
</ul> </ul>
</li> </li>
<li><h3><?php echo $html->link('Products', '/products/index'); ?></h3> <li><?php echo $html->link('Products', '/products/index'); ?>
<ul> <ul>
<li><?php echo $html->link('Product Index', '/products/index'); ?></li> <li><?php echo $html->link('Product Index', '/products/index'); ?></li>
<li><?php echo $html->link('Add Product', '/products/add'); ?></li> <li class="last"><?php echo $html->link('Add Product', '/products/add'); ?></li>
</ul> </ul>
</li> </li>
<li><h3><?php echo $html->link('Quotes', '/quotes/index'); ?></h3> <li><?php echo $html->link('Quotes', '/quotes/index'); ?>
<ul> <ul>
<li><?php echo $html->link('Quote Index', '/quotes/index'); ?></li> <li><?php echo $html->link('Quote Index', '/quotes/index'); ?></li>
<li><?php echo $html->link('Find Quote', '/quotes/find'); ?></li> <li class="last"><?php echo $html->link('Find Quote', '/quotes/find'); ?></li>
</ul> </ul>
</li> </li>
<li><h3><?php echo $html->link('Principles', '/principles/index'); ?></h3> <li><?php echo $html->link('Principles', '/principles/index'); ?>
<ul> <ul>
<li><?php echo $html->link('Principle Index', '/principles/index'); ?></li> <li><?php echo $html->link('Principle Index', '/principles/index'); ?></li>
<li><?php echo $html->link('Add Principle', '/principles/add'); ?></li> <li class="last"><?php echo $html->link('Add Principle', '/principles/add'); ?></li>
</ul> </ul>
</li> </li>
<li><h3><?php echo $html->link('Users', '/users/index'); ?></h3> <li><?php echo $html->link('Users', '/users/index'); ?>
<ul> <ul>
<li><?php echo $html->link('Users Index', '/users/index'); ?></li> <li><?php echo $html->link('Users Index', '/users/index'); ?></li>
<li><?php echo $html->link('Add User', '/users/add'); ?></li> <li class="last"><?php echo $html->link('Add User', '/users/add'); ?></li>
</ul> </ul>
</li> </li>
<li><h3><?php echo $html->link('Help', '/pages/help'); ?></h3> <li><?php echo $html->link('Help', '/pages/help'); ?>
<ul> <ul>
<li><?php echo $html->link('About', '/pages/about'); ?></li> <li class="last"><?php echo $html->link('About', '/pages/about'); ?></li>
</ul> </ul>
</li> </li>
@ -110,7 +110,7 @@
</ul> </ul>
</div> </div>
</div> </div>
<div id="content"> <div id="content">
<?php <?php

View file

View file

@ -135,7 +135,8 @@ ul.principle-emails {
#header{ #header{
/* background: #E9E9E9 url(../img/top-gradient2.png) repeat-x bottom; */ /* background: #E9E9E9 url(../img/top-gradient2.png) repeat-x bottom; */
background: #7bf47b url(../img/gradient-blue4.png) repeat-x bottom; /* background: #4686c3 url(../img/gradient-blue4.png) repeat-x bottom; */
background: #4686c3;
/* background: #6BBA70; */ /* background: #6BBA70; */
padding-bottom: 2%; padding-bottom: 2%;
} }
@ -176,81 +177,95 @@ ul.principle-emails {
color: #FFFFFF; color: #FFFFFF;
} }
/* nav CSS based on http://www.queness.com/post/1047/easy-to-style-jquery-drop-down-menu-tutorial */
#nav { #nav {
width: 100%; width: 100%;
margin:0;
padding:0;
list-style:none;
} }
#nav h3 { /* make the LI display inline */
font-size: 120%; /* it's position relative so that position absolute */
font-weight: bold; /* can be used in submenu */
color:#FFFFFF; #nav li {
/* background: #E9E9E9; */ float:left;
padding-left: 0.1em; display:block;
padding-top: 0; width:120px;
padding-right: 0; padding-right: 1em;
padding-bottom: 0; position:relative;
z-index:500;
margin:0 1px;
background: #4686c3;
} }
#nav h3 a{ /* this is the parent menu */
font-size: 160%; #nav li a {
font-weight: normal; display:block;
color:#FFFFFF; width: 120px;
width: 100%; padding:8px 5px 0 5px;
/* background: #E9E9E9; */ height:23px;
text-decoration:none; text-decoration:none;
color:#fff;
text-align:center;
} }
#nav h3 a:hover { #nav li a:hover {
/* background: #E9E9E9; */ color:#fff;
} }
#nav, #nav ul { /* all lists */ /* you can make a different style for default selected value */
padding: 0; #nav a.selected {
margin: 0; color:#f00;
list-style: none;
line-height: 1;
} }
#nav a { /* submenu, it's hidden by default */
padding-left: 0.5em; #nav ul {
padding-bottom:0.5em; position:absolute;
display: block; left:0;
width: 10em; display:none;
margin:0 0 0 -1px;
padding:0;
list-style:none;
} }
#nav a:hover { #nav ul li {
float:left;
border-top:1px solid #000;
border-left:1px solid #000;
border-right:1px solid #000;
/* border: 1px solid #000;*/
} }
#nav li { /* all list items */ /* used in the nav. so the borders are clean and 1px without doubling up */
float: left; li .last {
width: 8em; /* width needed or else Opera goes nuts */ border-bottom:1px solid #000;
}
}
#nav li ul { /* second-level lists */
position: absolute;
width: 10em;
left: -999em; /* using left instead of display to hide menus because display: none it read by screen readers */
}
#nav li:hover ul, #nav li.sfhover ul { /* lists nested under hovered list items */
left: auto;
}
#nav li ul a {
background: #4687c3;
color: #FFFFFF;
}
#nav li ul a:hover {
background:#5d9cd7;
/* display block will make the link fill the whole area of LI */
#nav ul a {
display:block;
height: auto;
padding: 8px 5px;
font-size: 80%;
}
#nav ul a:hover {
text-decoration:underline;
}
/*used for the jquery menu */
.clear {
padding: 0;
margin: 0;
clear: both;
} }
/* END NAV */
#content{ #content{
background: #fff; background: #fff;
@ -1023,7 +1038,7 @@ div.tipbox {
li.selected { background-color: #ffb; } li.selected { background-color: #ffb; }
span { span {
color: #2F782A;
font-weight: bold; font-weight: bold;
font-size: 100%; font-size: 100%;
} }

View file

@ -9,20 +9,25 @@
$(function() { $(function() {
$("#dialog").hide();
$("#customerName").change(function () {
$("#dialog").dialog('close'); //Remove any previously opened dialogs
$("#customerName").autocomplete({
$.post("/customers/similarCustomers", $("#customerName").serialize(), function(data) {
source: "/customers/completeCustomer", $("#similarCustList").html(data);
minLength: 1 });
});
$("#dialog").dialog({position: 'right', width: 400});
}),
$("#CustomerCountryName").autocomplete({ $("#CustomerCountryName").autocomplete({
source: "/countries/completeCountry", source: "/countries/completeCountry",
minLength: 2, minLength: 3,
select: function(event, ui) { select: function(event, ui) {
//alert("You selected " + ui.item.value + " ID:"+ ui.item.id); //alert("You selected " + ui.item.value + " ID:"+ ui.item.id);
$("#CustomerCountryId").val(ui.item.id); $("#CustomerCountryId").val(ui.item.id);

View file

@ -0,0 +1,73 @@
/* This file isn't currently in use. Should complete / fix this up at some point.*/
$(function() {
$('#$enqid').editable('/enquiries/update_status', {
id : 'data[Enquiry][id]',
name: 'data[Enquiry][status_id]',
data : '$jsonList',
type : 'select',
indicator : 'Saving...',
submit : 'Update Status',
cssclass: 'MER-inplace-select',
callback : function(value, settings) {
var match = /won/i.test(value);
if(match == true) {
$('#row$enqid').removeClass().addClass('jobwon');
return;
}
match = /lost/i.test(value);
if(match == true) {
$('#row$enqid').removeClass().addClass('joblost');
return;
}
match = /cancelled/i.test(value);
if(match == true) {
$('#row$enqid').removeClass().addClass('joblost');
return;
}
match = /information sent/i.test(value);
if(match == true) {
$('#row$enqid').removeClass().addClass('informationsent');
return;
}
match = /issued/i.test(value);
if(match == true) {
$('#row$enqid').removeClass().addClass('quoted');
return;
}
match = /request for quotation/i.test(value);
if(match == true) {
$('#row$enqid').removeClass().addClass('requestforquote');
return;
}
match = /assigned/i.test(value);
if(match == true) {
$('#row$enqid').removeClass();
return;
}
}
});
}
function makeEditable(selectedID) {
}

10
webroot/js/menu.js Normal file
View file

@ -0,0 +1,10 @@
$(function() {
$('#nav li').hover(
function() {
$('ul', this).slideDown(100); //show submenu
},
function() {
$('ul', this).slideUp(100); //hide submenu
})
});