From 90eb9023f2a44034d1d1f4605f7373bc6932c668 Mon Sep 17 00:00:00 2001 From: Karl Cordes Date: Thu, 9 Jul 2009 17:09:59 +1000 Subject: [PATCH] Added Industry tagging and GUI --- .gitignore | 2 + controllers/customers_controller.php | 27 ++++++++- controllers/industries_controller.php | 48 +++++++++++---- models/customer.php | 4 +- views/customers/edit.ctp | 2 +- views/customers/view.ctp | 3 +- views/industries/.add.ctp.swp | Bin 12288 -> 12288 bytes views/industries/.edit.ctp.swo | Bin 12288 -> 0 bytes views/industries/add.ctp | 22 ++++++- views/industries/edit.ctp | 5 +- views/industries/index.ctp | 84 ++++++++++---------------- views/industries/view.ctp | 19 ++---- views/layouts/default.ctp | 1 + webroot/css/quotenik.css | 21 +++++++ 14 files changed, 146 insertions(+), 92 deletions(-) delete mode 100644 views/industries/.edit.ctp.swo 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 76746ec81947eefa450f32b189f0dbd8590978c2..33195d201c8255b77d0631d7eba3e41511a5d70f 100644 GIT binary patch delta 550 zcmaLT&nts*90%~v#9?OUW*2Mpanc0y zuNu7()y$eq6KOl+?>19;VOUa_sY==EJ*{g{6{6)*n=B1lMN{yo!m~L|69(^Pd?BUV zg0rZ?zWd^Q#L(=5l`rx{oaZ#2kfbmPy&%|PWlHG3DZ#Jm+_b+lS11Up7DhsIX;SvB zs7gfEMMfB!Ld)b#CjER+(^$+-_f_{YYi@w?z^{3X)T}_FTA-gZs{Q=W1myHMBj4LA JUsgJkW1nh6iyQy| delta 351 zcmZojXh={vI28P7WATQTr;tbu&3=G+cML81}s%&&Q!OtkVnOERD ze?2b`14AhggOrK_sYm<_47-4M9T3+6aXAo20kIqqO9C+u5WnODssrLPKzs~{vw-+L zF9Smn5dQ?4)dIw|KwJjIAhUabxE+YwfH(|@b$}QOHgmD8Yh-RdTg|MULszV44d1umol+%a@yNXHqg@)PR%VSsZ>|6wNp^{ z%g;+y*VMEIii=Ga(C61z;N-N)Nlj19OR=-DFUTlRh>zD$cT7o9fZL~OZEt6z4^=aH Ht$r{7dUsG2 diff --git a/views/industries/.edit.ctp.swo b/views/industries/.edit.ctp.swo deleted file mode 100644 index 76d8b00d5377eb136292df47081b3f8a54cbfc24..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI2zi-n(6vwX&NCgTA286_Lv_*ELByP$;rMiv~KcoUhNC*~&>S|w_Q!lo;JI7=| zNU*`g|G>n+AHc)}e*pghBN8(MNbt@!O{CJML`=~;=_@DaclYjn?!6^>TT2huH|UjS zi@-Qd$ja@FTQ@(RBd-<+*2V`Ygc@gK-+O(gygbjn$5~={EOuJWWsjw)*B3n3 zo`|DN8zs2*cqB|SH0fb>MH?i51jZ7`OsBCjM=me7mKNqO(z9nCj9r2TNB{{S0VIF~ zkN^@u0!RP}Ocw!@&X8Xa(h<;k&`c$G;6MUM00|%gB!C2v01`j~NB{{S0VIF~ri1{C z2>Eu55Plp2g8%>RZvbCT5%M1N4)he%2R#A>pbMZMCkgou`U?64`T%+hdIS1AM@SC( zd4iBAwas>~&30>@(o@@kC#5?Zhrt940IlTsrvPq9C zr%sK^c&$#EQf%NlVG2@AQt)X4k9T zZ4$T8;LD%7~_CmWV-d3+-}hy;t~f8D zw%GYL9JMNVTi-XJ_kEb__UJ&NG=dn0A?yt~RGgWSdn)4| 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(__('New Industry', true), array('action'=>'add')); ?>
  • -
  • link(__('List Industries', true), array('controller'=> 'industries', 'action'=>'index')); ?>
  • -
  • link(__('New Parent Industry', true), array('controller'=> 'industries', 'action'=>'add')); ?>
  • -
  • link(__('List Customers', true), array('controller'=> 'customers', 'action'=>'index')); ?>
  • -
  • link(__('New Customer', true), array('controller'=> 'customers', 'action'=>'add')); ?>
  • -
+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 "
    "; + foreach ($industries as $industry) { + if($industry['Industry']['parent_id'] == $parent['id']) { + echo "
  • ".$html->link($industry['Industry']['name'], array('action'=>'view', $industry['Industry']['id']))."
  • "; + } + } + 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 @@