mirror of
				https://github.com/gyurix1968/guacamole-client.git
				synced 2025-10-30 00:23:21 +00:00 
			
		
		
		
	Ticket #268: Remove now-unused UserManager class.
This commit is contained in:
		| @@ -353,229 +353,6 @@ GuacAdmin.ListItem = function(type, title) { | ||||
|  | ||||
| }; | ||||
|  | ||||
|  | ||||
| /** | ||||
|  * User management component. | ||||
|  * @constructor | ||||
|  */ | ||||
| GuacAdmin.UserManager = function() { | ||||
|  | ||||
|     /** | ||||
|      * Reference to this UserManager. | ||||
|      */ | ||||
|     var user_manager = this; | ||||
|  | ||||
|     /** | ||||
|      * Container element for UserManager. | ||||
|      */ | ||||
|     var element = GuacUI.createElement("div", "user-list"); | ||||
|  | ||||
|     // Create connection display elements | ||||
|     var add_item = GuacUI.createChildElement(element, "div", "add-user"); | ||||
|  | ||||
|     GuacUI.createChildElement(add_item, "div",  "icon user add"); | ||||
|     var name = GuacUI.createChildElement(add_item, "input", "name"); | ||||
|     name.setAttribute("type", "text"); | ||||
|     name.setAttribute("placeholder", "Add user"); | ||||
|  | ||||
|     var add_button = GuacUI.createChildElement(add_item, "button"); | ||||
|     add_button.textContent = "Add"; | ||||
|  | ||||
|     // If "Add" clicked, trigger onadd event | ||||
|     add_button.onclick = function() { | ||||
|         if (user_manager.onadd) { | ||||
|  | ||||
|             // Clear name if successful | ||||
|             if (user_manager.onadd(name.value)) | ||||
|                 name.value = ""; | ||||
|  | ||||
|         } | ||||
|     }; | ||||
|  | ||||
|     /** | ||||
|      * The selected username. | ||||
|      */ | ||||
|     this.selected = null; | ||||
|  | ||||
|     /** | ||||
|      * Set of all user GuacAdmin.ListItems. | ||||
|      */ | ||||
|     this.items = {}; | ||||
|  | ||||
|     /** | ||||
|      * Returns the DOM element representing this UserManager. | ||||
|      */ | ||||
|     this.getElement = function() { | ||||
|         return element; | ||||
|     }; | ||||
|  | ||||
|     /** | ||||
|      * Adds the given username to the users visible within this UserManager. | ||||
|      */ | ||||
|     this.add = function(username) { | ||||
|  | ||||
|         // Create item | ||||
|         var item = new GuacAdmin.ListItem("user", username); | ||||
|         var item_element = item.getElement(); | ||||
|  | ||||
|         // Select on click | ||||
|         item_element.onclick = function() { | ||||
|  | ||||
|             // If nothing selected, select this item | ||||
|             if (!user_manager.selected) { | ||||
|  | ||||
|                 // Change styling to reflect selected item | ||||
|                 GuacUI.addClass(element, "disabled"); | ||||
|                 GuacUI.addClass(item_element, "selected"); | ||||
|  | ||||
|                 // Update selected item | ||||
|                 user_manager.selected = username; | ||||
|  | ||||
|                 // User property form. | ||||
|                 var user_properties = new GuacAdmin.Form( | ||||
|  | ||||
|                     /* Fields */ | ||||
|                     [new GuacAdmin.Field.PASSWORD("Password:", [], | ||||
|                          ["f12a1930-7195-11e2-bcfd-0800200c9a66"]), | ||||
|  | ||||
|                      new GuacAdmin.Field.PASSWORD("Re-enter Password:", [], | ||||
|                          ["f12a1930-7195-11e2-bcfd-0800200c9a66"]), | ||||
|                      | ||||
|                      new GuacAdmin.Field.LIST("Connections:", | ||||
|                          ["A", "B", "C"], | ||||
|                          ["A"])], | ||||
|  | ||||
|                     /* Buttons */ | ||||
|                     [new GuacAdmin.Button("Save"), | ||||
|                      new GuacAdmin.Button("Cancel"), | ||||
|                      new GuacAdmin.Button("Delete")] | ||||
|  | ||||
|                 ); | ||||
|  | ||||
|                 // Set up events | ||||
|                 user_properties.onaction = function(title, fields) { | ||||
|  | ||||
|                     // Call removal handler, keep window up if not allowed. | ||||
|                     if (title == "Delete") { | ||||
|                         if (user_manager.onremove) { | ||||
|                             if (!user_manager.onremove(user_manager.selected)) | ||||
|                                 return; | ||||
|                         } | ||||
|                         else | ||||
|                             return; | ||||
|                     } | ||||
|  | ||||
|                     // Call save handler, keep window up if not allowed. | ||||
|                     if (title == "Save") { | ||||
|  | ||||
|                         if (user_manager.onsave) { | ||||
|  | ||||
|                             // FIXME: Validate passwords match | ||||
|                             var password = fields[0][0]; | ||||
|                             var connections = fields[2]; | ||||
|  | ||||
|                             if (!user_manager.onsave(user_manager.selected, password, connections)) | ||||
|                                 return; | ||||
|                         } | ||||
|                         else | ||||
|                             return; | ||||
|  | ||||
|                     } | ||||
|  | ||||
|                     // Hide | ||||
|                     user_manager.selected = null; | ||||
|                     item_element.removeChild(user_properties.getElement()); | ||||
|                     GuacUI.removeClass(element, "disabled"); | ||||
|                     GuacUI.removeClass(item_element, "selected"); | ||||
|                      | ||||
|                 }; | ||||
|  | ||||
|                 // Display properties | ||||
|                 item_element.appendChild(user_properties.getElement()); | ||||
|  | ||||
|             } | ||||
|  | ||||
|         }; | ||||
|  | ||||
|         // Append item | ||||
|         element.appendChild(item_element); | ||||
|         user_manager.items[username] = item; | ||||
|  | ||||
|     }; | ||||
|  | ||||
|     /** | ||||
|      * Removes the given username from the users visible within this UserManager. | ||||
|      */ | ||||
|     this.remove = function(username) { | ||||
|  | ||||
|         // If user exists, remove corresponding element and item entry | ||||
|         var item = user_manager.items[username]; | ||||
|         if (item) { | ||||
|             element.removeChild(item.getElement()); | ||||
|             delete user_manager.items[username]; | ||||
|         } | ||||
|  | ||||
|     }; | ||||
|  | ||||
|     /** | ||||
|      * Removes all visible usernames. | ||||
|      */ | ||||
|     this.clear = function() { | ||||
|  | ||||
|         // Remove all elements | ||||
|         for (var item in user_manager.items) | ||||
|             element.removeChild(user_manager.items[item].getElement()); | ||||
|  | ||||
|         // Remove all items | ||||
|         user_manager.items = {}; | ||||
|  | ||||
|     }; | ||||
|  | ||||
|     /** | ||||
|      * Sets all visible usernames. | ||||
|      *  | ||||
|      * @param {String[]} users Array of usernames to add. | ||||
|      */ | ||||
|     this.setUsers = function(users) { | ||||
|  | ||||
|         // Clear all users | ||||
|         user_manager.clear(); | ||||
|  | ||||
|         // Add given users | ||||
|         for (var i=0; i<users.length; i++) | ||||
|             user_manager.add(users[i]); | ||||
|  | ||||
|     }; | ||||
|  | ||||
|     /** | ||||
|      * Event handler called when the user wishes to add a given user. | ||||
|      *  | ||||
|      * @event | ||||
|      * @param {String} username The username added. | ||||
|      */ | ||||
|     this.onadd = null; | ||||
|  | ||||
|     /** | ||||
|      * Event handler called when the user wishes to remove a given user. | ||||
|      *  | ||||
|      * @event | ||||
|      * @param {String} username The username removed. | ||||
|      */ | ||||
|     this.onremove = null; | ||||
|  | ||||
|     /** | ||||
|      * Event handler called when the user has edited a given user, and wishes | ||||
|      * to save the updated user to the server. | ||||
|      *  | ||||
|      * @event | ||||
|      * @param {String} username The username edited. | ||||
|      * @param {String} password The password chosen. | ||||
|      * @param {String[]} connections The IDs of the connections chosen. | ||||
|      */ | ||||
|     this.onsave = null; | ||||
|  | ||||
| }; | ||||
|  | ||||
| /* | ||||
|  * Set handler for logout | ||||
|  */ | ||||
|   | ||||
		Reference in New Issue
	
	Block a user