diff --git a/horizon/static/horizon/js/horizon.d3linechart.js b/horizon/static/horizon/js/horizon.d3linechart.js index 804da8e24e..3fa97923d1 100644 --- a/horizon/static/horizon/js/horizon.d3linechart.js +++ b/horizon/static/horizon/js/horizon.d3linechart.js @@ -384,7 +384,8 @@ horizon.d3_line_chart = { // bigger. $(self.legend_element).css('height', ''); // FIXME add proper fail message - horizon.alert('error', gettext('An error occurred. Please try again later.')); + horizon.toast.add('error', + gettext('An error occurred. Please try again later.')); }; /************************************************************************/ diff --git a/horizon/static/horizon/js/horizon.firewalls.js b/horizon/static/horizon/js/horizon.firewalls.js index 99e6b05fad..15fd64c1ac 100644 --- a/horizon/static/horizon/js/horizon.firewalls.js +++ b/horizon/static/horizon/js/horizon.firewalls.js @@ -29,7 +29,7 @@ horizon.firewalls = { error: function() { if(via_user_submit) { horizon.clearErrorMessages(); - horizon.alert('error', gettext('There was a problem communicating with the server, please try again.')); + horizon.toast.add('error', gettext('There was a problem communicating with the server, please try again.')); } } }); diff --git a/horizon/static/horizon/js/horizon.instances.js b/horizon/static/horizon/js/horizon.instances.js index 028680ee6f..ab00b4e39a 100644 --- a/horizon/static/horizon/js/horizon.instances.js +++ b/horizon/static/horizon/js/horizon.instances.js @@ -29,7 +29,7 @@ horizon.instances = { error: function() { if(via_user_submit) { horizon.clearErrorMessages(); - horizon.alert('error', gettext('There was a problem communicating with the server, please try again.')); + horizon.toast.add('error', gettext('There was a problem communicating with the server, please try again.')); } } }); @@ -273,13 +273,13 @@ horizon.addInitFunction(horizon.instances.init = function () { }; reader.onerror = function() { horizon.clearErrorMessages(); - horizon.alert('error', gettext('Could not read the file')); + horizon.toast.add('error', gettext('Could not read the file')); }; reader.readAsText(file); } else { horizon.clearErrorMessages(); - horizon.alert('error', gettext('Could not decrypt the password')); + horizon.toast.add('error', gettext('Could not decrypt the password')); } }); /* @@ -308,7 +308,7 @@ horizon.addInitFunction(horizon.instances.init = function () { var decrypted_password = horizon.instances.decrypt_password(encrypted_password, private_key); if (decrypted_password === false || decrypted_password === null) { horizon.clearErrorMessages(); - horizon.alert('error', gettext('Could not decrypt the password')); + horizon.toast.add('error', gettext('Could not decrypt the password')); } else { $("#id_decrypted_password").val(decrypted_password); diff --git a/horizon/static/horizon/js/horizon.modals.js b/horizon/static/horizon/js/horizon.modals.js index 1574e1afeb..c926c9c7fc 100644 --- a/horizon/static/horizon/js/horizon.modals.js +++ b/horizon/static/horizon/js/horizon.modals.js @@ -320,7 +320,7 @@ horizon.addInitFunction(horizon.modals.init = function() { } else { $('.ajax-modal, .dropdown-toggle').removeAttr("disabled"); $formElement.closest(".modal").modal("hide"); - horizon.alert("danger", gettext("There was an error submitting the form. Please try again.")); + horizon.toast.add("danger", gettext("There was an error submitting the form. Please try again.")); } } @@ -425,7 +425,7 @@ horizon.addInitFunction(horizon.modals.init = function() { else { if (!horizon.ajax.get_messages(jqXHR)) { // Generic error handler. Really generic. - horizon.alert("danger", gettext("An error occurred. Please try again later.")); + horizon.toast.add("danger", gettext("An error occurred. Please try again later.")); } } }, diff --git a/horizon/static/horizon/js/horizon.networktopologycommon.js b/horizon/static/horizon/js/horizon.networktopologycommon.js index 29e2a9fb07..292ebeecbe 100644 --- a/horizon/static/horizon/js/horizon.networktopologycommon.js +++ b/horizon/static/horizon/js/horizon.networktopologycommon.js @@ -71,7 +71,7 @@ horizon.networktopologymessager = { angular.element(window).on('message', function(e) { var message = angular.element.parseJSON(e.originalEvent.data); if (self.previous_message !== message.message) { - horizon.alert(message.type, message.message); + horizon.toast.add(message.type, message.message); self.previous_message = message.message; self.delete_post_message(message.iframe_id); self.messageNotify(message); diff --git a/horizon/static/horizon/js/horizon.tables_inline_edit.js b/horizon/static/horizon/js/horizon.tables_inline_edit.js index 0e33e20d4d..4d217f8bac 100644 --- a/horizon/static/horizon/js/horizon.tables_inline_edit.js +++ b/horizon/static/horizon/js/horizon.tables_inline_edit.js @@ -83,13 +83,13 @@ horizon.inline_edit = { if (redir_url){ location.href = redir_url; } else { - horizon.alert("error", gettext("Not authorized to do this operation.")); + horizon.toast.add("error", gettext("Not authorized to do this operation.")); } } else { if (!horizon.ajax.get_messages(jqXHR)) { // Generic error handler. Really generic. - horizon.alert("error", gettext("An error occurred. Please try again later.")); + horizon.toast.add("error", gettext("An error occurred. Please try again later.")); } } }, @@ -158,13 +158,13 @@ horizon.inline_edit = { if (redir_url){ location.href = redir_url; } else { - horizon.alert("error", gettext("Not authorized to do this operation.")); + horizon.toast.add("error", gettext("Not authorized to do this operation.")); } } else { if (!horizon.ajax.get_messages(jqXHR)) { // Generic error handler. Really generic. - horizon.alert("error", gettext("An error occurred. Please try again later.")); + horizon.toast.add("error", gettext("An error occurred. Please try again later.")); } } }, diff --git a/openstack_dashboard/dashboards/project/instances/templates/instances/_detail_console.html b/openstack_dashboard/dashboards/project/instances/templates/instances/_detail_console.html index 2a1dfff7ef..15cf537015 100644 --- a/openstack_dashboard/dashboards/project/instances/templates/instances/_detail_console.html +++ b/openstack_dashboard/dashboards/project/instances/templates/instances/_detail_console.html @@ -22,7 +22,7 @@ {% else %}
{% blocktrans %}Unable to load console. Please reload page to try again.{% endblocktrans %}
{% endif %} diff --git a/openstack_dashboard/static/app/app.module.js b/openstack_dashboard/static/app/app.module.js index 8c2df73f1b..52c49cd373 100644 --- a/openstack_dashboard/static/app/app.module.js +++ b/openstack_dashboard/static/app/app.module.js @@ -96,6 +96,7 @@ 'gettextCatalog', 'horizon.framework.conf.spinner_options', 'horizon.framework.util.tech-debt.helper-functions', + 'horizon.framework.widgets.toast.service', '$cookieStore', '$http', '$cookies', @@ -106,6 +107,7 @@ gettextCatalog, spinnerOptions, hzUtils, + toastService, $cookieStore, $http, $cookies, @@ -119,6 +121,8 @@ horizon.conf.spinner_options = spinnerOptions; + horizon.toast = toastService; + if (angular.version.major === 1 && angular.version.minor < 4) { horizon.cookies = angular.extend({}, $cookieStore, { getObject: $cookieStore.get, diff --git a/openstack_dashboard/static/app/core/openstack-service-api/settings.service.js b/openstack_dashboard/static/app/core/openstack-service-api/settings.service.js index b62e6aa24a..61b13a71e1 100644 --- a/openstack_dashboard/static/app/core/openstack-service-api/settings.service.js +++ b/openstack_dashboard/static/app/core/openstack-service-api/settings.service.js @@ -71,8 +71,8 @@ function onError() { var message = gettext('Unable to retrieve settings.'); - if (!suppressError && horizon.alert) { - horizon.alert('error', message); + if (!suppressError && horizon.toast) { + horizon.toast.add('error', message); } return message; diff --git a/openstack_dashboard/static/app/core/openstack-service-api/settings.service.spec.js b/openstack_dashboard/static/app/core/openstack-service-api/settings.service.spec.js index 72eed67962..dfd3fad62b 100644 --- a/openstack_dashboard/static/app/core/openstack-service-api/settings.service.spec.js +++ b/openstack_dashboard/static/app/core/openstack-service-api/settings.service.spec.js @@ -16,7 +16,7 @@ (function () { 'use strict'; - horizon.alert = angular.noop; + horizon.toast = angular.noop; var $httpBackend; var responseMockOpts = {succeed: true}; @@ -65,7 +65,7 @@ it('should fail when error response', function () { responseMockOpts.succeed = false; - spyOn(horizon, 'alert'); + spyOn(horizon.toast, 'add'); settingsService.getSettings().then( function (actual) { fail('Should not have succeeded: ' + angular.toJson(actual)); @@ -75,13 +75,13 @@ } ); $httpBackend.flush(); - expect(horizon.alert).toHaveBeenCalledWith('error', + expect(horizon.toast.add).toHaveBeenCalledWith('error', gettext('Unable to retrieve settings.')); }); it('should suppress error messages if asked', function () { responseMockOpts.succeed = false; - spyOn(horizon, 'alert'); + spyOn(horizon.toast, 'add'); settingsService.getSettings(true).then( function (actual) { fail('Should not have succeeded: ' + angular.toJson(actual)); @@ -91,7 +91,7 @@ } ); $httpBackend.flush(); - expect(horizon.alert).not.toHaveBeenCalled(); + expect(horizon.toast.add).not.toHaveBeenCalled(); }); }); diff --git a/releasenotes/notes/use-toast-instead-of-alert-ef2f7dec2bd1121a.yaml b/releasenotes/notes/use-toast-instead-of-alert-ef2f7dec2bd1121a.yaml new file mode 100644 index 0000000000..dd8d82aca1 --- /dev/null +++ b/releasenotes/notes/use-toast-instead-of-alert-ef2f7dec2bd1121a.yaml @@ -0,0 +1,15 @@ +--- +prelude: > + In an effort to establish Angular conventions, + use the framework's toastService rather than the + legacy horizon.alert(...) in client-side code. + horizon.alert is still used by the django messaging + framework, so horizon.messages.js still exists. +deprecations: + - All previous instances of horizon.alert(...) used by + client-side have been replaced with horizon.toast. + Alert messages via horizon.alert(...) should be + avoided when writing new JavaScript code. + horizon.toast.add('error', gettext(...)) should be + used instead. +