- CheckboxList's LabelFor now takes attributes as optional argument
[castle.git] / MonoRail / Castle.MonoRail.Framework / Internal / WizardUtils.cs
blobc2eca9afbddd47a4a72e6fd9dc70cd4346d2b7d3
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.Framework.Internal
17 using System;
18 using System.Collections;
20 /// <summary>
21 /// Utility class for wizard related queries and operations
22 /// </summary>
23 public static class WizardUtils
25 /// <summary>
26 /// Constructs the wizard namespace.
27 /// </summary>
28 /// <param name="controllerContext">The controller context.</param>
29 /// <returns></returns>
30 public static String ConstructWizardNamespace(IControllerContext controllerContext)
32 return String.Format("wizard.{0}", controllerContext.Name);
35 /// <summary>
36 /// Determines whether the current wizard has a previous step.
37 /// </summary>
38 /// <param name="engineContext">The engine context.</param>
39 /// <param name="controller">The controller.</param>
40 /// <param name="controllerContext">The controller context.</param>
41 /// <returns>
42 /// <c>true</c> if has previous step; otherwise, <c>false</c>.
43 /// </returns>
44 public static bool HasPreviousStep(IEngineContext engineContext, IController controller, IControllerContext controllerContext)
46 String wizardName = WizardUtils.ConstructWizardNamespace(controllerContext);
48 int currentIndex = (int) engineContext.Session[wizardName + "currentstepindex"];
50 return currentIndex > 0;
53 /// <summary>
54 /// Determines whether the current wizard has a next step.
55 /// </summary>
56 /// <param name="engineContext">The engine context.</param>
57 /// <param name="controller">The controller.</param>
58 /// <param name="controllerContext">The controller context.</param>
59 /// <returns>
60 /// <c>true</c> if has next step; otherwise, <c>false</c>.
61 /// </returns>
62 public static bool HasNextStep(IEngineContext engineContext, IController controller, IControllerContext controllerContext)
64 String wizardName = WizardUtils.ConstructWizardNamespace(controllerContext);
66 IList stepList = (IList) engineContext.Items["wizard.step.list"];
68 int currentIndex = (int) engineContext.Session[wizardName + "currentstepindex"];
70 return (currentIndex + 1) < stepList.Count;
73 /// <summary>
74 /// Gets the index of the current step.
75 /// </summary>
76 /// <param name="engineContext">The engine context.</param>
77 /// <param name="controller">The controller.</param>
78 /// <param name="controllerContext">The controller context.</param>
79 /// <returns></returns>
80 public static int GetCurrentStepIndex(IEngineContext engineContext, IController controller, IControllerContext controllerContext)
82 String wizardName = WizardUtils.ConstructWizardNamespace(controllerContext);
84 int curIndex = (int) engineContext.Session[wizardName + "currentstepindex"];
86 return curIndex;
89 /// <summary>
90 /// Gets the name of the current step.
91 /// </summary>
92 /// <param name="engineContext">The engine context.</param>
93 /// <param name="controller">The controller.</param>
94 /// <param name="controllerContext">The controller context.</param>
95 /// <returns></returns>
96 public static String GetCurrentStepName(IEngineContext engineContext, IController controller, IControllerContext controllerContext)
98 String wizardName = WizardUtils.ConstructWizardNamespace(controllerContext);
100 int curIndex = (int) engineContext.Session[wizardName + "currentstepindex"];
102 IList stepList = (IList) engineContext.Items["wizard.step.list"];
104 return (String) stepList[curIndex];
107 /// <summary>
108 /// Gets the name of the previous step.
109 /// </summary>
110 /// <param name="engineContext">The engine context.</param>
111 /// <param name="controller">The controller.</param>
112 /// <param name="controllerContext">The controller context.</param>
113 /// <returns></returns>
114 public static String GetPreviousStepName(IEngineContext engineContext, IController controller, IControllerContext controllerContext)
116 String wizardName = WizardUtils.ConstructWizardNamespace(controllerContext);
118 int curIndex = (int) engineContext.Session[wizardName + "currentstepindex"];
120 IList stepList = (IList) engineContext.Items["wizard.step.list"];
122 if ((curIndex - 1) >= 0)
124 return (String) stepList[curIndex - 1];
127 return null;
130 /// <summary>
131 /// Gets the name of the next step.
132 /// </summary>
133 /// <param name="index">The step index.</param>
134 /// <param name="engineContext">The engine context.</param>
135 /// <param name="controller">The controller.</param>
136 /// <param name="controllerContext">The controller context.</param>
137 /// <returns></returns>
138 public static string GetStepName(int index, IEngineContext engineContext, IController controller, IControllerContext controllerContext)
140 IList stepList = (IList) engineContext.Items["wizard.step.list"];
142 if ((index) < stepList.Count)
144 return (String) stepList[index];
147 return null;
150 /// <summary>
151 /// Gets the name of the next step.
152 /// </summary>
153 /// <param name="engineContext">The engine context.</param>
154 /// <param name="controller">The controller.</param>
155 /// <param name="controllerContext">The controller context.</param>
156 /// <returns></returns>
157 public static String GetNextStepName(IEngineContext engineContext, IController controller, IControllerContext controllerContext)
159 String wizardName = WizardUtils.ConstructWizardNamespace(controllerContext);
161 int curIndex = (int) engineContext.Session[wizardName + "currentstepindex"];
163 IList stepList = (IList) engineContext.Items["wizard.step.list"];
165 if ((curIndex + 1) < stepList.Count)
167 return (String) stepList[curIndex + 1];
170 return null;
173 /// <summary>
174 /// Registers the current step info/state.
175 /// </summary>
176 /// <param name="engineContext">The engine context.</param>
177 /// <param name="controller">The controller.</param>
178 /// <param name="controllerContext">The controller context.</param>
179 /// <param name="actionName">Name of the action.</param>
180 public static void RegisterCurrentStepInfo(IEngineContext engineContext, IController controller,
181 IControllerContext controllerContext, String actionName)
183 IList stepList = (IList) engineContext.Items["wizard.step.list"];
185 for(int i = 0; i < stepList.Count; i++)
187 String stepName = (String) stepList[i];
189 if (actionName == stepName)
191 RegisterCurrentStepInfo(engineContext, controller, controllerContext, i, stepName);
192 break;
197 /// <summary>
198 /// Registers the current step info/state.
199 /// </summary>
200 /// <param name="engineContext">The engine context.</param>
201 /// <param name="controller">The controller.</param>
202 /// <param name="controllerContext">The controller context.</param>
203 /// <param name="stepIndex">Index of the step.</param>
204 /// <param name="stepName">Name of the step.</param>
205 public static void RegisterCurrentStepInfo(IEngineContext engineContext, IController controller,
206 IControllerContext controllerContext, int stepIndex, String stepName)
208 String wizardName = WizardUtils.ConstructWizardNamespace(controllerContext);
210 engineContext.Session[wizardName + "currentstepindex"] = stepIndex;
211 engineContext.Session[wizardName + "currentstep"] = stepName;