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

34 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(`
<a href="" class='govuk-button govuk-button--warning govuk-!-margin-right-1'>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('govuk-button govuk-!-margin-right-1');
// 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);