diff --git a/app/assets/javascripts/hyrax.js b/app/assets/javascripts/hyrax.js index 5e1cd7643f..b2ac1cffa0 100644 --- a/app/assets/javascripts/hyrax.js +++ b/app/assets/javascripts/hyrax.js @@ -22,9 +22,12 @@ //= require action_cable //= require hyrax/monkey_patch_turbolinks -//= require hyrax/fileupload +// blueimp's standalone micro-templating helper, used by the permissions and +// relationships editors (formerly loaded via the old upload widget) +//= require fileupload/tmpl // Provide AMD module support //= require almond +//= require hyrax/fileupload //= require hyrax/notification //= require hyrax/app //= require hyrax/config diff --git a/app/assets/javascripts/hyrax/fileupload.js b/app/assets/javascripts/hyrax/fileupload.js index 4fffedc21e..606913a4bb 100644 --- a/app/assets/javascripts/hyrax/fileupload.js +++ b/app/assets/javascripts/hyrax/fileupload.js @@ -1,8 +1,18 @@ //= require hyrax/uploader -// This file is the default initialization of the fileupload. If you want to call -// hyraxUploader with other options (like afterSubmit), then override this file. +// This file is the default initialization of the file upload widgets. If you +// want to initialize Hyrax.Uploader with other options, override this file. Blacklight.onLoad(function() { - var options = {}; - $('#fileupload').hyraxUploader(options); - $('#fileuploadlogo').hyraxUploader({downloadTemplateId: 'logo-template-download'}); + // expose the uploader for view-level initializers and overrides + window.Hyrax = window.Hyrax || {}; + if (!window.Hyrax.Uploader) { + window.Hyrax.Uploader = require('hyrax/uploader').Uploader; + } + + var main = document.getElementById('fileupload'); + if (main && !main.hyraxUploader) { new Hyrax.Uploader(main, {}); } + + var logo = document.getElementById('fileuploadlogo'); + if (logo && !logo.hyraxUploader) { + new Hyrax.Uploader(logo, { rowTemplate: 'hyrax-upload-row-logo' }); + } }); diff --git a/app/assets/javascripts/hyrax/save_work/uploaded_files.es6 b/app/assets/javascripts/hyrax/save_work/uploaded_files.es6 index 68882914a6..ae7da08d9e 100644 --- a/app/assets/javascripts/hyrax/save_work/uploaded_files.es6 +++ b/app/assets/javascripts/hyrax/save_work/uploaded_files.es6 @@ -12,6 +12,11 @@ export class UploadedFiles { this.uploadsInProgress -= 1 callback(e, data) }) + // canceled or errored uploads no longer count as in progress + this.element.on('fileuploadfail', (e, data) => { + this.uploadsInProgress -= 1 + callback(e, data) + }) this.element.on('fileuploaddestroyed', callback) } diff --git a/app/assets/javascripts/hyrax/uploader.es6 b/app/assets/javascripts/hyrax/uploader.es6 new file mode 100644 index 0000000000..ca20f4bf09 --- /dev/null +++ b/app/assets/javascripts/hyrax/uploader.es6 @@ -0,0 +1,502 @@ +// Hyrax.Uploader — dependency-free replacement for the vendored blueimp +// jQuery-File-Upload widget. +// +// Speaks Hyrax's two-step staged upload protocol: +// +// 1. POST /uploads with `files[]=` pre-creates a +// Hyrax::UploadedFile record and returns its id; +// 2. the file's bytes are POSTed with that `id`, split into sequential +// chunks with a Content-Range header when the file exceeds +// `maxChunkSize` — keeping each request small enough for proxies that +// cap request size (e.g. Cloudflare's 100 MB limit); +// 3. completed uploads render a row from a server-side