You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@guacamole.apache.org by vn...@apache.org on 2018/05/04 08:26:59 UTC

[05/21] guacamole-client git commit: GUACAMOLE-220: Add common directive for displaying the save/clone/cancel/delete buttons shared by all object management pages.

GUACAMOLE-220: Add common directive for displaying the save/clone/cancel/delete buttons shared by all object management pages.


Project: http://git-wip-us.apache.org/repos/asf/guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/guacamole-client/commit/e045da13
Tree: http://git-wip-us.apache.org/repos/asf/guacamole-client/tree/e045da13
Diff: http://git-wip-us.apache.org/repos/asf/guacamole-client/diff/e045da13

Branch: refs/heads/master
Commit: e045da132c729d0567f256708d204d607c053f9f
Parents: 4f43ddc
Author: Michael Jumper <mj...@apache.org>
Authored: Tue May 1 09:46:46 2018 -0700
Committer: Michael Jumper <mj...@apache.org>
Committed: Tue May 1 17:20:32 2018 -0700

----------------------------------------------------------------------
 .../app/manage/directives/managementButtons.js  | 201 +++++++++++++++++++
 .../app/manage/templates/managementButtons.html |   6 +
 2 files changed, 207 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/e045da13/guacamole/src/main/webapp/app/manage/directives/managementButtons.js
