mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +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);
|
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))
|
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
|
?? _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
|
//todo: need a better solution for modifying some parts when translating - or go with a completely different experience
|
||||||
if (contentItem.Has<RoutePart>()) {
|
if (contentItem.Has<RoutePart>()) {
|
||||||
var routePart = contentItem.As<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;
|
routePart.Path = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
contentItem.As<LocalizationPart>().Culture.Culture = null;
|
||||||
var model = new AddLocalizationViewModel {
|
var model = new AddLocalizationViewModel {
|
||||||
Id = id,
|
Id = id,
|
||||||
SelectedCulture = selectedCulture,
|
SelectedCulture = selectedCulture,
|
||||||
@@ -76,16 +77,19 @@ namespace Orchard.Core.Localization.Controllers {
|
|||||||
var viewModel = new AddLocalizationViewModel();
|
var viewModel = new AddLocalizationViewModel();
|
||||||
TryUpdateModel(viewModel);
|
TryUpdateModel(viewModel);
|
||||||
|
|
||||||
ContentItem contentItemTranslation;
|
ContentItem contentItemTranslation = null;
|
||||||
var existingTranslation = _localizationService.GetLocalizedContentItem(contentItem, viewModel.SelectedCulture);
|
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);
|
contentItemTranslation = _contentManager.Get(existingTranslation.ContentItem.Id, VersionOptions.DraftRequired);
|
||||||
}
|
}
|
||||||
else { // create
|
else {
|
||||||
|
// create
|
||||||
contentItemTranslation = _contentManager.New(contentItem.ContentType);
|
contentItemTranslation = _contentManager.New(contentItem.ContentType);
|
||||||
var localized = contentItemTranslation.As<LocalizationPart>();
|
var localized = contentItemTranslation.As<LocalizationPart>();
|
||||||
localized.MasterContentItem = contentItem;
|
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);
|
_contentManager.Create(contentItemTranslation, VersionOptions.Draft);
|
||||||
|
|
||||||
if (!contentItem.Has<IPublishingControlAspect>() && contentItem.VersionRecord != null && contentItem.VersionRecord.Published) {
|
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) {
|
if (!ModelState.IsValid) {
|
||||||
Services.TransactionManager.Cancel();
|
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);
|
PrepareEditorViewModel(viewModel.Content);
|
||||||
return View(viewModel);
|
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);
|
var metadata = _contentManager.GetItemMetadata(viewModel.Content.Item);
|
||||||
if (metadata.EditorRouteValues == null)
|
if (metadata.EditorRouteValues == null)
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ namespace Orchard.Core.Localization.Drivers {
|
|||||||
var model = new EditLocalizationViewModel {
|
var model = new EditLocalizationViewModel {
|
||||||
SelectedCulture = part.Culture != null ? part.Culture.Culture : null,
|
SelectedCulture = part.Culture != null ? part.Culture.Culture : null,
|
||||||
SiteCultures = _cultureManager.ListCultures().Where(s => s != _cultureManager.GetSiteCulture() && !localizations.Select(l => l.Culture.Culture).Contains(s)),
|
SiteCultures = _cultureManager.ListCultures().Where(s => s != _cultureManager.GetSiteCulture() && !localizations.Select(l => l.Culture.Culture).Contains(s)),
|
||||||
|
ContentItem = part,
|
||||||
MasterContentItem = part.MasterContentItem,
|
MasterContentItem = part.MasterContentItem,
|
||||||
ContentLocalizations = new ContentLocalizationsViewModel(part) { Localizations = localizations }
|
ContentLocalizations = new ContentLocalizationsViewModel(part) { Localizations = localizations }
|
||||||
};
|
};
|
||||||
@@ -55,17 +56,20 @@ namespace Orchard.Core.Localization.Drivers {
|
|||||||
return _localizationService.GetLocalizations(part.ContentItem)
|
return _localizationService.GetLocalizations(part.ContentItem)
|
||||||
.Select(c => {
|
.Select(c => {
|
||||||
var localized = c.ContentItem.As<LocalizationPart>();
|
var localized = c.ContentItem.As<LocalizationPart>();
|
||||||
if (localized.Culture == null) {
|
if (localized.Culture == null)
|
||||||
localized.Culture = _cultureManager.GetCultureByName(_cultureManager.GetCurrentCulture(new HttpContextWrapper(HttpContext.Current)));
|
localized.Culture = _cultureManager.GetCultureByName(_cultureManager.GetSiteCulture());
|
||||||
}
|
|
||||||
return c;
|
return c;
|
||||||
}).ToList();
|
}).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerable<LocalizationPart> GetEditorLocalizations(LocalizationPart part) {
|
private IEnumerable<LocalizationPart> GetEditorLocalizations(LocalizationPart part) {
|
||||||
return _localizationService.GetLocalizations(part.ContentItem)
|
return _localizationService.GetLocalizations(part.ContentItem)
|
||||||
.Select(c => c.ContentItem.As<LocalizationPart>())
|
.Select(c => {
|
||||||
.Where(l => l.MasterContentItem != null).ToList();
|
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.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
using Orchard.Mvc.ViewModels;
|
using Orchard.Mvc.ViewModels;
|
||||||
|
|
||||||
namespace Orchard.Core.Localization.ViewModels {
|
namespace Orchard.Core.Localization.ViewModels {
|
||||||
public class AddLocalizationViewModel : BaseViewModel {
|
public class AddLocalizationViewModel : BaseViewModel {
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
[Required]
|
||||||
public string SelectedCulture { get; set; }
|
public string SelectedCulture { get; set; }
|
||||||
public IEnumerable<string> SiteCultures { get; set; }
|
public IEnumerable<string> SiteCultures { get; set; }
|
||||||
public ContentItemViewModel Content { get; set; }
|
public ContentItemViewModel Content { get; set; }
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ namespace Orchard.Core.Localization.ViewModels {
|
|||||||
public class EditLocalizationViewModel : BaseViewModel {
|
public class EditLocalizationViewModel : BaseViewModel {
|
||||||
public string SelectedCulture { get; set; }
|
public string SelectedCulture { get; set; }
|
||||||
public IEnumerable<string> SiteCultures { get; set; }
|
public IEnumerable<string> SiteCultures { get; set; }
|
||||||
|
public IContent ContentItem { get; set; }
|
||||||
public IContent MasterContentItem { get; set; }
|
public IContent MasterContentItem { get; set; }
|
||||||
public ContentLocalizationsViewModel ContentLocalizations { get; set; }
|
public ContentLocalizationsViewModel ContentLocalizations { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<Orchard.Core.Localization.ViewModels.AddLocalizationViewModel>" %>
|
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<Orchard.Core.Localization.ViewModels.AddLocalizationViewModel>" %>
|
||||||
<fieldset class="localization culture-selection">
|
<fieldset class="localization culture-selection">
|
||||||
<label for="SelectedCulture"><%:T("Culture ") %></label>
|
<label for="SelectedCulture"><%:T("Content Localization") %></label><%
|
||||||
<%:Html.DropDownList("SelectedCulture", new SelectList(Model.SiteCultures, Model.SelectedCulture)) %>
|
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>
|
</fieldset>
|
||||||
@@ -1,24 +1,23 @@
|
|||||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<Orchard.Core.Localization.ViewModels.EditLocalizationViewModel>" %>
|
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<Orchard.Core.Localization.ViewModels.EditLocalizationViewModel>" %>
|
||||||
<%
|
<%
|
||||||
Html.RegisterStyle("admin.css");
|
Html.RegisterStyle("admin.css");
|
||||||
Html.RegisterStyle("base.css");
|
if (Model.ContentItem.ContentItem.Id > 0 && Model.SelectedCulture != null && Model.ContentLocalizations.Localizations.Count() > 0) {
|
||||||
if (Model.ContentLocalizations.MasterId > 0) { %>
|
Html.RegisterStyle("base.css");%>
|
||||||
<fieldset class="localization culture-selection"><%
|
<fieldset class="localization culture-selection">
|
||||||
if (Model.MasterContentItem != null) { %>
|
|
||||||
<fieldset class="culture-selected">
|
<fieldset class="culture-selected">
|
||||||
<label for="SelectedCulture"><%:T("Content Localization") %></label>
|
<label for="SelectedCulture"><%:T("Content Localization")%></label>
|
||||||
<div><%:T("This is the {0} variation of {1}.",
|
<div><%=T("This is the <em>{0}</em> variation of {1}.",
|
||||||
Html.DropDownList("SelectedCulture", new SelectList(Model.SiteCultures, Model.SelectedCulture)),
|
Html.Encode(Model.SelectedCulture),
|
||||||
Html.ItemEditLink(Model.MasterContentItem)) %></div>
|
Html.ItemEditLink(Model.MasterContentItem ?? Model.ContentItem))%></div>
|
||||||
|
<%:Html.Hidden("SelectedCulture", Model.SelectedCulture)%>
|
||||||
</fieldset><%
|
</fieldset><%
|
||||||
}
|
if (Model.ContentLocalizations.Localizations.Count() > 0) {%>
|
||||||
if (Model.ContentLocalizations.Localizations.Count() > 0) { //todo: find a good place for this info on the content edit page %>
|
|
||||||
<dl class="content-localization">
|
<dl class="content-localization">
|
||||||
<dt><%:Model.MasterContentItem != null ? T("Other translations:") : T("Translations:") %></dt>
|
<dt><%:T("Other translations:")%></dt>
|
||||||
<dd class="content-localizations">
|
<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>
|
</dd>
|
||||||
</dl><%
|
</dl><%
|
||||||
} %>
|
}%>
|
||||||
</fieldset><%
|
</fieldset><%
|
||||||
} %>
|
} %>
|
||||||
@@ -51,17 +51,17 @@ namespace Orchard.Core.PublishLater.Drivers {
|
|||||||
switch (model.Command) {
|
switch (model.Command) {
|
||||||
case "PublishNow":
|
case "PublishNow":
|
||||||
_commonService.Publish(model.ContentItem);
|
_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;
|
break;
|
||||||
case "PublishLater":
|
case "PublishLater":
|
||||||
DateTime scheduled;
|
DateTime scheduled;
|
||||||
if (DateTime.TryParse(string.Format("{0} {1}", model.ScheduledPublishUtcDate, model.ScheduledPublishUtcTime), out scheduled))
|
if (DateTime.TryParse(string.Format("{0} {1}", model.ScheduledPublishUtcDate, model.ScheduledPublishUtcTime), out scheduled))
|
||||||
model.ScheduledPublishUtc = scheduled;
|
model.ScheduledPublishUtc = scheduled;
|
||||||
_publishLaterService.Publish(model.ContentItem, model.ScheduledPublishUtc.HasValue ? model.ScheduledPublishUtc.Value : DateTime.MaxValue);
|
_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;
|
break;
|
||||||
case "SaveDraft":
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<h3><%:Model.DisplayName%></h3><%
|
<h3><%:Model.DisplayName%></h3><%
|
||||||
var creatable = Model.Settings.GetModel<ContentTypeSettings>().Creatable;
|
var creatable = Model.Settings.GetModel<ContentTypeSettings>().Creatable;
|
||||||
if (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>
|
||||||
<div class="related"><%
|
<div class="related"><%
|
||||||
|
|||||||
Reference in New Issue
Block a user