1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.student.common.kitchensink;
18
19 import org.kuali.rice.krad.util.GlobalVariables;
20 import org.kuali.rice.krad.web.controller.UifControllerBase;
21 import org.kuali.rice.krad.web.form.UifFormBase;
22 import org.kuali.student.common.uif.util.GrowlIcon;
23 import org.kuali.student.common.uif.util.KSUifUtils;
24 import org.springframework.stereotype.Controller;
25 import org.springframework.validation.BindingResult;
26 import org.springframework.web.bind.annotation.ModelAttribute;
27 import org.springframework.web.bind.annotation.RequestMapping;
28 import org.springframework.web.bind.annotation.RequestMethod;
29 import org.springframework.web.bind.annotation.RequestParam;
30 import org.springframework.web.servlet.ModelAndView;
31
32 import javax.servlet.http.HttpServletRequest;
33 import javax.servlet.http.HttpServletResponse;
34 import java.util.ArrayList;
35 import java.util.Arrays;
36 import java.util.List;
37 import java.util.Map;
38
39
40
41
42
43
44 @Controller
45 @RequestMapping(value = "/kitchensink")
46 public class KitchenSinkController extends UifControllerBase {
47
48
49
50
51 @Override
52 protected KitchenSinkForm createInitialForm(HttpServletRequest request) {
53 return new KitchenSinkForm();
54 }
55
56 @Override
57 @RequestMapping(params = "methodToCall=start")
58 public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
59 HttpServletRequest request, HttpServletResponse response) {
60 KitchenSinkForm uiTestForm = (KitchenSinkForm) form;
61
62
63 uiTestForm.setCheckboxSelections(Arrays.asList("3"));
64
65 uiTestForm.setRadioButtonSelection("2");
66
67 uiTestForm.setDropdownSelection("2");
68
69 return getUIFModelAndView(uiTestForm);
70 }
71
72 @RequestMapping(params = "methodToCall=collection")
73 public ModelAndView collection(@ModelAttribute("KualiForm") KitchenSinkForm form, BindingResult result,
74 HttpServletRequest request, HttpServletResponse response) {
75
76 List<KitchenSinkFormCollection1> collectionList = new ArrayList<KitchenSinkFormCollection1>();
77 collectionList.add(new KitchenSinkFormCollection1("Item #1", "A primary item", "2001-01-01"));
78 collectionList.add(new KitchenSinkFormCollection1("John Adams", "A founding father", "1735-10-30"));
79 collectionList.add(new KitchenSinkFormCollection1("Big Bang Theory", "A funny show", "2007-09-24"));
80 collectionList.add(new KitchenSinkFormCollection1("Chainbreaker IPA", "A tasty beverage", "2011-06-09"));
81 form.setCollection(collectionList);
82
83
84
85
86
87
88 return getUIFModelAndView(form);
89 }
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114 @RequestMapping(params = "methodToCall=collectionOne")
115 public ModelAndView collectionOne(@ModelAttribute("KualiForm") KitchenSinkForm form, BindingResult result,
116 HttpServletRequest request, HttpServletResponse response) {
117
118 List<KitchenSinkFormCollection1> collectionList = new ArrayList<KitchenSinkFormCollection1>();
119 collectionList.add(new KitchenSinkFormCollection1("A", "First letter of the alphabet", "1970-01-01"));
120 form.setCollection(collectionList);
121
122 return getUIFModelAndView(form);
123 }
124
125 @RequestMapping(params = "methodToCall=collectionTerm")
126 public ModelAndView collectionTerm(@ModelAttribute("KualiForm") KitchenSinkForm form, BindingResult result,
127 HttpServletRequest request, HttpServletResponse response) {
128
129 List<KitchenSinkFormCollection1> collectionList = new ArrayList<KitchenSinkFormCollection1>();
130 collectionList.add(new KitchenSinkFormCollection1("Fall 1997", "kuali.atp.type.Fall", "1997-09-01"));
131 collectionList.add(new KitchenSinkFormCollection1("Winter 2000", "kuali.atp.type.Winter", "2000-01-01"));
132 form.setCollection(collectionList);
133
134 return getUIFModelAndView(form);
135 }
136
137 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addLineCollectionAsForm")
138 public ModelAndView addLineCollectionAsForm(@ModelAttribute("KualiForm") KitchenSinkForm form, BindingResult result,
139 HttpServletRequest request, HttpServletResponse response) {
140 List<KitchenSinkFormCollection1> collectionList = form.getCollection();
141 Map<String, Object> newCollectionLines = form.getNewCollectionLines();
142 if (null != newCollectionLines && !newCollectionLines.isEmpty()) {
143 for (Map.Entry<String, Object> entry : newCollectionLines.entrySet()) {
144
145
146
147
148 KitchenSinkFormCollection1 collection = (KitchenSinkFormCollection1)entry.getValue();
149 collection.setId(KitchenSinkFormCollection1.assignId());
150 }
151 GlobalVariables.getMessageMap().addGrowlMessage("NOTE", "kitchensink.addLine");
152 }
153
154 return super.addLine(form, result, request, response);
155 }
156
157 @RequestMapping(params = "methodToCall=getActivities")
158 public ModelAndView getActivities(
159 @RequestParam(value = "actionParameters", required = false) Map<String, Integer> actionParameters,
160 @ModelAttribute("KualiForm") KitchenSinkForm form,
161 BindingResult result,
162 HttpServletRequest request,
163 HttpServletResponse response) throws Exception {
164
165 List<KitchenSinkMockActivityData> activities = new ArrayList<KitchenSinkMockActivityData>();
166
167 Integer index = actionParameters.get("index");
168
169 if (displayScheduleList != null && !(displayScheduleList.size() < index.intValue())) {
170 activities = displayScheduleList.get(index.intValue()).getActivities();
171 }
172
173 form.setActivityList(activities);
174 return getUIFModelAndView(form);
175 }
176
177 @RequestMapping(params = "methodToCall=growl")
178 public ModelAndView growl(@ModelAttribute("KualiForm") KitchenSinkForm form, BindingResult result,
179 HttpServletRequest request, HttpServletResponse response) {
180 GlobalVariables.getMessageMap().addGrowlMessage("", "kitchensink.custom", "This is an example of a growl with no icon.");
181 return getUIFModelAndView(form);
182 }
183
184 @RequestMapping(params = "methodToCall=growlError")
185 public ModelAndView growlError(@ModelAttribute("KualiForm") KitchenSinkForm form, BindingResult result,
186 HttpServletRequest request, HttpServletResponse response) {
187 KSUifUtils.addGrowlMessageIcon(GrowlIcon.ERROR, "kitchensink.custom", "This is an example of an error growl.");
188 return getUIFModelAndView(form);
189 }
190
191 @RequestMapping(params = "methodToCall=growlInfo")
192 public ModelAndView growlInfo(@ModelAttribute("KualiForm") KitchenSinkForm form, BindingResult result,
193 HttpServletRequest request, HttpServletResponse response) {
194 KSUifUtils.addGrowlMessageIcon(GrowlIcon.INFORMATION, "kitchensink.custom", "This is an example of an information growl.");
195 return getUIFModelAndView(form);
196 }
197
198 @RequestMapping(params = "methodToCall=growlSuccess")
199 public ModelAndView growlSuccess(@ModelAttribute("KualiForm") KitchenSinkForm form, BindingResult result,
200 HttpServletRequest request, HttpServletResponse response) {
201 KSUifUtils.addGrowlMessageIcon(GrowlIcon.SUCCESS, "kitchensink.custom", "This is an example of a success growl.");
202 return getUIFModelAndView(form);
203 }
204
205 @RequestMapping(params = "methodToCall=growlWarning")
206 public ModelAndView growlWarning(@ModelAttribute("KualiForm") KitchenSinkForm form, BindingResult result,
207 HttpServletRequest request, HttpServletResponse response) {
208 KSUifUtils.addGrowlMessageIcon(GrowlIcon.WARNING, "kitchensink.custom", "This is an example of a warning growl.");
209 return getUIFModelAndView(form);
210 }
211
212 @RequestMapping(params = "methodToCall=dialogButtonConfirm")
213 public ModelAndView dialogButtonConfirm(@ModelAttribute("KualiForm") KitchenSinkForm form, BindingResult result,
214 HttpServletRequest request, HttpServletResponse response) throws Exception {
215 String dialogId = "messageBoxDialog";
216
217 if (!hasDialogBeenAnswered(dialogId, form)) {
218 return showDialog(dialogId, form, request, response);
219 }
220
221
222 String dialogResponse = getStringDialogResponse(dialogId, form, request, response);
223 if ("Y".equals(dialogResponse)) {
224 KSUifUtils.addGrowlMessageIcon(GrowlIcon.SUCCESS, "kitchensink.custom", "You clicked the button.");
225 }
226 else {
227 KSUifUtils.addGrowlMessageIcon(GrowlIcon.ERROR, "kitchensink.custom", "Be more careful next time.");
228 }
229
230
231 form.getDialogManager().resetDialogStatus(dialogId);
232
233 return getUIFModelAndView(form);
234 }
235
236
237 @RequestMapping(params = "methodToCall=customDialog")
238 public ModelAndView customDialog(@ModelAttribute("KualiForm") KitchenSinkForm form, BindingResult result,
239 HttpServletRequest request, HttpServletResponse response) throws Exception {
240 String dialogId = "lightboxDialog2";
241
242 if (!hasDialogBeenAnswered(dialogId, form)) {
243 return showDialog(dialogId, form, request, response);
244 }
245
246
247 form.getDialogManager().resetDialogStatus(dialogId);
248 return getUIFModelAndView(form);
249 }
250
251
252 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=saveForm")
253 public ModelAndView saveForm(@ModelAttribute("KualiForm") KitchenSinkForm form, BindingResult result,
254 HttpServletRequest request, HttpServletResponse response) {
255
256
257
258
259
260 GlobalVariables.getMessageMap().addGrowlMessage("NOTE", "kitchensink.saveForm");
261 return getUIFModelAndView(form);
262 }
263
264 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=saveLightboxForm")
265 public ModelAndView saveLightboxForm(@ModelAttribute("KualiForm") KitchenSinkForm form, BindingResult result,
266 HttpServletRequest request, HttpServletResponse response)
267 throws Exception {
268 String dialogId = "lightboxDialog1";
269
270
271
272 form.setStringField1("Lightbox Form Saved");
273
274 KSUifUtils.addGrowlMessageIcon(GrowlIcon.INFORMATION, "kitchensink.custom", "Lightbox form saved.");
275
276 return returnFromLightbox(form, result, request, response);
277
278
279 }
280
281 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=processFormRowSelection")
282 public ModelAndView processFormRowSelection(@ModelAttribute("KualiForm") KitchenSinkForm form, BindingResult result,
283 HttpServletRequest request, HttpServletResponse response) {
284
285
286
287
288 StringBuilder sb = new StringBuilder();
289 for (KitchenSinkFormCollection1 collection : form.getCollection()) {
290 if (collection.getSelected()) {
291
292 if (sb.length() > 0) {
293 sb.append(", ");
294 }
295 sb.append(collection.getName());
296 }
297 }
298 GlobalVariables.getMessageMap().addGrowlMessage("PROCESSED:", "kitchensink.custom", sb.toString());
299 return getUIFModelAndView(form);
300 }
301
302 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=popoverMethodToCall")
303 public ModelAndView popoverMethodToCall(@ModelAttribute("KualiForm") KitchenSinkForm form, BindingResult result,
304 HttpServletRequest request, HttpServletResponse response) throws Exception {
305 form.setStringField2(
306 "Text set in server-side method before the popover is displayed. "
307 + form.getStringField2()
308 );
309 return getUIFModelAndView(form);
310 }
311
312 private int popupCount = 0;
313 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=popoverRefreshBeforeDisplay")
314 public ModelAndView popoverRefreshBeforeDisplay(@ModelAttribute("KualiForm") KitchenSinkForm form, BindingResult result,
315 HttpServletRequest request, HttpServletResponse response) throws Exception {
316 form.setStringField3(Integer.toString(++popupCount));
317 return getUIFModelAndView(form);
318 }
319
320 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=processPopoverForm")
321 public ModelAndView processPopoverForm(@ModelAttribute("KualiForm") KitchenSinkForm form, BindingResult result,
322 HttpServletRequest request, HttpServletResponse response) {
323 GlobalVariables.getMessageMap().addGrowlMessage("NOTE", "kitchensink.custom", "processPopoverForm");
324 if ("error".equals(form.getStringField1().toLowerCase())) {
325 GlobalVariables.getMessageMap().putErrorForSectionId("stringField1","kitchensink.custom","Popover form with error is displayed automatically.");
326 }
327 return getUIFModelAndView(form);
328 }
329
330 List<KitchenSinkMockDisplayScheduleData> displayScheduleList = KitchenSinkMockDisplayScheduleData.mockTestData();
331
332 }