From 3065fd1daa595e4931d243c4f00203270f7ae7ed Mon Sep 17 00:00:00 2001 From: Karl Cordes Date: Tue, 19 Apr 2011 16:04:40 +1000 Subject: [PATCH] ajax_add Job added --- controllers/jobs_controller.php | 39 ++++++++++++++++++++++++++++++++- views/enquiries/view.ctp | 3 ++- views/jobs/ajax_add.ctp | 0 views/layouts/default.ctp | 7 ++++++ webroot/js/add_job.js | 20 +++++++++++++++++ webroot/js/addjob.js | 35 ----------------------------- 6 files changed, 67 insertions(+), 37 deletions(-) create mode 100644 views/jobs/ajax_add.ctp create mode 100644 webroot/js/add_job.js delete mode 100755 webroot/js/addjob.js diff --git a/controllers/jobs_controller.php b/controllers/jobs_controller.php index d46179ba..060fdc3e 100755 --- a/controllers/jobs_controller.php +++ b/controllers/jobs_controller.php @@ -296,7 +296,7 @@ class JobsController extends AppController { function ajax_edit() { if(!empty($this->data)) { - print_r($this->data); + //print_r($this->data); if ($this->Job->save($this->data)) { echo "SUCCESS"; } @@ -347,6 +347,43 @@ class JobsController extends AppController { } + + function ajax_add($enquiryID) { + $this->layout = 'ajax'; + + if(!isset($enquiryID)) { + return; + } + else { + + $this->Job->create(); + + $job_offset = 6141; + + $number_of_jobs = $this->Job->findCount(); + $new_job_number = $job_offset + $number_of_jobs; + + $enquiry = $this->Job->Enquiry->findById($enquiryID); + $monthYearShort = strtoupper(date("My")); + + $jobLetter = $enquiry['State']['enqform']; + + $this->data['Job']['title'] = $monthYearShort.$jobLetter."J".$new_job_number; + $this->data['Job']['state_id'] = $enquiry['Enquiry']['state_id']; + $this->data['Job']['customer_id'] = $enquiry['Enquiry']['customer_id']; + $this->data['Job']['contact_id'] = $enquiry['Enquiry']['contact_id']; + $this->data['Job']['enquiry_id'] = $enquiry['Enquiry']['id']; + + if ($this->Job->save($this->data)) { + echo "SUCCESS"; + } + else { + echo "FAILURE"; + } + } + } + + function add() { diff --git a/views/enquiries/view.ctp b/views/enquiries/view.ctp index bf5fcdc5..820bbac5 100755 --- a/views/enquiries/view.ctp +++ b/views/enquiries/view.ctp @@ -208,8 +208,9 @@ $class = ' class="altrow"';?>
+ link('add_job');?>
diff --git a/views/jobs/ajax_add.ctp b/views/jobs/ajax_add.ctp new file mode 100644 index 00000000..e69de29b diff --git a/views/layouts/default.ctp b/views/layouts/default.ctp index 6624dd7b..9a5608a6 100755 --- a/views/layouts/default.ctp +++ b/views/layouts/default.ctp @@ -64,7 +64,14 @@
  • link('Jobs', '/jobs/index'); ?>
  • diff --git a/webroot/js/add_job.js b/webroot/js/add_job.js new file mode 100644 index 00000000..d1facb8b --- /dev/null +++ b/webroot/js/add_job.js @@ -0,0 +1,20 @@ +$(function() { + $(".addJob").click(function() { + $(".addJob").button('disable'); + addJob(); + }); + + // $(".addJob").dblclick(addJob); + + + function addJob() { + + var enquiryID = $(".addJob").attr("id"); + + $.post('/jobs/ajax_add/'+enquiryID, function(data) { + window.location.href = '/jobs'; + }); + + } + +}); \ No newline at end of file diff --git a/webroot/js/addjob.js b/webroot/js/addjob.js deleted file mode 100755 index 21d3c402..00000000 --- a/webroot/js/addjob.js +++ /dev/null @@ -1,35 +0,0 @@ -/** - * file: addjob.js - * - * - */ - -$(function() { - - - $('#JobDateOrderReceivedDisplay').datepicker({ - showButtonPanel: true, - dateFormat: 'DD d MM yy', - altFormat: 'yy-mm-dd', - altField: '#JobDateOrderReceived' - - }); - - - - - $('#JobDateOrderSentToCustomerDisplay').datepicker({ - showButtonPanel: true, - dateFormat: 'DD d MM yy', - altFormat: 'yy-mm-dd', - altField: '#JobDateOrderSentToCustomer' - - }); - - - - - - - -}); \ No newline at end of file