Code styling in Fields/Enumeration.Edit.cshtml

This commit is contained in:
Benedek Farkas 2024-12-09 12:30:35 +01:00
parent 9043de7728
commit 91ef0a206c

View File

@ -1,28 +1,51 @@
@model Orchard.Fields.Fields.EnumerationField
@using Orchard.Fields.Settings;
@{
var settings = Model.PartFieldDefinition.Settings.GetModel<EnumerationFieldSettings>();
string[] options = (!String.IsNullOrWhiteSpace(settings.Options)) ? settings.Options.Split(new string[] { System.Environment.NewLine }, StringSplitOptions.None) : new string[] { T("Select an option").ToString() };
string[] options = (!String.IsNullOrWhiteSpace(settings.Options)) ?
settings.Options.Split(new string[] { System.Environment.NewLine }, StringSplitOptions.None)
: new string[] { T("Select an option").ToString() };
}
<fieldset>
<label for="@Html.FieldIdFor(m => m.Value)" @if (settings.Required) { <text> class="required" </text> }>@Model.DisplayName</label>
@switch (settings.ListMode) {
case ListMode.Dropdown:
@Html.DropDownListFor(m => m.Value, new SelectList(options, Model.SelectedValues.FirstOrDefault()), settings.Required ? new { required = "required" } : null)
@Html.DropDownListFor(
m => m.Value,
new SelectList(options, Model.SelectedValues.FirstOrDefault()),
settings.Required ? new { required = "required" } : null)
break;
case ListMode.Radiobutton:
foreach (var option in options) {
if (string.IsNullOrWhiteSpace(option)) {
<label>@Html.RadioButton("Value", "", string.IsNullOrWhiteSpace(Model.SelectedValues.FirstOrDefault()), settings.Required ? new { required = "required" } : null)<i>@T("unset")</i></label> }
<label>@Html.RadioButton(
"Value",
"",
string.IsNullOrWhiteSpace(Model.SelectedValues.FirstOrDefault()),
settings.Required ? new { required = "required" } : null)<i>@T("unset")</i>
</label>
}
else {
<label>@Html.RadioButton("Value", option, (option == Model.SelectedValues.FirstOrDefault()), settings.Required ? new { required = "required" } : null)@option</label> }
<label>@Html.RadioButton(
"Value",
option,
option == Model.SelectedValues.FirstOrDefault(),
settings.Required ? new { required = "required" } : null)@option
</label>
}
}
break;
case ListMode.Listbox:
<input name="@Html.FieldNameFor(m => m.SelectedValues)" type="hidden" />
@Html.ListBoxFor(m => m.SelectedValues, new MultiSelectList(options, Model.SelectedValues), settings.Required ? new { required = "required" } : null)
@Html.ListBoxFor(
m => m.SelectedValues,
new MultiSelectList(options, Model.SelectedValues),
settings.Required ? new { required = "required" } : null)
break;
case ListMode.Checkbox:
@ -32,7 +55,9 @@
index++;
if (!string.IsNullOrWhiteSpace(option)) {
<div>
<input type="checkbox" name="@Html.FieldNameFor(m => m.SelectedValues)" value="@option" @((Model.SelectedValues != null && Model.SelectedValues.Contains(option)) ? "checked=\"checked\"" : "") class="check-box" id="@Html.FieldIdFor(m => m.SelectedValues)-@index" />
<input type="checkbox" name="@Html.FieldNameFor(m => m.SelectedValues)" value="@option"
@((Model.SelectedValues != null && Model.SelectedValues.Contains(option)) ? "checked=\"checked\"" : "")
class="check-box" id="@Html.FieldIdFor(m => m.SelectedValues)-@index" />
<label class="forcheckbox" for="@Html.FieldIdFor(m => m.SelectedValues)-@index">@option</label>
</div>
}