Some updates to the translation experience to the home page setting and slug less likely to be clobbered*

* bit of a small hack, the content localization experience should be revisited before spending much time on fixing this fix

--HG--
branch : dev
This commit is contained in:
Nathan Heskew
2010-07-24 01:03:56 -07:00
parent ec4a444537
commit c6fc71e89d
3 changed files with 36 additions and 5 deletions

View File

@@ -6,6 +6,7 @@ using Orchard.ContentManagement.Aspects;
using Orchard.Core.Localization.Models;
using Orchard.Core.Localization.Services;
using Orchard.Core.Localization.ViewModels;
using Orchard.Core.Routable.Models;
using Orchard.Localization;
using Orchard.Localization.Services;
using Orchard.Mvc.Results;
@@ -43,14 +44,23 @@ namespace Orchard.Core.Localization.Controllers {
}
var siteCultures = _cultureManager.ListCultures().Where(s => s != _localizationService.GetContentCulture(contentItem));
var selectedCulture = siteCultures.SingleOrDefault(s => string.Equals(s, to, StringComparison.OrdinalIgnoreCase))
?? _cultureManager.GetCurrentCulture(HttpContext); // could be null but the person doing the translating might be translating into their current culture
//todo: need a better solution for modifying some parts when translating - or go with a completely different experience
if (contentItem.Has<RoutePart>()) {
var routePart = contentItem.As<RoutePart>();
routePart.Slug = string.Format("{0}{2}{1}", routePart.Slug, siteCultures.Any(s => string.Equals(s, selectedCulture, StringComparison.OrdinalIgnoreCase)) ? selectedCulture : siteCultures.ElementAt(0), !string.IsNullOrWhiteSpace(routePart.Slug) ? "-" : "");
routePart.Path = null;
}
var model = new AddLocalizationViewModel {
Id = id,
SelectedCulture = siteCultures.Any(s => s == to)
? to
: _cultureManager.GetCurrentCulture(HttpContext), // could be null but the person doing the translating might be translating into their current culture
SelectedCulture = selectedCulture,
SiteCultures = siteCultures,
Content = _contentManager.BuildEditorModel(contentItem)
};
Services.TransactionManager.Cancel();
PrepareEditorViewModel(model.Content);
return View(model);

View File

@@ -5,4 +5,25 @@ Model.Content.Zones.AddRenderPartial("primary:before", "CultureSelection", Model
<% using (Html.BeginFormAntiForgeryPost()) { %>
<%:Html.ValidationSummary() %>
<%:Html.EditorForItem(m=>m.Content) %>
<%} %>
<%} %>
<% using (this.Capture("end-of-page-scripts")) { %>
<script type="text/javascript">
(function ($) {
// grab the slug input
var slug = $("#Routable_Slug");
if (slug) {
// grab the current culture
var culture = $("#SelectedCulture");
var currentCulture = culture.val();
// when the culture is changed update the slug
culture.change(function () {
var slugValue = slug.val();
var newCulture = $(this).val();
if (slugValue && slugValue.match(currentCulture + "$")) {
slug.val(slugValue.replace(new RegExp(currentCulture + "$", "i"), newCulture));
currentCulture = newCulture;
}
});
}
})(jQuery);</script>
<% } %>

View File

@@ -76,7 +76,7 @@ namespace Orchard.Core.Routable.Drivers {
}
var location = part.GetLocation("Editor");
model.PromoteToHomePage = model.Id != 0 && _routableHomePageProvider != null && CurrentSite.HomePage == _routableHomePageProvider.GetSettingValue(model.Id);
model.PromoteToHomePage = model.Id != 0 && part.Path != null && _routableHomePageProvider != null && CurrentSite.HomePage == _routableHomePageProvider.GetSettingValue(model.Id);
return ContentPartTemplate(model, TemplateName, Prefix).Location(location);
}