Updating displays/editors api to include a content item view model.

--HG--
extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4043002
This commit is contained in:
loudej
2009-12-03 01:08:29 +00:00
parent e93efa87e4
commit 4f34920dbb
18 changed files with 160 additions and 51 deletions

View File

@@ -40,7 +40,7 @@ namespace Orchard.Sandbox.Controllers {
var page = _contentManager.Get<SandboxPage>(id);
var model = new PageShowViewModel {
Page = page,
ItemView = _contentManager.GetDisplays(page, null, null)
ItemView = _contentManager.GetDisplays(page, null, "Detail")
};
return View(model);
}

View File

@@ -4,6 +4,7 @@ using Orchard.Core.Common.Models;
using Orchard.Data;
using Orchard.Models;
using Orchard.Models.Driver;
using Orchard.Models.ViewModels;
namespace Orchard.Sandbox.Models {
public class SandboxContentProvider : ContentProvider {
@@ -43,6 +44,15 @@ namespace Orchard.Sandbox.Models {
});
});
//TODO: helper that glues this for free - include list of known-displaytype prefixes
OnGetDisplays<SandboxPage>((context, page) => context.ItemView.TemplateName = "SandboxPage" + context.DisplayType);
OnGetEditors<SandboxPage>((context, page) => context.ItemView.TemplateName = "SandboxPage");
OnUpdateEditors<SandboxPage>((context, page) => {
context.Updater.TryUpdateModel((ItemEditorViewModel<SandboxPage>)context.ItemView, "", null, null);
context.ItemView.TemplateName = "SandboxPage";
});
// add settings to site, and simple record-template gui
Filters.Add(new ActivatingFilter<ContentPart<SandboxSettingsRecord>>("site"));
Filters.Add(new StorageFilter<SandboxSettingsRecord>(settingsRepository) { AutomaticallyCreateMissingRecord = true });

View File

@@ -75,6 +75,9 @@
</ItemGroup>
<ItemGroup>
<Content Include="Package.txt" />
<Content Include="Views\Models\DisplayTemplates\SandboxPageList.ascx" />
<Content Include="Views\Models\DisplayTemplates\SandboxPageDetail.ascx" />
<Content Include="Views\Models\EditorTemplates\SandboxPage.ascx" />
<Content Include="Views\Models\EditorTemplates\SandboxSettingsRecord.ascx" />
<Content Include="Views\Page\Edit.aspx" />
<Content Include="Views\Page\Create.aspx" />

View File

@@ -0,0 +1,14 @@
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<ItemDisplayViewModel<SandboxPage>>" %>
<%@ Import Namespace="Orchard.Mvc.Html"%>
<%@ Import Namespace="Orchard.Sandbox.Models" %>
<%@ Import Namespace="Orchard.Models.ViewModels" %>
<%@ Import Namespace="Orchard.Models" %>
<h1><%=Html.Encode(Model.Item.Record.Name) %></h1>
<%foreach (var display in Model.Displays) { %>
<%=Html.DisplayFor(m=>display.Model, display.TemplateName, display.Prefix) %>
<%} %>
<p>
<%=Html.ItemEditLink("Edit this page", Model.Item) %>, <%=Html.ActionLink("Return to list", "index") %></p>

View File

@@ -0,0 +1,8 @@
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<ItemDisplayViewModel<SandboxPage>>" %>
<%@ Import Namespace="Orchard.Sandbox.Models" %>
<%@ Import Namespace="Orchard.Models.ViewModels" %>
<%@ Import Namespace="Orchard.Models" %>
<h1><%=Html.Encode(Model.Item.Record.Name) %></h1>
<%foreach (var display in Model.Displays) { %>
<%=Html.DisplayFor(m=>display.Model, display.TemplateName, display.Prefix??"") %>
<%} %>

View File

@@ -0,0 +1,14 @@
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<ItemEditorViewModel<SandboxPage>>" %>
<%@ Import Namespace="Orchard.Sandbox.Models" %>
<%@ Import Namespace="Orchard.Models.ViewModels" %>
<%@ Import Namespace="Orchard.Models" %>
<li>
<%=Html.LabelFor(m => m.Item.Record.Name)%>
<%=Html.EditorFor(m => m.Item.Record.Name)%>
</li>
<%foreach (var e in Model.Editors) { %>
<%=Html.EditorFor(m=>e.Model, e.TemplateName, e.Prefix??"") %>
<%} %>

View File

@@ -1,14 +1,12 @@
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Orchard.Sandbox.Models.SandboxSettingsRecord>" %>
<h3>Sandbox</h3>
<ol>
<li>
<%= Html.LabelFor(x=>x.AllowAnonymousEdits) %>
<%= Html.EditorFor(x=>x.AllowAnonymousEdits) %>
<%= Html.ValidationMessage("AllowAnonymousEdits", "*")%>
</li>
<li>
<%= Html.LabelFor(x => x.NameOfThemeWhenEditingPage)%>
<%= Html.EditorFor(x=>x.NameOfThemeWhenEditingPage) %>
<%= Html.ValidationMessage("NameOfThemeWhenEditingPage", "*")%>
</li>
</ol>
<fieldset>
<legend>Sandbox</legend>
<%= Html.LabelFor(x=>x.AllowAnonymousEdits) %>
<%= Html.EditorFor(x=>x.AllowAnonymousEdits) %>
<%= Html.ValidationMessage("AllowAnonymousEdits", "*")%>
<br />
<%= Html.LabelFor(x => x.NameOfThemeWhenEditingPage)%>
<%= Html.EditorFor(x=>x.NameOfThemeWhenEditingPage) %>
<%= Html.ValidationMessage("NameOfThemeWhenEditingPage", "*")%>
<br />
</fieldset>

View File

@@ -24,13 +24,17 @@
Edit Page</h3>
<%using (Html.BeginForm()) { %>
<ul>
<li>
<%=Html.EditorFor(m => m.ItemView, Model.ItemView.TemplateName, Model.ItemView.Prefix ?? "")%>
<li><input type="submit" name="submit" value="Save" /></li>
<%-- <li>
<%=Html.LabelFor(x => x.Page.Record.Name)%><%=Html.EditorFor(x => x.Page.Record.Name)%></li>
<%foreach (var x in Model.ItemView.Editors) { %>
<%=Html.EditorFor(m=>x.Model, x.TemplateName, x.Prefix) %>
<%} %>
<li>
<input type="submit" name="submit" value="Save" /></li>
<input type="submit" name="submit" value="Save" /></li>--%>
</ul>
<%} %>
</div>

View File

@@ -20,13 +20,14 @@
</div>
<div id="main">
<% Html.RenderPartial("Messages", Model.Messages); %>
<h1><%=Html.Encode(Model.Page.Record.Name) %></h1>
<%=Html.DisplayFor(m => m.ItemView, Model.ItemView.TemplateName, "")%>
<%-- <h1><%=Html.Encode(Model.Page.Record.Name) %></h1>
<%foreach (var display in Model.ItemView.Displays) { %>
<%=Html.DisplayFor(m=>display.Model, display.TemplateName, display.Prefix) %>
<%} %>
<p>
<%=Html.ActionLink("Edit this page", "edit", new{Model.Page.ContentItem.Id}, new{}) %>, <%=Html.ActionLink("Return to list", "index") %></p>
</div>
--%> </div>
<div id="footer">
<% Html.Include("footer"); %>
</div>