From f4c21006de4429e0f7a868ddfff0c329abea6b0b Mon Sep 17 00:00:00 2001 From: Anna Sidwell Date: Thu, 26 Apr 2018 18:03:04 +1000 Subject: [PATCH] Add AJAX file delete support and upload notifications, make UI nicer --- apps/files/static/files/upload.js | 215 +++++++++++++++--- apps/map/forms.py | 20 +- apps/map/templates/map/form.html | 35 +++ .../map/templates/map/forms/widgets/file.html | 7 + 4 files changed, 235 insertions(+), 42 deletions(-) create mode 100644 apps/map/templates/map/forms/widgets/file.html 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 = $("