mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Initial culture management UI (could still use a few tweaks in appearance)
--HG-- branch : dev
This commit is contained in:
@@ -164,6 +164,7 @@
|
|||||||
<Compile Include="Scheduling\Services\ScheduledTaskManager.cs" />
|
<Compile Include="Scheduling\Services\ScheduledTaskManager.cs" />
|
||||||
<Compile Include="Scheduling\Services\ScheduledTaskExecutor.cs" />
|
<Compile Include="Scheduling\Services\ScheduledTaskExecutor.cs" />
|
||||||
<Compile Include="Scheduling\Models\Task.cs" />
|
<Compile Include="Scheduling\Models\Task.cs" />
|
||||||
|
<Compile Include="Settings\ViewModels\SiteCulturesViewModel.cs" />
|
||||||
<Compile Include="Settings\Drivers\SiteSettingsDriver.cs" />
|
<Compile Include="Settings\Drivers\SiteSettingsDriver.cs" />
|
||||||
<Compile Include="Settings\Metadata\ContentDefinitionManager.cs" />
|
<Compile Include="Settings\Metadata\ContentDefinitionManager.cs" />
|
||||||
<Compile Include="Settings\Metadata\Records\ContentFieldDefinitionRecord.cs" />
|
<Compile Include="Settings\Metadata\Records\ContentFieldDefinitionRecord.cs" />
|
||||||
@@ -216,7 +217,11 @@
|
|||||||
<Content Include="Routable\Module.txt" />
|
<Content Include="Routable\Module.txt" />
|
||||||
<Content Include="Routable\Views\Item\Display.aspx" />
|
<Content Include="Routable\Views\Item\Display.aspx" />
|
||||||
<Content Include="Settings\Module.txt" />
|
<Content Include="Settings\Module.txt" />
|
||||||
|
<Content Include="Settings\Styles\admin.css" />
|
||||||
<Content Include="Settings\Views\Admin\Index.ascx" />
|
<Content Include="Settings\Views\Admin\Index.ascx" />
|
||||||
|
<Content Include="Settings\Views\Admin\Culture.ascx" />
|
||||||
|
<Content Include="Settings\Views\DisplayTemplates\CurrentCulture.ascx" />
|
||||||
|
<Content Include="Settings\Views\DisplayTemplates\RemovableCulture.ascx" />
|
||||||
<Content Include="Web.config" />
|
<Content Include="Web.config" />
|
||||||
<Content Include="XmlRpc\Module.txt" />
|
<Content Include="XmlRpc\Module.txt" />
|
||||||
<Content Include="XmlRpc\Views\Home\Index.aspx" />
|
<Content Include="XmlRpc\Views\Home\Index.aspx" />
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
using System.Web.Mvc;
|
using System.Globalization;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Web.Mvc;
|
||||||
using Orchard.Core.Settings.Models;
|
using Orchard.Core.Settings.Models;
|
||||||
using Orchard.Core.Settings.ViewModels;
|
using Orchard.Core.Settings.ViewModels;
|
||||||
using Orchard.Localization;
|
using Orchard.Localization;
|
||||||
@@ -29,7 +31,7 @@ namespace Orchard.Core.Settings.Controllers {
|
|||||||
|
|
||||||
var model = new SettingsIndexViewModel {
|
var model = new SettingsIndexViewModel {
|
||||||
Site = _siteService.GetSiteSettings().As<SiteSettings>(),
|
Site = _siteService.GetSiteSettings().As<SiteSettings>(),
|
||||||
AvailableCultures = _cultureManager.ListCultures()
|
SiteCultures = _cultureManager.ListCultures()
|
||||||
};
|
};
|
||||||
model.ViewModel = Services.ContentManager.BuildEditorModel(model.Site);
|
model.ViewModel = Services.ContentManager.BuildEditorModel(model.Site);
|
||||||
return View(model);
|
return View(model);
|
||||||
@@ -51,6 +53,39 @@ namespace Orchard.Core.Settings.Controllers {
|
|||||||
return RedirectToAction("Index");
|
return RedirectToAction("Index");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ActionResult Culture() {
|
||||||
|
//todo: class and/or method attributes for our auth?
|
||||||
|
if (!Services.Authorizer.Authorize(Permissions.ManageSettings, T("Not authorized to manage settings")))
|
||||||
|
return new HttpUnauthorizedResult();
|
||||||
|
|
||||||
|
var viewModel = new SiteCulturesViewModel {
|
||||||
|
CurrentCulture = CultureInfo.CurrentCulture.Name,
|
||||||
|
SiteCultures = _cultureManager.ListCultures(),
|
||||||
|
};
|
||||||
|
viewModel.AvailableSystemCultures = CultureInfo.GetCultures(CultureTypes.SpecificCultures)
|
||||||
|
.Select(ci => ci.Name)
|
||||||
|
.Where(s => !viewModel.SiteCultures.Contains(s));
|
||||||
|
|
||||||
|
return View(viewModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public ActionResult AddCulture(string cultureName) {
|
||||||
|
if (!Services.Authorizer.Authorize(Permissions.ManageSettings, T("Not authorized to manage settings")))
|
||||||
|
return new HttpUnauthorizedResult();
|
||||||
|
|
||||||
|
_cultureManager.AddCulture(cultureName);
|
||||||
|
return RedirectToAction("Culture");
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public ActionResult DeleteCulture(string cultureName) {
|
||||||
|
if (!Services.Authorizer.Authorize(Permissions.ManageSettings, T("Not authorized to manage settings")))
|
||||||
|
return new HttpUnauthorizedResult();
|
||||||
|
|
||||||
|
_cultureManager.DeleteCulture(cultureName);
|
||||||
|
return RedirectToAction("Culture");
|
||||||
|
}
|
||||||
|
|
||||||
bool IUpdateModel.TryUpdateModel<TModel>(TModel model, string prefix, string[] includeProperties, string[] excludeProperties) {
|
bool IUpdateModel.TryUpdateModel<TModel>(TModel model, string prefix, string[] includeProperties, string[] excludeProperties) {
|
||||||
return TryUpdateModel(model, prefix, includeProperties, excludeProperties);
|
return TryUpdateModel(model, prefix, includeProperties, excludeProperties);
|
||||||
|
|||||||
18
src/Orchard.Web/Core/Settings/Styles/admin.css
Normal file
18
src/Orchard.Web/Core/Settings/Styles/admin.css
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
.site-cultures {
|
||||||
|
font-size:1.2em;
|
||||||
|
overflow:auto;
|
||||||
|
}
|
||||||
|
.site-cultures li {
|
||||||
|
clear:left;
|
||||||
|
float:left;
|
||||||
|
overflow:auto;
|
||||||
|
padding:1px 6px;
|
||||||
|
margin:0 0 0 1em;
|
||||||
|
}
|
||||||
|
.site-cultures li:hover {
|
||||||
|
background:#EAEAEA;
|
||||||
|
}
|
||||||
|
.site-cultures div {
|
||||||
|
float:left;
|
||||||
|
width:6em;
|
||||||
|
}
|
||||||
@@ -7,7 +7,7 @@ using Orchard.Core.Settings.Models;
|
|||||||
namespace Orchard.Core.Settings.ViewModels {
|
namespace Orchard.Core.Settings.ViewModels {
|
||||||
public class SettingsIndexViewModel : BaseViewModel {
|
public class SettingsIndexViewModel : BaseViewModel {
|
||||||
public SiteSettings Site { get; set; }
|
public SiteSettings Site { get; set; }
|
||||||
public IEnumerable<string> AvailableCultures { get; set; }
|
public IEnumerable<string> SiteCultures { get; set; }
|
||||||
public ContentItemViewModel ViewModel { get; set; }
|
public ContentItemViewModel ViewModel { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using Orchard.Mvc.ViewModels;
|
||||||
|
|
||||||
|
namespace Orchard.Core.Settings.ViewModels {
|
||||||
|
public class SiteCulturesViewModel : BaseViewModel {
|
||||||
|
public string CurrentCulture { get; set; }
|
||||||
|
public IEnumerable<string> SiteCultures { get; set; }
|
||||||
|
public IEnumerable<string> AvailableSystemCultures { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
17
src/Orchard.Web/Core/Settings/Views/Admin/Culture.ascx
Normal file
17
src/Orchard.Web/Core/Settings/Views/Admin/Culture.ascx
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<SiteCulturesViewModel>" %>
|
||||||
|
<%@ Import Namespace="Orchard.Core.Settings.ViewModels" %><%
|
||||||
|
Html.RegisterStyle("admin.css"); %>
|
||||||
|
<h1><%:Html.TitleForPage(T("Manage Settings").ToString()) %></h1>
|
||||||
|
<h2><%:T("Cultures this site supports") %></h2>
|
||||||
|
<%=Html.UnorderedList(
|
||||||
|
Model.SiteCultures.OrderBy(s => s),
|
||||||
|
(s, i) => Html.DisplayFor(scvm => s, s == Model.CurrentCulture ? "CurrentCulture" : "RemovableCulture", "").ToString(),
|
||||||
|
"site-cultures", "culture", "odd")%>
|
||||||
|
<% using (Html.BeginFormAntiForgeryPost("AddCulture")) { %>
|
||||||
|
<%:Html.ValidationSummary() %>
|
||||||
|
<fieldset>
|
||||||
|
<legend><%:T("Add a culture...") %></legend>
|
||||||
|
<%:Html.DropDownList("CultureName", new SelectList(Model.AvailableSystemCultures.OrderBy(s => s), Model.CurrentCulture)) %>
|
||||||
|
<button class="primaryAction" type="submit"><%:T("Add") %></button>
|
||||||
|
</fieldset>
|
||||||
|
<% } %>
|
||||||
@@ -1,34 +1,35 @@
|
|||||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<SettingsIndexViewModel>" %>
|
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<SettingsIndexViewModel>" %>
|
||||||
<%@ Import Namespace="Orchard.Core.Settings.ViewModels"%>
|
<%@ Import Namespace="Orchard.Core.Settings.ViewModels" %>
|
||||||
<h1><%: Html.TitleForPage(T("Manage Settings").ToString())%></h1>
|
<h1><%:Html.TitleForPage(T("Manage Settings").ToString()) %></h1>
|
||||||
<%using (Html.BeginFormAntiForgeryPost()) { %>
|
<% using (Html.BeginFormAntiForgeryPost()) { %>
|
||||||
<%: Html.ValidationSummary() %>
|
<%:Html.ValidationSummary() %>
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend><%: T("Global Settings")%></legend>
|
<legend><%:T("Global Settings") %></legend>
|
||||||
<div>
|
<div>
|
||||||
<label for="SiteName"><%: T("Site name") %></label>
|
<label for="SiteName"><%:T("Site name") %></label>
|
||||||
<%: Html.EditorFor(m => m.SiteName)%>
|
<%:Html.EditorFor(m => m.SiteName) %>
|
||||||
<%: Html.ValidationMessage("SiteName", "*") %>
|
<%:Html.ValidationMessage("SiteName", "*") %>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<label for="SiteCulture"><%:T("Default Site Culture") %></label>
|
<label for="SiteCulture"><%:T("Default Site Culture") %></label>
|
||||||
<%=Html.DropDownList("SiteCulture", new SelectList(Model.AvailableCultures, Model.SiteCulture)) %>
|
<%:Html.DropDownList("SiteCulture", new SelectList(Model.SiteCultures, Model.SiteCulture)) %>
|
||||||
<%=Html.ValidationMessage("SiteCulture", "*") %>
|
<%:Html.ValidationMessage("SiteCulture", "*") %>
|
||||||
|
<%:Html.ActionLink(T("Add or remove supported cultures for the site.").ToString(), "Culture") %>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<label for="PageTitleSeparator"><%: T("Page title separator") %></label>
|
<label for="PageTitleSeparator"><%:T("Page title separator") %></label>
|
||||||
<%: Html.EditorFor(x => x.PageTitleSeparator)%>
|
<%:Html.EditorFor(x => x.PageTitleSeparator) %>
|
||||||
<%: Html.ValidationMessage("PageTitleSeparator", "*")%>
|
<%:Html.ValidationMessage("PageTitleSeparator", "*") %>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<label for="SuperUser"><%: T("Super user") %></label>
|
<label for="SuperUser"><%:T("Super user") %></label>
|
||||||
<%: Html.EditorFor(x=>x.SuperUser) %>
|
<%:Html.EditorFor(x=>x.SuperUser) %>
|
||||||
<%: Html.ValidationMessage("SuperUser", "*") %>
|
<%:Html.ValidationMessage("SuperUser", "*") %>
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<%: Html.EditorForItem(Model.ViewModel) %>
|
<%:Html.EditorForItem(Model.ViewModel) %>
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<%: Html.EditorFor(s => s.Id) %>
|
<%:Html.EditorFor(s => s.Id) %>
|
||||||
<input class="button primaryAction" type="submit" value="<%: T("Save") %>" />
|
<input class="button primaryAction" type="submit" value="<%:T("Save") %>" />
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<% } %>
|
<% } %>
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<string>" %>
|
||||||
|
<strong><%:Model %></strong>
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<string>" %>
|
||||||
|
<div><%:Model %></div>
|
||||||
|
<% using (Html.BeginFormAntiForgeryPost(Url.Action("DeleteCulture", "Admin", new { area = "Settings" }), FormMethod.Post, new {@class = "inline link"})) { %>
|
||||||
|
<%=Html.Hidden("cultureName", Model, new { id = "" }) %>
|
||||||
|
<button type="submit" title="<%:T("Delete") %>">x</button>
|
||||||
|
<% } %>
|
||||||
@@ -32,6 +32,16 @@ namespace Orchard.Localization.Services {
|
|||||||
_cultureRepository.Create(new CultureRecord { Culture = cultureName });
|
_cultureRepository.Create(new CultureRecord { Culture = cultureName });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void DeleteCulture(string cultureName) {
|
||||||
|
if (!IsValidCulture(cultureName)) {
|
||||||
|
throw new ArgumentException("cultureName");
|
||||||
|
}
|
||||||
|
|
||||||
|
var culture = _cultureRepository.Get(cr => cr.Culture == cultureName);
|
||||||
|
if (culture != null)
|
||||||
|
_cultureRepository.Delete(culture);
|
||||||
|
}
|
||||||
|
|
||||||
public string GetCurrentCulture(HttpContext requestContext) {
|
public string GetCurrentCulture(HttpContext requestContext) {
|
||||||
var requestCulture = _cultureSelectors
|
var requestCulture = _cultureSelectors
|
||||||
.Select(x => x.GetCulture(requestContext))
|
.Select(x => x.GetCulture(requestContext))
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ namespace Orchard.Localization.Services {
|
|||||||
public interface ICultureManager : IDependency {
|
public interface ICultureManager : IDependency {
|
||||||
IEnumerable<string> ListCultures();
|
IEnumerable<string> ListCultures();
|
||||||
void AddCulture(string cultureName);
|
void AddCulture(string cultureName);
|
||||||
|
void DeleteCulture(string cultureName);
|
||||||
string GetCurrentCulture(HttpContext requestContext);
|
string GetCurrentCulture(HttpContext requestContext);
|
||||||
CultureRecord GetCultureById(int id);
|
CultureRecord GetCultureById(int id);
|
||||||
string GetSiteCulture();
|
string GetSiteCulture();
|
||||||
|
|||||||
Reference in New Issue
Block a user