Skip to content

Commit

Permalink
delete attachments
Browse files Browse the repository at this point in the history
  • Loading branch information
sdebacker committed Jan 27, 2015
1 parent 0d373ec commit ad6efe1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/views/admin/_image-fieldset.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@if($model->$field)
<div>
{{ $model->present()->thumb(150, 150, ['resize'], $field) }}
<small class="text-danger delete-attachment" data-key="{{ $field }}">Supprimer</small>
<small class="text-danger delete-attachment" data-table="{{ $model->getTable() }}" data-id="{{ $model->id }}" data-field="{{ $field }}">Supprimer</small>
</div>
@endif
<div class="media-body">
Expand Down
23 changes: 13 additions & 10 deletions public/js/admin/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,27 +74,30 @@ function initTinymce(selector) {
*/
$('.delete-attachment').click(function(){

var urlForDeleteImg = document.URL.split('?')[0],
key = $(this).data('key'),
data = {};

if (! confirm('Delete ' + key + '?')) {
var field = $(this).data('field'),
id = $(this).data('id'),
table = $(this).data('table'),
data = {},
$this = $(this),
url = '/api/v1/' + table + '/' + id;

if (! confirm('Delete ' + field + '?')) {
return false;
}

urlForDeleteImg = urlForDeleteImg.replace(/\/edit$/, '');
data['id'] = urlForDeleteImg.split('/').pop();
data[key] = 'delete';
data['id'] = id;
data[field] = 'delete';

$.ajax({
type: 'PUT',
url: urlForDeleteImg,
url: url,
data: data
}).done(function() {
location.reload();
$this.parent().remove();
}).fail(function () {
alertify.error('An error occurred while deleting attachment.');
});

return false;
});

Expand Down

0 comments on commit ad6efe1

Please sign in to comment.