replace horizon.alert used by client-side with horizon.toast

Only horizon.alert() calls. Not changing the django message
template.

Change-Id: I3f2f4ea6a64abbd073efd80a434094ca1baaf0b5
This commit is contained in:
Cindy Lu 2016-08-02 18:09:02 -07:00
parent 73630ca4af
commit f2c0504ccc
11 changed files with 41 additions and 21 deletions

View File

@ -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.'));
};
/************************************************************************/

View File

@ -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.'));
}
}
});

View File

@ -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);

View File

@ -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."));
}
}
},

View File

@ -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);

View File

@ -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."));
}
}
},

View File

@ -22,7 +22,7 @@
</script>
{% else %}
<script type="text/javascript">
horizon.alert('error', '{% blocktrans %}Console is currently unavailable.{% endblocktrans %}');
horizon.toast.add('error', '{% blocktrans %}Console is currently unavailable.{% endblocktrans %}');
</script>
<div class="well">{% blocktrans %}Unable to load console. Please reload page to try again.{% endblocktrans %}</div>
{% endif %}

View File

@ -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,

View File

@ -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;

View File

@ -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();
});
});

View File

@ -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.