-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
zabulus
committed
Nov 17, 2014
1 parent
19223f4
commit fcea6f3
Showing
11 changed files
with
246 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
ChameleonForms.Example/Views/ExampleForms/EditorTemplates/ChildView.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
@model ChameleonForms.Example.Controllers.ChildViewModel | ||
|
||
@{ | ||
ViewBag.Title = "ChildView"; | ||
} | ||
|
||
<h2>ChildView</h2> | ||
|
||
@this.ChameleonSection().FieldFor(x => x.ChildField) |
4 changes: 4 additions & 0 deletions
4
ChameleonForms.Example/Views/ExampleForms/EditorTemplates/PartialViewModel.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
@model ViewModelExample | ||
|
||
@this.ChameleonSection().PartialFor(x => x.Child, "ChildView") | ||
@this.ChameleonSection().FieldFor(x => x.SomeCheckbox) |
16 changes: 16 additions & 0 deletions
16
ChameleonForms.Example/Views/ExampleForms/PartialFor.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
@model ViewModelExample | ||
|
||
@{ | ||
ViewBag.Title = "ViewUsingPartial"; | ||
Layout = "~/Views/Shared/_BootstrapLayout.cshtml"; | ||
} | ||
|
||
<h2>ViewUsingPartial</h2> | ||
|
||
@using (var f = Html.BeginChameleonForm()) | ||
{ | ||
using (var s = f.BeginSection()) | ||
{ | ||
@s.PartialFor(x => x, "PartialViewModel"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
using ChameleonForms.Component.Config; | ||
using ChameleonForms.Templates; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Linq.Expressions; | ||
using System.Text; | ||
using System.Web; | ||
using System.Web.Mvc.Html; | ||
|
||
namespace ChameleonForms.Component | ||
{ | ||
class PartialSection<TModel, TChild, TTemplate> : ISection<TChild> where TTemplate : IFormTemplate | ||
{ | ||
private Section<TModel, TTemplate> section; | ||
private Expression<Func<TModel, TChild>> parEx; | ||
|
||
public PartialSection(Section<TModel, TTemplate> section, Expression<Func<TModel, TChild>> parEx) | ||
{ | ||
this.section = section; | ||
this.parEx = parEx; | ||
} | ||
|
||
public IFieldConfiguration FieldFor<TProperty>(Expression<Func<TChild, TProperty>> expression) | ||
{ | ||
return this.section.FieldFor(ExpressionExtensions.Combine(parEx, expression)); | ||
} | ||
|
||
public IHtmlString PartialFor<TChild2>(Expression<Func<TChild, TChild2>> expression) | ||
{ | ||
return this.section.PartialFor(ExpressionExtensions.Combine(parEx, expression)); | ||
} | ||
|
||
public IHtmlString PartialFor<TChild2>(Expression<Func<TChild, TChild2>> expression, string templateName) | ||
{ | ||
return this.section.PartialFor(ExpressionExtensions.Combine(parEx, expression), templateName); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Extensions to add partial for for sections | ||
/// </summary> | ||
public static class PartialExtensions | ||
{ | ||
/// <summary> | ||
/// Extension injects parent section into editor view | ||
/// </summary> | ||
/// <typeparam name="TModel">The view model type for the current view</typeparam> | ||
/// <typeparam name="TTemplate">The type of HTML template renderer the form is using</typeparam> | ||
/// <typeparam name="TValue">The view model type for the nested view</typeparam> | ||
/// <param name="section">Form section</param> | ||
/// <param name="expression">A lamdba expression to identify the field to render the field for</param> | ||
/// <param name="templateName">The name of the template to use to render the object.</param> | ||
/// <returns>Rendered view</returns> | ||
public static IHtmlString PartialFor<TModel, TTemplate, TValue>(this Section<TModel, TTemplate> section, Expression<Func<TModel, TValue>> expression, string templateName) where TTemplate : IFormTemplate | ||
{ | ||
object newViewData = new { ChameleonSection = section, ChameleonExpression = expression }; | ||
return section.Form.HtmlHelper.EditorFor(expression, templateName, null, newViewData); | ||
} | ||
|
||
/// <summary> | ||
/// Extension injects parent section into editor view | ||
/// </summary> | ||
/// <typeparam name="TModel">The view model type for the current view</typeparam> | ||
/// <typeparam name="TTemplate">The type of HTML template renderer the form is using</typeparam> | ||
/// <typeparam name="TValue">The view model type for the nested view</typeparam> | ||
/// <param name="section">Form section</param> | ||
/// <param name="expression">A lamdba expression to identify the field to render the field for</param> | ||
/// <returns>Rendered view</returns> | ||
public static IHtmlString PartialFor<TModel, TTemplate, TValue>(this Section<TModel, TTemplate> section, Expression<Func<TModel, TValue>> expression) where TTemplate : IFormTemplate | ||
{ | ||
object newViewData = new { ChameleonSection = section, ChameleonExpression = expression }; | ||
return section.Form.HtmlHelper.EditorFor(expression, null, null, newViewData); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using ChameleonForms; | ||
using ChameleonForms.Component; | ||
using ChameleonForms.Templates; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Linq.Expressions; | ||
using System.Text; | ||
|
||
namespace System.Web.Mvc | ||
{ | ||
/// <summary> | ||
/// Extension to use in nested partial view. | ||
/// </summary> | ||
public static class WebViewPageExtensions | ||
{ | ||
/// <summary> | ||
/// Get section from upper view | ||
/// </summary> | ||
/// <typeparam name="TModel">View model of nested partial view</typeparam> | ||
/// <param name="self">View page for nested view</param> | ||
/// <returns>Returns section of parent view</returns> | ||
public static ISection<TModel> ChameleonSection<TModel>(this WebViewPage<TModel> self) | ||
{ | ||
object parentSectionObject; | ||
if (!self.ViewData.TryGetValue("ChameleonSection", out parentSectionObject)) | ||
{ | ||
throw new InvalidOperationException("Chameleon Section is unavailable for now"); | ||
} | ||
|
||
object parentExpression; | ||
if (!self.ViewData.TryGetValue("ChameleonExpression", out parentExpression)) | ||
{ | ||
throw new InvalidOperationException("Chameleon Section is unavailable for now"); | ||
} | ||
|
||
ISection parentSection = parentSectionObject as ISection; | ||
return parentSection.CreateChildSection<TModel>(parentExpression); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fcea6f3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TeamCity ChameleonForms :: Continuous Integration Build 198 is now running
fcea6f3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TeamCity ChameleonForms :: Continuous Integration Build 1.1.1-PullRequest104+015 outcome was SUCCESS
Summary: Tests passed: 2997 Build time: 0:0:0
fcea6f3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TeamCity ChameleonForms :: Continuous Integration Build 205 is now running
fcea6f3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TeamCity ChameleonForms :: Continuous Integration Build 1.2.1-PullRequest104+001 outcome was SUCCESS
Summary: Tests passed: 819 Build time: 0:0:0