----------------------------------------------------------------------
diff --git a/guacamole/src/main/webapp/app/manage/directives/managementButtons.js b/guacamole/src/main/webapp/app/manage/directives/managementButtons.js
new file mode 100644
index 0000000..4074548
--- /dev/null
+++ b/guacamole/src/main/webapp/app/manage/directives/managementButtons.js
@@ -0,0 +1,201 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * Directive which displays a set of object management buttons (save, delete,
+ * clone, etc.) representing the actions available to the current user in
+ * context of the object being edited/created.
+ */
+angular.module('manage').directive('managementButtons', ['$injector',
+    function managementButtons($injector) {
+
+    // Required services
+    var guacNotification = $injector.get('guacNotification');
+
+    var directive = {
+
+        restrict    : 'E',
+        replace     : true,
+        templateUrl : 'app/manage/templates/managementButtons.html',
+
+        scope : {
+
+            /**
+             * The translation namespace associated with all applicable
+             * translation strings. This directive requires at least the
+             * following translation strings within the given namespace:
+             *
+             *     - ACTION_CANCEL
+             *     - ACTION_CLONE
+             *     - ACTION_DELETE
+             *     - ACTION_SAVE
+             *     - DIALOG_HEADER_CONFIRM_DELETE
+             *     - TEXT_CONFIRM_DELETE
+             *
+             * @type String
+             */
+            namespace : '=',
+
+            /**
+             * The permissions which dictate the management actions available
+             * to the current user.
+             *
+             * @type ManagementPermissions
+             */
+            permissions : '=',
+
+            /**
+             * The function to invoke to save the arbitrary object being edited
+             * if the current user has permission to do so. The provided
+             * function MUST return a promise which is resolved if the save
+             * operation succeeds and is rejected with an {@link Error} if the
+             * save operation fails.
+             *
+             * @type Function
+             */
+            save : '&',
+
+            /**
+             * The function to invoke when the current user chooses to clone
+             * the object being edited. The provided function MUST perform the
+             * actions necessary to produce an interface which will clone the
+             * object.
+             *
+             * @type Function
+             */
+            clone : '&',
+
+            /**
+             * The function to invoke to delete the arbitrary object being edited
+             * if the current user has permission to do so. The provided
+             * function MUST return a promise which is resolved if the delete
+             * operation succeeds and is rejected with an {@link Error} if the
+             * delete operation fails.
+             *
+             * @type Function
+             */
+            delete : '&',
+
+            /**
+             * The function to invoke when the current user chooses to cancel
+             * the edit in progress, or when a save/delete operation has
+             * succeeded. The provided function MUST perform the actions
+             * necessary to return the user to a reasonable starting point.
+             *
+             * @type Function
+             */
+            return : '&'
+
+        }
+
+    };
+
+    directive.controller = ['$scope', function managementButtonsController($scope) {
+
+        /**
+         * An action to be provided along with the object sent to showStatus which
+         * immediately deletes the current connection.
+         */
+        var DELETE_ACTION = {
+            name      : $scope.namespace + '.ACTION_DELETE',
+            className : 'danger',
+            callback  : function deleteCallback() {
+                deleteObjectImmediately();
+                guacNotification.showStatus(false);
+            }
+        };
+
+        /**
+         * An action to be provided along with the object sent to showStatus which
+         * closes the currently-shown status dialog.
+         */
+        var CANCEL_ACTION = {
+            name     : $scope.namespace + '.ACTION_CANCEL',
+            callback : function cancelCallback() {
+                guacNotification.showStatus(false);
+            }
+        };
+
+        /**
+         * Invokes the provided return function to navigate the user back to
+         * the page they started from.
+         */
+        var navigateBack = function navigateBack() {
+            $scope['return']($scope.$parent);
+        };
+
+        /**
+         * Invokes the provided delete function, immediately deleting the
+         * current object without prompting the user for confirmation. If
+         * deletion is successful, the user is navigated back to the page they
+         * started from. If the deletion fails, an error notification is
+         * displayed.
+         */
+        var deleteObjectImmediately = function deleteObjectImmediately() {
+            $scope['delete']($scope.$parent).then(navigateBack, guacNotification.SHOW_REQUEST_ERROR);
+        };
+
+        /**
+         * Cancels all pending edits, returning to the page the user started
+         * from.
+         */
+        $scope.cancel = navigateBack;
+
+        /**
+         * Cancels all pending edits, invoking the provided clone function to
+         * open an edit page for a new object which is prepopulated with the
+         * data from the current object.
+         */
+        $scope.cloneObject = function cloneObject () {
+            $scope.clone($scope.$parent);
+        };
+
+        /**
+         * Invokes the provided save function to saves the current object. If
+         * saving is successful, the user is navigated back to the page they
+         * started from. If saving fails, an error notification is displayed.
+         */
+        $scope.saveObject = function saveObject() {
+            $scope.save($scope.$parent).then(navigateBack, guacNotification.SHOW_REQUEST_ERROR);
+        };
+
+        /**
+         * Deletes the current object, prompting the user first to confirm that
+         * deletion is desired. If the user confirms that deletion is desired,
+         * the object is deleted through invoking the provided delete function.
+         * The user is automatically navigated back to the page they started
+         * from or given an error notification depending on whether deletion
+         * succeeds.
+         */
+        $scope.deleteObject = function deleteObject() {
+
+            // Confirm deletion request
+            guacNotification.showStatus({
+                title   : $scope.namespace + '.DIALOG_HEADER_CONFIRM_DELETE',
+                text    : { key : $scope.namespace + '.TEXT_CONFIRM_DELETE' },
+                actions : [ DELETE_ACTION, CANCEL_ACTION]
+            });
+
+        };
+
+    }];
+
+    return directive;
+
+}]);

http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/e045da13/guacamole/src/main/webapp/app/manage/templates/managementButtons.html
----------------------------------------------------------------------
diff --git a/guacamole/src/main/webapp/app/manage/templates/managementButtons.html b/guacamole/src/main/webapp/app/manage/templates/managementButtons.html
new file mode 100644
index 0000000..d43209a
--- /dev/null
+++ b/guacamole/src/main/webapp/app/manage/templates/managementButtons.html
@@ -0,0 +1,6 @@
+<div class="action-buttons">
+    <button ng-show="permissions.canSaveObject" ng-click="saveObject()">{{namespace + '.ACTION_SAVE' | translate}}</button>
+    <button ng-show="permissions.canCloneObject" ng-click="cloneObject()">{{namespace + '.ACTION_CLONE' | translate}}</button>
+    <button ng-click="cancel()">{{namespace + '.ACTION_CANCEL' | translate}}</button>
+    <button ng-show="permissions.canDeleteObject" ng-click="deleteObject()" class="danger">{{namespace + '.ACTION_DELETE' | translate}}</button>
+</div>