Retiring ContentItemViewModel

...and all that entails
- things like IZone and IZoneCollection are barely roughed in

--HG--
branch : theming
This commit is contained in:
Nathan Heskew
2010-09-03 16:04:42 -07:00
parent 0d91cf30ac
commit 043bcf54ee
76 changed files with 419 additions and 357 deletions

View File

@@ -12,10 +12,10 @@ using Orchard.Core.Common.Models;
using Orchard.Core.Contents.Settings;
using Orchard.Core.Contents.ViewModels;
using Orchard.Data;
using Orchard.DisplayManagement;
using Orchard.Localization;
using Orchard.Logging;
using Orchard.Mvc.Results;
using Orchard.Mvc.ViewModels;
using Orchard.UI.Notify;
namespace Orchard.Core.Contents.Controllers {
@@ -29,15 +29,18 @@ namespace Orchard.Core.Contents.Controllers {
IOrchardServices orchardServices,
IContentManager contentManager,
IContentDefinitionManager contentDefinitionManager,
ITransactionManager transactionManager) {
ITransactionManager transactionManager,
IShapeHelperFactory shapeHelperFactory) {
Services = orchardServices;
_contentManager = contentManager;
_contentDefinitionManager = contentDefinitionManager;
_transactionManager = transactionManager;
T = NullLocalizer.Instance;
Logger = NullLogger.Instance;
Shape = shapeHelperFactory.CreateHelper();
}
dynamic Shape { get; set; }
public IOrchardServices Services { get; private set; }
public Localizer T { get; set; }
public ILogger Logger { get; set; }
@@ -110,7 +113,7 @@ namespace Orchard.Core.Contents.Controllers {
.Select(ctd => new KeyValuePair<string, string>(ctd.Name, ctd.DisplayName))
.ToList().OrderBy(kvp => kvp.Key);
return View("List", model);
return View(Shape.Model(model));
}
private IEnumerable<ContentTypeDefinition> GetCreatableTypes() {
@@ -188,9 +191,8 @@ namespace Orchard.Core.Contents.Controllers {
private ListContentsViewModel.Entry BuildEntry(ContentItem contentItem) {
var entry = new ListContentsViewModel.Entry {
ContentItem = contentItem,
ContentItem = _contentManager.BuildDisplayModel(contentItem, "SummaryAdmin"),
ContentItemMetadata = _contentManager.GetItemMetadata(contentItem),
ViewModel = _contentManager.BuildDisplayShape(contentItem, "SummaryAdmin"),
};
if (string.IsNullOrEmpty(entry.ContentItemMetadata.DisplayText)) {
entry.ContentItemMetadata.DisplayText = string.Format("[{0}#{1}]", contentItem.ContentType, contentItem.Id);
@@ -207,11 +209,7 @@ namespace Orchard.Core.Contents.Controllers {
}
ActionResult CreatableTypeList() {
var model = new ListContentTypesViewModel {
Types = GetCreatableTypes()
};
return View("CreatableTypeList", model);
return View(Shape.Model(Types: GetCreatableTypes()));
}
public ActionResult Create(string id) {
@@ -223,35 +221,32 @@ namespace Orchard.Core.Contents.Controllers {
if (!Services.Authorizer.Authorize(Permissions.PublishContent, contentItem, T("Cannot create content")))
return new HttpUnauthorizedResult();
var model = new CreateItemViewModel {
Id = id,
Content = _contentManager.BuildEditorShape(contentItem)
};
PrepareEditorViewModel(model.Content);
return View("Create", model);
var model = _contentManager.BuildEditorModel(contentItem);
return View(Shape.Model(Content: model));
}
[HttpPost]
public ActionResult Create(CreateItemViewModel model) {
var contentItem = _contentManager.New(model.Id);
[HttpPost, ActionName("Create")]
public ActionResult CreatePOST(string id) {
var contentItem = _contentManager.New(id);
if (!Services.Authorizer.Authorize(Permissions.PublishContent, contentItem, T("Couldn't create content")))
return new HttpUnauthorizedResult();
_contentManager.Create(contentItem, VersionOptions.Draft);
model.Content = _contentManager.UpdateEditorShape(contentItem, this);
var model = _contentManager.UpdateEditorModel(contentItem, this);
if (!ModelState.IsValid) {
_transactionManager.Cancel();
PrepareEditorViewModel(model.Content);
return View("Create", model);
return View(Shape.Model(Content: model));
}
if (!contentItem.Has<IPublishingControlAspect>())
_contentManager.Publish(contentItem);
Services.Notifier.Information(string.IsNullOrWhiteSpace(model.Content.Item.TypeDefinition.DisplayName) ? T("Your content has been created.") : T("Your {0} has been created.", model.Content.Item.TypeDefinition.DisplayName));
Services.Notifier.Information(string.IsNullOrWhiteSpace(model.TypeDefinition.DisplayName)
? T("Your content has been created.")
: T("Your {0} has been created.", model.TypeDefinition.DisplayName));
return RedirectToAction("Edit", new RouteValueDictionary { { "Id", contentItem.Id } });
}
@@ -264,19 +259,14 @@ namespace Orchard.Core.Contents.Controllers {
if (!Services.Authorizer.Authorize(Permissions.EditOthersContent, contentItem, T("Cannot edit content")))
return new HttpUnauthorizedResult();
var model = new EditItemViewModel {
Id = id,
Content = _contentManager.BuildEditorShape(contentItem)
};
var model = _contentManager.BuildEditorModel(contentItem);
PrepareEditorViewModel(model.Content);
return View("Edit", model);
return View(Shape.Model(Content: model));
}
[HttpPost]
public ActionResult Edit(EditItemViewModel model) {
var contentItem = _contentManager.Get(model.Id, VersionOptions.DraftRequired);
[HttpPost, ActionName("Edit")]
public ActionResult EditPOST(int id) {
var contentItem = _contentManager.Get(id, VersionOptions.DraftRequired);
if (contentItem == null)
return new NotFoundResult();
@@ -284,18 +274,19 @@ namespace Orchard.Core.Contents.Controllers {
if (!Services.Authorizer.Authorize(Permissions.EditOthersContent, contentItem, T("Couldn't edit content")))
return new HttpUnauthorizedResult();
model.Content = _contentManager.UpdateEditorShape(contentItem, this);
var model = _contentManager.UpdateEditorModel(contentItem, this);
if (!ModelState.IsValid) {
_transactionManager.Cancel();
PrepareEditorViewModel(model.Content);
return View("Edit", model);
return View("Edit", Shape.Model(Content: model));
}
//need to go about this differently - to know when to publish (IPlublishableAspect ?)
if (!contentItem.Has<IPublishingControlAspect>())
_contentManager.Publish(contentItem);
Services.Notifier.Information(string.IsNullOrWhiteSpace(model.Content.Item.TypeDefinition.DisplayName) ? T("Your content has been saved.") : T("Your {0} has been saved.", model.Content.Item.TypeDefinition.DisplayName));
Services.Notifier.Information(string.IsNullOrWhiteSpace(model.TypeDefinition.DisplayName)
? T("Your content has been saved.")
: T("Your {0} has been saved.", model.TypeDefinition.DisplayName));
return RedirectToAction("Edit", new RouteValueDictionary { { "Id", contentItem.Id } });
}
@@ -308,7 +299,9 @@ namespace Orchard.Core.Contents.Controllers {
if (contentItem != null) {
_contentManager.Remove(contentItem);
Services.Notifier.Information(string.IsNullOrWhiteSpace(contentItem.TypeDefinition.DisplayName) ? T("That content has been removed.") : T("That {0} has been removed.", contentItem.TypeDefinition.DisplayName));
Services.Notifier.Information(string.IsNullOrWhiteSpace(contentItem.TypeDefinition.DisplayName)
? T("That content has been removed.")
: T("That {0} has been removed.", contentItem.TypeDefinition.DisplayName));
}
if (!String.IsNullOrEmpty(returnUrl))
@@ -355,12 +348,6 @@ namespace Orchard.Core.Contents.Controllers {
return RedirectToAction("List");
}
private static void PrepareEditorViewModel(ContentItemViewModel itemViewModel) {
if (string.IsNullOrEmpty(itemViewModel.TemplateName)) {
itemViewModel.TemplateName = "Items/Contents.Item";
}
}
bool IUpdateModel.TryUpdateModel<TModel>(TModel model, string prefix, string[] includeProperties, string[] excludeProperties) {
return TryUpdateModel(model, prefix, includeProperties, excludeProperties);
}