From 5c7152dec1f7cca186bbb75b464777cc85a9bea3 Mon Sep 17 00:00:00 2001 From: Chris Houseknecht Date: Wed, 30 Jul 2014 18:13:55 -0400 Subject: [PATCH] File drag-n-drop Added an onerror handler to the FileReader. If the file cannot be read for some reason, throw an alert dialog letting user know things went wrong. --- awx/ui/static/lib/ansible/directives.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/awx/ui/static/lib/ansible/directives.js b/awx/ui/static/lib/ansible/directives.js index 8cc70ffc40..c324a29a4d 100644 --- a/awx/ui/static/lib/ansible/directives.js +++ b/awx/ui/static/lib/ansible/directives.js @@ -760,7 +760,7 @@ angular.module('AWDirectives', ['RestServices', 'Utilities', 'AuthService', 'Job // Support dropping files on an element. Used on credentials page for SSH/RSA private keys // Inspired by https://developer.mozilla.org/en-US/docs/Using_files_from_web_applications // - .directive('awDropFile', [ function() { + .directive('awDropFile', ['Alert', function(Alert) { return { require: 'ngModel', link: function(scope, element, attrs, ctrl) { @@ -783,6 +783,9 @@ angular.module('AWDirectives', ['RestServices', 'Utilities', 'AuthService', 'Job ctrl.$setViewValue(reader.result); ctrl.$render(); }; + reader.onerror = function() { + Alert('Error','There was an error reading the selected file.'); + } reader.readAsText(files[0]); }); }