Skip to content

Commit

Permalink
Merge pull request #3 from Lombiq/issue/COLI-230
Browse files Browse the repository at this point in the history
COLI-230: Patient and Caregiver profile editor
  • Loading branch information
BenedekFarkas authored Oct 24, 2020
2 parents e05731c + 480cb4d commit e212701
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 5 deletions.
16 changes: 16 additions & 0 deletions Extensions/ContentPartDriverExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,21 @@ public static ContentShapeResult InputFieldDisplayShape<TContent>(
Func<InputFieldViewModel> viewModelFactory) where TContent : ContentPart, new() =>
driver.ContentShape(shapeName, () =>
(shapeFactory as dynamic).Lombiq_Fields_InputField(ViewModel: viewModelFactory()));

public static ContentShapeResult TextBoxEditorShape<TContent>(
this ContentPartDriver<TContent> driver,
string shapeName,
IShapeFactory shapeFactory,
Func<EditorViewModel> viewModelFactory) where TContent : ContentPart, new() =>
driver.ContentShape(shapeName, () =>
(shapeFactory as dynamic).Lombiq_Editors_TextboxEditor(ViewModel: viewModelFactory()));

public static ContentShapeResult DateTimeEditorShape<TContent>(
this ContentPartDriver<TContent> driver,
string shapeName,
IShapeFactory shapeFactory,
Func<DateTimeEditorViewModel> viewModelFactory) where TContent : ContentPart, new() =>
driver.ContentShape(shapeName, () =>
(shapeFactory as dynamic).Lombiq_Editors_DateTimeEditor(ViewModel: viewModelFactory()));
}
}
29 changes: 27 additions & 2 deletions ViewModels/DropdownEditorViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Piedone.HelpfulExtensions;
using Orchard.Localization;
using Piedone.HelpfulExtensions;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
Expand Down Expand Up @@ -31,6 +32,8 @@ public class DropdownEditorViewModel : EditorViewModel, IParentElementValueDepen
#endregion


public DropdownEditorViewModel() { }

public DropdownEditorViewModel(IEnumerable<string> values, params string[] selectedValues)
{
foreach (var value in values) SelectList.Add(new SelectListItem
Expand All @@ -55,7 +58,29 @@ public DropdownEditorViewModel(NameValueCollection queryString, string technical

Name = TechnicalName = technicalName;
}
}

public DropdownEditorViewModel() { }

public static class DropdownEditorViewModelExtensions
{
public static DropdownEditorViewModel WithDefaultBooleanOptions(
this DropdownEditorViewModel viewModel,
Localizer T,
bool? selectedValue) => viewModel.WithDefaultBooleanOptions(T("Yes").Text, T("No").Text, selectedValue);

public static DropdownEditorViewModel WithDefaultBooleanOptions(
this DropdownEditorViewModel viewModel,
string trueLabel,
string falseLabel,
bool? selectedValue)
{
viewModel.SelectList = new List<SelectListItem>()
{
new SelectListItem() { Text = trueLabel ?? "True", Value = "True", Selected = selectedValue == true },
new SelectListItem() { Text = falseLabel ?? "False", Value = "False", Selected = selectedValue == false }
};

return viewModel;
}
}
}
15 changes: 13 additions & 2 deletions Views/Lombiq.Editors.SelectizeDropdownEditor.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,15 @@
{ "id", selectizeInputId }
};

if (!string.IsNullOrEmpty(viewModel.Label))
var labelAttributes = new Dictionary<string, object>
{
attributes.Add("placeholder", viewModel.Label);
{ "class", "editorLabel textboxEditor__label " + DefaultBlockName + "__label" },
{ "for", selectizeInputId }
};

if (!string.IsNullOrEmpty(viewModel.Placeholder))
{
attributes.Add("placeholder", viewModel.Placeholder);
}

var jsonConverter = WorkContext.Resolve<IJsonConverter>();
Expand All @@ -38,6 +44,11 @@
}

<div class="editor editorField form-group @DefaultBlockName @BlockName">
@if (!string.IsNullOrEmpty(viewModel.Label))
{
@Html.Label(viewModel.Label, labelAttributes)
}

@Html.TextBox(viewModel.TechnicalName, "", attributes)
</div>

Expand Down
7 changes: 6 additions & 1 deletion Views/Lombiq.Editors.TextBoxEditor.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,16 @@

if (viewModel.Required)
{
textboxAttributes["required"] = true;
textboxAttributes["required"] = "";
textboxAttributes["class"] = textboxAttributes["class"] + " required";
labelAttributes["class"] = labelAttributes["class"] + " required";
}

if (viewModel.Disabled)
{
textboxAttributes["disabled"] = "";
}

if (!string.IsNullOrEmpty(viewModel.Placeholder))
{
textboxAttributes["placeholder"] = viewModel.Placeholder;
Expand Down

0 comments on commit e212701

Please sign in to comment.