mirror of
				https://github.com/gyurix1968/guacamole-client.git
				synced 2025-10-31 00:53:21 +00:00 
			
		
		
		
	GUAC-605: Simplify status modal API.
This commit is contained in:
		| @@ -178,17 +178,18 @@ angular.module('home').controller('clientController', ['$scope', '$routeParams', | |||||||
|     // Show status dialog when client status changes |     // Show status dialog when client status changes | ||||||
|     $scope.$on('guacClientStateChange', function clientStateChangeListener(event, client, status) { |     $scope.$on('guacClientStateChange', function clientStateChangeListener(event, client, status) { | ||||||
|  |  | ||||||
|         // Hide previous status, if any |  | ||||||
|         statusModal.deactivate(); |  | ||||||
|  |  | ||||||
|         // Show new status if not yet connected |         // Show new status if not yet connected | ||||||
|         if (status !== "connected") { |         if (status !== "connected") { | ||||||
|             statusModal.activate({ |             statusModal.showStatus({ | ||||||
|                 title: "client.status.connectingStatusTitle", |                 title: "client.status.connectingStatusTitle", | ||||||
|                 text: "client.status.clientStates." + status |                 text: "client.status.clientStates." + status | ||||||
|             }); |             }); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  |         // Hide status upon connecting | ||||||
|  |         else | ||||||
|  |             statusModal.showStatus(false); | ||||||
|  |  | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     // Show status dialog when client errors occur |     // Show status dialog when client errors occur | ||||||
| @@ -197,14 +198,11 @@ angular.module('home').controller('clientController', ['$scope', '$routeParams', | |||||||
|         // Disconnect |         // Disconnect | ||||||
|         $scope.id = null; |         $scope.id = null; | ||||||
|  |  | ||||||
|         // Hide any existing status |  | ||||||
|         statusModal.deactivate(); |  | ||||||
|  |  | ||||||
|         // Determine translation name of error |         // Determine translation name of error | ||||||
|         var errorName = (status in CLIENT_ERRORS) ? status.toString(16) : "DEFAULT"; |         var errorName = (status in CLIENT_ERRORS) ? status.toString(16) : "DEFAULT"; | ||||||
|  |  | ||||||
|         // Show error status |         // Show error status | ||||||
|         statusModal.activate({ |         statusModal.showStatus({ | ||||||
|             className: "error", |             className: "error", | ||||||
|             title: "client.error.connectionErrorTitle", |             title: "client.error.connectionErrorTitle", | ||||||
|             text: "client.error.clientErrors." + errorName, |             text: "client.error.clientErrors." + errorName, | ||||||
| @@ -216,12 +214,9 @@ angular.module('home').controller('clientController', ['$scope', '$routeParams', | |||||||
|     // Show status dialog when tunnel status changes |     // Show status dialog when tunnel status changes | ||||||
|     $scope.$on('guacTunnelStateChange', function tunnelStateChangeListener(event, tunnel, status) { |     $scope.$on('guacTunnelStateChange', function tunnelStateChangeListener(event, tunnel, status) { | ||||||
|  |  | ||||||
|         // Hide previous status, if any |  | ||||||
|         statusModal.deactivate(); |  | ||||||
|  |  | ||||||
|         // Show new status only if disconnected |         // Show new status only if disconnected | ||||||
|         if (status === "closed") { |         if (status === "closed") { | ||||||
|             statusModal.activate({ |             statusModal.showStatus({ | ||||||
|                 title: "client.status.closedStatusTitle", |                 title: "client.status.closedStatusTitle", | ||||||
|                 text: "client.status.tunnelStates." + status |                 text: "client.status.tunnelStates." + status | ||||||
|             }); |             }); | ||||||
| @@ -235,14 +230,11 @@ angular.module('home').controller('clientController', ['$scope', '$routeParams', | |||||||
|         // Disconnect |         // Disconnect | ||||||
|         $scope.id = null; |         $scope.id = null; | ||||||
|  |  | ||||||
|         // Hide any existing status |  | ||||||
|         statusModal.deactivate(); |  | ||||||
|  |  | ||||||
|         // Determine translation name of error |         // Determine translation name of error | ||||||
|         var errorName = (status in TUNNEL_ERRORS) ? status.toString(16) : "DEFAULT"; |         var errorName = (status in TUNNEL_ERRORS) ? status.toString(16) : "DEFAULT"; | ||||||
|  |  | ||||||
|         // Show error status |         // Show error status | ||||||
|         statusModal.activate({ |         statusModal.showStatus({ | ||||||
|             className: "error", |             className: "error", | ||||||
|             title: "client.error.connectionErrorTitle", |             title: "client.error.connectionErrorTitle", | ||||||
|             text: "client.error.tunnelErrors." + errorName, |             text: "client.error.tunnelErrors." + errorName, | ||||||
|   | |||||||
| @@ -29,20 +29,18 @@ angular.module('manage').controller('statusController', ['$scope', '$rootScope', | |||||||
|     var statusModal = $injector.get('statusModal'); |     var statusModal = $injector.get('statusModal'); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Fires a guacStatusAction event signalling a chosen action. By default, |      * Fires a guacStatusAction event signalling a chosen action. The status | ||||||
|      * the status modal will be closed, but this can be prevented by calling |      * modal will be cloased prior to firing the action event. | ||||||
|      * preventDefault() on the event. |  | ||||||
|      * |      * | ||||||
|      * @param {String} action The name of the action. |      * @param {String} action The name of the action. | ||||||
|      */ |      */ | ||||||
|     $scope.fireAction = function fireAction(action) { |     $scope.fireAction = function fireAction(action) { | ||||||
|  |  | ||||||
|         // Fire action event |         // Hide status modal | ||||||
|         var actionEvent = $rootScope.$broadcast('guacStatusAction', action); |         statusModal.showStatus(false); | ||||||
|  |  | ||||||
|         // Close modal unless default is prevented |         // Fire action event | ||||||
|         if (!actionEvent.defaultPrevented) |         $rootScope.$broadcast('guacStatusAction', action); | ||||||
|             statusModal.deactivate(); |  | ||||||
|  |  | ||||||
|     }; |     }; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -26,11 +26,53 @@ | |||||||
| angular.module('manage').factory('statusModal', ['btfModal',  | angular.module('manage').factory('statusModal', ['btfModal',  | ||||||
|         function statusModal(btfModal) { |         function statusModal(btfModal) { | ||||||
|  |  | ||||||
|  |     var service = {}; | ||||||
|  |  | ||||||
|     // Create the modal object to be used later to actually create the modal |     // Create the modal object to be used later to actually create the modal | ||||||
|     return btfModal({ |     var modalService = btfModal({ | ||||||
|         controller: 'statusController', |         controller: 'statusController', | ||||||
|         controllerAs: 'modal', |         controllerAs: 'modal', | ||||||
|         templateUrl: 'app/index/templates/status.html' |         templateUrl: 'app/index/templates/status.html' | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Whether the status modal is currently displayed. | ||||||
|  |      * | ||||||
|  |      * @type Boolean | ||||||
|  |      */ | ||||||
|  |     service.shown = false; | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Shows or hides the status modal. | ||||||
|  |      * | ||||||
|  |      * @param {Boolean|Object} status The status to show, or false to hide the | ||||||
|  |      *                                current status. | ||||||
|  |      * @param {String} [status.title] The title of the status modal. | ||||||
|  |      * @param {String} [status.text] The body text of the status modal. | ||||||
|  |      * @param {String} [status.className] The CSS class name to apply to the | ||||||
|  |      *                                    modal, in addition to the default | ||||||
|  |      *                                    "dialog" and "status" classes. | ||||||
|  |      * @param {String[]} [status.actions] Array of action names which | ||||||
|  |      *                                    correspond to button captions. Each | ||||||
|  |      *                                    action will be displayed as a button | ||||||
|  |      *                                    within the status modal. Clickin a | ||||||
|  |      *                                    button will fire a guacStatusAction | ||||||
|  |      *                                    event. | ||||||
|  |      */ | ||||||
|  |     service.showStatus = function showStatus(status) { | ||||||
|  |  | ||||||
|  |         // Hide any existing status | ||||||
|  |         modalService.deactivate(); | ||||||
|  |         service.shown = false; | ||||||
|  |  | ||||||
|  |         // Show new status if requested | ||||||
|  |         if (status) { | ||||||
|  |             modalService.activate(status); | ||||||
|  |             service.shown = true; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |     }; | ||||||
|  |  | ||||||
|  |     return service; | ||||||
|  |  | ||||||
| }]); | }]); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user