Removed untyped contructor from ComponentRegistration and add a protected setter.
[castle.git] / MonoRail / Castle.MonoRail.ActiveRecordSupport / Scaffold / NewAction.cs
blob5ff2d653ba0d8019e1b01bd243c32a1714275295
1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle.MonoRail.ActiveRecordSupport.Scaffold
17 using System;
18 using Castle.MonoRail.Framework;
20 using Castle.Components.Common.TemplateEngine;
23 /// <summary>
24 /// Renders an inclusion form
25 /// </summary>
26 /// <remarks>
27 /// Searchs for a template named <c>new{name}</c>
28 /// </remarks>
29 public class NewAction : AbstractScaffoldAction
31 protected object instance;
33 /// <summary>
34 /// Initializes a new instance of the <see cref="NewAction"/> class.
35 /// </summary>
36 /// <param name="modelType">Type of the model.</param>
37 /// <param name="templateEngine">The template engine.</param>
38 /// <param name="useModelName">Indicates that we should use the model name on urls</param>
39 /// <param name="useDefaultLayout">Whether we should use our layout.</param>
40 public NewAction(Type modelType, ITemplateEngine templateEngine, bool useModelName, bool useDefaultLayout) :
41 base(modelType, templateEngine, useModelName, useDefaultLayout)
45 /// <summary>
46 /// Computes the name of the template.
47 /// </summary>
48 /// <param name="controller">The controller.</param>
49 /// <returns></returns>
50 protected override string ComputeTemplateName(IControllerContext controller)
52 return String.Format(@"{0}\new{1}", controller.Name, Model.Type.Name);
55 /// <summary>
56 /// Implementors should perform the action for the
57 /// scaffolding, like new or create.
58 /// </summary>
59 /// <param name="engineContext">The engine context.</param>
60 /// <param name="controller">The controller.</param>
61 /// <param name="controllerContext">The controller context.</param>
62 protected override void PerformActionProcess(IEngineContext engineContext, IController controller, IControllerContext controllerContext)
64 base.PerformActionProcess(engineContext, controller, controllerContext);
66 if (instance == null)
68 instance = Activator.CreateInstance(Model.Type);
71 string prefix = Model.Type.Name;
73 controllerContext.PropertyBag["prefix"] = prefix;
74 controllerContext.PropertyBag[prefix + "type"] = Model.Type;
75 controllerContext.PropertyBag["instance"] = instance;
78 protected override void RenderStandardHtml(IEngineContext engineContext, IController controller, IControllerContext controllerContext)
80 SetUpHelpers(engineContext, controller, controllerContext);
81 RenderFromTemplate("new.vm", engineContext, controller, controllerContext);