diff --git a/apps/files/static/files/upload.js b/apps/files/static/files/upload.js index dbd858c..952724d 100644 --- a/apps/files/static/files/upload.js +++ b/apps/files/static/files/upload.js @@ -1,40 +1,193 @@ -$(function () { - // un-set "name" attributes to avoid submitting to server - $(".fileupload").removeAttr('name'); - // set up all file inputs for jQuery-fileUpload - $(".fileupload").fileupload({ - dataType: 'json', - paramName: 'file', - done: function (e, data) { - // process server response - if (data.result.is_valid) { - var $field = $('#id_' + $(this).attr('data-field')), - $ul = $(this).siblings('ul'), - $li = $("
  • "), - $remove = $(''), - ids = $field.val().split(",").filter(function (v) { - return v != ''; - }); +class MultipleFilesWidget { + constructor(div) { + this.root = div + this.fieldName = this.root.getAttribute('data-field') + this.fileList = [] + this.element = { + list: this.root.querySelector('.filewidget--list'), + uploadButton: this.root.querySelector('.filewidget--input'), + field: document.querySelector(`[name="${this.fieldName}"]`) + } - ids.push(data.result.id); - - if (!$ul.length) { - $ul = $("