2010-06-09 16:14:47 -07:00
|
|
|
|
using System.Globalization;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Web.Mvc;
|
2009-11-18 21:55:11 +00:00
|
|
|
|
using Orchard.Core.Settings.Models;
|
|
|
|
|
using Orchard.Core.Settings.ViewModels;
|
2010-09-03 16:04:42 -07:00
|
|
|
|
using Orchard.DisplayManagement;
|
2009-11-18 21:55:11 +00:00
|
|
|
|
using Orchard.Localization;
|
2009-12-21 20:29:53 +00:00
|
|
|
|
using Orchard.ContentManagement;
|
2010-06-08 16:26:08 -07:00
|
|
|
|
using Orchard.Localization.Services;
|
2009-11-18 21:55:11 +00:00
|
|
|
|
using Orchard.Settings;
|
|
|
|
|
using Orchard.UI.Notify;
|
|
|
|
|
|
|
|
|
|
namespace Orchard.Core.Settings.Controllers {
|
|
|
|
|
[ValidateInput(false)]
|
2009-11-19 05:31:39 +00:00
|
|
|
|
public class AdminController : Controller, IUpdateModel {
|
2009-11-18 21:55:11 +00:00
|
|
|
|
private readonly ISiteService _siteService;
|
2010-06-08 16:26:08 -07:00
|
|
|
|
private readonly ICultureManager _cultureManager;
|
2010-01-22 05:25:54 +00:00
|
|
|
|
public IOrchardServices Services { get; private set; }
|
2009-11-18 21:55:11 +00:00
|
|
|
|
|
2010-09-03 16:04:42 -07:00
|
|
|
|
public AdminController(
|
|
|
|
|
ISiteService siteService,
|
|
|
|
|
IOrchardServices services,
|
|
|
|
|
ICultureManager cultureManager,
|
|
|
|
|
IShapeHelperFactory shapeHelperFactory) {
|
2009-11-18 21:55:11 +00:00
|
|
|
|
_siteService = siteService;
|
2010-06-08 16:26:08 -07:00
|
|
|
|
_cultureManager = cultureManager;
|
2010-01-22 05:25:54 +00:00
|
|
|
|
Services = services;
|
2009-11-18 21:55:11 +00:00
|
|
|
|
T = NullLocalizer.Instance;
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-03 16:04:42 -07:00
|
|
|
|
dynamic Shape { get; set; }
|
2009-11-18 21:55:11 +00:00
|
|
|
|
public Localizer T { get; set; }
|
|
|
|
|
|
2009-12-02 06:16:22 +00:00
|
|
|
|
public ActionResult Index(string tabName) {
|
2010-01-22 05:25:54 +00:00
|
|
|
|
if (!Services.Authorizer.Authorize(Permissions.ManageSettings, T("Not authorized to manage settings")))
|
|
|
|
|
return new HttpUnauthorizedResult();
|
|
|
|
|
|
2010-09-03 16:04:42 -07:00
|
|
|
|
var site = _siteService.GetSiteSettings().As<SiteSettingsPart>();
|
2010-01-17 09:14:45 +00:00
|
|
|
|
var model = new SettingsIndexViewModel {
|
2010-09-10 15:47:52 -07:00
|
|
|
|
Site = site,
|
2010-06-09 16:14:47 -07:00
|
|
|
|
SiteCultures = _cultureManager.ListCultures()
|
2009-12-30 00:36:35 +00:00
|
|
|
|
};
|
2010-09-10 15:47:52 -07:00
|
|
|
|
return View(model);
|
2009-11-18 21:55:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-12-30 00:36:35 +00:00
|
|
|
|
[HttpPost, ActionName("Index")]
|
|
|
|
|
public ActionResult IndexPOST(string tabName) {
|
2010-01-22 05:25:54 +00:00
|
|
|
|
if (!Services.Authorizer.Authorize(Permissions.ManageSettings, T("Not authorized to manage settings")))
|
|
|
|
|
return new HttpUnauthorizedResult();
|
|
|
|
|
|
2010-09-03 16:04:42 -07:00
|
|
|
|
var site = _siteService.GetSiteSettings().As<SiteSettingsPart>();
|
|
|
|
|
var model = new SettingsIndexViewModel { Site = Services.ContentManager.UpdateEditorModel(site, this) };
|
2009-11-19 01:03:23 +00:00
|
|
|
|
|
2010-09-03 16:04:42 -07:00
|
|
|
|
if (!ModelState.IsValid) {
|
|
|
|
|
Services.TransactionManager.Cancel();
|
2010-09-10 15:47:52 -07:00
|
|
|
|
return View(model);
|
2009-11-18 21:55:11 +00:00
|
|
|
|
}
|
2009-11-19 01:03:23 +00:00
|
|
|
|
|
2010-01-22 05:25:54 +00:00
|
|
|
|
Services.Notifier.Information(T("Settings updated"));
|
2009-11-19 01:03:23 +00:00
|
|
|
|
return RedirectToAction("Index");
|
2009-11-18 21:55:11 +00:00
|
|
|
|
}
|
2009-11-19 01:03:23 +00:00
|
|
|
|
|
2010-06-09 16:14:47 -07:00
|
|
|
|
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();
|
|
|
|
|
|
2010-09-03 16:04:42 -07:00
|
|
|
|
var model = new SiteCulturesViewModel {
|
2010-07-12 03:03:18 -07:00
|
|
|
|
CurrentCulture = _cultureManager.GetCurrentCulture(HttpContext),
|
2010-06-09 16:14:47 -07:00
|
|
|
|
SiteCultures = _cultureManager.ListCultures(),
|
|
|
|
|
};
|
2010-09-03 16:04:42 -07:00
|
|
|
|
model.AvailableSystemCultures = CultureInfo.GetCultures(CultureTypes.SpecificCultures)
|
2010-06-09 16:14:47 -07:00
|
|
|
|
.Select(ci => ci.Name)
|
2010-09-03 16:04:42 -07:00
|
|
|
|
.Where(s => !model.SiteCultures.Contains(s));
|
2010-06-09 16:14:47 -07:00
|
|
|
|
|
2010-09-10 15:47:52 -07:00
|
|
|
|
return View(model);
|
2010-06-09 16:14:47 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[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");
|
|
|
|
|
}
|
2009-11-19 01:03:23 +00:00
|
|
|
|
|
2009-11-19 05:31:39 +00:00
|
|
|
|
bool IUpdateModel.TryUpdateModel<TModel>(TModel model, string prefix, string[] includeProperties, string[] excludeProperties) {
|
2009-11-19 01:03:23 +00:00
|
|
|
|
return TryUpdateModel(model, prefix, includeProperties, excludeProperties);
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-08 06:13:08 +00:00
|
|
|
|
void IUpdateModel.AddModelError(string key, LocalizedString errorMessage) {
|
|
|
|
|
ModelState.AddModelError(key, errorMessage.ToString());
|
|
|
|
|
}
|
2009-11-18 21:55:11 +00:00
|
|
|
|
}
|
|
|
|
|
}
|