summaryrefslogtreecommitdiff
path: root/public/assets/js/lib/views/details/settings.js
diff options
context:
space:
mode:
Diffstat (limited to 'public/assets/js/lib/views/details/settings.js')
-rw-r--r--public/assets/js/lib/views/details/settings.js80
1 files changed, 80 insertions, 0 deletions
diff --git a/public/assets/js/lib/views/details/settings.js b/public/assets/js/lib/views/details/settings.js
index b1fd956..c2ff078 100644
--- a/public/assets/js/lib/views/details/settings.js
+++ b/public/assets/js/lib/views/details/settings.js
@@ -14,6 +14,9 @@ var ThreadSettingsForm = FormView.extend({
"click #allowed_names [type=checkbox]": "removeAllowed",
"keydown [name=allowed_field]": "keydownAllowed",
"blur [name=allowed_field]": "updateAllowed",
+ "click [name=file_id]": "toggleFile",
+ "click tr.file": "toggleFileRow",
+ "click #move_files": "moveFiles",
},
action: "",
@@ -111,6 +114,28 @@ var ThreadSettingsForm = FormView.extend({
}.bind(this))
},
+ loadThreads: function(threads){
+ // update the dropdown list of threads
+ var $thread_select = this.$('[name=thread]')
+ if (!threads || !threads.length) {
+ $thread_select.parent().hide()
+ return
+ }
+ $thread_select.parent().show()
+ threads
+ .map( (a) => [a.title.toLowerCase(), a])
+ .sort( (a,b) => a[0].localeCompare(b[0]) )
+ .forEach((pair) => {
+ const thread = pair[1]
+ var option = document.createElement('option')
+ option.value = thread.id
+ // console.log(thread, get_revision(thread))
+ option.innerHTML = '[' + thread.id + get_revision(thread) + '] ' + sanitize(thread.title)
+ $thread_select.append(option)
+ })
+ // console.log(threads)
+ },
+
toggleAllowed: function(e){
var checked = this.$('[name=privacy]').prop('checked')
this.$(".allowed_field_container").toggle(checked)
@@ -228,6 +253,61 @@ var ThreadSettingsForm = FormView.extend({
app.view.files.resort(sort_name)
},
+ toggleFile: function(e){
+ // e.preventDefault()
+ e.stopPropagation()
+ const $input = $(e.currentTarget)
+ const $tr = $input.closest('tr.file')
+ const value = e.currentTarget.checked
+ // $(e.currentTarget).prop('checked', value)
+ // console.log('check', $input, value)
+ this.toggleFileChecked($tr, null, value)
+ },
+ toggleFileRow: function(e){
+ // e.preventDefault()
+ e.stopPropagation()
+ const $tr = $(e.currentTarget)
+ const $input = $tr.find('input[type="checkbox"]')
+ const value = ! $input.prop('checked')
+ this.toggleFileChecked($tr, $input, value)
+ },
+ toggleFileChecked: function($tr, $input, value){
+ $tr.toggleClass('checked', value)
+ if ($input) $input.prop('checked', value)
+ },
+
+ moveFiles: function(){
+ var thread_id = this.$("[name=thread]").val()
+ // if (!thread_id) return alert("Please choose a thread")
+ var file_ids = toArray(this.el.querySelectorAll("[name=file_id]:checked")).map(input => input.value)
+ console.log("thread:", thread_id)
+ console.log("files:", file_ids)
+ var promises = file_ids.map(file_id => {
+ return new Promise((resolve, reject) => {
+ $.ajax({
+ method: "GET",
+ url: '/api/file/' + file_id + '/move/' + thread_id,
+ headers: { "csrf-token": $("[name=_csrf]").attr("value") },
+ dataType: "json",
+ success: function(data){
+ console.log('moved', file_id)
+ resolve(data)
+ },
+ error: function(){
+ console.log('error moving', file_id)
+ reject()
+ }
+ })
+ })
+ })
+ Promise.all(promises).then( () => {
+ window.location.href = '/details/' + thread_id
+ }).catch(() =>{
+ console.error('whaaaaa')
+ alert('there was a problem moving the files...')
+ })
+ },
+
deleteThread: function(e){
var data = this.options.parent.data
var id = data.thread.id