From 296336e43113620142d81022706a2977b1e35430 Mon Sep 17 00:00:00 2001 From: Karl Cordes Date: Fri, 29 Mar 2013 16:30:35 +1100 Subject: [PATCH] Fixed removing attachments --- app/controllers/documents_controller.php | 6 +++--- app/views/documents/get_attachments.ctp | 4 ++-- app/views/documents/view.ctp | 2 +- app/webroot/js/document_add_edit.js | 11 ++--------- app/webroot/js/document_attachments.js | 2 +- 5 files changed, 9 insertions(+), 16 deletions(-) diff --git a/app/controllers/documents_controller.php b/app/controllers/documents_controller.php index 4f811b5b..9752eaa2 100755 --- a/app/controllers/documents_controller.php +++ b/app/controllers/documents_controller.php @@ -139,9 +139,9 @@ class DocumentsController extends AppController { function removeAttachments() { $this->layout = 'ajax'; - - foreach($this->data as $attachment) { - $this->Document->DocumentAttachment->delete($attachment); + foreach($this->data['DocumentAttachment'] as $attachment) { + + $this->Document->DocumentAttachment->delete($attachment['id']); } echo 'SUCCESS'; } diff --git a/app/views/documents/get_attachments.ctp b/app/views/documents/get_attachments.ctp index b2549fb5..85c295b2 100644 --- a/app/views/documents/get_attachments.ctp +++ b/app/views/documents/get_attachments.ctp @@ -7,10 +7,10 @@ $attachment) { ?> - input('DocumentAttachment.id', array('type'=>'checkbox', 'value'=> $attachment['DocumentAttachment']['id'], 'label' => false, 'class'=>'documentAttachment-checkbox')); ?> + input("DocumentAttachment.{$index}.id", array('type'=>'checkbox', 'value'=> $attachment['DocumentAttachment']['id'], 'label' => false, 'class'=>'documentAttachment-checkbox')); ?> link($attachment['Attachment']['filename'], '/attachments/view/'.$attachment['Attachment']['id']); ?> diff --git a/app/views/documents/view.ctp b/app/views/documents/view.ctp index 6a4da433..0c261447 100755 --- a/app/views/documents/view.ctp +++ b/app/views/documents/view.ctp @@ -47,7 +47,7 @@ echo $form->input("DocPage.content", array('class'=>'page', 'label'=>'Page', 'be foreach($attachments as $index => $attachment) { ?> - input("DocumentAttachment[{$index}].id", + input("DocumentAttachment.{$index}.id", array('type'=>'checkbox', 'value'=> $attachment['DocumentAttachment']['id'], 'label' => false, 'class'=>'documentAttachment-checkbox')); ?> diff --git a/app/webroot/js/document_add_edit.js b/app/webroot/js/document_add_edit.js index c07fba4c..ff13d715 100755 --- a/app/webroot/js/document_add_edit.js +++ b/app/webroot/js/document_add_edit.js @@ -544,16 +544,9 @@ function savePages() { }); $.post('/documents/ajax_edit', docPages, function(data) { - if(data =='SUCCESS') { $("#flashMessage").html("Pages Saved Successfully"); - } - else { - $("#flashMessage").html("Unable to Save Pages"); - } - - $("#flashMessage").show(); - - loadLineItems(); + $("#flashMessage").show(); + loadLineItems(); }); } diff --git a/app/webroot/js/document_attachments.js b/app/webroot/js/document_attachments.js index 7baf2960..7fd8feeb 100755 --- a/app/webroot/js/document_attachments.js +++ b/app/webroot/js/document_attachments.js @@ -57,7 +57,7 @@ $(function() { function removeAttachments() { var selectedAttachments = $(".documentAttachment-checkbox:checked"); - $.post('/documents/removeAttachments', selectedAttachments, function(data) { + $.post('/documents/removeAttachments', selectedAttachments, function(data) { loadAttachments(); });