Fixed bug with adding attachments from the same principle. Closes #67

This commit is contained in:
Karl Cordes 2013-04-01 11:52:31 +11:00
parent 5b9b2139ce
commit 476768a32d
3 changed files with 5 additions and 3 deletions

View file

@ -118,7 +118,7 @@ class DocumentsController extends AppController {
function saveAttachments() { function saveAttachments() {
$this->layout = 'ajax'; $this->layout = 'ajax';
if($this->data) { if($this->data) {
$attachments = array(); $attachments = array();
foreach($this->data['DocumentAttachment']['attachment_id'] as $i => $attachment_id) { foreach($this->data['DocumentAttachment']['attachment_id'] as $i => $attachment_id) {
$docID = $this->data['DocumentAttachment']['document_id']; $docID = $this->data['DocumentAttachment']['document_id'];

View file

@ -46,7 +46,9 @@ echo $form->input("DocPage.content", array('class'=>'page', 'label'=>'Page', 'be
<?php <?php
foreach($attachments as $index => $attachment) { foreach($attachments as $index => $attachment) {
?> ?>
<tr> <tr>
<?php echo $form->input('DocumentAttachment.document_id',
array('type'=>'hidden', 'value'=> $document['Document']['id'])); ?>
<td><?php echo $form->input("DocumentAttachment.{$index}.id", <td><?php echo $form->input("DocumentAttachment.{$index}.id",
array('type'=>'checkbox', array('type'=>'checkbox',
'value'=> $attachment['DocumentAttachment']['id'], 'value'=> $attachment['DocumentAttachment']['id'],

View file

@ -15,7 +15,7 @@ $(function() {
buttons: { buttons: {
"Add Attachment": function() { "Add Attachment": function() {
var attachmentInputs = $('#DocumentAttachmentAddForm').find('input'); var attachmentInputs = $('#DocumentAttachmentAddForm').find('input:checked, #DocumentAttachmentDocumentId');
$.post('/documents/saveAttachments', attachmentInputs, function(data) { $.post('/documents/saveAttachments', attachmentInputs, function(data) {
$("#addAttachmentModal").dialog( "close" ); $("#addAttachmentModal").dialog( "close" );