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='file-upload-button-cancel'>Cancel upload</a>
|
|
|
|
|
`);
|
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
|
|
|
|
2016-03-02 21:36:41 +00:00
|
|
|
// 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-03-02 21:36:41 +00:00
|
|
|
|
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);
|