summaryrefslogtreecommitdiff
path: root/public/assets/js/lib
diff options
context:
space:
mode:
authorpep <yes@peepee.me>2020-07-28 08:49:23 +0000
committerpep <yes@peepee.me>2020-07-28 08:49:23 +0000
commitd051c6d71f2d2e24ca113f127ff7e0b143d0042a (patch)
treecbdb16aa708d3efe5eab6b291c6ee8baaeae94d0 /public/assets/js/lib
parent77720e1a510cb5311f77c8a63f920223c72f899a (diff)
fixed multiple files thing
Diffstat (limited to 'public/assets/js/lib')
-rw-r--r--public/assets/js/lib/views/details/settings.js36
1 files changed, 36 insertions, 0 deletions
diff --git a/public/assets/js/lib/views/details/settings.js b/public/assets/js/lib/views/details/settings.js
index c2ff078..a027b12 100644
--- a/public/assets/js/lib/views/details/settings.js
+++ b/public/assets/js/lib/views/details/settings.js
@@ -17,6 +17,7 @@ var ThreadSettingsForm = FormView.extend({
"click [name=file_id]": "toggleFile",
"click tr.file": "toggleFileRow",
"click #move_files": "moveFiles",
+ "click .files_delete": "deleteFiles",
},
action: "",
@@ -307,6 +308,41 @@ var ThreadSettingsForm = FormView.extend({
alert('there was a problem moving the files...')
})
},
+ deleteFiles: function(){
+ var inputs_checked = toArray(this.el.querySelectorAll("[name=file_id]:checked"))
+ var file_names = inputs_checked.map(input => input.parentElement.nextElementSibling.firstElementChild.innerHTML)
+ if (! inputs_checked.length) return
+ var msg = "Are you sure you want to delete these files? \n\n" +
+ file_names.join("\n")
+ var should_remove = confirm(msg)
+ if (should_remove) {
+ }
+ var promises = inputs_checked.map(node => {
+ return new Promise((resolve, reject) => {
+ $.ajax({
+ method: "DELETE",
+ url: "/api/file/" + node.value,
+ headers: { "csrf-token": $("[name=_csrf]").attr("value") },
+ data: JSON.stringify({ csrf: csrf() }),
+ dataType: "json",
+ success: function(data){
+ console.log(data)
+ $(node).closest('.file').remove()
+ },
+ error: function(){
+ console.log('error deleting file', node.value)
+ reject()
+ }
+ })
+ })
+ })
+ Promise.all(promises).then( () => {
+ window.location.href = '/details/' + thread_id
+ }).catch(() =>{
+ console.error('whaaaaa')
+ alert('there was a problem deleting the files...')
+ })
+ },
deleteThread: function(e){
var data = this.options.parent.data