codecombat/app/views/admin/FilesView.coffee

44 lines
1.2 KiB
CoffeeScript
Raw Normal View History

RootView = require 'views/core/RootView'
2014-01-03 13:32:13 -05:00
template = require 'templates/admin/files'
tableTemplate = require 'templates/admin/files_table'
module.exports = class FilesView extends RootView
2014-06-30 22:16:26 -04:00
id: 'admin-files-view'
2014-01-03 13:32:13 -05:00
template: template
2014-06-30 22:16:26 -04:00
2014-01-03 13:32:13 -05:00
events:
'click #upload-button': -> filepicker.pick {mimetypes:'audio/*'}, @onFileChosen
'change #folder-select': 'loadFiles'
2014-06-30 22:16:26 -04:00
2014-01-03 13:32:13 -05:00
afterRender: ->
super()
require('core/services/filepicker')() # Initialize if needed
2014-01-03 13:32:13 -05:00
@loadFiles()
2014-06-30 22:16:26 -04:00
2014-01-03 13:32:13 -05:00
onFileChosen: (InkBlob) =>
body =
url: InkBlob.url
filename: InkBlob.filename
mimetype: InkBlob.mimetype
path: @currentFolder()
force: true
2014-01-03 13:32:13 -05:00
# Automatically overwrite if the same path was put in here before
# body.force = true # if InkBlob.filename is @data
@uploadingPath = [@currentFolder(), InkBlob.filename].join('/')
2014-06-30 22:16:26 -04:00
$.ajax('/file', {type: 'POST', data: body, success: @onFileUploaded})
2014-01-03 13:32:13 -05:00
onFileUploaded: (e) =>
@loadFiles()
2014-06-30 22:16:26 -04:00
2014-01-03 13:32:13 -05:00
currentFolder: -> @$el.find('#folder-select').val()
loadFiles: ->
$.ajax
url: "/file/#{@currentFolder()}/"
success: @onLoadedFiles
2014-06-30 22:16:26 -04:00
2014-01-03 13:32:13 -05:00
onLoadedFiles: (res) =>
table = tableTemplate({files:res})
2014-06-30 22:16:26 -04:00
@$el.find('#file-table').replaceWith(table)