Work on attachments. Mostly finished
This commit is contained in:
parent
a9c8153668
commit
d5c995ae74
74
controllers/attachments_controller.php
Normal file
74
controllers/attachments_controller.php
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
<?php
|
||||
class AttachmentsController extends AppController {
|
||||
|
||||
var $name = 'Attachments';
|
||||
var $helpers = array('Html', 'Form','Number','Time');
|
||||
|
||||
function index() {
|
||||
$this->Attachment->recursive = 1;
|
||||
$this->set('attachments', $this->paginate());
|
||||
}
|
||||
|
||||
function view($id = null) {
|
||||
if (!$id) {
|
||||
$this->Session->setFlash(__('Invalid Attachment.', true));
|
||||
$this->redirect(array('action'=>'index'));
|
||||
}
|
||||
$this->set('attachment', $this->Attachment->read(null, $id));
|
||||
$this->layout = 'pdf';
|
||||
}
|
||||
|
||||
function add() {
|
||||
if (!empty($this->data)) {
|
||||
|
||||
$attachment = $this->Attachment->process_attachment($this->data);
|
||||
|
||||
|
||||
$this->Attachment->create();
|
||||
|
||||
if ($this->Attachment->save($attachment)) {
|
||||
$this->Session->setFlash(__('The Attachment has been saved', true));
|
||||
$this->redirect(array('action'=>'index'));
|
||||
} else {
|
||||
$this->Session->setFlash(__('The Attachment could not be saved. Please, try again.', true));
|
||||
}
|
||||
}
|
||||
$principles = $this->Attachment->Principle->find('list');
|
||||
$this->set(compact('products', 'principles'));
|
||||
}
|
||||
|
||||
function edit($id = null) {
|
||||
if (!$id && empty($this->data)) {
|
||||
$this->Session->setFlash(__('Invalid Attachment', true));
|
||||
$this->redirect(array('action'=>'index'));
|
||||
}
|
||||
if (!empty($this->data)) {
|
||||
$attachment = $this->Attachment->process_attachment($this->data);
|
||||
if ($this->Attachment->save($attachment)) {
|
||||
$this->Session->setFlash(__('The Attachment has been saved', true));
|
||||
$this->redirect(array('action'=>'index'));
|
||||
} else {
|
||||
$this->Session->setFlash(__('The Attachment could not be saved. Please, try again.', true));
|
||||
}
|
||||
}
|
||||
if (empty($this->data)) {
|
||||
$this->data = $this->Attachment->read(null, $id);
|
||||
}
|
||||
$products = $this->Attachment->Product->find('list');
|
||||
$principles = $this->Attachment->Principle->find('list');
|
||||
$this->set(compact('products','principles'));
|
||||
}
|
||||
|
||||
function delete($id = null) {
|
||||
if (!$id) {
|
||||
$this->Session->setFlash(__('Invalid id for Attachment', true));
|
||||
$this->redirect(array('action'=>'index'));
|
||||
}
|
||||
if ($this->Attachment->del($id)) {
|
||||
$this->Session->setFlash(__('Attachment deleted', true));
|
||||
$this->redirect(array('action'=>'index'));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
|
|
@ -39,7 +39,8 @@ class DocumentsController extends AppController {
|
|||
$this->set('currency', $this->Document->getCurrency($document));
|
||||
$this->set('enquiry', $this->Document->getEnquiry($document));
|
||||
|
||||
|
||||
$this->set('attachments', $this->Document->DocumentAttachment->find('all', array('conditions'=>array('document_id'=> $id))));
|
||||
$this->set('principles', $this->Document->LineItem->Product->Principle->find('list'));
|
||||
|
||||
switch($docType) {
|
||||
case 'quote':
|
||||
|
|
@ -65,8 +66,6 @@ class DocumentsController extends AppController {
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function getProducts($principleID = null) {
|
||||
$this->layout = 'ajax';
|
||||
|
||||
|
|
@ -96,6 +95,52 @@ class DocumentsController extends AppController {
|
|||
}
|
||||
|
||||
|
||||
function getAttachments($documentID) {
|
||||
$this->layout = 'ajax';
|
||||
if(!$documentID) {
|
||||
echo "FAIL";
|
||||
}
|
||||
else {
|
||||
$this->set('attachments', $this->Document->DocumentAttachment->find('all', array('conditions'=>array('document_id'=> $documentID))));
|
||||
}
|
||||
}
|
||||
|
||||
function getAttachmentsByPrinciple($principleID) {
|
||||
$this->layout = 'ajax';
|
||||
if(!$principleID) {
|
||||
echo "FAIL";
|
||||
}
|
||||
else {
|
||||
$attachments = $this->Document->DocumentAttachment->Attachment->find('all', array('conditions'=>array('principle_id'=> $principleID)));
|
||||
$this->set('attachments', $attachments);
|
||||
}
|
||||
}
|
||||
|
||||
function saveAttachments() {
|
||||
$this->layout = 'ajax';
|
||||
if($this->data) {
|
||||
$attachments = array();
|
||||
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);
|
||||
|
||||
$attachment['DocumentAttachment']['document_id'] = $this->data['DocumentAttachment']['document_id'];
|
||||
$attachment['DocumentAttachment']['attachment_id'] = $attachment_id;
|
||||
if(!$this->Document->DocumentAttachment->save($attachment)) {
|
||||
echo "FAIL";
|
||||
return;
|
||||
}
|
||||
}
|
||||
echo "SUCCESS";
|
||||
}
|
||||
else {
|
||||
echo "FAIL";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a New Document
|
||||
*
|
||||
|
|
@ -591,13 +636,21 @@ 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));
|
||||
return;
|
||||
}
|
||||
else {
|
||||
$pdf_dir = Configure::read('pdf_directory');
|
||||
$this->Email->attachments = array($pdf_dir.'/'.$document['Document']['pdf_filename']);
|
||||
|
||||
$attachment_files = array($pdf_dir.$document['Document']['pdf_filename']);
|
||||
foreach($attachments as $attachment) {
|
||||
$attachment_files[] = $attachment['Attachment']['filename'];
|
||||
}
|
||||
$this->Email->attachments = $attachment_files;
|
||||
|
||||
}
|
||||
|
||||
$enquiry = $this->Document->getEnquiry($document);
|
||||
|
|
@ -605,7 +658,7 @@ class DocumentsController extends AppController {
|
|||
$this->Email->to = $enquiry['Contact']['email'];
|
||||
|
||||
//Uncomment this when going live
|
||||
// $this->Email->cc = array($enquiry['User']['email']);
|
||||
$this->Email->cc = array($enquiry['User']['email']);
|
||||
// $this->Email->bcc = array('carpis@cmctechnologies.com.au');
|
||||
|
||||
$this->Email->subject = $enquiry['Enquiry']['title'].' ';
|
||||
|
|
@ -618,7 +671,7 @@ class DocumentsController extends AppController {
|
|||
$this->set('DocFullName', $this->Document->getDocFullName($document['Document']['type']));
|
||||
if($this->Email->send()) {
|
||||
$this->Session->setFlash(__('The Email has been sent', true));
|
||||
// $this->redirect(array('action'=>'view/'.$id), null, false);
|
||||
$this->redirect(array('action'=>'view/'.$id), null, false);
|
||||
}
|
||||
else {
|
||||
$this->set('smtp_errors', $this->Email->smtpError);
|
||||
|
|
|
|||
77
models/attachment.php
Normal file
77
models/attachment.php
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
class Attachment extends AppModel {
|
||||
|
||||
var $name = 'Attachment';
|
||||
var $validate = array(
|
||||
'principle_id' => array('numeric'),
|
||||
'name' => array('notempty'),
|
||||
'type' => array('notempty'),
|
||||
'size' => array('numeric'),
|
||||
'archived' => array('numeric'),
|
||||
);
|
||||
|
||||
//The Associations below have been created with all possible keys, those that are not needed can be removed
|
||||
var $belongsTo = array(
|
||||
'Principle' => array(
|
||||
'className' => 'Principle',
|
||||
'foreignKey' => 'principle_id',
|
||||
'conditions' => '',
|
||||
'fields' => '',
|
||||
'order' => ''
|
||||
)
|
||||
);
|
||||
|
||||
var $hasMany = array(
|
||||
'DocumentAttachment' => array(
|
||||
'className' => 'DocumentAttachment',
|
||||
'foreignKey' => 'attachment_id'
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
// Based on comment 8 from: http://bakery.cakephp.org/articles/view/improved-advance-validation-with-parameters
|
||||
|
||||
function isUploadedFile($params){
|
||||
$val = array_shift($params);
|
||||
if ((isset($val['error']) && $val['error'] == 0) ||
|
||||
(!empty( $val['tmp_name']) && $val['tmp_name'] != 'none')) {
|
||||
return is_uploaded_file($val['tmp_name']);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Passed a PHP upload
|
||||
* array('name', 'type', 'tmp_name', 'error' 'size').
|
||||
*
|
||||
* Move the uploaded file to the storage directory
|
||||
* and return a cake array for insertion.
|
||||
*
|
||||
*/
|
||||
|
||||
function process_attachment($attachment) {
|
||||
|
||||
$upload = $attachment['Attachment']['file'];
|
||||
|
||||
$new_filename = Configure::read('attachments_directory').time().$upload['name'];
|
||||
|
||||
$moved = move_uploaded_file($upload['tmp_name'], $new_filename);
|
||||
|
||||
if($moved) {
|
||||
$attachment['Attachment']['filename'] = $upload['name'];
|
||||
$attachment['Attachment']['file'] = $new_filename;
|
||||
$attachment['Attachment']['size'] = $upload['size'];
|
||||
$attachment['Attachment']['type'] = $upload['type'];
|
||||
return $attachment;
|
||||
}
|
||||
else {
|
||||
die("Error! Unable to move the uploaded file");
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
|
|
@ -28,7 +28,14 @@ class Document extends AppModel {
|
|||
'className'=> 'DocPage',
|
||||
'foreignKey' => 'document_id',
|
||||
'order' => 'DocPage.page_number ASC'
|
||||
)
|
||||
),
|
||||
|
||||
'DocumentAttachment' => array(
|
||||
'className'=> 'DocumentAttachment',
|
||||
'foreignKey' => 'document_id',
|
||||
'order' => 'DocumentAttachment.id ASC'
|
||||
),
|
||||
|
||||
);
|
||||
|
||||
|
||||
|
|
@ -53,7 +60,6 @@ class Document extends AppModel {
|
|||
)
|
||||
);
|
||||
|
||||
|
||||
//So much refactoring possible on this.
|
||||
function getCurrency($document) {
|
||||
|
||||
|
|
|
|||
28
models/document_attachment.php
Normal file
28
models/document_attachment.php
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
class DocumentAttachment extends AppModel {
|
||||
|
||||
var $name = 'DocumentAttachment';
|
||||
|
||||
var $useTable = 'document_attachments';
|
||||
|
||||
|
||||
//The Associations below have been created with all possible keys, those that are not needed can be removed
|
||||
var $belongsTo = array(
|
||||
'Document' => array(
|
||||
'className' => 'Document',
|
||||
'foreignKey' => 'document_id',
|
||||
'conditions' => '',
|
||||
'fields' => '',
|
||||
'order' => ''
|
||||
),
|
||||
'Attachment' => array(
|
||||
'className' => 'Attachment',
|
||||
'foreignKey' => 'attachment_id',
|
||||
'conditions' => '',
|
||||
'fields' => '',
|
||||
'order' => ''
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
?>
|
||||
14
views/attachments/add.ctp
Normal file
14
views/attachments/add.ctp
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
<div class="attachments form">
|
||||
<?php echo $form->create('Attachment', array('type'=>'file'));?>
|
||||
<fieldset>
|
||||
<legend><?php __('Add Attachment');?></legend>
|
||||
<?php
|
||||
echo $form->input('principle_id');
|
||||
echo $form->input('name');
|
||||
echo $form->file('file');
|
||||
echo $form->input('description');
|
||||
echo $form->input('archived');
|
||||
?>
|
||||
</fieldset>
|
||||
<?php echo $form->end('Submit');?>
|
||||
</div>
|
||||
23
views/attachments/edit.ctp
Normal file
23
views/attachments/edit.ctp
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
<div class="attachments form">
|
||||
<?php echo $form->create('Attachment');?>
|
||||
<fieldset>
|
||||
<legend><?php __('Edit Attachment');?></legend>
|
||||
<?php
|
||||
echo $form->input('id');
|
||||
echo $form->input('principle_id');
|
||||
echo $form->input('name');
|
||||
echo $form->input('filename');
|
||||
echo $form->input('type');
|
||||
echo $form->input('size');
|
||||
echo $form->input('description');
|
||||
echo $form->input('archived');
|
||||
?>
|
||||
</fieldset>
|
||||
<?php echo $form->end('Submit');?>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<ul>
|
||||
<li><?php echo $html->link(__('Delete', true), array('action' => 'delete', $form->value('Attachment.id')), null, sprintf(__('Are you sure you want to delete # %s?', true), $form->value('Attachment.id'))); ?></li>
|
||||
<li><?php echo $html->link(__('List Attachments', true), array('action' => 'index'));?></li>
|
||||
</ul>
|
||||
</div>
|
||||
75
views/attachments/index.ctp
Normal file
75
views/attachments/index.ctp
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
<div class="attachments index">
|
||||
<h2><?php __('Attachments');?></h2>
|
||||
<p>
|
||||
<?php
|
||||
echo $paginator->counter(array(
|
||||
'format' => __('Page %page% of %pages%, showing %current% records out of %count% total, starting on record %start%, ending on %end%', true)
|
||||
));
|
||||
?></p>
|
||||
<table cellpadding="0" cellspacing="0">
|
||||
<tr>
|
||||
<th><?php echo $paginator->sort('id');?></th>
|
||||
<th><?php echo $paginator->sort('principle_id');?></th>
|
||||
<th><?php echo $paginator->sort('created');?></th>
|
||||
<th><?php echo $paginator->sort('name');?></th>
|
||||
<th><?php echo $paginator->sort('type');?></th>
|
||||
<th><?php echo $paginator->sort('size');?></th>
|
||||
<th><?php echo $paginator->sort('description');?></th>
|
||||
<th class="actions"><?php __('Actions');?></th>
|
||||
</tr>
|
||||
<?php
|
||||
$i = 0;
|
||||
foreach ($attachments as $attachment):
|
||||
$class = null;
|
||||
if ($i++ % 2 == 0) {
|
||||
$class = ' class="altrow"';
|
||||
}
|
||||
?>
|
||||
<tr<?php echo $class;?>>
|
||||
<td>
|
||||
<?php echo $attachment['Attachment']['id']; ?>
|
||||
</td>
|
||||
<td>
|
||||
<?php
|
||||
if($attachment['Principle']['short_name']) {
|
||||
echo $html->link($attachment['Principle']['short_name'], '/principles/view/'.$attachment['Principle']['id']);
|
||||
}
|
||||
else {
|
||||
echo $html->link($attachment['Principle']['name'], '/principles/view/'.$attachment['Principle']['id']);
|
||||
}
|
||||
?>
|
||||
</td>
|
||||
<td>
|
||||
<?php echo $time->nice($attachment['Attachment']['created']); ?>
|
||||
</td>
|
||||
<td>
|
||||
<?php echo $attachment['Attachment']['name']; ?>
|
||||
</td>
|
||||
<td>
|
||||
<?php echo $attachment['Attachment']['type']; ?>
|
||||
</td>
|
||||
<td>
|
||||
<?php echo $number->toReadAbleSize($attachment['Attachment']['size']); ?>
|
||||
</td>
|
||||
<td>
|
||||
<?php echo $attachment['Attachment']['description']; ?>
|
||||
</td>
|
||||
<td class="actions">
|
||||
<?php echo $html->link(__('View', true), array('action' => 'view', $attachment['Attachment']['id'])); ?>
|
||||
<?php echo $html->link(__('Edit', true), array('action' => 'edit', $attachment['Attachment']['id'])); ?>
|
||||
<?php echo $html->link(__('Delete', true), array('action' => 'delete', $attachment['Attachment']['id']), null, sprintf(__('Are you sure you want to delete # %s?', true), $attachment['Attachment']['id'])); ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
</div>
|
||||
<div class="paging">
|
||||
<?php echo $paginator->prev('<< '.__('previous', true), array(), null, array('class'=>'disabled'));?>
|
||||
| <?php echo $paginator->numbers();?>
|
||||
<?php echo $paginator->next(__('next', true).' >>', array(), null, array('class' => 'disabled'));?>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<ul>
|
||||
<li><?php echo $html->link(__('New Attachment', true), array('action' => 'add')); ?></li>
|
||||
</ul>
|
||||
</div>
|
||||
17
views/attachments/view.ctp
Normal file
17
views/attachments/view.ctp
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
<?php if (file_exists($attachment['Attachment']['filename'])) {
|
||||
header('Content-Description: File Transfer');
|
||||
header('Content-Type: application/octet-stream');
|
||||
header('Content-Disposition: attachment; filename='.basename($attachment['Attachment']['filename']));
|
||||
header('Content-Transfer-Encoding: binary');
|
||||
header('Expires: 0');
|
||||
header('Cache-Control: must-revalidate');
|
||||
header('Pragma: public');
|
||||
header('Content-Length: ' . filesize($attachment['Attachment']['filename']));
|
||||
ob_clean();
|
||||
flush();
|
||||
readfile($attachment['Attachment']['filename']);
|
||||
exit;
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
10
views/documents/get_attachments.ctp
Normal file
10
views/documents/get_attachments.ctp
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<?
|
||||
foreach($attachments as $attachment) {
|
||||
echo "<li>";
|
||||
echo $html->link($attachment['Attachment']['name'],
|
||||
"/attachments/view/{$attachment['Attachment']['id']}");
|
||||
echo "</li>";
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
24
views/documents/get_attachments_by_principle.ctp
Normal file
24
views/documents/get_attachments_by_principle.ctp
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
<table>
|
||||
<thead>
|
||||
<th>Add</td>
|
||||
<th>Filename</th>
|
||||
<th>Name</th>
|
||||
<th>Desc</th>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
foreach($attachments as $attachment) {
|
||||
?>
|
||||
<tr>
|
||||
<td>
|
||||
<input name="data[DocumentAttachment][attachment_id][]" type="checkbox" value="<?php echo $attachment['Attachment']['id']; ?>">
|
||||
</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>
|
||||
0
views/documents/save_attachments.ctp
Normal file
0
views/documents/save_attachments.ctp
Normal file
|
|
@ -3,6 +3,7 @@ echo $javascript->link('ckeditor/ckeditor');
|
|||
echo $javascript->link('ckeditor/adapters/jquery');
|
||||
|
||||
echo $javascript->link('document_add_edit');
|
||||
echo $javascript->link('document_attachments');
|
||||
|
||||
?>
|
||||
<?=$this->element('pdf_created_message'); ?>
|
||||
|
|
@ -30,12 +31,40 @@ echo $this->element($docTypeElement);
|
|||
<div id="editLineItemModal" title="Edit Line Item">
|
||||
</div>
|
||||
|
||||
<div id="QuoteDetails" title="Edit Quote Details">
|
||||
<div id="Attachments" title="Attachments">
|
||||
<h2 class="document-attachments">Attachments</h2><button id="addAttachment">Add Attachment</button>
|
||||
<table>
|
||||
<thead>
|
||||
<th>Filename</th>
|
||||
<th>Name</th>
|
||||
<th>Desc</th>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
foreach($attachments as $attachment) {
|
||||
?>
|
||||
<tr>
|
||||
<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']['id']; ?></td>
|
||||
<td><?php echo $attachment['Attachment']['description']; ?></td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
</div>
|
||||
|
||||
<div id="addAttachmentModal" title="Add Attachment">
|
||||
<?php echo $this->element('add_attachment'); ?>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div id="QuoteDetails" title="Edit Quote Details">
|
||||
|
||||
<div id="Attachments" title="Attachments">
|
||||
</div>
|
||||
|
||||
|
||||
|
|
@ -51,3 +80,4 @@ echo $this->element($docTypeElement);
|
|||
<?php //debug($enquiry);?>
|
||||
|
||||
<?php // debug($document);?>
|
||||
<?php debug($attachments);?>
|
||||
|
|
|
|||
14
views/elements/add_attachment.ctp
Normal file
14
views/elements/add_attachment.ctp
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
|
||||
<? echo $form->create('DocumentAttachment', array('default'=>false)); ?>
|
||||
<? echo $form->input('DocumentAttachment.document_id', array('type'=>'hidden', 'value'=> $document['Document']['id'])); ?>
|
||||
<? echo $form->input('DocumentAttachment.principle_id', array('id'=>'attachmentPrincipleSelect', 'label'=>'Principle','empty'=>'Select Principle'));?>
|
||||
|
||||
<div id="principleAttachments">
|
||||
|
||||
</div>
|
||||
|
||||
<?
|
||||
echo $form->end();
|
||||
?>
|
||||
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
<? echo $form->input('Product.principle_id', array('id'=>'principleSelect', 'label'=>'Principle','empty'=>'Select Principle'));?>
|
||||
<? echo $form->input('Product.principle_id', array('id'=>'principleAttachmentSelect', 'label'=>'Principle','empty'=>'Select Principle'));?>
|
||||
<div id="productsDiv"></div>
|
||||
<div id="productDetails"></div>
|
||||
|
||||
|
|
|
|||
|
|
@ -130,6 +130,7 @@ if ($currentuser['User']['access_level'] == 'manager' || $currentuser['User']['a
|
|||
<li><?php echo $html->link('Principles', '/principles/index'); ?>
|
||||
<ul>
|
||||
<li><?php echo $html->link('Principle Index', '/principles/index'); ?></li>
|
||||
<li><?php echo $html->link('Attachments', '/attachments/index'); ?></li>
|
||||
<li class="last"><?php echo $html->link('Add Principle', '/principles/add'); ?></li>
|
||||
</ul>
|
||||
</li>
|
||||
|
|
|
|||
|
|
@ -1650,3 +1650,15 @@ tr.no_items {
|
|||
font-size: 2em;
|
||||
padding: 0.5em;
|
||||
}
|
||||
#Attachments {
|
||||
margin-top: 1.5em;
|
||||
}
|
||||
h2.document-attachments {
|
||||
|
||||
}
|
||||
|
||||
|
||||
#attachments-list {
|
||||
margin-top: 0.5em;
|
||||
list-style: none;
|
||||
}
|
||||
|
|
|
|||
64
webroot/js/document_attachments.js
Normal file
64
webroot/js/document_attachments.js
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
$(function() {
|
||||
var documentID = $("#documentID").html();
|
||||
|
||||
|
||||
$("#addAttachment").click(function() {
|
||||
$("#addAttachmentModal").dialog('open');
|
||||
});
|
||||
|
||||
|
||||
$("#addAttachmentModal").dialog({
|
||||
autoOpen: false,
|
||||
height: 900,
|
||||
width: 600,
|
||||
modal: true,
|
||||
buttons: {
|
||||
"Add Attachment": 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")
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
},
|
||||
Cancel: function() {
|
||||
$( this ).dialog( "close" );
|
||||
}
|
||||
},
|
||||
close: function() {
|
||||
loadAttachments();
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
$("#attachmentPrincipleSelect").change(function() {
|
||||
var principleID = $(this).val();
|
||||
loadPrincipleAttachments(principleID);
|
||||
});
|
||||
|
||||
function loadPrincipleAttachments(id) {
|
||||
$.get('/documents/getAttachmentsByPrinciple/'+id, function(attachments) {
|
||||
$('#principleAttachments').html(attachments);
|
||||
});
|
||||
}
|
||||
|
||||
function loadAttachments() {
|
||||
|
||||
$.get('/documents/getAttachments/'+documentID, function(attachments) {
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
Loading…
Reference in a new issue