Fixed broken line item attachments

This commit is contained in:
Karl Cordes 2012-12-02 13:17:09 +11:00
parent d5c995ae74
commit 3e46f30dd2
7 changed files with 75 additions and 46 deletions

View file

@ -123,20 +123,24 @@ class DocumentsController extends AppController {
foreach($this->data['DocumentAttachment']['attachment_id'] as $i => $attachment_id) {
$docID = $this->data['DocumentAttachment']['document_id'];
$query = "DELETE FROM document_attachments WHERE document_id = {$docID} AND attachment_id = {$attachment_id}";
echo $query."<br>";
//$this->Document->DocumentAttachment->query($query);
$this->Document->DocumentAttachment->query($query);
$attachment['DocumentAttachment']['document_id'] = $this->data['DocumentAttachment']['document_id'];
$attachment['DocumentAttachment']['attachment_id'] = $attachment_id;
if(!$this->Document->DocumentAttachment->save($attachment)) {
echo "FAIL";
return;
}
$attachment[$i]['DocumentAttachment']['document_id'] = $this->data['DocumentAttachment']['document_id'];
$attachment[$i]['DocumentAttachment']['attachment_id'] = $attachment_id;
}
echo "SUCCESS";
if($this->Document->DocumentAttachment->saveAll($attachment)) {
echo "SUCCESS";
}
else {
echo "FAIL";
}
}
else {
echo "FAIL";
}
function removeAttachments() {
$this->layout = 'ajax';
foreach($this->data as $attachment) {
$this->Document->DocumentAttachment->delete($attachment);
}
}
@ -636,7 +640,6 @@ class DocumentsController extends AppController {
$document = $this->Document->read(null,$id);
$attachments = $this->Document->DocumentAttachment->find('all', array('DocumentAttachment.document_id' => $id));
if(empty($document['Document']['pdf_filename'])) {
$this->Session->setFlash(__('Error. Please generate the PDF before attempting to email it', true));
@ -646,8 +649,9 @@ class DocumentsController extends AppController {
$pdf_dir = Configure::read('pdf_directory');
$attachment_files = array($pdf_dir.$document['Document']['pdf_filename']);
foreach($attachments as $attachment) {
$attachment_files[] = $attachment['Attachment']['filename'];
foreach($document['DocumentAttachment'] as $document_attachment) {
$attachment = $this->Document->DocumentAttachment->Attachment->read(null, $document_attachment['attachment_id']);
$attachment_files[] = $attachment['Attachment']['file'];
}
$this->Email->attachments = $attachment_files;

View file

@ -1,10 +1,23 @@
<?
<table>
<thead>
<th></th>
<th>Filename</th>
<th>Name</th>
<th>Desc</th>
</thead>
<tbody>
<?php
foreach($attachments as $attachment) {
echo "<li>";
echo $html->link($attachment['Attachment']['name'],
"/attachments/view/{$attachment['Attachment']['id']}");
echo "</li>";
}
?>
<tr>
<td><?php echo $form->input('DocumentAttachment.id', array('type'=>'checkbox', 'value'=> $attachment['DocumentAttachment']['id'], 'label' => false)); ?></td>
<td>
<?php echo $html->link($attachment['Attachment']['filename'], '/attachments/view/'.$attachment['Attachment']['id']); ?>
</td>
<td><?php echo $attachment['Attachment']['name']; ?></td>
<td><?php echo $attachment['Attachment']['description']; ?></td>
</tr>
<?php } ?>
</tbody>
</table>

View file

View file

@ -33,28 +33,37 @@ echo $form->input("DocPage.content", array('class'=>'page', 'label'=>'Page', 'be
<div id="Attachments" title="Attachments">
<h2 class="document-attachments">Attachments</h2><button id="addAttachment">Add Attachment</button>
<table>
<div id="attachments-table">
<table>
<thead>
<th></th>
<th>Filename</th>
<th>Name</th>
<th>Desc</th>
</thead>
<tbody>
<?php
foreach($attachments as $attachment) {
foreach($attachments as $index => $attachment) {
?>
<tr>
<td><?php echo $form->input("DocumentAttachment[{$index}].id",
array('type'=>'checkbox',
'value'=> $attachment['DocumentAttachment']['id'],
'label' => false, 'class'=>'documentAttachment-checkbox')); ?></td>
<td>
<?php echo $html->link($attachment['Attachment']['filename'], '/attachments/view/'.$attachment['Attachment']['id']); ?>
<?php echo $html->link($attachment['Attachment']['filename'], '/attachments/view/'.$attachment['Attachment']['id']); ?>
</td>
<td><?php echo $attachment['Attachment']['name']; ?></td>
<td><?php echo $attachment['Attachment']['id']; ?></td>
<td><?php echo $attachment['Attachment']['description']; ?></td>
</tr>
</tr>
<?php } ?>
</tbody>
</table>
</div> <!-- #attachments-table -->
<button id="removeAttachments">Remove Selected</button>
</div>
<div id="addAttachmentModal" title="Add Attachment">

View file

@ -1,4 +1,4 @@
<? echo $form->input('Product.principle_id', array('id'=>'principleAttachmentSelect', 'label'=>'Principle','empty'=>'Select Principle'));?>
<? echo $form->input('Product.principle_id', array('id'=>'principleSelect', 'label'=>'Principle','empty'=>'Select Principle'));?>
<div id="productsDiv"></div>
<div id="productDetails"></div>

View file

@ -1578,6 +1578,7 @@ div.address span {
}
table.lineItems {
margin-top: 0.2em;
border: 1px solid;
border-spacing: 0px;
}
@ -1647,8 +1648,8 @@ div.warning {
tr.no_items {
font-size: 2em;
padding: 0.5em;
font-size: 1.5em;
padding: 1em;
}
#Attachments {
margin-top: 1.5em;

View file

@ -18,24 +18,18 @@ $(function() {
var attachmentInputs = $('#DocumentAttachmentAddForm').find('input');
$.post('/documents/saveAttachments', attachmentInputs, function(data) {
if(data == 'SUCCESS') {
loadAttachments();
$(this).dialog('close');
}
else {
alert("Attachments could not be saved")
}
$("#addAttachmentModal").dialog( "close" );
});
},
Cancel: function() {
$( this ).dialog( "close" );
}
}
},
close: function() {
loadAttachments();
}
}
});
@ -45,6 +39,10 @@ $(function() {
loadPrincipleAttachments(principleID);
});
$("#removeAttachments").click(function() {
removeAttachments();
});
function loadPrincipleAttachments(id) {
$.get('/documents/getAttachmentsByPrinciple/'+id, function(attachments) {
$('#principleAttachments').html(attachments);
@ -52,12 +50,16 @@ $(function() {
}
function loadAttachments() {
$.get('/documents/getAttachments/'+documentID, function(attachments) {
$("#attachments-table").html(attachments);
});
}
function removeAttachments() {
var selectedAttachments = $(".documentAttachment-checkbox:checked");
$.post('/documents/removeAttachments', selectedAttachments, function(data) {
loadAttachments();
});
}