mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-01-19 17:51:45 +08:00
fixed validation of the LocalizationPart (#8464)
This commit is contained in:
@@ -14,6 +14,7 @@ namespace Orchard.Localization.Drivers {
|
|||||||
private readonly ICultureManager _cultureManager;
|
private readonly ICultureManager _cultureManager;
|
||||||
private readonly ILocalizationService _localizationService;
|
private readonly ILocalizationService _localizationService;
|
||||||
private readonly IContentManager _contentManager;
|
private readonly IContentManager _contentManager;
|
||||||
|
private string _selectedLanguage = string.Empty;
|
||||||
|
|
||||||
public LocalizationPartDriver(ICultureManager cultureManager, ILocalizationService localizationService, IContentManager contentManager) {
|
public LocalizationPartDriver(ICultureManager cultureManager, ILocalizationService localizationService, IContentManager contentManager) {
|
||||||
_cultureManager = cultureManager;
|
_cultureManager = cultureManager;
|
||||||
@@ -59,12 +60,25 @@ namespace Orchard.Localization.Drivers {
|
|||||||
RetrieveMissingCultures(masterContentItem.As<LocalizationPart>(), true) :
|
RetrieveMissingCultures(masterContentItem.As<LocalizationPart>(), true) :
|
||||||
RetrieveMissingCultures(part, part.Culture != null);
|
RetrieveMissingCultures(part, part.Culture != null);
|
||||||
|
|
||||||
|
// if localizationpart is present remove it from the list of missingcultures
|
||||||
|
if (part.Culture != null && missingCultures.Contains(part.Culture.Culture)) {
|
||||||
|
missingCultures.Remove(part.Culture.Culture);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool displayLanguageSelection = true;
|
||||||
|
if (string.IsNullOrEmpty(_selectedLanguage)) {
|
||||||
|
if (part.Culture != null && !string.IsNullOrEmpty(part.Culture.Culture)) {
|
||||||
|
displayLanguageSelection = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var model = new EditLocalizationViewModel {
|
var model = new EditLocalizationViewModel {
|
||||||
SelectedCulture = GetCulture(part),
|
SelectedCulture = GetCulture(part),
|
||||||
MissingCultures = missingCultures,
|
MissingCultures = missingCultures,
|
||||||
ContentItem = part,
|
ContentItem = part,
|
||||||
MasterContentItem = masterContentItem,
|
MasterContentItem = masterContentItem,
|
||||||
ContentLocalizations = new ContentLocalizationsViewModel(part) { Localizations = localizations }
|
ContentLocalizations = new ContentLocalizationsViewModel(part) { Localizations = localizations },
|
||||||
|
DisplayLanguageSelection = displayLanguageSelection
|
||||||
};
|
};
|
||||||
|
|
||||||
return ContentShape("Parts_Localization_ContentTranslations_Edit",
|
return ContentShape("Parts_Localization_ContentTranslations_Edit",
|
||||||
@@ -73,15 +87,16 @@ namespace Orchard.Localization.Drivers {
|
|||||||
|
|
||||||
protected override DriverResult Editor(LocalizationPart part, IUpdateModel updater, dynamic shapeHelper) {
|
protected override DriverResult Editor(LocalizationPart part, IUpdateModel updater, dynamic shapeHelper) {
|
||||||
var model = new EditLocalizationViewModel();
|
var model = new EditLocalizationViewModel();
|
||||||
if (updater != null && updater.TryUpdateModel(model, TemplatePrefix, null, null)
|
updater.TryUpdateModel(model, TemplatePrefix, null, null);
|
||||||
// GetCulture(part) is checked against null value, because the content
|
// GetCulture(part) is checked against null value, because the content
|
||||||
// culture has to be set only if it's not set already.
|
// culture has to be set only if it's not set already.
|
||||||
&& GetCulture(part) == null
|
if (GetCulture(part) == null
|
||||||
// model.SelectedCulture is checked against null value, because the editor
|
// model.SelectedCulture is checked against null value, because the editor
|
||||||
// group may not contain LocalizationPart when the content item is saved for
|
// group may not contain LocalizationPart when the content item is saved for
|
||||||
// the first time.
|
// the first time.
|
||||||
&& !string.IsNullOrEmpty(model.SelectedCulture)) {
|
&& !string.IsNullOrEmpty(model.SelectedCulture)) {
|
||||||
_localizationService.SetContentCulture(part, model.SelectedCulture);
|
_localizationService.SetContentCulture(part, model.SelectedCulture);
|
||||||
|
_selectedLanguage = model.SelectedCulture;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Editor(part, shapeHelper);
|
return Editor(part, shapeHelper);
|
||||||
|
|||||||
@@ -8,5 +8,6 @@ namespace Orchard.Localization.ViewModels {
|
|||||||
public IContent ContentItem { 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; }
|
||||||
|
public bool DisplayLanguageSelection { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
<fieldset class="localization culture-selection">
|
<fieldset class="localization culture-selection">
|
||||||
<label for="@Html.FieldIdFor(m => m.SelectedCulture)">@T("Content Localization")</label>
|
<label for="@Html.FieldIdFor(m => m.SelectedCulture)">@T("Content Localization")</label>
|
||||||
<div>
|
<div>
|
||||||
@if (!string.IsNullOrEmpty(Model.SelectedCulture)) {
|
@if ((!string.IsNullOrEmpty(Model.SelectedCulture) && ViewData.ModelState.IsValid) || !Model.DisplayLanguageSelection) {
|
||||||
@T("This is the <em>{0}</em> variation of the content",
|
@T("This is the <em>{0}</em> variation of the content",
|
||||||
Html.Encode(Model.SelectedCulture))
|
Html.Encode(Model.SelectedCulture))
|
||||||
|
|
||||||
@@ -47,7 +47,8 @@
|
|||||||
Html.FieldIdFor(m => m.SelectedCulture),
|
Html.FieldIdFor(m => m.SelectedCulture),
|
||||||
Html.FieldNameFor(m => m.SelectedCulture),
|
Html.FieldNameFor(m => m.SelectedCulture),
|
||||||
Model.MissingCultures,
|
Model.MissingCultures,
|
||||||
Model.SelectedCulture),
|
Model.SelectedCulture,
|
||||||
|
!ViewData.ModelState.IsValid),
|
||||||
Html.ItemEditLink(masterContent));
|
Html.ItemEditLink(masterContent));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -56,9 +57,10 @@
|
|||||||
Html.FieldIdFor(m => m.SelectedCulture),
|
Html.FieldIdFor(m => m.SelectedCulture),
|
||||||
Html.FieldNameFor(m => m.SelectedCulture),
|
Html.FieldNameFor(m => m.SelectedCulture),
|
||||||
Model.MissingCultures,
|
Model.MissingCultures,
|
||||||
Model.SelectedCulture));
|
Model.SelectedCulture,
|
||||||
|
!ViewData.ModelState.IsValid));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Model.ContentLocalizations.Localizations.Any()) {
|
if (Model.ContentLocalizations.Localizations.Any()) {
|
||||||
<dl class="content-localization">
|
<dl class="content-localization">
|
||||||
<dt>@T("Other translations:")</dt>
|
<dt>@T("Other translations:")</dt>
|
||||||
@@ -68,37 +70,48 @@
|
|||||||
Html.ItemEditLink(c.Culture.Culture, c, new { ReturnUrl = returnUrl }), "localizations");
|
Html.ItemEditLink(c.Culture.Culture, c, new { ReturnUrl = returnUrl }), "localizations");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@Html.UnorderedList(Model.ContentLocalizations.Localizations, (c, i) =>
|
@Html.UnorderedList(Model.ContentLocalizations.Localizations, (c, i) =>
|
||||||
Html.ItemEditLink(c.Culture.Culture, c), "localizations");
|
Html.ItemEditLink(c.Culture.Culture, c), "localizations");
|
||||||
}
|
}
|
||||||
</dd>
|
</dd>
|
||||||
</dl>
|
</dl>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@functions{
|
@functions{
|
||||||
private IHtmlString BuildSelectedCultureList(string id, string name, IEnumerable<string> siteCultures, string culture) {
|
private IHtmlString BuildSelectedCultureList(string id, string name, IEnumerable<string> siteCultures, string culture, bool addSelectedCulture) {
|
||||||
TagBuilder selectTag = new TagBuilder("select");
|
TagBuilder selectTag = new TagBuilder("select");
|
||||||
selectTag.Attributes["id"] = id;
|
selectTag.Attributes["id"] = id;
|
||||||
selectTag.Attributes["name"] = name;
|
selectTag.Attributes["name"] = name;
|
||||||
|
|
||||||
|
if (addSelectedCulture) {
|
||||||
|
TagBuilder optionTagCulture = new TagBuilder("option");
|
||||||
|
optionTagCulture.Attributes["data-content-dir"] = CultureInfo.GetCultureInfo(culture).TextInfo.IsRightToLeft ? "rtl" : "ltr";
|
||||||
|
optionTagCulture.Attributes["selected"] = "selected";
|
||||||
|
optionTagCulture.SetInnerText(Html.Encode(culture));
|
||||||
|
selectTag.InnerHtml += optionTagCulture.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
foreach (var siteCulture in siteCultures) {
|
foreach (var siteCulture in siteCultures) {
|
||||||
TagBuilder optionTag = new TagBuilder("option");
|
TagBuilder optionTag = new TagBuilder("option");
|
||||||
optionTag.Attributes["data-content-dir"] = CultureInfo.GetCultureInfo(siteCulture).TextInfo.IsRightToLeft ? "rtl" : "ltr";
|
optionTag.Attributes["data-content-dir"] = CultureInfo.GetCultureInfo(siteCulture).TextInfo.IsRightToLeft ? "rtl" : "ltr";
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(culture)) {
|
// If the form is in error, the culture remains the one previously selected.
|
||||||
if (siteCulture == WorkContext.CurrentSite.SiteCulture) {
|
if (!addSelectedCulture) {
|
||||||
optionTag.Attributes["selected"] = "selected";
|
if (string.IsNullOrEmpty(culture)) {
|
||||||
|
if (siteCulture == WorkContext.CurrentSite.SiteCulture) {
|
||||||
|
optionTag.Attributes["selected"] = "selected";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
else {
|
||||||
else {
|
if (siteCulture == culture) {
|
||||||
if (siteCulture == culture) {
|
optionTag.Attributes["selected"] = "selected";
|
||||||
optionTag.Attributes["selected"] = "selected";
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
optionTag.SetInnerText(Html.Encode(siteCulture));
|
optionTag.SetInnerText(Html.Encode(siteCulture));
|
||||||
|
|||||||
Reference in New Issue
Block a user