mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-12-02 19:44:02 +08:00
Some work on the content localization create/edit experience
--HG-- branch : dev
This commit is contained in:
@@ -43,17 +43,18 @@ namespace Orchard.Core.Localization.Controllers {
|
||||
return RedirectToAction(Convert.ToString(metadata.EditorRouteValues["action"]), metadata.EditorRouteValues);
|
||||
}
|
||||
|
||||
var siteCultures = _cultureManager.ListCultures().Where(s => s != _localizationService.GetContentCulture(contentItem));
|
||||
var siteCultures = _cultureManager.ListCultures().Where(s => s != _localizationService.GetContentCulture(contentItem) && s != _cultureManager.GetSiteCulture());
|
||||
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.Slug = string.Format("{0}{2}{1}", routePart.Slug, siteCultures.Any(s => string.Equals(s, selectedCulture, StringComparison.OrdinalIgnoreCase)) ? selectedCulture : "", !string.IsNullOrWhiteSpace(routePart.Slug) ? "-" : "");
|
||||
routePart.Path = null;
|
||||
}
|
||||
|
||||
contentItem.As<LocalizationPart>().Culture.Culture = null;
|
||||
var model = new AddLocalizationViewModel {
|
||||
Id = id,
|
||||
SelectedCulture = selectedCulture,
|
||||
@@ -76,16 +77,19 @@ namespace Orchard.Core.Localization.Controllers {
|
||||
var viewModel = new AddLocalizationViewModel();
|
||||
TryUpdateModel(viewModel);
|
||||
|
||||
ContentItem contentItemTranslation;
|
||||
ContentItem contentItemTranslation = null;
|
||||
var existingTranslation = _localizationService.GetLocalizedContentItem(contentItem, viewModel.SelectedCulture);
|
||||
if (existingTranslation != null) { // edit existing
|
||||
if (existingTranslation != null) {
|
||||
// edit existing
|
||||
contentItemTranslation = _contentManager.Get(existingTranslation.ContentItem.Id, VersionOptions.DraftRequired);
|
||||
}
|
||||
else { // create
|
||||
else {
|
||||
// create
|
||||
contentItemTranslation = _contentManager.New(contentItem.ContentType);
|
||||
var localized = contentItemTranslation.As<LocalizationPart>();
|
||||
localized.MasterContentItem = contentItem;
|
||||
localized.Culture = _cultureManager.GetCultureByName(viewModel.SelectedCulture);
|
||||
if (!string.IsNullOrWhiteSpace(viewModel.SelectedCulture))
|
||||
localized.Culture = _cultureManager.GetCultureByName(viewModel.SelectedCulture);
|
||||
_contentManager.Create(contentItemTranslation, VersionOptions.Draft);
|
||||
|
||||
if (!contentItem.Has<IPublishingControlAspect>() && contentItem.VersionRecord != null && contentItem.VersionRecord.Published) {
|
||||
@@ -93,17 +97,18 @@ namespace Orchard.Core.Localization.Controllers {
|
||||
}
|
||||
}
|
||||
|
||||
if (ModelState.IsValid)
|
||||
viewModel.Content = _contentManager.UpdateEditorModel(contentItemTranslation, this);
|
||||
viewModel.Content = _contentManager.UpdateEditorModel(contentItemTranslation, this);
|
||||
|
||||
if (!ModelState.IsValid) {
|
||||
Services.TransactionManager.Cancel();
|
||||
viewModel.SiteCultures = _cultureManager.ListCultures().Where(s => s != _localizationService.GetContentCulture(contentItem));
|
||||
viewModel.SiteCultures = _cultureManager.ListCultures().Where(s => s != _localizationService.GetContentCulture(contentItem) && s != _cultureManager.GetSiteCulture());
|
||||
contentItem.As<LocalizationPart>().Culture.Culture = null;
|
||||
viewModel.Content = _contentManager.BuildEditorModel(contentItem);
|
||||
PrepareEditorViewModel(viewModel.Content);
|
||||
return View(viewModel);
|
||||
}
|
||||
|
||||
Services.Notifier.Information(T("Created content item translation"));
|
||||
Services.Notifier.Information(T("Created content item translation."));
|
||||
|
||||
var metadata = _contentManager.GetItemMetadata(viewModel.Content.Item);
|
||||
if (metadata.EditorRouteValues == null)
|
||||
|
||||
@@ -35,6 +35,7 @@ namespace Orchard.Core.Localization.Drivers {
|
||||
var model = new EditLocalizationViewModel {
|
||||
SelectedCulture = part.Culture != null ? part.Culture.Culture : null,
|
||||
SiteCultures = _cultureManager.ListCultures().Where(s => s != _cultureManager.GetSiteCulture() && !localizations.Select(l => l.Culture.Culture).Contains(s)),
|
||||
ContentItem = part,
|
||||
MasterContentItem = part.MasterContentItem,
|
||||
ContentLocalizations = new ContentLocalizationsViewModel(part) { Localizations = localizations }
|
||||
};
|
||||
@@ -55,17 +56,20 @@ namespace Orchard.Core.Localization.Drivers {
|
||||
return _localizationService.GetLocalizations(part.ContentItem)
|
||||
.Select(c => {
|
||||
var localized = c.ContentItem.As<LocalizationPart>();
|
||||
if (localized.Culture == null) {
|
||||
localized.Culture = _cultureManager.GetCultureByName(_cultureManager.GetCurrentCulture(new HttpContextWrapper(HttpContext.Current)));
|
||||
}
|
||||
if (localized.Culture == null)
|
||||
localized.Culture = _cultureManager.GetCultureByName(_cultureManager.GetSiteCulture());
|
||||
return c;
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
private IEnumerable<LocalizationPart> GetEditorLocalizations(LocalizationPart part) {
|
||||
return _localizationService.GetLocalizations(part.ContentItem)
|
||||
.Select(c => c.ContentItem.As<LocalizationPart>())
|
||||
.Where(l => l.MasterContentItem != null).ToList();
|
||||
.Select(c => {
|
||||
var localized = c.ContentItem.As<LocalizationPart>();
|
||||
if (localized.Culture == null)
|
||||
localized.Culture = _cultureManager.GetCultureByName(_cultureManager.GetSiteCulture());
|
||||
return c;
|
||||
}).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Orchard.Mvc.ViewModels;
|
||||
|
||||
namespace Orchard.Core.Localization.ViewModels {
|
||||
public class AddLocalizationViewModel : BaseViewModel {
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public string SelectedCulture { get; set; }
|
||||
public IEnumerable<string> SiteCultures { get; set; }
|
||||
public ContentItemViewModel Content { get; set; }
|
||||
|
||||
@@ -6,6 +6,7 @@ namespace Orchard.Core.Localization.ViewModels {
|
||||
public class EditLocalizationViewModel : BaseViewModel {
|
||||
public string SelectedCulture { get; set; }
|
||||
public IEnumerable<string> SiteCultures { get; set; }
|
||||
public IContent ContentItem { get; set; }
|
||||
public IContent MasterContentItem { get; set; }
|
||||
public ContentLocalizationsViewModel ContentLocalizations { get; set; }
|
||||
}
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<Orchard.Core.Localization.ViewModels.AddLocalizationViewModel>" %>
|
||||
<fieldset class="localization culture-selection">
|
||||
<label for="SelectedCulture"><%:T("Culture ") %></label>
|
||||
<%:Html.DropDownList("SelectedCulture", new SelectList(Model.SiteCultures, Model.SelectedCulture)) %>
|
||||
<label for="SelectedCulture"><%:T("Content Localization") %></label><%
|
||||
var siteCultures = Model.SiteCultures.ToList();
|
||||
siteCultures.Insert(0, ""); %>
|
||||
<div><%=T("This is the <em>{0}</em> variation of {1}.",
|
||||
Html.DropDownList("SelectedCulture", new SelectList(siteCultures, Model.SelectedCulture)),
|
||||
Html.ItemEditLink(Model.Content.Item)) %></div>
|
||||
</fieldset>
|
||||
@@ -1,24 +1,23 @@
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<Orchard.Core.Localization.ViewModels.EditLocalizationViewModel>" %>
|
||||
<%
|
||||
Html.RegisterStyle("admin.css");
|
||||
Html.RegisterStyle("base.css");
|
||||
if (Model.ContentLocalizations.MasterId > 0) { %>
|
||||
<fieldset class="localization culture-selection"><%
|
||||
if (Model.MasterContentItem != null) { %>
|
||||
Html.RegisterStyle("admin.css");
|
||||
if (Model.ContentItem.ContentItem.Id > 0 && Model.SelectedCulture != null && Model.ContentLocalizations.Localizations.Count() > 0) {
|
||||
Html.RegisterStyle("base.css");%>
|
||||
<fieldset class="localization culture-selection">
|
||||
<fieldset class="culture-selected">
|
||||
<label for="SelectedCulture"><%:T("Content Localization") %></label>
|
||||
<div><%:T("This is the {0} variation of {1}.",
|
||||
Html.DropDownList("SelectedCulture", new SelectList(Model.SiteCultures, Model.SelectedCulture)),
|
||||
Html.ItemEditLink(Model.MasterContentItem)) %></div>
|
||||
<label for="SelectedCulture"><%:T("Content Localization")%></label>
|
||||
<div><%=T("This is the <em>{0}</em> variation of {1}.",
|
||||
Html.Encode(Model.SelectedCulture),
|
||||
Html.ItemEditLink(Model.MasterContentItem ?? Model.ContentItem))%></div>
|
||||
<%:Html.Hidden("SelectedCulture", Model.SelectedCulture)%>
|
||||
</fieldset><%
|
||||
}
|
||||
if (Model.ContentLocalizations.Localizations.Count() > 0) { //todo: find a good place for this info on the content edit page %>
|
||||
if (Model.ContentLocalizations.Localizations.Count() > 0) {%>
|
||||
<dl class="content-localization">
|
||||
<dt><%:Model.MasterContentItem != null ? T("Other translations:") : T("Translations:") %></dt>
|
||||
<dt><%:T("Other translations:")%></dt>
|
||||
<dd class="content-localizations">
|
||||
<%:Html.UnorderedList(Model.ContentLocalizations.Localizations, (c, i) => Html.ItemEditLink(c.Culture.Culture, c), "localizations") %>
|
||||
<%:Html.UnorderedList(Model.ContentLocalizations.Localizations, (c, i) => Html.ItemEditLink(c.Culture.Culture, c), "localizations")%>
|
||||
</dd>
|
||||
</dl><%
|
||||
} %>
|
||||
}%>
|
||||
</fieldset><%
|
||||
} %>
|
||||
} %>
|
||||
@@ -51,17 +51,17 @@ namespace Orchard.Core.PublishLater.Drivers {
|
||||
switch (model.Command) {
|
||||
case "PublishNow":
|
||||
_commonService.Publish(model.ContentItem);
|
||||
Services.Notifier.Information(T("{0} has been published!", model.ContentItem.TypeDefinition.DisplayName));
|
||||
//Services.Notifier.Information(T("{0} has been published!", model.ContentItem.TypeDefinition.DisplayName));
|
||||
break;
|
||||
case "PublishLater":
|
||||
DateTime scheduled;
|
||||
if (DateTime.TryParse(string.Format("{0} {1}", model.ScheduledPublishUtcDate, model.ScheduledPublishUtcTime), out scheduled))
|
||||
model.ScheduledPublishUtc = scheduled;
|
||||
_publishLaterService.Publish(model.ContentItem, model.ScheduledPublishUtc.HasValue ? model.ScheduledPublishUtc.Value : DateTime.MaxValue);
|
||||
Services.Notifier.Information(T("{0} has been scheduled for publishing!", model.ContentItem.TypeDefinition.DisplayName));
|
||||
//Services.Notifier.Information(T("{0} has been scheduled for publishing!", model.ContentItem.TypeDefinition.DisplayName));
|
||||
break;
|
||||
case "SaveDraft":
|
||||
Services.Notifier.Information(T("{0} draft has been saved!", model.ContentItem.TypeDefinition.DisplayName));
|
||||
//Services.Notifier.Information(T("{0} draft has been saved!", model.ContentItem.TypeDefinition.DisplayName));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<h3><%:Model.DisplayName%></h3><%
|
||||
var creatable = Model.Settings.GetModel<ContentTypeSettings>().Creatable;
|
||||
if (creatable) { %>
|
||||
<p class="pageStatus"><%:Html.ActionLink(T("Create a new {0}", Model.DisplayName).Text, "Create", new {area = "Contents", id = Model.Name}) %></p><%
|
||||
<p class="pageStatus"><%:Html.ActionLink(T("Create New {0}", Model.DisplayName).Text, "Create", new {area = "Contents", id = Model.Name}) %></p><%
|
||||
} %>
|
||||
</div>
|
||||
<div class="related"><%
|
||||
|
||||
Reference in New Issue
Block a user