1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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
18 using Castle
.MonoRail
.Framework
;
20 using Castle
.Components
.Common
.TemplateEngine
;
24 /// Renders an inclusion form
27 /// Searchs for a template named <c>new{name}</c>
29 public class NewAction
: AbstractScaffoldAction
31 protected object instance
;
34 /// Initializes a new instance of the <see cref="NewAction"/> class.
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
)
46 /// Computes the name of the template.
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
);
56 /// Implementors should perform the action for the
57 /// scaffolding, like new or create.
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
);
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
);