Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update boolean/toggle/checkbox label prevalues #8477

Merged
Expand Up @@ -79,30 +79,36 @@

setLabelText();

// must wait until the current digest cycle is finished before we emit this event on init,
// Must wait until the current digest cycle is finished before we emit this event on init,
// otherwise other property editors might not yet be ready to receive the event
$timeout(function () {
eventsService.emit("toggleValue", { value: scope.checked });
}, 100);
}

function setLabelText() {

// set default label for "on"

if (scope.labelOn) {
scope.displayLabelOn = scope.labelOn;
} else {
localizationService.localize("general_on").then(function (value) {
scope.displayLabelOn = value;
});
}

// set default label for "Off"

if (scope.labelOff) {
scope.displayLabelOff = scope.labelOff;
} else {
localizationService.localize("general_off").then(function (value) {
scope.displayLabelOff = value;
}

if (scope.displayLabelOn.length === 0 && scope.displayLabelOff.length === 0)
{
var labelKeys = [
"general_on",
"general_off"
];

localizationService.localizeMany(labelKeys).then(function (data) {
// Set default label for "On"
scope.displayLabelOn = data[0];

// Set default label for "Off"
scope.displayLabelOff = data[1];
});
}

Expand Down
Expand Up @@ -7,9 +7,14 @@ function booleanEditorController($scope, angularHelper) {
// Maybe sometime later we can make it support "Yes/No" or "On/Off" as well similar to ng-true-value and ng-false-value in Angular.
var config = {
truevalue: "1",
falsevalue: "0"
falsevalue: "0",
showLabels: false
};

if ($scope.model.config && $scope.model.config.showLabels && Object.toBoolean($scope.model.config.showLabels)) {
config.showLabels = true;
}

// Map the user config
Utilities.extend(config, $scope.model.config);

Expand Down
Expand Up @@ -3,9 +3,9 @@
input-id="{{model.alias}}"
checked="renderModel.value"
on-click="toggle()"
show-labels="{{model.config.labelOn ? 'true': 'false'}}"
show-labels="{{model.config.showLabels}}"
label-position="right"
label-on="{{model.config.labelOn}}"
label-off="{{model.config.labelOn}}">
label-off="{{model.config.labelOff}}">
</umb-toggle>
</div>
14 changes: 10 additions & 4 deletions src/Umbraco.Web/PropertyEditors/TrueFalseConfiguration.cs
Expand Up @@ -7,10 +7,16 @@ namespace Umbraco.Web.PropertyEditors
/// </summary>
public class TrueFalseConfiguration
{
[ConfigurationField("default","Initial State", "boolean",Description = "The initial state for this checkbox, when it is displayed for the first time in the backoffice, eg. for a new content item.")]
public string Default { get; set; } // TODO: well, true or false?!
[ConfigurationField("default", "Initial State", "boolean", Description = "The initial state for the toggle, when it is displayed for the first time in the backoffice, eg. for a new content item.")]
public bool Default { get; set; }

[ConfigurationField("labelOn", "Write a label text", "textstring")]
public string Label { get; set; }
[ConfigurationField("showLabels", "Show toggle labels", "boolean", Description = "Show labels next to toggle button.")]
public bool ShowLabels { get; set; }

[ConfigurationField("labelOn", "Label On", "textstring", Description = "Label text when enabled.")]
public string LabelOn { get; set; }

[ConfigurationField("labelOff", "Label Off", "textstring", Description = "Label text when disabled.")]
public string LabelOff { get; set; }
}
}
2 changes: 1 addition & 1 deletion src/Umbraco.Web/PropertyEditors/TrueFalsePropertyEditor.cs
Expand Up @@ -10,7 +10,7 @@ namespace Umbraco.Web.PropertyEditors
[DataEditor(
Constants.PropertyEditors.Aliases.Boolean,
EditorType.PropertyValue | EditorType.MacroParameter,
"Checkbox",
"Toggle",
"boolean",
ValueType = ValueTypes.Integer,
Group = Constants.PropertyEditors.Groups.Common,
Expand Down