Added shipments delete

This commit is contained in:
Karl Cordes 2013-04-29 23:00:24 +10:00
parent 24eaa4c0cd
commit 573971310d
5 changed files with 36 additions and 22 deletions

View file

@ -237,13 +237,12 @@ class ShipmentsController extends AppController {
function delete($id = null) { function delete($id = null) {
if (!$id) { $this->layout = 'ajax';
$this->Session->setFlash(__('Invalid id for Shipment', true));
$this->redirect(array('action'=>'index'));
}
if ($this->Shipment->del($id)) { if ($this->Shipment->del($id)) {
$this->Session->setFlash(__('Shipment deleted', true)); return "Deleted"; // This should be returning status codes
$this->redirect(array('action'=>'index')); }
else {
return "Fail"; //All over the app.
} }
} }

View file

@ -34,6 +34,8 @@
<tr> <tr>
<td class="actions"> <td class="actions">
<button id="<?=$shipment['Shipment']['id']?>" class="editButton">Edit</button> <button id="<?=$shipment['Shipment']['id']?>" class="editButton">Edit</button>
<button class="deleteButton">Delete</button>
</td> </td>
<td> <td>
<?php <?php

View file

View file

@ -1677,3 +1677,8 @@ ul.document-buttons {
ul.document-buttons li { ul.document-buttons li {
padding: 0.5em; padding: 0.5em;
} }
.deleteButton {
display: block;
clear: both;
}

View file

@ -66,6 +66,7 @@ $(function() {
$( ".newShipment" ).button().click(function() { $( ".newShipment" ).button().click(function() {
$.get('/shipments/add/', false, function(data) { $.get('/shipments/add/', false, function(data) {
$("#add-form").html(data); $("#add-form").html(data);
@ -80,14 +81,24 @@ $(function() {
$(".editButton").button().click(function() { $(".editButton").button().click(function() {
var id = $(this).attr('id'); var id = $(this).attr('id');
$.get('/shipments/edit/'+id, false, function(data) { $.get('/shipments/edit/'+id, false, function(data) {
$("#edit-form").html(data); $("#edit-form").html(data);
$( "#edit-form" ).dialog( "open" ); $( "#edit-form" ).dialog( "open" );
} ); } );
});
$(".deleteButton").click(function() {
var id = $(this).prev().attr('id');
var confirmed = confirm("Permanently delete this shipment?");
if(confirmed) {
$.get('/shipments/delete/'+id, false, function() {
window.location.reload();
});
}
}); });
@ -98,7 +109,4 @@ $(function() {
}); });