summaryrefslogtreecommitdiff
path: root/public/assets
diff options
context:
space:
mode:
Diffstat (limited to 'public/assets')
-rw-r--r--public/assets/js/lib/views/details/commentform.js10
-rw-r--r--public/assets/js/lib/views/details/files.js10
-rw-r--r--public/assets/js/lib/views/details/settings.js29
3 files changed, 36 insertions, 13 deletions
diff --git a/public/assets/js/lib/views/details/commentform.js b/public/assets/js/lib/views/details/commentform.js
index f3d79ac..2759fd6 100644
--- a/public/assets/js/lib/views/details/commentform.js
+++ b/public/assets/js/lib/views/details/commentform.js
@@ -49,6 +49,8 @@ var CommentForm = FormView.extend({
},
success: function(data){
+ console.log("data from server")
+ console.log(data)
$("[name=comment").val('')
$("[name=files").val('')
// window.location.reload()
@@ -57,7 +59,11 @@ var CommentForm = FormView.extend({
console.log("this is data")
console.log(data)
data.comment && this.parent.comments.load([data.comment])
- data.files && this.parent.files.load(data.files)
- data.files && this.parent.gallery.load(data.files)
+ window.joe = this
+ if (data.files){
+ this.options.parent.data.files = this.options.parent.data.files.concat(data.files)
+ this.parent.files.load()
+ this.parent.gallery.load(data.files)
+ }
}
})
diff --git a/public/assets/js/lib/views/details/files.js b/public/assets/js/lib/views/details/files.js
index 915f90b..beed3e6 100644
--- a/public/assets/js/lib/views/details/files.js
+++ b/public/assets/js/lib/views/details/files.js
@@ -16,12 +16,17 @@ var FilesView = FormView.extend({
},
load: function(files, thread){
- if (! files.length) {
+ this.files = this.options.parent.data.files
+ window.ok = this.options.parent
+ if (! this.files.length) {
+ console.log("hiding")
this.$el.hide()
+ }else{
+ console.log("showing")
+ this.$el.show()
}
var total = 0, has_music = false
- this.files = this.files.concat(files)
this.thread = thread || this.thread
this.files.forEach(function(file){
if (is_image(file.filename)) {
@@ -44,7 +49,6 @@ var FilesView = FormView.extend({
}
},
- files: [],
sortedFiles: [],
currentSort: 'name',
reversed: false,
diff --git a/public/assets/js/lib/views/details/settings.js b/public/assets/js/lib/views/details/settings.js
index b270f02..55c8771 100644
--- a/public/assets/js/lib/views/details/settings.js
+++ b/public/assets/js/lib/views/details/settings.js
@@ -216,7 +216,6 @@ var ThreadSettingsForm = FormView.extend({
},
success: function(data){
- console.log(data)
window.location.href = "/details/" + this.options.parent.data.thread.id
},
@@ -309,6 +308,10 @@ var ThreadSettingsForm = FormView.extend({
})
},
deleteFiles: function(){
+ var thread_files = this.options.parent.data.files
+ var files_view = this.options.parent.files
+ window.hoe = files_view
+ window.before = this.options.parent.data.files
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
@@ -320,13 +323,20 @@ var ThreadSettingsForm = FormView.extend({
return new Promise((resolve, reject) => {
$.ajax({
method: "DELETE",
- url: "/api/file/" + node.value,
+ 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()
+
+ thread_files.splice(
+ thread_files.findIndex(
+ (file) => {
+ return (file.id === parseInt(node.value)) }
+ ),1)[0]
+
+ resolve()
},
error: function(){
console.log('error deleting file', node.value)
@@ -336,8 +346,9 @@ var ThreadSettingsForm = FormView.extend({
})
})
Promise.all(promises).then( () => {
- window.location.href = '/details/' + thread_id
- }).catch(() =>{
+ files_view.load()
+ }).catch((error) =>{
+ console.log(error)
console.error('whaaaaa')
alert('there was a problem deleting the files...')
})
@@ -370,11 +381,12 @@ var ThreadSettingsForm = FormView.extend({
deleteFile: function(e){
e.preventDefault()
e.stopPropagation()
+ var data = this.options.parent.data
+ var files_view = this.options.parent.files
var $el = $(e.currentTarget)
var $parent = $el.closest('.file')
var file_id = $el.data('id')
if (! file_id) return
- var data = this.options.parent.data
var file = data.files.find(f => f.id === file_id)
if (! file) return
var msg = "Are you sure you want to delete this file?\n\n#" + file_id + ' "' + sanitizeHTML(file.filename) + '"'
@@ -386,9 +398,10 @@ var ThreadSettingsForm = FormView.extend({
headers: { "csrf-token": $("[name=_csrf]").attr("value") },
data: JSON.stringify({ csrf: csrf() }),
dataType: "json",
- success: function(data){
- console.log(data)
+ success: function(resp){
+ data.files.splice(data.files.findIndex((f) => parseInt(f.id) === file_id ), 1)
$parent.remove()
+ files_view.load()
}
})
}