001 /** 002 * Copyright 2005-2012 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package edu.sampleu.demo.kitchensink; 017 018 import org.kuali.rice.krad.uif.UifConstants; 019 import org.kuali.rice.krad.uif.view.DialogManager; 020 import org.kuali.rice.krad.web.controller.UifControllerBase; 021 import org.kuali.rice.krad.web.form.UifFormBase; 022 import org.springframework.stereotype.Controller; 023 import org.springframework.validation.BindingResult; 024 import org.springframework.web.bind.annotation.ModelAttribute; 025 import org.springframework.web.bind.annotation.RequestMapping; 026 import org.springframework.web.servlet.ModelAndView; 027 028 import javax.servlet.http.HttpServletRequest; 029 import javax.servlet.http.HttpServletResponse; 030 031 /** 032 * a controller for the configuration test view 033 * 034 * @author Kuali Rice Team (rice.collab@kuali.org) 035 */ 036 @Controller 037 @RequestMapping(value = "/dialog-configuration-test") 038 public class DialogTestViewUifController extends UifControllerBase { 039 040 @Override 041 protected UifFormBase createInitialForm(HttpServletRequest request) { 042 return new UifDialogTestForm(); 043 } 044 045 /** 046 * Displays page for testing dialogs 047 */ 048 @Override 049 @RequestMapping(params = "methodToCall=start") 050 public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, 051 HttpServletRequest request, HttpServletResponse response) { 052 return super.start(form, result, request, response); 053 } 054 055 /** 056 * Exercises the Dialog framework. 057 * 058 * <p> 059 * Asks a series of questions of the user while processing a client request. Demonstrates the ability to go back 060 * to the client bring up a Lightbox modal dialog. 061 * <br> 062 * Displays a few dialogs back to the user. First a yes/no dialog asking the user to pick an author. 063 * Depending on which author was chosen, the user is asked to select a book. 064 * The user is then given a chance to start the selection process over or continue on. 065 * </p> 066 * 067 * @param form - test form 068 * @param result - Spring form binding result 069 * @param request - http request 070 * @param response - http response 071 * @return 072 * @throws Exception 073 */ 074 @RequestMapping(params = "methodToCall=save") 075 public ModelAndView save(@ModelAttribute("KualiForm") UifDialogTestForm form, BindingResult result, 076 HttpServletRequest request, HttpServletResponse response) throws Exception { 077 ModelAndView mv; 078 079 // dialog names 080 String dialog1 = "chooseAuthorDialog"; 081 String dialog2a = "chooseEastmanBookDialog"; 082 String dialog2b = "chooseSeussBookDialog"; 083 String dialog3 = "myRestart"; 084 085 // local copies of dialog answers 086 boolean whichAuthor = false; 087 String chosenBook; 088 boolean doRestart = false; 089 090 // choose which author 091 if (!hasDialogBeenAnswered(dialog1, form)){ 092 // redirect back to client to display lightbox 093 return showDialog(dialog1, form, request, response); 094 } 095 whichAuthor = getBooleanDialogResponse(dialog1, form, request, response); 096 097 // continue on here if they answered the the first question 098 if (whichAuthor){ 099 form.setField1("You Selected: P.D. Eastman"); 100 101 // popup a 2nd consecutive dialog 102 if (!hasDialogBeenAnswered(dialog2a,form)){ 103 // redirect back to client to display lightbox 104 return showDialog(dialog2a, form, request, response); 105 } 106 chosenBook = form.getDialogManager().getDialogExplanation(dialog2a); 107 108 // return back to the client displaying the choices 109 form.setField1("You selected: "+chosenBook+" by P.D. Eastman. Here we go..."); 110 } else { 111 form.setField1("You Selected: Dr. Seuss"); 112 // in this case, return to client and wait for them to submit again before showing next dialog 113 // In the above case, the 1st and 2nd dialog are displayed consecutively before returning to the client. 114 // But in this example, we return to the client and wait for them to hit the submit button again 115 if (!hasDialogBeenDisplayed(dialog2b, form)){ 116 form.getDialogManager().addDialog(dialog2b, form.getMethodToCall()); 117 return getUIFModelAndView(form, "DialogView-Page1"); 118 } 119 120 // now display the dialog to choose which book 121 if (!hasDialogBeenAnswered(dialog2b, form)){ 122 return showDialog(dialog2b, form, request, response); 123 } 124 chosenBook = form.getDialogManager().getDialogExplanation(dialog2b); 125 126 // display which story the user has selected 127 form.setField1("You selected: "+chosenBook+" by Dr. Seuss. Here we go..."); 128 } 129 130 // Wait at the client page for another page submit 131 if (!hasDialogBeenDisplayed(dialog3, form)) { 132 form.getDialogManager().addDialog(dialog3, form.getMethodToCall()); 133 return getUIFModelAndView(form, "DialogView-Page1"); 134 }; 135 136 // Ask them if they want to start over 137 if (!hasDialogBeenAnswered(dialog3,form)){ 138 return showDialog(dialog3, form, request, response); 139 } 140 doRestart = getBooleanDialogResponse(dialog3, form, request, response); 141 142 // clear the dialog manager entries, so when we come back, we'll ask all the questions again 143 if (doRestart){ 144 form.getDialogManager().removeAllDialogs(); 145 form.setField1("Ok, let's start over."); 146 return getUIFModelAndView(form, "DialogView-Page1"); 147 } 148 149 // we're done, go to the next page 150 return getUIFModelAndView(form, "DialogView-Page2"); 151 } 152 153 /** 154 * not used at this time 155 * 156 * @param form - test form 157 * @param result - Spring form binding result 158 * @param request - http request 159 * @param response - http response 160 * @return 161 */ 162 @RequestMapping(params = "methodToCall=goBack") 163 public ModelAndView goBack(@ModelAttribute("KualiForm") UifDialogTestForm form, BindingResult result, 164 HttpServletRequest request, HttpServletResponse response) { 165 166 // TODO: Put "Are Your Sure?" dialog here 167 form.getDialogManager().removeAllDialogs(); 168 form.setField1("Ok, let's start over."); 169 return getUIFModelAndView(form, "DialogView-Page1"); 170 } 171 172 /** 173 * Test method for a controller that invokes a dialog lightbox. 174 * 175 * @param form - test form 176 * @param result - Spring form binding result 177 * @param request - http request 178 * @param response - http response 179 * @return 180 * @throws Exception 181 */ 182 @RequestMapping(params = "methodToCall=" + "doRadioDialogExample") 183 public ModelAndView doSomething(@ModelAttribute("KualiForm") UifDialogTestForm form, BindingResult result, 184 HttpServletRequest request, HttpServletResponse response) throws Exception { 185 String dialog1 = "sampleRadioButtonDialog"; 186 if (!hasDialogBeenAnswered(dialog1, form)){ 187 // redirect back to client to display lightbox 188 return showDialog(dialog1, form, request, response); 189 } 190 // Get value from chosen radio button 191 String choice = form.getDialogManager().getDialogExplanation(dialog1); 192 if (choice == null){ 193 form.setField1("You didn't select one of the radio buttons"); 194 } else { 195 form.setField1("You chose Radio Option "+choice); 196 } 197 198 // clear dialog history so they can press the button again 199 form.getDialogManager().removeDialog(dialog1); 200 // reload page1 201 return getUIFModelAndView(form, "DialogView-Page1"); 202 } 203 204 /** 205 * Test method for a controller that invokes a dialog lightbox. 206 * 207 * @param form - test form 208 * @param result - Spring form binding result 209 * @param request - http request 210 * @param response - http response 211 * @return 212 * @throws Exception 213 */ 214 @RequestMapping(params = "methodToCall=" + "doOkCancelExample") 215 public ModelAndView doOKCancelExample(@ModelAttribute("KualiForm") UifDialogTestForm form, BindingResult result, 216 HttpServletRequest request, HttpServletResponse response) throws Exception { 217 String dialog1 = "preDefinedDialogOkCancel"; 218 if (!hasDialogBeenAnswered(dialog1, form)){ 219 // redirect back to client to display lightbox 220 return showDialog(dialog1, form, request, response); 221 } 222 // Get user choice 223 boolean choice = getBooleanDialogResponse(dialog1, form, request, response); 224 StringBuilder sb = new StringBuilder("You selected "); 225 sb.append((choice)?"OK":"Cancel"); 226 form.setField1(sb.toString()); 227 228 // clear dialog history so they can press the button again 229 form.getDialogManager().removeDialog(dialog1); 230 // reload page1 231 return getUIFModelAndView(form, "DialogView-Page1"); 232 } 233 234 /** 235 * Test method for a controller that invokes a dialog lightbox. 236 * 237 * @param form - test form 238 * @param result - Spring form binding result 239 * @param request - http request 240 * @param response - http response 241 * @return 242 * @throws Exception 243 */ 244 @RequestMapping(params = "methodToCall=" + "doRegularGroupAsDialog") 245 public ModelAndView doRegularGroupAsDialog(@ModelAttribute("KualiForm") UifDialogTestForm form, BindingResult result, 246 HttpServletRequest request, HttpServletResponse response) throws Exception { 247 String dialog1 = "myRegularGroup"; 248 if (!hasDialogBeenAnswered(dialog1, form)){ 249 // redirect back to client to display lightbox 250 return showDialog(dialog1, form, request, response); 251 } 252 // Get value from chosen radio button 253 boolean choice = getBooleanDialogResponse(dialog1, form, request, response); 254 StringBuilder sb = new StringBuilder("You selected "); 255 sb.append((choice)?"Yes":"No"); 256 form.setField1(sb.toString()); 257 258 // clear dialog history so they can press the button again 259 form.getDialogManager().removeDialog(dialog1); 260 // reload page1 261 return getUIFModelAndView(form, "DialogView-Page1"); 262 } 263 264 //KULRICE-8319 265 @RequestMapping(params = "methodToCall=" + "testExpressionDialog") 266 public ModelAndView testExpressionDialog(@ModelAttribute("KualiForm") UifDialogTestForm form, BindingResult result, 267 HttpServletRequest request, HttpServletResponse response) throws Exception { 268 String dialog4 = "schedulingConfirmDialog"; 269 if (!hasDialogBeenAnswered(dialog4,form)){ 270 form.setField3("TestVal"); 271 return showDialog(dialog4, form, request, response); 272 } 273 274 // clear dialog history so they can press the button again 275 form.getDialogManager().removeDialog(dialog4); 276 // reload page1 277 return getUIFModelAndView(form, "DialogView-Page1"); 278 } 279 280 281 /** 282 * Test method for a controller that invokes a dialog lightbox. 283 * 284 * @param form - test form 285 * @param result - Spring form binding result 286 * @param request - http request 287 * @param response - http response 288 * @return 289 * @throws Exception 290 */ 291 @RequestMapping(params = "methodToCall=" + "doExtendedDialog") 292 public ModelAndView doExtendedDialog(@ModelAttribute("KualiForm") UifDialogTestForm form, BindingResult result, 293 HttpServletRequest request, HttpServletResponse response) throws Exception { 294 String dialog1 = "extendedDialogGroup"; 295 if (!hasDialogBeenAnswered(dialog1, form)){ 296 // redirect back to client to display lightbox 297 return showDialog(dialog1, form, request, response); 298 } 299 // Get value from chosen radio button 300 boolean choice = getBooleanDialogResponse(dialog1, form, request, response); 301 StringBuilder sb = new StringBuilder("You selected "); 302 sb.append((choice)?"Yes":"No"); 303 form.setField1(sb.toString()); 304 305 // clear dialog history so they can press the button again 306 form.getDialogManager().removeDialog(dialog1); 307 // reload page1 308 return getUIFModelAndView(form, "DialogView-Page1"); 309 } 310 /** 311 * Test method for a controller that displays the response in a ightbox. 312 * 313 * @param form - test form 314 * @param result - Spring form binding result 315 * @param request - http request 316 * @param response - http response 317 * @return 318 * @throws Exception 319 */ 320 @RequestMapping(params = "methodToCall=" + "doResponseInLightBox") 321 public ModelAndView doResponseInLightBox(@ModelAttribute("KualiForm") UifDialogTestForm form, BindingResult result, 322 HttpServletRequest request, HttpServletResponse response) throws Exception { 323 String dialog1 = "myRegularGroup"; 324 if (!hasDialogBeenAnswered(dialog1, form)){ 325 // redirect back to client to display lightbox 326 return showDialog(dialog1, form, request, response); 327 } 328 // Get value from chosen radio button 329 boolean choice = getBooleanDialogResponse(dialog1, form, request, response); 330 StringBuilder sb = new StringBuilder("You selected "); 331 sb.append((choice)?"Yes":"No"); 332 form.setField1(sb.toString()); 333 334 // clear dialog history so they can press the button again 335 form.getDialogManager().removeDialog(dialog1); 336 // reload page1 337 return getUIFModelAndView(form, "DialogView-Page1"); 338 } 339 340 }