mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Adding the option to activate patterns per culture or not. Falling back to the default culture pattern(s) if not activated.
This commit is contained in:
@@ -67,10 +67,12 @@ namespace Orchard.Autoroute.Drivers {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//if we are creating from a form post we use the form value for culture
|
if (settings.UseCulturePattern) {
|
||||||
HttpContextBase context = _httpContextAccessor.Current();
|
//if we are creating from a form post we use the form value for culture
|
||||||
if (context.Request.Form["Localization.SelectedCulture"] != null) {
|
HttpContextBase context = _httpContextAccessor.Current();
|
||||||
itemCulture = context.Request.Form["Localization.SelectedCulture"].ToString();
|
if (context.Request.Form["Localization.SelectedCulture"] != null) {
|
||||||
|
itemCulture = context.Request.Form["Localization.SelectedCulture"].ToString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if the content type has no pattern for autoroute, then use a default one
|
// if the content type has no pattern for autoroute, then use a default one
|
||||||
@@ -155,12 +157,18 @@ namespace Orchard.Autoroute.Drivers {
|
|||||||
if (useCustomPattern != null) {
|
if (useCustomPattern != null) {
|
||||||
part.UseCustomPattern = bool.Parse(useCustomPattern);
|
part.UseCustomPattern = bool.Parse(useCustomPattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var useCulturePattern = context.Attribute(part.PartDefinition.Name, "UseCulturePattern");
|
||||||
|
if (useCulturePattern != null) {
|
||||||
|
part.UseCulturePattern = bool.Parse(useCulturePattern);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Exporting(AutoroutePart part, ContentManagement.Handlers.ExportContentContext context) {
|
protected override void Exporting(AutoroutePart part, ContentManagement.Handlers.ExportContentContext context) {
|
||||||
context.Element(part.PartDefinition.Name).SetAttributeValue("Alias", String.IsNullOrEmpty(part.Record.DisplayAlias) ? "/" : part.Record.DisplayAlias);
|
context.Element(part.PartDefinition.Name).SetAttributeValue("Alias", String.IsNullOrEmpty(part.Record.DisplayAlias) ? "/" : part.Record.DisplayAlias);
|
||||||
context.Element(part.PartDefinition.Name).SetAttributeValue("CustomPattern", part.Record.CustomPattern);
|
context.Element(part.PartDefinition.Name).SetAttributeValue("CustomPattern", part.Record.CustomPattern);
|
||||||
context.Element(part.PartDefinition.Name).SetAttributeValue("UseCustomPattern", part.Record.UseCustomPattern);
|
context.Element(part.PartDefinition.Name).SetAttributeValue("UseCustomPattern", part.Record.UseCustomPattern);
|
||||||
|
context.Element(part.PartDefinition.Name).SetAttributeValue("UseCulturePattern", part.Record.UseCulturePattern);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,8 +19,24 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
$("#Parts_3__AutorouteSettings_UseCulturePattern[type=checkbox]").click(function () {
|
||||||
|
if ($(this).attr("checked") == "checked") {
|
||||||
|
$(".autoroute-cultures li:not(:first)").hide();
|
||||||
|
$(".autoroute-cultures li").removeClass("selected");
|
||||||
|
$(".autoroute-cultures li:first").addClass("selected");
|
||||||
|
$("#content .items").hide();
|
||||||
|
$("#content .items.default").show();
|
||||||
|
$(this).removeAttr('checked');
|
||||||
|
} else {
|
||||||
|
$(".autoroute-cultures li:not(:first)").show();
|
||||||
|
$("#content .items.default").show();
|
||||||
|
$(this).attr('checked', 'checked');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
$(function () {
|
$(function () {
|
||||||
var browser = new AutorouteCultureBrowser($("#main"));
|
var browser = new AutorouteCultureBrowser($("#main"));
|
||||||
browser.initialize();
|
browser.initialize();
|
||||||
|
|
||||||
});
|
});
|
||||||
})(jQuery);
|
})(jQuery);
|
||||||
@@ -53,7 +53,7 @@ namespace Orchard.Autoroute.Services {
|
|||||||
if (part == null) {
|
if (part == null) {
|
||||||
throw new ArgumentNullException("part");
|
throw new ArgumentNullException("part");
|
||||||
}
|
}
|
||||||
|
var settings = part.TypePartDefinition.Settings.GetModel<AutorouteSettings>();
|
||||||
var itemCulture = _cultureManager.GetSiteCulture();
|
var itemCulture = _cultureManager.GetSiteCulture();
|
||||||
|
|
||||||
//if we are editing an existing content item
|
//if we are editing an existing content item
|
||||||
@@ -66,10 +66,12 @@ namespace Orchard.Autoroute.Services {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//if we are creating from a form post we use the form value for culture
|
if (settings.UseCulturePattern) {
|
||||||
HttpContextBase context = _httpContextAccessor.Current();
|
//if we are creating from a form post we use the form value for culture
|
||||||
if (context.Request.Form["Localization.SelectedCulture"] != null) {
|
HttpContextBase context = _httpContextAccessor.Current();
|
||||||
itemCulture = context.Request.Form["Localization.SelectedCulture"].ToString();
|
if (context.Request.Form["Localization.SelectedCulture"] != null) {
|
||||||
|
itemCulture = context.Request.Form["Localization.SelectedCulture"].ToString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
string pattern = GetDefaultPattern(part.ContentItem.ContentType, itemCulture).Pattern;
|
string pattern = GetDefaultPattern(part.ContentItem.ContentType, itemCulture).Pattern;
|
||||||
|
|||||||
@@ -38,29 +38,22 @@
|
|||||||
<div id="local-navigation">
|
<div id="local-navigation">
|
||||||
<ul class="autoroute-cultures localmenu group">
|
<ul class="autoroute-cultures localmenu group">
|
||||||
@{
|
@{
|
||||||
int i = 0;
|
int i = 1;
|
||||||
string cssClass = "";
|
string cssClass = "";
|
||||||
}
|
}
|
||||||
|
<li class="first selected"><a class="culture" href="#cat-@Model.DefaultSiteCulture">@Model.DefaultSiteCulture</a></li>
|
||||||
@foreach (var culture in Model.SiteCultures) {
|
@foreach (var culture in Model.SiteCultures) {
|
||||||
cssClass = "";
|
if (culture != Model.DefaultSiteCulture) {
|
||||||
if (Model.UseCulturePattern) {
|
cssClass = i == Model.SiteCultures.Count - 1 ? "last" : "middle";
|
||||||
cssClass = i == 0 ? "first selected" : i == Model.SiteCultures.Count - 1 ? "last" : "middle";
|
<li class="@cssClass" style="@(Model.UseCulturePattern == false ? "display:none;" : "")"><a class="culture" href="#cat-@culture">@culture</a></li>
|
||||||
<li class="@cssClass"><a class="culture" href="#cat-@culture">@culture</a></li>
|
i++;
|
||||||
} else {
|
|
||||||
cssClass = i == 0 ? "first" : i == Model.SiteCultures.Count - 1 ? "last" : "middle";
|
|
||||||
if (culture == Model.DefaultSiteCulture) {
|
|
||||||
<li class="@cssClass"><a class="culture" href="#cat-@culture">@culture</a></li>
|
|
||||||
} else {
|
|
||||||
<li class="@cssClass" style="display:none;"><a class="culture" href="#cat-@culture">@culture</a></li>
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div id="content">
|
<div id="content">
|
||||||
@foreach (var culture in Model.SiteCultures) {
|
@foreach (var culture in Model.SiteCultures) {
|
||||||
<fieldset id="cat-@culture" class="items" style="@(cultureCount == 0 ? "display:block;" : "display:none;")">
|
<fieldset id="cat-@culture" class="items @(culture == Model.DefaultSiteCulture ? "default" : "")" style="@(culture == Model.DefaultSiteCulture ? "display:block;" : "display:none;")">
|
||||||
<table class="autoroute-settings-patterns">
|
<table class="autoroute-settings-patterns">
|
||||||
<tr>
|
<tr>
|
||||||
<th class="autoroute-settings-default">@T("Default")</th>
|
<th class="autoroute-settings-default">@T("Default")</th>
|
||||||
@@ -88,4 +81,15 @@
|
|||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Display.TokenHint()
|
@Display.TokenHint()
|
||||||
|
|||||||
Reference in New Issue
Block a user