Files
notifications-admin/app/assets/javascripts/fileUpload.js
T

35 lines
1.0 KiB
JavaScript
Raw Normal View History

2016-02-02 17:28:30 +00:00
(function(Modules) {
"use strict";
Modules.FileUpload = function() {
2016-04-08 14:00:30 +01:00
this.submit = () => this.$form.trigger('submit');
2016-02-02 17:28:30 +00:00
2016-04-08 14:00:30 +01:00
this.showCancelButton = () => $('.file-upload-button', this.$form).replaceWith(`
2023-06-08 13:12:00 -04:00
<a href="" class='usa-button usa-button--secondary'>Cancel upload</a>
2016-04-08 14:00:30 +01:00
`);
2016-02-02 17:28:30 +00:00
this.start = function(component) {
2016-04-08 14:00:30 +01:00
this.$form = $(component);
2016-02-02 17:28:30 +00:00
// The label gets styled like a button and is used to hide the native file upload control. This is so that
// users see a button that looks like the others on the site.
this.$form.find('label.file-upload-button').addClass('usa-button margin-bottom-1').attr( {role: 'button', tabindex: '0'} );
// Clear the form if the user navigates back to the page
2016-04-08 14:00:30 +01:00
$(window).on("pageshow", () => this.$form[0].reset());
2016-02-02 17:28:30 +00:00
// Need to put the event on the container, not the input for it to work properly
2016-04-08 14:00:30 +01:00
this.$form.on(
'change', '.file-upload-field',
() => this.submit() && this.showCancelButton()
);
2016-02-02 17:28:30 +00:00
};
};
})(window.GOVUK.Modules);