Enhanced form-field radio functionality

The form-field radio button functionality has been extended to support
separate specification of button label and value. Previously, a single
value was used for both items.

Change-Id: Id050c47f5fff9e10f4191e03b43ad4fb414ddf2f
This commit is contained in:
Peter Piela 2017-07-31 09:03:02 -04:00
parent d56e262bff
commit e178834244
7 changed files with 43 additions and 32 deletions

View File

@ -160,8 +160,9 @@
title: gettext("PXE enabled"),
desc: gettext(
"Indicates whether this port should be used when PXE booting this node"),
options: ['True', 'False'],
value: 'True'});
options: [{label: 'True', value: true},
{label: 'False', value: false}],
value: true});
ctrl.portgroup_uuid = new formFieldService.FormField({
type: "select",

View File

@ -59,22 +59,31 @@
id: "standalonePorts",
title: gettext("Standalone Ports Supported"),
desc: gettext(
"Specifies whether ports in this portgroup can be used as standalone ports."),
options: ['True', 'False'],
value: 'True'});
"Specifies whether ports in this portgroup can be used as standalone ports."), // eslint-disable-line max-len
options: [{label: 'True', value: true},
{label: 'False', value: false}],
value: true});
var modeOptions = function(modes) {
var options = [];
angular.forEach(modes, function(mode) {
options.push({label:mode, value: mode});
});
return options;
};
ctrl.mode = new formFieldService.FormField({
type: "radio",
id: "mode",
title: gettext("Mode"),
desc: gettext("Linux portgroup mode. For possible values refer to https://www.kernel.org/doc/Documentation/networking/bonding.txt"), // eslint-disable-line max-len
options: ['balance-rr',
'active-backup',
'balance-xor',
'broadcast',
'802.3ad',
'balance-tlb',
'balance-alb'],
options: modeOptions(['balance-rr',
'active-backup',
'balance-xor',
'broadcast',
'802.3ad',
'balance-tlb',
'balance-alb']),
value: 'active-backup'});
ctrl.properties = new propertyCollectionService.PropertyCollection({

View File

@ -65,9 +65,7 @@
port.local_link_connection = attr;
}
if (ctrl.pxeEnabled.value !== 'True') {
port.pxe_enabled = ctrl.pxeEnabled.value;
}
port.pxe_enabled = ctrl.pxeEnabled.value;
if (ctrl.portgroup_uuid.value !== null) {
port.portgroup_uuid = ctrl.portgroup_uuid.value;

View File

@ -71,7 +71,7 @@
ctrl.address.disable();
}
ctrl.pxeEnabled.value = port.pxe_enabled ? 'True' : 'False';
ctrl.pxeEnabled.value = port.pxe_enabled;
ctrl.portgroup_uuid.value = port.portgroup_uuid;
@ -105,7 +105,7 @@
patcher.buildPatch(port.address, ctrl.address.value, "/address");
patcher.buildPatch(port.pxe_enabled,
ctrl.pxeEnabled.value === 'True',
ctrl.pxeEnabled.value,
"/pxe_enabled");
patcher.buildPatch(port.local_link_connection,
ctrl.localLinkConnection.toPortAttr(),

View File

@ -54,7 +54,7 @@
ctrl.name.value = portgroup.name;
ctrl.standalone_ports_supported.value =
portgroup.standalone_ports_supported ? 'True' : 'False';
portgroup.standalone_ports_supported;
ctrl.mode.value = portgroup.mode;
@ -75,7 +75,7 @@
patcher.buildPatch(portgroup.address, ctrl.address.value, "/address");
patcher.buildPatch(portgroup.name, ctrl.name.value, "/name");
patcher.buildPatch(portgroup.standalone_ports_supported,
ctrl.standalone_ports_supported.value === 'True',
ctrl.standalone_ports_supported.value,
"/standalone_ports_supported");
patcher.buildPatch(portgroup.mode,
ctrl.mode.value,

View File

@ -42,7 +42,7 @@
ng-model="field.value"
ng-repeat="opt in field.options"
ng-disabled="field.disabled"
uib-btn-radio="opt">{$ opt $}</label>
uib-btn-radio="opt.value">{$ opt.label $}</label>
</div>
<div ng-switch-when="select">
<select id="field.id"

View File

@ -30,27 +30,30 @@
* @description Utility class for managing form fields.
* Used is association with the form-field directive.
*
* @param {object} args - Base properties are:
* @param {object} args - Base properties are:
* type [string] - Field type. One of: 'input', 'radio', 'select'
* id [string] - id/name of the DOM value element
* title [string] - Label used to identify the field to the user
* options - type == radio [array]:
* List of options for a radio field
* options - type == radio [array of object]:
* List of option objects for a radio field.
* Each object has 'label' and 'value'
* properties.
* type == select [string]:
* String expression that is passed to ng-options
* String expression that is passed to ng-options
* value - Initial value of the field
* required [boolean] - Does the field require a value
* desc [string] - Field description
* pattern [RegExp] - Regular expression pattern used to match
* valid input values
* valid input values
* disabled [boolean] - Is the field disabled
* info [string] - Additional information about the current state of
* the field. It will be displayed in a tooltip
* associated with the field.
* autoFocus [boolean] - True if the focus should be set to this field. Only
* applies to fields of type input.
* change [string] - Expression to be evaluated when the value of this
* field changes. Only applies to fields of type input.
* info [string] - Additional information about the current state
* of the field. It will be displayed in a tooltip
* associated with the field.
* autoFocus [boolean] - True if the focus should be set to this field.
* Only applies to fields of type input.
* change [string] - Expression to be evaluated when the value of
* this field changes. Only applies to fields of
* type input.
*
* @return {void}
*/