Fixing IOC-60, Custom Parameters do not play a role in resolving chains
[castle.git] / MonoRail / Castle.MonoRail.ActiveRecordScaffold / Helpers / PresentationHelper.cs
blob54463bcb3b02f79ff59d5fba1fa2482cbeab6da3
1 // Copyright 2004-2007 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.ActiveRecordScaffold.Helpers
17 using System;
18 using System.Collections;
20 using Castle.ActiveRecord.Framework.Internal;
21 using Castle.MonoRail.Framework.Helpers;
24 public class PresentationHelper : AbstractHelper
26 public String StartAlternateTR(int index, String styleClass, String altStyleClass)
28 return String.Format("<tr class=\"{0}\">", index % 2 == 0 ? styleClass : altStyleClass);
31 public String BestAlignFor(Type type)
33 if (type == typeof(String))
35 return "left";
38 return "center";
41 public String Form(String action, String id, String method, String onSubmit)
43 HtmlHelper hh = new HtmlHelper();
45 string fullAction = string.Format("{0}.{1}", action, Controller.Context.UrlInfo.Extension);
47 return hh.Form(fullAction, id, method, onSubmit);
50 public String LinkToBack(String text, IDictionary attributes)
52 return String.Format( "<a href=\"javascript:history.go(-1);\" {1}>{0}</a>",
53 text, GetAttributes(attributes) );
56 public String LinkToList(ActiveRecordModel model, bool useModelName, String text, IDictionary attributes)
58 if (useModelName)
60 return String.Format("<a href=\"list{0}.{1}\" {3}>{2}</a>", model.Type.Name,
61 Controller.Context.UrlInfo.Extension, text, GetAttributes(attributes));
63 else
65 return String.Format("<a href=\"list.{0}\" {2}>{1}</a>",
66 Controller.Context.UrlInfo.Extension, text, GetAttributes(attributes));
70 public String LinkToNew(ActiveRecordModel model, bool useModelName, String text, IDictionary attributes)
72 if (useModelName)
74 return String.Format("<a href=\"new{0}.{1}\" {3}>{2}</a>", model.Type.Name,
75 Controller.Context.UrlInfo.Extension, text, GetAttributes(attributes));
77 else
79 return String.Format("<a href=\"new.{0}\" {2}>{1}</a>",
80 Controller.Context.UrlInfo.Extension, text, GetAttributes(attributes));
84 public String LinkToEdit(ActiveRecordModel model, bool useModelName,
85 String text, object key, IDictionary attributes)
87 if (useModelName)
89 return String.Format("<a href=\"edit{0}.{1}?id={4}\" {3}>{2}</a>", model.Type.Name,
90 Controller.Context.UrlInfo.Extension, text, GetAttributes(attributes), key);
92 else
94 return String.Format("<a href=\"edit.{0}?id={3}\" {2}>{1}</a>",
95 Controller.Context.UrlInfo.Extension, text, GetAttributes(attributes), key);
99 public String LinkToConfirm(ActiveRecordModel model, bool useModelName, String text, object key, IDictionary attributes)
101 if (useModelName)
103 return String.Format("<a href=\"confirm{0}.{1}?id={4}\" {3}>{2}</a>", model.Type.Name,
104 Controller.Context.UrlInfo.Extension, text, GetAttributes(attributes), key);
106 else
108 return String.Format("<a href=\"confirm.{0}?id={3}\" {2}>{1}</a>",
109 Controller.Context.UrlInfo.Extension, text, GetAttributes(attributes), key);
113 public String LinkToRemove(ActiveRecordModel model, bool useModelName, String text, object key, IDictionary attributes)
115 if (useModelName)
117 return String.Format("<a href=\"remove{0}.{1}?id={4}\" {3}>{2}</a>", model.Type.Name,
118 Controller.Context.UrlInfo.Extension, text, GetAttributes(attributes), key);
120 else
122 return String.Format("<a href=\"remove.{0}?id={3}\" {2}>{1}</a>",
123 Controller.Context.UrlInfo.Extension, text, GetAttributes(attributes), key);