From a3ebcddb360ac82c89d413004feaab5a9ca8bd72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrik=20Kom=C3=A1nek?= Date: Mon, 17 Oct 2016 12:45:18 +0200 Subject: [PATCH 1/4] Making the upload button to be disabled before selecting a file to upload. --- app/assets/javascripts/import.js | 9 +++++++++ app/views/miq_ae_tools/_import_export.html.haml | 6 +++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/import.js b/app/assets/javascripts/import.js index 026214963be..3d382ba974f 100644 --- a/app/assets/javascripts/import.js +++ b/app/assets/javascripts/import.js @@ -9,6 +9,15 @@ 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..e883577e755 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,6 +150,10 @@ $(function() { miqInitSelectPicker(); + $("#upload_file").on("change", function() { + ImportSetup.setUpUploadImportButton('#upload-datastore-import') + }); + $('#upload-datastore-import').click(function() { miqSparkleOn(); }); From 737f94e1aec34bee62ca989f29b12e0796a432d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrik=20Kom=C3=A1nek?= Date: Wed, 19 Oct 2016 16:10:42 +0200 Subject: [PATCH 2/4] Changing click method to on("click", ....). --- app/views/miq_ae_tools/_import_export.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/miq_ae_tools/_import_export.html.haml b/app/views/miq_ae_tools/_import_export.html.haml index e883577e755..bf6244df76d 100644 --- a/app/views/miq_ae_tools/_import_export.html.haml +++ b/app/views/miq_ae_tools/_import_export.html.haml @@ -154,7 +154,7 @@ ImportSetup.setUpUploadImportButton('#upload-datastore-import') }); - $('#upload-datastore-import').click(function() { + $('#upload-datastore-import').on("click", function() { miqSparkleOn(); }); From a08d89bb8ff1e1fa8f1c235f6ae55f4bbd15f8c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrik=20Kom=C3=A1nek?= Date: Wed, 19 Oct 2016 16:11:39 +0200 Subject: [PATCH 3/4] Refactoring the rest of the upload buttons. Making them to use the setUpUploadImportButton function. --- app/assets/javascripts/import.js | 3 +-- app/views/report/_export_custom_reports.html.haml | 14 ++++---------- app/views/report/_export_widgets.html.haml | 13 +++---------- 3 files changed, 8 insertions(+), 22 deletions(-) diff --git a/app/assets/javascripts/import.js b/app/assets/javascripts/import.js index 3d382ba974f..fc50be2c3ec 100644 --- a/app/assets/javascripts/import.js +++ b/app/assets/javascripts/import.js @@ -12,8 +12,7 @@ var ImportSetup = { setUpUploadImportButton: function(button_id) { if ($("#upload_file").val()){ $(button_id).prop('disabled', false); - } - else { + } else { $(button_id).prop('disabled', true); } }, 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 From 1858835645ee46da44142c3b2633756f2e1c2edf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrik=20Kom=C3=A1nek?= Date: Fri, 21 Oct 2016 20:11:16 +0200 Subject: [PATCH 4/4] Adding a spec for ImportSetup.setUpUploadImportButton function. --- spec/javascripts/import_spec.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) 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 += '
' + html += ' '; + html += '
'; + html += '
'; + html += ' '; + html += '
'; + + setFixtures(html); + }); + + it('make upload button to not be disabled', function(){ + $('#upload_button').prop('disabled', true); + $('#upload_file').prop('value', 'test_value'); + ImportSetup.setUpUploadImportButton('#upload_button'); + expect($('#upload_button').prop('disabled')).toEqual(false); + }); + + it('make upload button to be disabled', function(){ + $('#upload_button').prop('disabled', false); + ImportSetup.setUpUploadImportButton('#upload_button'); + expect($('#upload_button').prop('disabled')).toEqual(true); + }); + }); }); describe('#clearMessages', function() {