/* * Copyright (C) 2013 Glyptodon LLC * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ /** * General set of UI elements and UI-related functions regarding * administration. */ var GuacAdmin = { "containers" : { "connection_list" : document.getElementById("connection-list"), "user_list" : document.getElementById("user-list"), "user_list_buttons" : document.getElementById("user-list-buttons"), }, "buttons" : { "back" : document.getElementById("back"), "logout" : document.getElementById("logout"), "add_connection" : document.getElementById("add-connection"), "add_connection_group" : document.getElementById("add-connection-group"), "add_user" : document.getElementById("add-user") }, "fields" : { "username" : document.getElementById("username") }, "cached_permissions" : null, "cached_protocols" : null, "cached_root_group" : null }; /** * An arbitrary input field. * * @constructor */ GuacAdmin.Field = function() { /** * Returns the DOM Element representing this field. * * @return {Element} The DOM Element representing this field. */ this.getElement = function() {}; /** * Returns the value of this field. * * @return {String} The value of this field. */ this.getValue = function() {}; /** * Sets the value of this field. * * @param {String} value The value of this field. */ this.setValue = function(value) {}; }; /** * Simple HTML input field. * * @augments GuacAdmin.Field * @param {String} type The type of HTML field. */ GuacAdmin.Field._HTML_INPUT = function(type) { // Call parent constructor GuacAdmin.Field.apply(this); // Create backing element var element = GuacUI.createElement("input"); element.setAttribute("type", type); this.getValue = function() { return element.value; }; this.getElement = function() { return element; }; this.setValue = function(value) { element.value = value; }; }; GuacAdmin.Field._HTML_INPUT.prototype = new GuacAdmin.Field(); /** * A basic text field. * * @augments GuacAdmin.Field._HTML_INPUT */ GuacAdmin.Field.TEXT = function() { GuacAdmin.Field._HTML_INPUT.apply(this, ["text"]); }; GuacAdmin.Field.TEXT.prototype = new GuacAdmin.Field._HTML_INPUT(); /** * A basic multiline text field. * * @augments GuacAdmin.Field */ GuacAdmin.Field.MULTILINE = function() { // Call parent constructor GuacAdmin.Field.apply(this); // Create backing element var element = GuacUI.createElement("textarea"); this.getValue = function() { return element.value; }; this.getElement = function() { return element; }; this.setValue = function(value) { element.value = value; }; }; GuacAdmin.Field.MULTILINE.prototype = new GuacAdmin.Field(); /** * A basic password field. * * @augments GuacAdmin.Field._HTML_INPUT */ GuacAdmin.Field.PASSWORD = function() { GuacAdmin.Field._HTML_INPUT.apply(this, ["password"]); }; GuacAdmin.Field.PASSWORD.prototype = new GuacAdmin.Field._HTML_INPUT(); /** * A basic numeric field, leveraging the new HTML5 field types. * * @augments GuacAdmin.Field._HTML_INPUT */ GuacAdmin.Field.NUMERIC = function() { GuacAdmin.Field._HTML_INPUT.apply(this, ["number"]); }; GuacAdmin.Field.NUMERIC.prototype = new GuacAdmin.Field._HTML_INPUT(); /** * Simple checkbox. * * @augments GuacAdmin.Field */ GuacAdmin.Field.CHECKBOX = function(value) { // Call parent constructor GuacAdmin.Field.apply(this); // Create backing element var element = GuacUI.createElement("input"); element.setAttribute("type", "checkbox"); element.setAttribute("value", value); this.getValue = function() { if (element.checked) return value; else return ""; }; this.getElement = function() { return element; }; this.setValue = function(new_value) { if (new_value == value) element.checked = true; else element.checked = false; }; }; GuacAdmin.Field.CHECKBOX.prototype = new GuacAdmin.Field(); /** * Enumerated field type. * * @augments GuacAdmin.Field */ GuacAdmin.Field.ENUM = function(values) { // Call parent constructor GuacAdmin.Field.apply(this); // Create backing element var element = GuacUI.createElement("select"); for (var i=0; i 0) { // History section var history_section = GuacUI.createChildElement(sections, "dd"); var history_table = GuacUI.createChildElement(history_section, "table", "history section"); var history_table_header = GuacUI.createChildElement( history_table, "tr"); GuacUI.createChildElement(history_table_header, "th").textContent = "Username"; GuacUI.createChildElement(history_table_header, "th").textContent = "Start Time"; GuacUI.createChildElement(history_table_header, "th").textContent = "Duration"; // Paginated body of history var history_buttons = GuacUI.createChildElement(history_section, "div", "list-pager-buttons"); var history_body = GuacUI.createChildElement(history_table, "tbody"); var history_pager = new GuacUI.Pager(history_body); // Add history for (i=0; i