-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ContainedStereotypes BagPartSettings to allow a user to include c…
…ontent-types by steryotype (#11978)
- Loading branch information
1 parent
40afd55
commit c13ef60
Showing
7 changed files
with
185 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/OrchardCore.Modules/OrchardCore.Flows/Models/BagPartSettingType.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace OrchardCore.Flows.Models; | ||
|
||
public enum BagPartSettingType | ||
{ | ||
None, | ||
ContentTypes, | ||
Stereotypes | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 52 additions & 1 deletion
53
src/OrchardCore.Modules/OrchardCore.Flows/Views/BagPartSettings.Edit.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,66 @@ | ||
@model OrchardCore.Flows.ViewModels.BagPartSettingsViewModel | ||
|
||
@using OrchardCore.Flows.Settings | ||
@using OrchardCore.Flows.Models | ||
<div class="mb-3"> | ||
<label asp-for="Source">@T["Contained Content Types"]</label> | ||
<div class="w-sm-50" id="@Html.IdFor(x => x.Source)"> | ||
<div class="form-check"> | ||
<input class="form-check-input" type="radio" asp-for="Source" id="SourceContentTypes" value="@(BagPartSettingType.ContentTypes)" checked="@(Model.Source == BagPartSettingType.ContentTypes))"> | ||
<label for="SourceContentTypes"> | ||
@T["Content Types"] | ||
</label> | ||
</div> | ||
<div class="form-check"> | ||
<input class="form-check-input" type="radio" asp-for="Source" id="SourceStereotype" value="@(BagPartSettingType.Stereotypes)" checked="@(Model.Source == BagPartSettingType.Stereotypes)"> | ||
<label for="SourceStereotype"> | ||
@T["Stereotype"] <span class="hint">@T["All content types of these Stereotypes"]</span> | ||
</label> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div class="mb-3" id="ContentTypesContainer"> | ||
<label asp-for="ContainedContentTypes">@T["Contained Content Types"]</label> | ||
<span class="hint">@T["The content types that this bag can contain, e.g. Slide for a Slide Show."]</span> | ||
@await Component.InvokeAsync("SelectContentTypes", new { selectedContentTypes = Model.ContainedContentTypes, htmlName = Html.NameFor(m => m.ContainedContentTypes) }) | ||
</div> | ||
|
||
<div class="mb-3" id="StereotypesContainer"> | ||
<div class="w-sm-50" id="@Html.IdFor(x => x.Source)"> | ||
<label asp-for="Stereotypes">@T["Stereotypes"]</label> | ||
<input asp-for="Stereotypes" class="form-control medium" /> | ||
<span class="hint">@T["The Stereotypes of the content types that this bag can contain. You may define multiple Stereotypes using the comma (,) as a separator"]</span> | ||
</div> | ||
</div> | ||
<div class="mb-3"> | ||
<div class="w-sm-50"> | ||
<label asp-for="DisplayType">@T["Display Type"]</label> | ||
<input asp-for="DisplayType" placeholder="Summary" class="form-control medium" /> | ||
</div> | ||
<span class="hint">@T["The display type to use when rendering the content items. Default is Summary."]</span> | ||
</div> | ||
|
||
<script at="Foot" asp-name="bagPartSettings"> | ||
document.addEventListener('DOMContentLoaded', function() { | ||
var sources = document.getElementsByName('@Html.NameFor(x => x.Source)'); | ||
var contentTypesContainer = document.getElementById('ContentTypesContainer'); | ||
var stereotypeContainer = document.getElementById('StereotypesContainer'); | ||
for (var i = 0; i < sources.length; i++) { | ||
var source = sources[i]; | ||
source.addEventListener('change', function(src) { | ||
if (!src.target.checked) { | ||
return; | ||
} | ||
if (src.target.value == '@(BagPartSettingType.Stereotypes)') { | ||
contentTypesContainer.classList.add('d-none'); | ||
stereotypeContainer.classList.remove('d-none'); | ||
} else { | ||
contentTypesContainer.classList.remove('d-none'); | ||
stereotypeContainer.classList.add('d-none'); | ||
} | ||
}); | ||
source.dispatchEvent(new Event('change')); | ||
} | ||
}); | ||
</script> |
57 changes: 57 additions & 0 deletions
57
...dCore/OrchardCore.ContentManagement.Abstractions/Metadata/Models/ContentTypeExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using System; | ||
using OrchardCore.ContentManagement.Metadata.Settings; | ||
|
||
namespace OrchardCore.ContentManagement.Metadata.Models; | ||
|
||
public static class ContentTypeExtensions | ||
{ | ||
public static bool HasStereotype(this ContentTypeDefinition contentTypeDefinition) | ||
{ | ||
return !String.IsNullOrEmpty(contentTypeDefinition.GetStereotypeOrDefault()); | ||
} | ||
|
||
public static string GetStereotypeOrDefault(this ContentTypeDefinition contentTypeDefinition) | ||
{ | ||
return contentTypeDefinition.GetSettings().Stereotype; | ||
} | ||
|
||
public static bool IsListable(this ContentTypeDefinition contentTypeDefinition) | ||
{ | ||
return contentTypeDefinition.GetSettings().Listable; | ||
} | ||
|
||
public static bool IsCreatable(this ContentTypeDefinition contentTypeDefinition) | ||
{ | ||
return contentTypeDefinition.GetSettings().Creatable; | ||
} | ||
|
||
public static bool IsDraftable(this ContentTypeDefinition contentTypeDefinition) | ||
{ | ||
return contentTypeDefinition.GetSettings().Draftable; | ||
} | ||
|
||
public static bool IsVersionable(this ContentTypeDefinition contentTypeDefinition) | ||
{ | ||
return contentTypeDefinition.GetSettings().Versionable; | ||
} | ||
|
||
public static bool IsSecurable(this ContentTypeDefinition contentTypeDefinition) | ||
{ | ||
return contentTypeDefinition.GetSettings().Securable; | ||
} | ||
|
||
public static bool HasDescription(this ContentTypeDefinition contentTypeDefinition) | ||
{ | ||
return !String.IsNullOrEmpty(contentTypeDefinition.GetSettings().Description); | ||
} | ||
|
||
public static string GetDescription(this ContentTypeDefinition contentTypeDefinition) | ||
{ | ||
return contentTypeDefinition.GetSettings().Description; | ||
} | ||
|
||
public static ContentTypeSettings GetSettings(this ContentTypeDefinition contentTypeDefinition) | ||
{ | ||
return contentTypeDefinition.GetSettings<ContentTypeSettings>(); | ||
} | ||
} |