From 1e5e9b607b56e8cf0fd15b9b58337baa6c0652aa Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Thu, 26 Apr 2018 21:20:05 -0700 Subject: [PATCH] GUACAMOLE-526: Add convenience function for displaying modal notifications for REST errors. --- .../notification/services/guacNotification.js | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/guacamole/src/main/webapp/app/notification/services/guacNotification.js b/guacamole/src/main/webapp/app/notification/services/guacNotification.js index c3d4a2bee..a1b8d1016 100644 --- a/guacamole/src/main/webapp/app/notification/services/guacNotification.js +++ b/guacamole/src/main/webapp/app/notification/services/guacNotification.js @@ -37,6 +37,19 @@ angular.module('notification').factory('guacNotification', ['$injector', */ var storedStatus = sessionStorageFactory.create(false); + /** + * An action to be provided along with the object sent to showStatus which + * closes the currently-shown status dialog. + * + * @type NotificationAction + */ + service.ACKNOWLEDGE_ACTION = { + name : 'APP.ACTION_ACKNOWLEDGE', + callback : function acknowledgeCallback() { + service.showStatus(false); + } + }; + /** * Retrieves the current status notification, which may simply be false if * no status is currently shown. @@ -79,6 +92,28 @@ angular.module('notification').factory('guacNotification', ['$injector', storedStatus(status); }; + /** + * Shows the given REST error response as a modal status. If a status + * notification is already currently shown, this function will have no + * effect. + * + * @param {Error} error + * The error object returned from the failed REST request. + * + * @example + * + * someService.updateObject(object) + * ['catch'](guacNotification.showRequestError); + */ + service.showRequestError = function showRequestError(error) { + service.showStatus({ + className : 'error', + title : 'APP.DIALOG_HEADER_ERROR', + text : error.translatableMessage, + actions : [ service.ACKNOWLEDGE_ACTION ] + }); + }; + // Hide status upon navigation $rootScope.$on('$routeChangeSuccess', function() { service.showStatus(false);