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
class CustomersController extends AppController {
var $name = 'Customers';
var $helpers = array('Html', 'Form', 'Time', 'Ajax');
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']);
var $name = 'Customers';
var $helpers = array('Html', 'Form', 'Time', 'Ajax');
var $components = array('RequestHandler');
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'))));
}
var $paginate = array(
'Customer' => array('order' => array('Customer.name' => 'asc'),
'limit' => 200
),
'Enquiry' => array('order' => array('Enquiry.id' => 'desc'))
);
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)) {
/* 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')));
}
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')));
}
/* Autocomplete the customer name - Used in: add.ctp */
function completeCustomer() {
$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')) ) {
$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"]);
//$this->set('customers_json', print_r($this->data));
if($query == null) {
return;
}
@ -113,12 +115,12 @@ class CustomersController extends AppController {
App::import('Core', 'Sanitize');
$query = Sanitize::clean($query);
$customers = $this->Customer->find('all', array(
'conditions' => array(
'Customer.name LIKE' => '%'.$query.'%'
),'fields' => array('Customer.name'),
'order' => array('Customer.name ASC')
'conditions' => array(
'Customer.name LIKE' => '%'.$query.'%'
),'fields' => array('Customer.name'),
'order' => array('Customer.name ASC')
@ -129,55 +131,77 @@ class CustomersController extends AppController {
$custid = $customer['Customer']['id'];
$cust_list[] = array('id'=> $custid, 'label' => $customer['Customer']['name']);
}
$customers_json = json_encode($cust_list);
$this->set('customers_json', $customers_json);
$this->set('customers_json', $customers_json);
$this->layout = 'ajax';
}
function find() {
if(!empty($this->data)) {
$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->redirect(array('action'=>'view/'.$customer['Customer']['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);
}
}
}
function similarCustomers() {
App::import('Core', 'Sanitize');
$query = Sanitize::clean($this->data['Customer']['name']);
$customers = $this->Customer->find('all', array(
'conditions' => array(
'Customer.name LIKE' => '%'.$query.'%'
),'fields' => array('Customer.name'),
'order' => array('Customer.name ASC')
));
$this->set('customers', $customers);
$this->layout = 'ajax';
}
function find() {
if(!empty($this->data)) {
$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->redirect(array('action'=>'view/'.$customer['Customer']['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
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_id', array('type'=>'hidden', 'value'=>1));
@ -44,3 +43,9 @@
</ul>
</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.form');
echo $javascript->link('menu');
echo $scripts_for_layout;
@ -50,59 +51,58 @@
?>
</div>
<div id = "nav">
<div id = "navdiv">
<ul id="nav">
<li><h3><?php echo $html->link('Enquiries', '/enquiries/index'); ?></h3>
<ul>
<li><?php echo $html->link('Enquiry Register', '/enquiries/index'); ?></li>
<li><?php echo $html->link('Enquiries', '/enquiries/index'); ?><ul>
<li class="last"><?php echo $html->link('Enquiry Register', '/enquiries/index'); ?></li>
</ul>
</li>
<li><h3><?php echo $html->link('Customers', '/customers/index'); ?></h3>
<li><?php echo $html->link('Customers', '/customers/index'); ?>
<ul>
<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('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>
</li>
<li><h3><?php echo $html->link('Contacts', '/contacts/index'); ?></h3>
<li><?php echo $html->link('Contacts', '/contacts/index'); ?>
<ul>
<li><?php echo $html->link('Contact Index', '/contacts/index'); ?></li>
</ul>
</li>
<li><h3><?php echo $html->link('Products', '/products/index'); ?></h3>
<li><?php echo $html->link('Products', '/products/index'); ?>
<ul>
<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>
</li>
<li><h3><?php echo $html->link('Quotes', '/quotes/index'); ?></h3>
<li><?php echo $html->link('Quotes', '/quotes/index'); ?>
<ul>
<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>
</li>
<li><h3><?php echo $html->link('Principles', '/principles/index'); ?></h3>
<li><?php echo $html->link('Principles', '/principles/index'); ?>
<ul>
<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>
</li>
<li><h3><?php echo $html->link('Users', '/users/index'); ?></h3>
<li><?php echo $html->link('Users', '/users/index'); ?>
<ul>
<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>
</li>
<li><h3><?php echo $html->link('Help', '/pages/help'); ?></h3>
<li><?php echo $html->link('Help', '/pages/help'); ?>
<ul>
<li><?php echo $html->link('About', '/pages/about'); ?></li>
<li class="last"><?php echo $html->link('About', '/pages/about'); ?></li>
</ul>
</li>
@ -110,7 +110,7 @@
</ul>
</div>
</div>
<div id="content">
<?php

View file

View file

@ -135,7 +135,8 @@ ul.principle-emails {
#header{
/* 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; */
padding-bottom: 2%;
}
@ -176,81 +177,95 @@ ul.principle-emails {
color: #FFFFFF;
}
/* nav CSS based on http://www.queness.com/post/1047/easy-to-style-jquery-drop-down-menu-tutorial */
#nav {
width: 100%;
margin:0;
padding:0;
list-style:none;
}
#nav h3 {
font-size: 120%;
font-weight: bold;
color:#FFFFFF;
/* background: #E9E9E9; */
padding-left: 0.1em;
padding-top: 0;
padding-right: 0;
padding-bottom: 0;
/* make the LI display inline */
/* it's position relative so that position absolute */
/* can be used in submenu */
#nav li {
float:left;
display:block;
width:120px;
padding-right: 1em;
position:relative;
z-index:500;
margin:0 1px;
background: #4686c3;
}
#nav h3 a{
font-size: 160%;
font-weight: normal;
color:#FFFFFF;
width: 100%;
/* background: #E9E9E9; */
/* this is the parent menu */
#nav li a {
display:block;
width: 120px;
padding:8px 5px 0 5px;
height:23px;
text-decoration:none;
color:#fff;
text-align:center;
}
#nav h3 a:hover {
/* background: #E9E9E9; */
#nav li a:hover {
color:#fff;
}
#nav, #nav ul { /* all lists */
padding: 0;
margin: 0;
list-style: none;
line-height: 1;
/* you can make a different style for default selected value */
#nav a.selected {
color:#f00;
}
#nav a {
padding-left: 0.5em;
padding-bottom:0.5em;
display: block;
width: 10em;
/* submenu, it's hidden by default */
#nav ul {
position:absolute;
left:0;
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 */
float: left;
width: 8em; /* width needed or else Opera goes nuts */
}
#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;
/* used in the nav. so the borders are clean and 1px without doubling up */
li .last {
border-bottom:1px solid #000;
}
/* 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{
background: #fff;
@ -1023,7 +1038,7 @@ div.tipbox {
li.selected { background-color: #ffb; }
span {
color: #2F782A;
font-weight: bold;
font-size: 100%;
}

View file

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