diff --git a/.gitignore b/.gitignore index be3f36d1..837bba12 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ tmp/cache/views/* tmp/sessions/* tmp/tests/* *.tar.gz +*.swp +*.swo diff --git a/controllers/customers_controller.php b/controllers/customers_controller.php index 491dc102..28b7cc8a 100755 --- a/controllers/customers_controller.php +++ b/controllers/customers_controller.php @@ -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); + } + } } ?> diff --git a/controllers/industries_controller.php b/controllers/industries_controller.php index b94df0a5..86cf321f 100644 --- a/controllers/industries_controller.php +++ b/controllers/industries_controller.php @@ -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)); } } + + $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); + } + + + - /* Parent Industries have NULL for their parent_id */ - $parents = $this->Industry->find('list', array('conditions' => array( - 'Industry.parent_id' => null))); - $this->set(compact('parents')); } 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) { diff --git a/models/customer.php b/models/customer.php index c8e6bbee..5c0fe723 100755 --- a/models/customer.php +++ b/models/customer.php @@ -3,9 +3,7 @@ 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' ) ); diff --git a/views/customers/edit.ctp b/views/customers/edit.ctp index e528efde..c15a2b62 100755 --- a/views/customers/edit.ctp +++ b/views/customers/edit.ctp @@ -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)); ?> diff --git a/views/customers/view.ctp b/views/customers/view.ctp index 526e2ae9..e7c58c71 100755 --- a/views/customers/view.ctp +++ b/views/customers/view.ctp @@ -56,7 +56,8 @@ } echo ""; endif; - +echo "
"; +echo "
".$html->link("Tag Industries for this Customer", array('action'=>'tagindustries',$customer['Customer']['id']))."
"; ?> diff --git a/views/industries/.add.ctp.swp b/views/industries/.add.ctp.swp index 76746ec8..33195d20 100644 Binary files a/views/industries/.add.ctp.swp and b/views/industries/.add.ctp.swp differ diff --git a/views/industries/.edit.ctp.swo b/views/industries/.edit.ctp.swo deleted file mode 100644 index 76d8b00d..00000000 Binary files a/views/industries/.edit.ctp.swo and /dev/null differ diff --git a/views/industries/add.ctp b/views/industries/add.ctp index 487e9fdb..9c435b75 100644 --- a/views/industries/add.ctp +++ b/views/industries/add.ctp @@ -1,11 +1,27 @@
create('Industry');?>
- + 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'])); +} + +?>
end('Submit');?>
diff --git a/views/industries/edit.ctp b/views/industries/edit.ctp index b39b5b4f..4b06d79f 100644 --- a/views/industries/edit.ctp +++ b/views/industries/edit.ctp @@ -5,8 +5,7 @@ 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'])); ?> end('Submit');?> @@ -22,4 +21,4 @@ -data); ?> + diff --git a/views/industries/index.ctp b/views/industries/index.ctp index b9f26152..75498451 100644 --- a/views/industries/index.ctp +++ b/views/industries/index.ctp @@ -1,56 +1,38 @@

-

-counter(array( -'format' => __('Page %page% of %pages%, showing %current% records out of %count% total, starting on record %start%, ending on %end%', true) -)); -?>

- - - - - - - -element('tipbox', array('tip' => "

Click on the green plus symbol to add new sub-Industries

")); ?> - > - - - - - - -
sort('id');?>sort('name');?>sort('parent_id');?>
- - - - - link($industry['ParentIndustry']['name'], array('controller'=> 'industries', 'action'=>'view', $industry['ParentIndustry']['id'])); ?> - - link(__('View', true), array('action'=>'view', $industry['Industry']['id'])); ?> - link(__('Edit', true), array('action'=>'edit', $industry['Industry']['id'])); ?> - link(__('Delete', true), array('action'=>'delete', $industry['Industry']['id']), null, sprintf(__('Are you sure you want to delete # %s?', true), $industry['Industry']['id'])); ?> -
-
-
- prev('<< '.__('previous', true), array(), null, array('class'=>'disabled'));?> - | numbers();?> - next(__('next', true).' >>', array(), null, array('class'=>'disabled'));?> -
+ +
- +link('Add new Industry', array('action'=>'add')); ?>
+ + + +
+".$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)).""; + echo ""; + + +endforeach; +?> + +
+ + + diff --git a/views/industries/view.ctp b/views/industries/view.ctp index 864bfbae..ae2f82ab 100644 --- a/views/industries/view.ctp +++ b/views/industries/view.ctp @@ -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']); } ?> @@ -44,7 +45,6 @@ link(__('View', true), array('controller'=> 'industries', 'action'=>'view', $subIndustry['id'])); ?> link(__('Edit', true), array('controller'=> 'industries', 'action'=>'edit', $subIndustry['id'])); ?> - link(__('Delete', true), array('controller'=> 'industries', 'action'=>'delete', $subIndustry['id']), null, sprintf(__('Are you sure you want to delete # %s?', true), $subIndustry['id'])); ?> @@ -63,18 +63,13 @@