Skip to content

Commit

Permalink
Add ability to delete item
Browse files Browse the repository at this point in the history
  • Loading branch information
rmccue committed Dec 30, 2009
1 parent e163682 commit 4c0d8e5
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
28 changes: 28 additions & 0 deletions numbat/static/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,32 @@ $(document).ready(function () {
"url": "api"
});
});

$('.deletelink').click(function () {
if ( !confirm('Are you sure you want to delete this item?'))
return false;
if ( !confirm('Really really sure? You can\'t undo this.'))
return false;

$.ajax({
// Data
"data": {
"method": "delete-item",
"item": $('#id').val()
},
"dataType": "json",

// Callbacks
"error": function () {
$(".submit-row").append('<p class="error">Couldn\'t remove row, an error occurred. <a href="#close">Close</a>.</p>');
},
"success": function () {
window.location.href = './';
},

// Request
"type": "POST",
"url": "api"
})
});
});
7 changes: 7 additions & 0 deletions numbat/views/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ protected function api() {
case 'delete-row':
$this->delete_row();
break;
case 'delete-item':
if (empty($_REQUEST['item']))
throw new Exception('No item specified');
$item = new Item($_REQUEST['item']);
$item->delete_item();
die(json_encode(array('msg' => 'Deleted item', 'code' => 0)));
return;
default:
throw new Exception('Invalid method specified');
}
Expand Down

0 comments on commit 4c0d8e5

Please sign in to comment.