aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2016-07-17 10:48:53 -0400
committerPaul Duncan <pabs@pablotron.org>2016-07-17 10:48:53 -0400
commit083dc329e5793cc441cfea5093326fe148ff6d22 (patch)
tree514221289cfa5aa805978bfd1433c0288a8e4bf3
parent4de3658cd7a13bc42de57f66ada25f61f546b46e (diff)
downloadguff-083dc329e5793cc441cfea5093326fe148ff6d22.tar.bz2
guff-083dc329e5793cc441cfea5093326fe148ff6d22.zip
add file delete
-rw-r--r--data/assets/js/admin/tabs/files.js35
1 files changed, 30 insertions, 5 deletions
diff --git a/data/assets/js/admin/tabs/files.js b/data/assets/js/admin/tabs/files.js
index d7021a3..6fcdde7 100644
--- a/data/assets/js/admin/tabs/files.js
+++ b/data/assets/js/admin/tabs/files.js
@@ -56,6 +56,10 @@ jQuery(function($) {
"</a>",
"</div><!-- btn-group -->",
],
+
+ delete_confirm: [
+ "Are you sure you want to delete \"%{name|h}\"?",
+ ],
});
function get_crumbs(path) {
@@ -161,20 +165,41 @@ jQuery(function($) {
});
$('#file-actions').on('click', 'a', function() {
- var data = $(this).data();
+ var action_id = $(this).data('id');
// hide dropdown
$('body').trigger('click');
- if (data.id == 'download') {
+ if (action_id == 'download') {
// alert('TODO: download file');
var url = $('#files .active').data('url');
if (url)
location.href = url;
- } else if (data.id == 'move') {
+ } else if (action_id == 'move') {
alert('TODO: move file');
- } else if (data.id == 'delete') {
- alert('TODO: delete file');
+ } else if (action_id == 'delete') {
+ var data = $('#files .active').data();
+
+ if (confirm(TEMPLATES.run('delete_confirm', data))) {
+ send('file/delete', {
+ path: data.path,
+ }).always(function() {
+ // TODO: need loading handler
+ }).fail(function(r) {
+ var error = r.responseText;
+
+ try {
+ var data = $.parseJSON(r.responseText);
+ if (data.error)
+ error = data.error;
+ } catch (e) {}
+
+ alert("Error: " + error);
+ }).done(function() {
+ // reload file list
+ reload();
+ });
+ }
}
// stop event