Customer Industries working ok now - Can fix up GUI later

This commit is contained in:
Karl Cordes 2009-07-07 12:11:10 +10:00
parent 5b1f72489b
commit 1390e62240
10 changed files with 54 additions and 13 deletions

View file

@ -64,7 +64,7 @@ class CustomersController extends AppController {
$this->redirect(array('action'=>'index')); $this->redirect(array('action'=>'index'));
} }
if (!empty($this->data)) { if (!empty($this->data)) {
if ($this->Customer->save($this->data)) { if ($this->Customer->saveAll($this->data)) {
$this->Session->setFlash(__('The Customer has been saved', true)); $this->Session->setFlash(__('The Customer has been saved', true));
$id = $this->Customer->id; $id = $this->Customer->id;
$this->redirect(array('action'=>'view/'.$id)); $this->redirect(array('action'=>'view/'.$id));
@ -75,7 +75,10 @@ class CustomersController extends AppController {
if (empty($this->data)) { if (empty($this->data)) {
$this->data = $this->Customer->read(null, $id); $this->data = $this->Customer->read(null, $id);
$this->set('customer_categories', $this->Customer->CustomerCategory->find('list')); $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 */ /* Autocomplete the customer name - Used in: add.ctp */

View file

@ -4,6 +4,11 @@ class IndustriesController extends AppController {
var $name = 'Industries'; var $name = 'Industries';
var $helpers = array('Html', 'Form'); var $helpers = array('Html', 'Form');
var $paginate = array(
'Industry' => array('order' => array('ParentIndustry.name' => 'asc', 'Industry.name' => 'asc'),
'limit' => 200
));
function index() { function index() {
$this->Industry->recursive = 0; $this->Industry->recursive = 0;
$this->set('industries', $this->paginate()); $this->set('industries', $this->paginate());
@ -27,6 +32,8 @@ class IndustriesController extends AppController {
$this->Session->setFlash(__('The Industry could not be saved. Please, try again.', true)); $this->Session->setFlash(__('The Industry could not be saved. Please, try again.', true));
} }
} }
/* Parent Industries have NULL for their parent_id */
$parents = $this->Industry->find('list', array('conditions' => array( $parents = $this->Industry->find('list', array('conditions' => array(
'Industry.parent_id' => null))); 'Industry.parent_id' => null)));
$this->set(compact('parents')); $this->set(compact('parents'));

View file

@ -76,7 +76,7 @@ class Customer extends AppModel {
'className' => 'Industry', 'className' => 'Industry',
'joinTable' => 'industries_customers', 'joinTable' => 'industries_customers',
'foreignKey' => 'customer_id', 'foreignKey' => 'customer_id',
'associationForeignKey' => 'industry_id' 'associationForeignKey' => 'industry_id',
) )
); );

View file

@ -8,9 +8,8 @@ class Industry extends AppModel {
var $hasAndBelongsToMany = array ( var $hasAndBelongsToMany = array (
'Customer' => array( 'Customer' => array(
'className' => 'Customer', 'className' => 'Customer',
'joinTable' => 'industries_customers' 'joinTable' => 'industries_customers',
// 'foreignKey' => 'industry_id', 'unique' => false
// 'associationForeignKey' => 'customer_id'
) )
); );

View file

@ -13,7 +13,14 @@
echo $form->label('Customer.customer_category_id', 'Customer Category'); echo $form->label('Customer.customer_category_id', 'Customer Category');
echo $form->select('customer_category_id', $customer_categories, $this->data['Customer']['customer_category_id'], array('label'=>'Customer Category'), false); echo $form->select('customer_category_id', $customer_categories, $this->data['Customer']['customer_category_id'], array('label'=>'Customer Category'), false);
echo '</div>'; echo '</div>';
echo $form->input('Industry.Industry', array('multiple'=>'checkbox', 'showParents'=>false, 'options' => $industries));
?> ?>
</fieldset> </fieldset>
<?php echo $form->end('Submit');?> <?php echo $form->end('Submit');?>
</div> </div>
@ -26,3 +33,4 @@
<li><?php echo $html->link(__('New Enquiry', true), array('controller'=> 'enquiries', 'action'=>'add')); ?> </li> <li><?php echo $html->link(__('New Enquiry', true), array('controller'=> 'enquiries', 'action'=>'add')); ?> </li>
</ul> </ul>
</div> </div>

View file

@ -46,6 +46,23 @@
</ul> </ul>
</div> </div>
<div class="related">
<h3><?php __('Industries that this Customer has been tagged in'); ?></h3>
<?php if(!empty($customer['Industry'])): ?>
<ul id="industrytaglist">
<?php foreach ($customer['Industry'] as $industry) {
echo "<li>".$html->link(__($industry['name'],true), array('action'=>'view', 'controller'=>'industries', $industry['id']))."</li>";
}
echo "</ul>";
endif;
?>
</div>
<div class="related"> <div class="related">
<h3><?php __('Contacts');?><?php echo $html->image('system-users.png'); ?></h3> <h3><?php __('Contacts');?><?php echo $html->image('system-users.png'); ?></h3>
<div class="actions"> <div class="actions">
@ -92,9 +109,6 @@
<?php endforeach; ?> <?php endforeach; ?>
</table> </table>
<?php endif; ?> <?php endif; ?>
</div> </div>

Binary file not shown.

Binary file not shown.

View file

@ -4,7 +4,7 @@
<legend><?php __('Add Industry');?></legend> <legend><?php __('Add Industry');?></legend>
<?php <?php
echo $form->input('name'); echo $form->input('name');
echo $form->input('parent_id'); echo $form->input('parent_id', array('empty' => 'None'));
?> ?>
</fieldset> </fieldset>
<?php echo $form->end('Submit');?> <?php echo $form->end('Submit');?>
@ -18,3 +18,4 @@
<li><?php echo $html->link(__('New Customer', true), array('controller'=> 'customers', 'action'=>'add')); ?> </li> <li><?php echo $html->link(__('New Customer', true), array('controller'=> 'customers', 'action'=>'add')); ?> </li>
</ul> </ul>
</div> </div>

View file

@ -106,6 +106,12 @@ ul.principle-emails {
} }
#industrytaglist li {
display: inline;
list-style-type: none;
font-size: 120%;
}
/* Layout */ /* Layout */
#container { #container {
text-align: left; text-align: left;
@ -667,6 +673,9 @@ input[type=checkbox] {
margin: 0px 6px 7px 2px; margin: 0px 6px 7px 2px;
width: auto; width: auto;
} }
input[type=radio] { input[type=radio] {
clear: left; clear: left;
float: left; float: left;