Some experimentation with form-like shapes

--HG--
branch : mvc3p1
This commit is contained in:
Nathan Heskew
2010-08-27 16:34:26 -07:00
parent dfe71231bb
commit 18ff48df34
4 changed files with 39 additions and 2 deletions

View File

@@ -54,7 +54,18 @@ namespace Orchard.DevTools.Controllers {
return View("Simple", new Simple { Title = "This is not themed", Quantity = 5 }); return View("Simple", new Simple { Title = "This is not themed", Quantity = 5 });
} }
public ActionResult FormShapes() {
var model = Shape.Form(Submit: Shape.FormSubmit(Text: T("Finish Setup")))
.Fieldsets(Shape.Zone(typeof (Array), Name: "Fieldsets"));
model.Fieldsets.Add(Shape.InputText(Name: "SiteName", Text: T("Site Name"), Value: T("some default/pre-pop value...")));
model.Fieldsets.Add(Shape.InputText(Name: "AdminUsername", Text: T("Admin Username")));
model.Fieldsets.Add(Shape.InputPassword(Name: "AdminPassword", Text: T("Admin Password")));
model.Fieldsets[0].Attributes(new {autofocus = "autofocus"}); // <-- could be applied by some other behavior - need to be able to modify attributes instead of clobbering them like this
return View(model);
}
public ActionResult UsingShapes() { public ActionResult UsingShapes() {

View File

@@ -125,6 +125,7 @@
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="Views\Home\FormShapes.cshtml" />
<None Include="Views\Home\UsingShapes.cshtml" /> <None Include="Views\Home\UsingShapes.cshtml" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />

View File

@@ -0,0 +1,3 @@
<div>
the form -> @Display(Model)
</div>

View File

@@ -1,6 +1,5 @@
using System.Web; using System.Web;
using System.Web.Mvc; using System.Web.Mvc;
using System.Web.Routing;
using ClaySharp; using ClaySharp;
using Orchard.DisplayManagement; using Orchard.DisplayManagement;
@@ -19,5 +18,28 @@ namespace Orchard.Mvc.Html {
tagBuilder.MergeAttribute("src", Url); tagBuilder.MergeAttribute("src", Url);
return Display(new HtmlString(tagBuilder.ToString(TagRenderMode.SelfClosing))); return Display(new HtmlString(tagBuilder.ToString(TagRenderMode.SelfClosing)));
} }
#region form and company
public IHtmlString Form(dynamic Display, dynamic Shape, object Submit) {
return Display(new HtmlString("<form>" + Display(Shape.Fieldsets, Submit).ToString() + "</form>"));
}
public IHtmlString FormSubmit(dynamic Display, dynamic Shape) {
return Display(new HtmlString("<button type='submit'>" + Shape.Text + "</button>"));
}
public IHtmlString InputPassword(dynamic Display, dynamic Shape) {
return Display(new HtmlString("<label>" + Shape.Text + "</label><input type='password' name='" + Shape.Name + "' value='" + (Shape.Value == null ? "" : Shape.Value) + "' />"));
}
public IHtmlString InputText(dynamic Display, dynamic Shape, INamedEnumerable<object> Attributes) {
// not optimal obviously, just testing the waters
return Display(new HtmlString("<label>" + Shape.Text + "</label>"
+ "<input type='text'" + (Attributes.Named.ContainsKey("autofocus") ? " autofocus" : "" )+ " name='" + Shape.Name
+ "' value='" + (Shape.Value == null ? "" : Shape.Value) + "' />")); // <- otherwise Shape.Value is "ClaySharp.Clay"
}
#endregion
} }
} }