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
.Framework
.Helpers
18 using System
.Collections
;
20 using Castle
.MonoRail
.Framework
.Internal
;
23 /// Provide useful helpers to be used in a layout view
24 /// or in the wizards steps views.
26 public class WizardHelper
: HtmlHelper
31 /// Initializes a new instance of the <see cref="WizardHelper"/> class.
33 public WizardHelper() { }
36 /// Initializes a new instance of the <see cref="WizardHelper"/> class.
37 /// setting the Controller, Context and ControllerContext.
39 /// <param name="engineContext">The engine context.</param>
40 public WizardHelper(IEngineContext engineContext
) : base(engineContext
) { }
45 /// Returns <c>true</c> if the current wizard
46 /// flow has a next step.
48 /// <returns></returns>
49 public bool HasNextStep()
51 return WizardUtils
.HasNextStep(Context
, Controller
, ControllerContext
);
55 /// Returns <c>true</c> if the current wizard
56 /// flow has an accessible previous step.
59 /// This will only return <c>true</c> if not
62 /// <returns></returns>
63 public bool HasPreviousStep()
65 return WizardUtils
.HasPreviousStep(Context
, Controller
, ControllerContext
);
69 /// Gets the name of the current step.
71 /// <value>The name of the current step.</value>
72 public int CurrentStepIndex
74 get { return WizardUtils.GetCurrentStepIndex(Context, Controller, ControllerContext); }
78 /// Returns the name of the previous step
80 public String PreviousStepName
82 get { return WizardUtils.GetPreviousStepName(Context, Controller, ControllerContext); }
86 /// Gets the name of the current step.
88 /// <value>The name of the current step.</value>
89 public string CurrentStepName
91 get { return WizardUtils.GetCurrentStepName(Context, Controller, ControllerContext); }
95 /// Returns the name of the next step
97 public String NextStepName
99 get { return WizardUtils.GetNextStepName(Context, Controller, ControllerContext); }
103 /// Gets a wizard step name by index.
105 /// <param name="stepindex">The stepindex.</param>
106 /// <returns></returns>
107 public String
GetStepName(int stepindex
)
109 return WizardUtils
.GetStepName(stepindex
, Context
, Controller
, ControllerContext
);
114 /// <overloads>This method has three overloads.</overloads>
116 /// Creates an anchor tag (link) to the specified step.
118 /// <a href="/page2.rails">linkText</a>
121 /// <param name="linkText">The label for the step</param>
122 /// <param name="step">The WizardStepPage to link to</param>
123 /// <returns></returns>
124 public String
LinkToStep(String linkText
, IWizardStepPage step
)
126 return LinkTo(linkText
, step
.WizardControllerContext
.Name
, step
.ActionName
);
130 /// Creates an anchor tag (link) to the specified step.
132 /// <a href="/page2.rails">linkText</a>
135 /// <param name="linkText">The label for the step</param>
136 /// <param name="step">The WizardStepPage to link to</param>
137 /// <param name="id">Object to use for the action ID argument.</param>
138 /// <returns></returns>
139 public String
LinkToStep(String linkText
, IWizardStepPage step
, object id
)
141 return LinkTo(linkText
, step
.WizardControllerContext
.Name
, step
.ActionName
, id
);
145 /// Creates an anchor tag (link) to the specified step.
147 /// <a href="/page2.rails">linkText</a>
150 /// <param name="linkText">The label for the step</param>
151 /// <param name="step">The WizardStepPage to link to</param>
152 /// <param name="id">Object to use for the action ID argument.</param>
153 /// <param name="attributes">Additional attributes for the <b>a</b> tag.</param>
154 /// <returns></returns>
155 public String
LinkToStep(String linkText
, IWizardStepPage step
, object id
, IDictionary attributes
)
157 return LinkToAttributed(linkText
, step
.WizardControllerContext
.Name
, step
.ActionName
, id
, attributes
);
162 #region LinkToNext and LinkToPrevious
164 /// <overloads>This method has four overloads.</overloads>
166 /// Creates an anchor tag (link) to the next step.
168 /// <a href="/page2.rails">linkText</a>
172 /// This helper assumes there is a next step. It's advised
173 /// that you use <see cref="HasNextStep"/> before calling this
175 /// <param name="linkText">The label for the link</param>
176 /// <returns></returns>
177 public String
LinkToNext(String linkText
)
179 return LinkTo( linkText
, ControllerContext
.Name
, NextStepName
);
183 /// Creates an anchor tag (link) to the next step.
185 /// <a href="/page2.rails">linkText</a>
189 /// This helper assumes there is a next step. It's advised
190 /// that you use <see cref="HasNextStep"/> before calling this
192 /// <param name="linkText">The label for the link</param>
193 /// <param name="attributes">Additional attributes for the <b>a</b> tag.</param>
194 /// <returns></returns>
195 public String
LinkToNext(String linkText
, IDictionary attributes
)
197 return LinkToAttributed(linkText
, ControllerContext
.Name
, NextStepName
, attributes
);
201 /// Creates an anchor tag (link) with an id attribute to the next step.
203 /// <a href="/page2.rails?Id=id">linkText</a>
207 /// This helper assumes there is a next step. It's advised
208 /// that you use <see cref="HasNextStep"/> before calling this
210 /// <param name="linkText">The label for the link</param>
211 /// <param name="id">Object to use for the action ID argument.</param>
212 /// <returns></returns>
213 public String
LinkToNext(String linkText
, object id
)
215 return LinkTo(linkText
, ControllerContext
.Name
, NextStepName
, id
);
219 /// Creates an anchor tag (link) with an id attribute to the next step.
221 /// <a href="/page2.rails?Id=id">linkText</a>
225 /// This helper assumes there is a previous step. It's advised
226 /// that you use <see cref="HasNextStep"/> before calling this
228 /// <param name="linkText">The label for the link</param>
229 /// <param name="id">Object to use for the action ID argument.</param>
230 /// <param name="attributes">Additional attributes for the <b>a</b> tag.</param>
231 /// <returns></returns>
232 public String
LinkToNext(String linkText
, object id
, IDictionary attributes
)
234 return LinkToAttributed(linkText
, ControllerContext
.Name
, NextStepName
, id
, attributes
);
237 /// <overloads>This method has four overloads.</overloads>
239 /// Creates an anchor tag (link) to the previous step.
241 /// <a href="/page2.rails">linkText</a>
245 /// This helper assumes there is a previous step. It's advised
246 /// that you use <see cref="HasPreviousStep"/> before calling this
248 /// <param name="linkText">The label for the link</param>
249 /// <returns></returns>
250 public String
LinkToPrevious(String linkText
)
252 return LinkTo(linkText
, ControllerContext
.Name
, PreviousStepName
);
256 /// Creates an anchor tag (link) to the previous step.
258 /// <a href="/page2.rails">linkText</a>
262 /// This helper assumes there is a previous step. It's advised
263 /// that you use <see cref="HasPreviousStep"/> before calling this
265 /// <param name="linkText">The label for the link</param>
266 /// <param name="attributes">Additional attributes for the <b>a</b> tag.</param>
267 /// <returns></returns>
268 public String
LinkToPrevious(String linkText
, IDictionary attributes
)
270 return LinkToAttributed(linkText
, ControllerContext
.Name
, PreviousStepName
, attributes
);
274 /// Creates an anchor tag (link) with an id attribute to the previous step.
276 /// <a href="/page2.rails?Id=id">linkText</a>
280 /// This helper assumes there is a previous step. It's advised
281 /// that you use <see cref="HasPreviousStep"/> before calling this
283 /// <param name="linkText">The label for the link</param>
284 /// <param name="id">Object to use for the action ID argument.</param>
285 /// <returns></returns>
286 public String
LinkToPrevious(String linkText
, object id
)
288 return LinkTo(linkText
, ControllerContext
.Name
, PreviousStepName
, id
);
292 /// Creates an anchor tag (link) with an id attribute to the previous step.
294 /// <a href="/page2.rails?Id=id">linkText</a>
298 /// This helper assumes there is a previous step. It's advised
299 /// that you use <see cref="HasPreviousStep"/> before calling this
301 /// <param name="linkText">The label for the link</param>
302 /// <param name="id">Object to use for the action ID argument.</param>
303 /// <param name="attributes">Additional attributes for the <b>a</b> tag.</param>
304 /// <returns></returns>
305 public String
LinkToPrevious(String linkText
, object id
, IDictionary attributes
)
307 return LinkToAttributed(linkText
, ControllerContext
.Name
, PreviousStepName
, id
, attributes
);