1 | package generic.installation |
---|
2 | |
---|
3 | import grails.plugins.springsecurity.Secured |
---|
4 | import dbnp.authentication.SecUser |
---|
5 | |
---|
6 | /** |
---|
7 | * ajaxflow Controller |
---|
8 | * |
---|
9 | * @author Jeroen Wesbeek |
---|
10 | * @since 20110318 |
---|
11 | * |
---|
12 | * Revision information: |
---|
13 | * $Rev: 66849 $ |
---|
14 | * $Author: duh $ |
---|
15 | * $Date: 2010-12-08 15:12:54 +0100 (Wed, 08 Dec 2010) $ |
---|
16 | */ |
---|
17 | @Secured(['ROLE_ADMIN']) |
---|
18 | class SetupController { |
---|
19 | // the pluginManager is used to check if the Grom |
---|
20 | // plugin is available so we can 'Grom' development |
---|
21 | // notifications to the unified notifications daemon |
---|
22 | // (see http://www.grails.org/plugin/grom) |
---|
23 | def pluginManager |
---|
24 | |
---|
25 | /** |
---|
26 | * index method, redirect to the webflow |
---|
27 | * @void |
---|
28 | */ |
---|
29 | def index = { |
---|
30 | // Grom a development message |
---|
31 | if (pluginManager.getGrailsPlugin('grom')) "redirecting into the webflow".grom() |
---|
32 | |
---|
33 | /** |
---|
34 | * Do you believe it in your head? |
---|
35 | * I can go with the flow |
---|
36 | * Don't say it doesn't matter (with the flow) matter anymore |
---|
37 | * I can go with the flow (I can go) |
---|
38 | * Do you believe it in your head? |
---|
39 | */ |
---|
40 | redirect(action: 'pages') |
---|
41 | } |
---|
42 | |
---|
43 | /** |
---|
44 | * WebFlow definition |
---|
45 | * @void |
---|
46 | */ |
---|
47 | def pagesFlow = { |
---|
48 | def authenticationService |
---|
49 | |
---|
50 | // start the flow |
---|
51 | onStart { |
---|
52 | // Grom a development message |
---|
53 | if (pluginManager.getGrailsPlugin('grom')) "entering the WebFlow".grom() |
---|
54 | |
---|
55 | // define variables in the flow scope which is availabe |
---|
56 | // throughout the complete webflow also have a look at |
---|
57 | // the Flow Scopes section on http://www.grails.org/WebFlow |
---|
58 | // |
---|
59 | // The following flow scope variables are used to generate |
---|
60 | // wizard tabs. Also see common/_tabs.gsp for more information |
---|
61 | flow.page = 0 |
---|
62 | flow.pages = [ |
---|
63 | [title: 'Page One'], |
---|
64 | [title: 'Page Two'], |
---|
65 | [title: 'Page Three'], |
---|
66 | [title: 'Page Four'], |
---|
67 | [title: 'Done'] |
---|
68 | ] |
---|
69 | flow.cancel = true; |
---|
70 | flow.quickSave = true; |
---|
71 | |
---|
72 | success() |
---|
73 | } |
---|
74 | |
---|
75 | // render the main wizard page which immediately |
---|
76 | // triggers the 'next' action (hence, the main |
---|
77 | // page dynamically renders the study template |
---|
78 | // and makes the flow jump to the study logic) |
---|
79 | mainPage { |
---|
80 | render(view: "/setup/index") |
---|
81 | onRender { |
---|
82 | // Grom a development message |
---|
83 | if (pluginManager.getGrailsPlugin('grom')) "rendering the main Ajaxflow page (index.gsp)".grom() |
---|
84 | |
---|
85 | // let the view know we're in page 1 |
---|
86 | flow.page = 1 |
---|
87 | success() |
---|
88 | } |
---|
89 | on("next").to "pageOne" |
---|
90 | } |
---|
91 | |
---|
92 | // first wizard page |
---|
93 | pageOne { |
---|
94 | render(view: "_page_one") |
---|
95 | onRender { |
---|
96 | // Grom a development message |
---|
97 | if (pluginManager.getGrailsPlugin('grom')) ".rendering the partial: pages/_page_one.gsp".grom() |
---|
98 | |
---|
99 | flow.page = 1 |
---|
100 | success() |
---|
101 | } |
---|
102 | on("next") { |
---|
103 | // put your bussiness logic (if applicable) in here |
---|
104 | }.to "pageTwo" |
---|
105 | on("toPageTwo") { |
---|
106 | // put your bussiness logic (if applicable) in here |
---|
107 | }.to "pageTwo" |
---|
108 | on("toPageThree") { |
---|
109 | // put your bussiness logic (if applicable) in here |
---|
110 | }.to "pageThree" |
---|
111 | on("toPageFour") { |
---|
112 | // put your bussiness logic (if applicable) in here |
---|
113 | }.to "pageFour" |
---|
114 | on("toPageFive") { |
---|
115 | // put your bussiness logic (if applicable) in here |
---|
116 | flow.page = 5 |
---|
117 | }.to "save" |
---|
118 | } |
---|
119 | |
---|
120 | // second wizard page |
---|
121 | pageTwo { |
---|
122 | render(view: "_page_two") |
---|
123 | onRender { |
---|
124 | // Grom a development message |
---|
125 | if (pluginManager.getGrailsPlugin('grom')) ".rendering the partial: pages/_page_two.gsp".grom() |
---|
126 | |
---|
127 | flow.page = 2 |
---|
128 | success() |
---|
129 | } |
---|
130 | on("next").to "pageThree" |
---|
131 | on("previous").to "pageOne" |
---|
132 | on("toPageOne").to "pageOne" |
---|
133 | on("toPageThree").to "pageThree" |
---|
134 | on("toPageFour").to "pageFour" |
---|
135 | on("toPageFive") { |
---|
136 | flow.page = 5 |
---|
137 | }.to "save" |
---|
138 | } |
---|
139 | |
---|
140 | // second wizard page |
---|
141 | pageThree { |
---|
142 | render(view: "_page_three") |
---|
143 | onRender { |
---|
144 | // Grom a development message |
---|
145 | if (pluginManager.getGrailsPlugin('grom')) ".rendering the partial pages/_page_three.gsp".grom() |
---|
146 | |
---|
147 | flow.page = 3 |
---|
148 | success() |
---|
149 | } |
---|
150 | on("next").to "pageFour" |
---|
151 | on("previous").to "pageTwo" |
---|
152 | on("toPageOne").to "pageOne" |
---|
153 | on("toPageTwo").to "pageTwo" |
---|
154 | on("toPageFour").to "pageFour" |
---|
155 | on("toPageFive") { |
---|
156 | flow.page = 5 |
---|
157 | }.to "save" |
---|
158 | } |
---|
159 | |
---|
160 | // second wizard page |
---|
161 | pageFour { |
---|
162 | render(view: "_page_four") |
---|
163 | onRender { |
---|
164 | // Grom a development message |
---|
165 | if (pluginManager.getGrailsPlugin('grom')) ".rendering the partial pages/_page_four.gsp".grom() |
---|
166 | |
---|
167 | flow.page = 4 |
---|
168 | success() |
---|
169 | } |
---|
170 | on("next") { |
---|
171 | // put some logic in here |
---|
172 | flow.page = 5 |
---|
173 | }.to "save" |
---|
174 | on("previous").to "pageThree" |
---|
175 | on("toPageOne").to "pageOne" |
---|
176 | on("toPageTwo").to "pageTwo" |
---|
177 | on("toPageThree").to "pageThree" |
---|
178 | on("toPageFive") { |
---|
179 | flow.page = 5 |
---|
180 | }.to "save" |
---|
181 | } |
---|
182 | |
---|
183 | // save action |
---|
184 | save { |
---|
185 | action { |
---|
186 | // here you can validate and save the |
---|
187 | // instances you have created in the |
---|
188 | // ajax flow. |
---|
189 | try { |
---|
190 | // Grom a development message |
---|
191 | if (pluginManager.getGrailsPlugin('grom')) ".persisting instances to the database...".grom() |
---|
192 | |
---|
193 | // put your bussiness logic in here |
---|
194 | success() |
---|
195 | } catch (Exception e) { |
---|
196 | // put your error handling logic in |
---|
197 | // here |
---|
198 | flow.page = 4 |
---|
199 | error() |
---|
200 | } |
---|
201 | } |
---|
202 | on("error").to "error" |
---|
203 | on(Exception).to "error" |
---|
204 | on("success").to "finalPage" |
---|
205 | } |
---|
206 | |
---|
207 | // render errors |
---|
208 | error { |
---|
209 | render(view: "_error") |
---|
210 | onRender { |
---|
211 | // Grom a development message |
---|
212 | if (pluginManager.getGrailsPlugin('grom')) ".rendering the partial pages/_error.gsp".grom() |
---|
213 | |
---|
214 | // set page to 4 so that the navigation |
---|
215 | // works (it is disabled on the final page) |
---|
216 | flow.page = 4 |
---|
217 | } |
---|
218 | on("next").to "save" |
---|
219 | on("previous").to "pageFour" |
---|
220 | on("toPageOne").to "pageOne" |
---|
221 | on("toPageTwo").to "pageTwo" |
---|
222 | on("toPageThree").to "pageThree" |
---|
223 | on("toPageFour").to "pageFour" |
---|
224 | on("toPageFive").to "save" |
---|
225 | |
---|
226 | } |
---|
227 | |
---|
228 | // last wizard page |
---|
229 | finalPage { |
---|
230 | render(view: "_final_page") |
---|
231 | onRender { |
---|
232 | // Grom a development message |
---|
233 | if (pluginManager.getGrailsPlugin('grom')) ".rendering the partial pages/_final_page.gsp".grom() |
---|
234 | |
---|
235 | success() |
---|
236 | } |
---|
237 | } |
---|
238 | } |
---|
239 | } |
---|