From f691abc6db12d47485e8eb3e3d9f6f90ae217559 Mon Sep 17 00:00:00 2001 From: Karl Cordes Date: Thu, 19 May 2011 09:46:22 +1000 Subject: [PATCH] Wooot. Finishing this today --- .gitignore | 1 + config/routes.php | 3 + controllers/doc_pages_controller.php | 1 + controllers/documents_controller.php | 37 +++---- models/doc_page.php | 8 +- models/document.php | 3 +- views/documents/index.ctp | 23 ++--- views/documents/view.ctp | 13 ++- views/elements/document_quote_view.ctp | 33 ++++--- webroot/css/quotenik.css | 9 ++ webroot/js/add_edit_shipment.js | 33 +------ webroot/js/document_add_edit.js | 131 +++++++++++++++++++++++-- webroot/js/global.js | 37 ++++++- 13 files changed, 235 insertions(+), 97 deletions(-) diff --git a/.gitignore b/.gitignore index d5c74071..b2da249e 100755 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ emails/* nbproject/* processed_vaultmsgs/* vaultmsgs/* +cake_eclipse_helper.php diff --git a/config/routes.php b/config/routes.php index 766503b7..cb7d3deb 100755 --- a/config/routes.php +++ b/config/routes.php @@ -44,4 +44,7 @@ Router::connect('/', array('controller' => 'enquiries', 'action' => 'index')); * developement. */ Router::connect('/tests', array('controller' => 'tests', 'action' => 'index')); + + + ?> diff --git a/controllers/doc_pages_controller.php b/controllers/doc_pages_controller.php index 26fab78f..db6baf02 100644 --- a/controllers/doc_pages_controller.php +++ b/controllers/doc_pages_controller.php @@ -3,6 +3,7 @@ class DocPagesController extends AppController { var $name = 'DocPages'; var $helpers = array('Html', 'Form'); + } diff --git a/controllers/documents_controller.php b/controllers/documents_controller.php index 68351f54..311674ee 100755 --- a/controllers/documents_controller.php +++ b/controllers/documents_controller.php @@ -36,6 +36,18 @@ class DocumentsController extends AppController { $this->data = $document; $this->set('docType',$docType); + $this->set('principles', $this->Document->LineItem->Product->Principle->find('list')); + } + + + + + function getProducts($principleID = null) { + $this->layout = 'ajax'; + + if($principleID == null) { + echo "INVALID PRINCIPLE ID"; + } } /** @@ -112,23 +124,9 @@ class DocumentsController extends AppController { } - /* function add() { - if (!empty($this->data)) { - $this->Document->create(); - if ($this->Document->save($this->data)) { - $this->Session->setFlash(__('The Document has been saved', true)); - $this->redirect(array('action'=>'index')); - } else { - $this->Session->setFlash(__('The Document could not be saved. Please, try again.', true)); - } - } - $customers = $this->Document->Customer->find('list'); - $enquiries = $this->Document->Enquiry->find('list'); - $jobs = $this->Document->Job->find('list'); - $users = $this->Document->User->find('list'); - $contacts = $this->Document->Contact->find('list'); - $this->set(compact('customers', 'enquiries', 'jobs', 'users', 'contacts')); - }*/ + + + function edit($id = null) { if (!$id && empty($this->data)) { @@ -136,6 +134,11 @@ class DocumentsController extends AppController { $this->redirect(array('action'=>'index')); } if (!empty($this->data)) { + $docID = $this->data['Document']['id']; + + $this->Document->DocPage->deleteAll(array('document_id'=>$docID)); + + $this->Document->DocPage->updateCounterCache(array('document_id'=>$docID)); if ($this->Document->saveAll($this->data)) { $this->Session->setFlash(__('The Document has been saved', true)); $this->redirect(array('action'=>'index')); diff --git a/models/doc_page.php b/models/doc_page.php index 8c267fcd..25948a4e 100755 --- a/models/doc_page.php +++ b/models/doc_page.php @@ -10,13 +10,11 @@ class DocPage extends AppModel { 'foreignKey' => 'document_id', 'conditions' => '', 'fields' => '', - 'order' => '' + 'order' => '', + 'counterCache' => 'doc_page_count' ) ); - - - var $order = 'DocPage.page_number ASC'; - + var $order = 'page_number ASC'; } ?> \ No newline at end of file diff --git a/models/document.php b/models/document.php index 210a4700..4d8a95b9 100755 --- a/models/document.php +++ b/models/document.php @@ -25,7 +25,8 @@ class Document extends AppModel { 'DocPage' => array( 'className'=> 'DocPage', - 'foreignKey' => 'document_id' + 'foreignKey' => 'document_id', + 'order' => 'DocPage.page_number ASC' ) ); diff --git a/views/documents/index.ctp b/views/documents/index.ctp index 64ad877c..23021eb3 100755 --- a/views/documents/index.ctp +++ b/views/documents/index.ctp @@ -10,6 +10,7 @@ echo $paginator->counter(array( sort('id');?> sort('created');?> + #Pages sort('user_id');?> @@ -28,13 +29,16 @@ foreach ($documents as $document): + + + + link($document['User']['username'], array('controller' => 'users', 'action' => 'view', $document['User']['id'])); ?> + link(__('View', true), array('action' => 'view', $document['Document']['id'])); ?> - link(__('Edit', true), array('action' => 'edit', $document['Document']['id'])); ?> - link(__('Delete', true), array('action' => 'delete', $document['Document']['id']), null, sprintf(__('Are you sure you want to delete # %s?', true), $document['Document']['id'])); ?> @@ -45,18 +49,3 @@ foreach ($documents as $document): | numbers();?> next(__('next', true).' >>', array(), null, array('class' => 'disabled'));?> -
- -
diff --git a/views/documents/view.ctp b/views/documents/view.ctp index 665a5076..36755503 100755 --- a/views/documents/view.ctp +++ b/views/documents/view.ctp @@ -19,5 +19,16 @@ switch($docType) { break; } - ?> + +
+ input("DocPage.content", array('class'=>'page', 'label'=>'Page', 'between'=>'')); + ?> +
+ + +
+ input('Product.principle_id', array('id'=>'principleSelect', 'label'=>'Principle','empty'=>'Select Principle'));?> + +
\ No newline at end of file diff --git a/views/elements/document_quote_view.ctp b/views/elements/document_quote_view.ctp index e43f018f..98282059 100644 --- a/views/elements/document_quote_view.ctp +++ b/views/elements/document_quote_view.ctp @@ -1,4 +1,9 @@ -

Quote:

+

Quote: 0) { + echo "Revision {$document['Quote']['revision']}"; +} +?> +

create('Document',array('type'=>'post','action'=>'edit')); @@ -6,27 +11,27 @@ echo $form->input('Document.id'); ?>
- +
- +
$page):?> -
+
+ input("DocPage.{$key}.id");?> + input("DocPage.{$key}.content", array('class'=>'page', 'label'=>'Page '.$page['page_number'], 'between'=>''));?> + input("DocPage.{$key}.document_id", array('type'=>'hidden'));?> + input("DocPage.{$key}.page_number", array('type'=>'hidden'));?> +
- input("DocPage.{$key}.id");?> - input("DocPage.{$key}.content", array('class'=>'page', 'label'=>'Page'));?> - input("DocPage.{$key}.document_id", array('type'=>'hidden'));?> +
- - - end('Save');?> -data);?> - - - +data);?> + + + diff --git a/webroot/css/quotenik.css b/webroot/css/quotenik.css index 490bcf56..572107de 100755 --- a/webroot/css/quotenik.css +++ b/webroot/css/quotenik.css @@ -1495,4 +1495,13 @@ div.address span { left: 50%; top: 50%; +} + +.pages { + width: 50%; +} + +.pages label { + display: inline; + padding-right: 0.2em; } \ No newline at end of file diff --git a/webroot/js/add_edit_shipment.js b/webroot/js/add_edit_shipment.js index 8659855d..313915fb 100644 --- a/webroot/js/add_edit_shipment.js +++ b/webroot/js/add_edit_shipment.js @@ -282,23 +282,9 @@ $(function() { newInvoiceForm.prepend(closeButton); $("#invoices").append(newInvoiceForm); - - - - } - - function getCakeID(model, count, field) { - return model+count+capitalizeFirstLetter(field); - } - - function getCakeName(model, count, field) { - return 'data['+model+']['+count+']['+field+']'; - } - - function capitalizeFirstLetter(string) { - return string.charAt(0).toUpperCase() + string.slice(1); } + /** * A more generic way of handling the HABTM @@ -325,23 +311,6 @@ $(function() { } - - function getSelectedID(elementID) { - var id; - $(elementID+" :selected").each(function(i, selected) { - id = this.value; - }); - return id; - } - - function getSelectedText(elementID) { - var text; - $(elementID+" :selected").each(function(i, selected) { - text = $(selected).text(); - }); - return text; - } - /** * Resets the Form to its default site */ diff --git a/webroot/js/document_add_edit.js b/webroot/js/document_add_edit.js index a2fd6f3a..aabf308f 100644 --- a/webroot/js/document_add_edit.js +++ b/webroot/js/document_add_edit.js @@ -1,16 +1,133 @@ + + + $(function() { - $("#addPage").button().click(function() { - alert("LETS ADD STUFFFF"); - return false; + + + + $( "#lineItemModal" ).dialog({ + autoOpen: false, + height: 900, + width: 600, + modal: true, + buttons: { + "Add Line Item": function() { + //var thisShipmentInputs = $('#ShipmentAddForm').find('input,select,textarea'); + + $.post('/line_items/ajax_add', null, function(data) { + $( "#lineItemModal" ).dialog('close'); + //window.location.reload(); //Change this to fetch a new copy of the table and update a
. + }); + + }, + Cancel: function() { + $( this ).dialog( "close" ); + //$("#ShipmentAddForm")[0].reset(); + $("#principlesList").empty(); + } + }, + close: function() { + + $("#importFields").hide(); + $("#principle").hide(); + + + } }); - - $("#addLineItem").button().click(function() { + //Setup CKEditor toolbars + var config = { + toolbar:[ + ['Cut','Copy','Paste','PasteText','PasteFromWord','-','Scayt'], + ['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'], + ['Image','Table','HorizontalRule','SpecialChar'], + '/', + ['Styles','Format'], + ['Bold','Italic','Strike'], + ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'], + ['Link','Unlink'], + ['Maximize','-','About'] + ] + }; + + + $("#pageContentFactory").hide(); + + + //Add a new Page Element. + $("#addPage").button().click(function(event) { + event.preventDefault(); + + + $('.page').ckeditor(function() { + this.destroy(); + }); + + + + var newPage = $('#pageContentFactory').clone(); + newPage.removeAttr('id'); + newPage.show(); + + + + var pageCount = $('.docPage').length; + + //alert(pageCount); + + pageCount++; + var model = 'DocPage'; + var field = 'content'; + var ID = getCakeID(model,pageCount, field); + var name = getCakeName(model, pageCount, field); + + newPage.find('label').attr('for', ID); + + newPage.find('textarea').attr('id', ID).attr('name', name); + newPage.addClass('docPage'); + + var hiddenName = getCakeName(model, pageCount, 'page_number'); + + newPage.append(''); + $('.pages').append(newPage); + + $('.page').ckeditor(config); return false; }); - $('.page').ckeditor(); + //Open the LineItem dialog + $("#addLineItem").button().click(function() { + + $( "#lineItemModal" ).dialog('open'); -}); \ No newline at end of file + return false; + }); + + $("#principleSelect").change(function() { + alert("OH YEAH LETS DO THIS"); + + }); + + + + // Initialize the editor. + // Callback function can be passed and executed after full instance creation. + $('.page').ckeditor(config); + + + //Remove this Page + $(".removePage").live('click',function() { + + $('.page').ckeditor(function() { + this.destroy(); + }); + + $(this).parents(".docPage").remove(); + + $('.page').ckeditor(config); + + }); + +}); diff --git a/webroot/js/global.js b/webroot/js/global.js index 7e9c34aa..82d5379f 100644 --- a/webroot/js/global.js +++ b/webroot/js/global.js @@ -14,7 +14,38 @@ $(function() { }) .ajaxStop(function() { $(this).hide(); - }) -; + }); -}); \ No newline at end of file + + + + +}); + +function getCakeID(model, count, field) { + return model+count+capitalizeFirstLetter(field); +} + +function getCakeName(model, count, field) { + return 'data['+model+']['+count+']['+field+']'; +} + +function capitalizeFirstLetter(string) { + return string.charAt(0).toUpperCase() + string.slice(1); +} + +function getSelectedID(elementID) { + var id; + $(elementID+" :selected").each(function(i, selected) { + id = this.value; + }); + return id; +} + +function getSelectedText(elementID) { + var text; + $(elementID+" :selected").each(function(i, selected) { + text = $(selected).text(); + }); + return text; +} \ No newline at end of file