/* * Guacamole - Clientless Remote Desktop * Copyright (C) 2010 Michael Jumper * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ /** * Main Guacamole admin namespace. * @namespace */ var GuacAdmin = GuacAdmin || {}; /** * An arbitrary input field. * * @constructor * @param {String} title A human-readable title for the field. * @param {String[]} available The allowed value(s), if any. * @param {String[]} selected The selected value(s), if any. */ GuacAdmin.Field = function(title, available, selected) { /** * A human-readable title describing this field. */ this.title = title; /** * All available values, if any. */ this.available = available || []; /** * All selected values, if any. */ this.selected = selected || []; /** * Returns the DOM Element representing this field. * * @return {Element} The DOM Element representing this field. */ this.getElement = function() {}; /** * Returns the selected values of this field. * * @return {String[]} All selected values. */ this.getSelected = function() {}; }; /** * Simple HTML input field. * * @augments GuacAdmin.Field */ GuacAdmin.Field._HTML_INPUT = function(type, title, available, selected) { // Call parent constructor GuacAdmin.Field.apply(this, [title, available, selected]); // Create backing element var element = GuacUI.createElement("input"); element.setAttribute("type", type); if (selected && selected.length == 1) element.setAttribute("value", selected[0]); this.getSelected = function() { return [element.value]; }; this.getElement = function() { return element; }; }; GuacAdmin.Field._HTML_INPUT.prototype = new GuacAdmin.Field(); /** * A basic text field. * * @augments GuacAdmin.Field._HTML_INPUT */ GuacAdmin.Field.TEXT = function(title, available, selected) { GuacAdmin.Field._HTML_INPUT.apply(this, ["text", title, available, selected]); }; GuacAdmin.Field.TEXT.prototype = new GuacAdmin.Field._HTML_INPUT(); /** * A basic password field. * * @augments GuacAdmin.Field._HTML_INPUT */ GuacAdmin.Field.PASSWORD = function(title, available, selected) { GuacAdmin.Field._HTML_INPUT.apply(this, ["password", title, available, selected]); }; GuacAdmin.Field.PASSWORD.prototype = new GuacAdmin.Field._HTML_INPUT(); /** * Multi-select list where each element has a corresponding checkbox. * * @augments GuacAdmin.Field */ GuacAdmin.Field.LIST = function(title, available, selected) { // Call parent constructor GuacAdmin.Field.apply(this, [title, available, selected]); var i; // All selected connections var is_selected = {}; for (i=0; i