mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-08 06:01:22 +00:00
#268: Add getElement() to button. Implement onsave event.
This commit is contained in:
@@ -85,6 +85,11 @@
|
|||||||
var user_manager = new GuacAdmin.UserManager();
|
var user_manager = new GuacAdmin.UserManager();
|
||||||
users.appendChild(user_manager.getElement());
|
users.appendChild(user_manager.getElement());
|
||||||
|
|
||||||
|
user_manager.onsave = function(id, password, connections) {
|
||||||
|
console.log(id, password, connections);
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
]]></script>
|
]]></script>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
@@ -23,9 +23,7 @@
|
|||||||
var GuacAdmin = GuacAdmin || {};
|
var GuacAdmin = GuacAdmin || {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An arbitrary input field. Note that this object is not a component, and has
|
* An arbitrary input field.
|
||||||
* no corresponding element. Other objects which use GuacAdmin.Field may
|
|
||||||
* interpret its values and render an element, however.
|
|
||||||
*
|
*
|
||||||
* @constructor
|
* @constructor
|
||||||
* @param {String} title A human-readable title for the field.
|
* @param {String} title A human-readable title for the field.
|
||||||
@@ -140,32 +138,36 @@ GuacAdmin.Field.LIST = function(title, available, selected) {
|
|||||||
var element = GuacUI.createElement("div", "list");
|
var element = GuacUI.createElement("div", "list");
|
||||||
for (i=0; i<available.length; i++) {
|
for (i=0; i<available.length; i++) {
|
||||||
|
|
||||||
// Get name
|
(function() {
|
||||||
var name = available[i];
|
|
||||||
|
|
||||||
// Containing div
|
// Get name
|
||||||
var list_item = GuacUI.createChildElement(element, "div", "connection");
|
var name = available[i];
|
||||||
|
|
||||||
// Checkbox
|
// Containing div
|
||||||
var checkbox = GuacUI.createChildElement(list_item, "input");
|
var list_item = GuacUI.createChildElement(element, "div", "connection");
|
||||||
checkbox.setAttribute("type", "checkbox");
|
|
||||||
if (is_selected[name])
|
|
||||||
checkbox.checked = true;
|
|
||||||
|
|
||||||
// Update selected set when changed
|
// Checkbox
|
||||||
checkbox.onclick =
|
var checkbox = GuacUI.createChildElement(list_item, "input");
|
||||||
checkbox.onchange = function() {
|
checkbox.setAttribute("type", "checkbox");
|
||||||
|
if (is_selected[name])
|
||||||
|
checkbox.checked = true;
|
||||||
|
|
||||||
if (checkbox.checked)
|
// Update selected set when changed
|
||||||
is_selected[name] = true;
|
checkbox.onclick =
|
||||||
else if (is_selected[name])
|
checkbox.onchange = function() {
|
||||||
delete is_selected[name];
|
|
||||||
|
|
||||||
};
|
if (checkbox.checked)
|
||||||
|
is_selected[name] = true;
|
||||||
|
else if (is_selected[name])
|
||||||
|
delete is_selected[name];
|
||||||
|
|
||||||
// Connection name
|
};
|
||||||
var name_element = GuacUI.createChildElement(list_item, "span", "name");
|
|
||||||
name_element.textContent = name;
|
// Connection name
|
||||||
|
var name_element = GuacUI.createChildElement(list_item, "span", "name");
|
||||||
|
name_element.textContent = name;
|
||||||
|
|
||||||
|
})();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -183,9 +185,7 @@ GuacAdmin.Field.LIST.prototype = new GuacAdmin.Field();
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An arbitrary button. Note that this object is not a component, and has
|
* An arbitrary button.
|
||||||
* no corresponding element. Other objects which use GuacAdmin.Button may
|
|
||||||
* interpret its values and render an element, however.
|
|
||||||
*
|
*
|
||||||
* @constructor
|
* @constructor
|
||||||
* @param {String} title A human-readable title for the button.
|
* @param {String} title A human-readable title for the button.
|
||||||
@@ -197,6 +197,17 @@ GuacAdmin.Button = function(title) {
|
|||||||
*/
|
*/
|
||||||
this.title = title;
|
this.title = title;
|
||||||
|
|
||||||
|
// Button element
|
||||||
|
var element = GuacUI.createElement("button");
|
||||||
|
element.textContent = title;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the DOM element associated with this button.
|
||||||
|
*/
|
||||||
|
this.getElement = function() {
|
||||||
|
return element;
|
||||||
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -223,10 +234,6 @@ GuacAdmin.Form = function(fields, buttons) {
|
|||||||
// Buttons
|
// Buttons
|
||||||
var button_div = GuacUI.createChildElement(element, "div", "object-buttons");
|
var button_div = GuacUI.createChildElement(element, "div", "object-buttons");
|
||||||
|
|
||||||
// Array of field value getters, corresponding to each field in the
|
|
||||||
// original field array.
|
|
||||||
var value_getters = [];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the DOM element representing this form.
|
* Returns the DOM element representing this form.
|
||||||
*/
|
*/
|
||||||
@@ -271,16 +278,14 @@ GuacAdmin.Form = function(fields, buttons) {
|
|||||||
|
|
||||||
for (i=0; i<buttons.length; i++) {
|
for (i=0; i<buttons.length; i++) {
|
||||||
|
|
||||||
// Add new button
|
|
||||||
var button = GuacUI.createChildElement(button_div, "button", name);
|
|
||||||
button.textContent = buttons[i].title;
|
|
||||||
|
|
||||||
// Set up event
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
|
// Get title and element
|
||||||
var title = buttons[i].title;
|
var title = buttons[i].title;
|
||||||
|
var button_element = buttons[i].getElement();
|
||||||
|
|
||||||
button.addEventListener("click", function(e) {
|
// Trigger onaction event when clicked
|
||||||
|
button_element.addEventListener("click", function(e) {
|
||||||
|
|
||||||
if (guac_form.onaction) {
|
if (guac_form.onaction) {
|
||||||
|
|
||||||
@@ -296,6 +301,9 @@ GuacAdmin.Form = function(fields, buttons) {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Add to cell
|
||||||
|
button_div.appendChild(button_element);
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -400,15 +408,31 @@ GuacAdmin.UserManager = function() {
|
|||||||
// Set up events
|
// Set up events
|
||||||
user_properties.onaction = function(title, fields) {
|
user_properties.onaction = function(title, fields) {
|
||||||
|
|
||||||
// FIXME: STUB
|
// Call removal handler, keep window up if not allowed.
|
||||||
if (title == "Delete") {
|
if (title == "Delete") {
|
||||||
alert("Deletion not yet supported.");
|
if (user_manager.onremove) {
|
||||||
return;
|
if (!user_manager.onremove(user_manager.selected))
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save user
|
// Call save handler, keep window up if not allowed.
|
||||||
if (title == "Save") {
|
if (title == "Save") {
|
||||||
console.log(fields);
|
|
||||||
|
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
|
// Hide
|
||||||
@@ -467,6 +491,8 @@ GuacAdmin.UserManager = function() {
|
|||||||
*
|
*
|
||||||
* @event
|
* @event
|
||||||
* @param {String} username The username edited.
|
* @param {String} username The username edited.
|
||||||
|
* @param {String} password The password chosen.
|
||||||
|
* @param {String[]} connections The IDs of the connections chosen.
|
||||||
*/
|
*/
|
||||||
this.onsave = null;
|
this.onsave = null;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user