diff --git a/app/assets/javascripts/import.js b/app/assets/javascripts/import.js index 026214963be..fc50be2c3ec 100644 --- a/app/assets/javascripts/import.js +++ b/app/assets/javascripts/import.js @@ -9,6 +9,14 @@ var ImportSetup = { }); }, + setUpUploadImportButton: function(button_id) { + if ($("#upload_file").val()){ + $(button_id).prop('disabled', false); + } else { + $(button_id).prop('disabled', true); + } + }, + listenForGitPostMessages: function() { window.addEventListener('message', function(event) { var unencodedMessage = event.data.message.replace(/"/g, '"'); diff --git a/app/views/miq_ae_tools/_import_export.html.haml b/app/views/miq_ae_tools/_import_export.html.haml index 0f630030541..bf6244df76d 100644 --- a/app/views/miq_ae_tools/_import_export.html.haml +++ b/app/views/miq_ae_tools/_import_export.html.haml @@ -22,7 +22,7 @@ :javascript $(":file").filestyle({icon: false, placeholder: "No file chosen"}); .col-md-6 - = submit_tag(_("Upload"), :id => "upload-datastore-import", :class => "upload btn btn-default") + = submit_tag(_("Upload"), :id => "upload-datastore-import", :class => "upload btn btn-default", :disabled => true) %hr %h3 @@ -150,7 +150,11 @@ $(function() { miqInitSelectPicker(); - $('#upload-datastore-import').click(function() { + $("#upload_file").on("change", function() { + ImportSetup.setUpUploadImportButton('#upload-datastore-import') + }); + + $('#upload-datastore-import').on("click", function() { miqSparkleOn(); }); diff --git a/app/views/report/_export_custom_reports.html.haml b/app/views/report/_export_custom_reports.html.haml index 49412074efc..eb1199c9d0f 100644 --- a/app/views/report/_export_custom_reports.html.haml +++ b/app/views/report/_export_custom_reports.html.haml @@ -27,16 +27,10 @@ .col-md-6 = submit_tag(_("Upload"), :class => "btn btn-default", :id => "upload_atags", :disabled => true) :javascript - $("#upload_file").on("change", - function(){ - if ($(this).val()){ - $('#upload_atags').prop('disabled', false); - } - else { - $('#upload_atags').prop('disabled', true); - } - } - ); + $("#upload_file").on("change", function() { + ImportSetup.setUpUploadImportButton('#upload_atags') + }); + %hr %h3 = _('Export') diff --git a/app/views/report/_export_widgets.html.haml b/app/views/report/_export_widgets.html.haml index 0924d12ecdc..52eb58697d4 100644 --- a/app/views/report/_export_widgets.html.haml +++ b/app/views/report/_export_widgets.html.haml @@ -47,16 +47,9 @@ .col-md-6 = submit_tag(_("Upload"), :class => "btn btn-default", :id => "upload_widget", :disabled => true) :javascript - $("#upload_file").on("change", - function(){ - if ($(this).val()){ - $('#upload_widget').prop('disabled', false); - } - else { - $('#upload_widget').prop('disabled', true); - } - } - ); + $("#upload_file").on("change", function() { + ImportSetup.setUpUploadImportButton('#upload_widget') + }); %hr %h3 diff --git a/spec/javascripts/import_spec.js b/spec/javascripts/import_spec.js index 383351340bd..3e988cec777 100644 --- a/spec/javascripts/import_spec.js +++ b/spec/javascripts/import_spec.js @@ -183,6 +183,33 @@ describe('import.js', function() { }); }); }); + + describe('SettingUpImportButton', function() { + beforeEach(function() { + var html = ''; + html += '