Added Industry tagging and GUI

This commit is contained in:
Karl Cordes 2009-07-09 17:09:59 +10:00
parent b09ed0140d
commit 90eb9023f2
14 changed files with 146 additions and 92 deletions

2
.gitignore vendored
View file

@ -5,3 +5,5 @@ tmp/cache/views/*
tmp/sessions/*
tmp/tests/*
*.tar.gz
*.swp
*.swo

View file

@ -4,6 +4,8 @@ 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
@ -59,10 +61,12 @@ class CustomersController extends AppController {
function edit($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 Customer has been saved', true));
@ -103,9 +107,28 @@ class CustomersController extends AppController {
$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

@ -11,7 +11,19 @@ class IndustriesController extends AppController {
function index() {
$this->Industry->recursive = 0;
$industries = $this->Industry->find('all', array('order'=>'Industry.name ASC'));
$this->set('industries', $this->paginate());
foreach ($industries as $industry) {
if(!$industry['Industry']['parent_id']) {
$parents[] = $industry['Industry'];
}
}
$this->set('parents', $parents);
}
function view($id = null) {
@ -24,19 +36,36 @@ class IndustriesController extends AppController {
function add() {
if (!empty($this->data)) {
$this->Industry->create();
if ($this->Industry->save($this->data)) {
$this->Session->setFlash(__('The Industry has been saved', true));
$newid = $this->Industry->id;
$new_industry = $this->Industry->findById($newid);
if($new_industry['Industry']['parent_id'] == 0) {
$this->Industry->create();
$this->data['Industry']['parent_id'] = $newid;
$this->data['Industry']['name'] = $new_industry['Industry']['name']." - General";
$this->Industry->save($this->data);
}
$this->Session->setFlash(__('The Industry has been saved', true));
$this->redirect(array('action'=>'index'));
} else {
$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(
'Industry.parent_id' => null)));
$this->set(compact('parents'));
$this->Industry->create();
if(isset($this->params['named']['parentid'])) {
$parent = $this->Industry->find('first', array('conditions' => array('Industry.id' => $this->params['named']['parentid']),
'fields' => 'Industry.id, Industry.name', 'recursive' => 0));
$this->set('parent', $parent);
}
}
function edit($id = null) {
@ -55,13 +84,6 @@ class IndustriesController extends AppController {
if (empty($this->data)) {
$this->data = $this->Industry->read(null, $id);
}
$parents = $this->Industry->find('list', array('conditions' => array(
'Industry.parent_id' => null,
'NOT' => array(
'Industry.id' => $this->data['Industry']['id']
))));
$customers = $this->Industry->Customer->find('list');
$this->set(compact('customers', 'parents'));
}
function delete($id = null) {

View file

@ -4,8 +4,6 @@ class Customer extends AppModel {
var $name = 'Customer';
var $validate = array(
'name' => array(
'rule' => 'isUnique',
@ -76,7 +74,7 @@ class Customer extends AppModel {
'className' => 'Industry',
'joinTable' => 'industries_customers',
'foreignKey' => 'customer_id',
'associationForeignKey' => 'industry_id',
'associationForeignKey' => 'industry_id'
)
);

View file

@ -16,7 +16,7 @@
echo $form->input('Industry.Industry', array('multiple'=>'checkbox', 'showParents'=>false, 'options' => $industries));
echo $form->input('Industry.Industry', array('multiple'=>'checkbox', 'showParents'=> false, 'options' => $industries));
?>

View file

@ -56,7 +56,8 @@
}
echo "</ul>";
endif;
echo "<br>";
echo "<div class=\"actions\">".$html->link("Tag Industries for this Customer", array('action'=>'tagindustries',$customer['Customer']['id']))."</div>";
?>

Binary file not shown.

Binary file not shown.

View file

@ -1,11 +1,27 @@
<div class="industries form">
<?php echo $form->create('Industry');?>
<fieldset>
<legend><?php __('Add Industry');?></legend>
<legend><?php
if(!isset($parent)) {
__('Add Industry');
}
else {
__('Add Sub-Industry to: '.$parent['Industry']['name']);
}
?></legend>
<?php
echo $form->input('name');
echo $form->input('parent_id', array('empty' => 'None'));
?>
if(!isset($parent)) {
echo $form->input('parent_id', array('type'=>'hidden', 'value' => 0));
}
else {
echo $form->input('parent_id', array('type'=>'hidden', 'value' => $parent['Industry']['id']));
}
?>
</fieldset>
<?php echo $form->end('Submit');?>
</div>

View file

@ -5,8 +5,7 @@
<?php
echo $form->input('id');
echo $form->input('name');
echo $form->input('parent_id');
echo $form->input('Customer');
echo $form->input('parent_id', array('type'=>'hidden', 'value' => $this->data['Industry']['parent_id']));
?>
</fieldset>
<?php echo $form->end('Submit');?>
@ -22,4 +21,4 @@
</ul>
</div>
<?php debug($this->data); ?>

View file

@ -1,56 +1,38 @@
<div class="industries index">
<h2><?php __('Industries');?></h2>
<p>
<?php
echo $paginator->counter(array(
'format' => __('Page %page% of %pages%, showing %current% records out of %count% total, starting on record %start%, ending on %end%', true)
));
?></p>
<table cellpadding="0" cellspacing="0">
<tr>
<th><?php echo $paginator->sort('id');?></th>
<th><?php echo $paginator->sort('name');?></th>
<th><?php echo $paginator->sort('parent_id');?></th>
<th class="actions"><?php __('Actions');?></th>
</tr>
<?php
$i = 0;
foreach ($industries as $industry):
$class = null;
if ($i++ % 2 == 0) {
$class = ' class="altrow"';
}
<?php echo $this->element('tipbox', array('tip' => "<p>Click on the green plus symbol to add new sub-Industries</p>"));
?>
<tr<?php echo $class;?>>
<td>
<?php echo $industry['Industry']['id']; ?>
</td>
<td>
<?php echo $industry['Industry']['name']; ?>
</td>
<td>
<?php echo $html->link($industry['ParentIndustry']['name'], array('controller'=> 'industries', 'action'=>'view', $industry['ParentIndustry']['id'])); ?>
</td>
<td class="actions">
<?php echo $html->link(__('View', true), array('action'=>'view', $industry['Industry']['id'])); ?>
<?php echo $html->link(__('Edit', true), array('action'=>'edit', $industry['Industry']['id'])); ?>
<?php echo $html->link(__('Delete', true), array('action'=>'delete', $industry['Industry']['id']), null, sprintf(__('Are you sure you want to delete # %s?', true), $industry['Industry']['id'])); ?>
</td>
</tr>
<?php endforeach; ?>
</table>
</div>
<div class="paging">
<?php echo $paginator->prev('<< '.__('previous', true), array(), null, array('class'=>'disabled'));?>
| <?php echo $paginator->numbers();?>
<?php echo $paginator->next(__('next', true).' >>', array(), null, array('class'=>'disabled'));?>
</div>
<div class="actions">
<ul>
<li><?php echo $html->link(__('New Industry', true), array('action'=>'add')); ?></li>
<li><?php echo $html->link(__('List Industries', true), array('controller'=> 'industries', 'action'=>'index')); ?> </li>
<li><?php echo $html->link(__('New Parent Industry', true), array('controller'=> 'industries', 'action'=>'add')); ?> </li>
<li><?php echo $html->link(__('List Customers', true), array('controller'=> 'customers', 'action'=>'index')); ?> </li>
<li><?php echo $html->link(__('New Customer', true), array('controller'=> 'customers', 'action'=>'add')); ?> </li>
</ul>
<?php
echo $html->link('Add new Industry', array('action'=>'add')); ?>
</div>
<div class="categorylist">
<?
foreach ($parents as $parent):
echo "<h3>".$html->link($parent['name'], array('action'=>'view', $parent['id'])).
$html->link(
$html->image("edit_add.png"),
array('action'=>'add', 'parentid:'.$parent['id']), array('escape'=>false))."</h3>";
echo "<ul>";
foreach ($industries as $industry) {
if($industry['Industry']['parent_id'] == $parent['id']) {
echo "<li>".$html->link($industry['Industry']['name'], array('action'=>'view', $industry['Industry']['id']))."</li>";
}
}
echo "</ul>";
endforeach;
?>
</div>
</div>

View file

@ -3,11 +3,12 @@
if($industry['ParentIndustry']['name']) {
__('Industry: '.$html->link($industry['ParentIndustry']['name'], array('controller'=> 'industries', 'action'=>'view', $industry['ParentIndustry']['id']))
__($html->link('Industry', array('action' => 'index')).": ".$html->link($industry['ParentIndustry']['name'],
array('controller'=> 'industries', 'action'=>'view', $industry['ParentIndustry']['id']))
.': '.$industry['Industry']['name']); }
else {
__('Industry: '.$industry['Industry']['name']);
__($html->link('Industry', array('action' => 'index')).": ".$industry['Industry']['name']);
}
?></h2>
@ -44,7 +45,6 @@
<td class="actions">
<?php echo $html->link(__('View', true), array('controller'=> 'industries', 'action'=>'view', $subIndustry['id'])); ?>
<?php echo $html->link(__('Edit', true), array('controller'=> 'industries', 'action'=>'edit', $subIndustry['id'])); ?>
<?php echo $html->link(__('Delete', true), array('controller'=> 'industries', 'action'=>'delete', $subIndustry['id']), null, sprintf(__('Are you sure you want to delete # %s?', true), $subIndustry['id'])); ?>
</td>
</tr>
<?php endforeach; ?>
@ -63,18 +63,13 @@
<div class="related">
<h3><?php __('Related Customers');?></h3>
<h3><?php __('Customers in this Industry');?></h3>
<?php if (!empty($industry['Customer'])):?>
<table cellpadding = "0" cellspacing = "0">
<tr>
<th><?php __('Id'); ?></th>
<th><?php __('Name'); ?></th>
<th><?php __('Abn'); ?></th>
<th><?php __('Created'); ?></th>
<th><?php __('Notes'); ?></th>
<th><?php __('Payment Terms'); ?></th>
<th><?php __('Discount Pricing Policies'); ?></th>
<th><?php __('Customer Category Id'); ?></th>
<th class="actions"><?php __('Actions');?></th>
</tr>
<?php
@ -86,18 +81,12 @@
}
?>
<tr<?php echo $class;?>>
<td><?php echo $customer['id'];?></td>
<td><?php echo $customer['name'];?></td>
<td><?php echo $customer['abn'];?></td>
<td><?php echo $customer['created'];?></td>
<td><?php echo $customer['notes'];?></td>
<td><?php echo $customer['payment_terms'];?></td>
<td><?php echo $customer['discount_pricing_policies'];?></td>
<td><?php echo $customer['customer_category_id'];?></td>
<td class="actions">
<?php echo $html->link(__('View', true), array('controller'=> 'customers', 'action'=>'view', $customer['id'])); ?>
<?php echo $html->link(__('Edit', true), array('controller'=> 'customers', 'action'=>'edit', $customer['id'])); ?>
<?php echo $html->link(__('Delete', true), array('controller'=> 'customers', 'action'=>'delete', $customer['id']), null, sprintf(__('Are you sure you want to delete # %s?', true), $customer['id'])); ?>
</td>
</tr>
<?php endforeach; ?>

View file

@ -91,6 +91,7 @@ if (window.attachEvent) window.attachEvent("onload", sfHover);
<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>
</ul>
</li>

View file

@ -307,6 +307,7 @@ padding: 0;
margin: 0;
}
/* Tables */
table {
background: #fff;
@ -974,3 +975,23 @@ div#qTip {
position: absolute;
z-index: 1000;
}
div.categorylist {
padding-left: 0.5em;
}
div.categorylist h3 {
padding-top: 0.4em;
}
div.categorylist h3 a{
color: #4CA5C1;
text-decoration: none;
padding-right: 0.5em;
}
div.categorylist h3 a:hover {
text-decoration: underline;
}