Removed untyped contructor from ComponentRegistration and add a protected setter.
[castle.git] / MonoRail / Castle.MonoRail.ActiveRecordSupport / Scaffold / Helpers / PresentationHelper.cs
blob1aa1160b76e01621bb2b856ac4216895c77c66bf
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.Helpers
17 using System;
18 using System.Collections;
19 using System.Collections.Specialized;
20 using Castle.ActiveRecord.Framework.Internal;
21 using Castle.MonoRail.Framework.Helpers;
23 public class PresentationHelper : AbstractHelper
25 public String StartAlternateTR(int index, String styleClass, String altStyleClass)
27 return String.Format("<tr class=\"{0}\">", index % 2 == 0 ? styleClass : altStyleClass);
30 public String BestAlignFor(Type type)
32 if (type == typeof(String))
34 return "left";
37 return "center";
40 public String LinkToBack(String text, IDictionary attributes)
42 return String.Format( "<a href=\"javascript:history.go(-1);\" {1}>{0}</a>",
43 text, GetAttributes(attributes) );
46 public String LinkToList(ActiveRecordModel model, bool useModelName, String text, IDictionary attributes)
48 string targetAction = "list" + (useModelName ? model.Type.Name : "");
50 return LinkTo(targetAction, text, attributes);
53 public String LinkToNew(ActiveRecordModel model, bool useModelName, String text, IDictionary attributes)
55 string targetAction = "new" + (useModelName ? model.Type.Name : "");
57 return LinkTo(targetAction, text, attributes);
60 public String LinkToEdit(ActiveRecordModel model, bool useModelName,
61 String text, object key, IDictionary attributes)
63 string targetAction = "edit" + (useModelName ? model.Type.Name : "");
65 return LinkTo(targetAction, key, text, attributes);
68 public String LinkToConfirm(ActiveRecordModel model, bool useModelName, String text, object key, IDictionary attributes)
70 string targetAction = "confirm" + (useModelName ? model.Type.Name : "");
72 return LinkTo(targetAction, key, text, attributes);
75 public String LinkToRemove(ActiveRecordModel model, bool useModelName, String text, object key, IDictionary attributes)
77 string targetAction = "remove" + (useModelName ? model.Type.Name : "");
79 return LinkTo(targetAction, text, attributes);
82 private string LinkTo(string action, string text, IDictionary attributes)
84 HybridDictionary dict = new HybridDictionary(true);
85 dict["action"] = action;
86 dict["params"] = ControllerContext.RouteMatch.Parameters;
88 return UrlHelper.Link(text, dict, attributes);
91 private string LinkTo(string action, object key, string text, IDictionary attributes)
93 HybridDictionary dict = new HybridDictionary(true);
94 dict["action"] = action;
95 dict["id"] = key;
96 ControllerContext.RouteMatch.AddNamed("id", key.ToString());
97 dict["params"] = ControllerContext.RouteMatch.Parameters;
99 return UrlHelper.Link(text, dict, attributes);