View Javadoc
1   /**
2    * Copyright 2005-2016 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.krad.demo.uif.controller;
17  
18  import org.kuali.rice.krad.util.GlobalVariables;
19  import org.kuali.rice.krad.web.form.DialogResponse;
20  import org.kuali.rice.krad.web.form.UifFormBase;
21  import org.springframework.stereotype.Controller;
22  import org.springframework.web.bind.annotation.ModelAttribute;
23  import org.springframework.web.bind.annotation.RequestMapping;
24  import org.springframework.web.servlet.ModelAndView;
25  
26  /**
27   * Controller for the dialog demo view.
28   *
29   * @author Kuali Rice Team (rice.collab@kuali.org)
30   */
31  @Controller
32  @RequestMapping(value = "/dialog")
33  public class DemoDialogController extends KradSampleAppController {
34  
35      protected static final String DEMO_DUPLICATE_DIALOG = "Demo-DialogGroup-ServerResponse1";
36      protected static final String DEMO_DISAPPROVE_CONFIRM = "Demo-DialogGroup-ServerResponse2";
37      protected static final String DEMO_DISAPPROVE_SURVEY = "Demo-DialogGroup-ServerResponse3";
38  
39      @RequestMapping(params = "methodToCall=save")
40      @Override
41      public ModelAndView save(@ModelAttribute("KualiForm") UifFormBase form) throws Exception {
42          // typically there would be conditional logic that triggers the dialog
43          DialogResponse duplicateDialogResponse = form.getDialogResponse(DEMO_DUPLICATE_DIALOG);
44          if (duplicateDialogResponse == null) {
45              return showDialog(DEMO_DUPLICATE_DIALOG, true, form);
46          }
47  
48          boolean verifiedDuplicate = duplicateDialogResponse.getResponseAsBoolean();
49          if (verifiedDuplicate) {
50              // continue with save
51              GlobalVariables.getMessageMap().putInfoForSectionId("demoDialogEx8", "demo.dialogs.saveConfirmation");
52          }
53  
54          return getModelAndView(form);
55      }
56  
57      @RequestMapping(params = "methodToCall=disapprove")
58      public ModelAndView disapprove(@ModelAttribute("KualiForm") UifFormBase form) throws Exception {
59          // typically there would be conditional logic that triggers the dialog
60          DialogResponse disapproveConfirm = form.getDialogResponse(DEMO_DISAPPROVE_CONFIRM);
61          if (disapproveConfirm == null) {
62              return showDialog(DEMO_DISAPPROVE_CONFIRM, true, form);
63          }
64  
65          // since the dialog was a confirmation, we don't need to check the answer, if they selected no the
66          // request will not be resent
67          String disapproveExplanation = disapproveConfirm.getExplanation();
68  
69          DialogResponse disapproveSurvey = form.getDialogResponse(DEMO_DISAPPROVE_SURVEY);
70          if (disapproveSurvey == null) {
71              return showDialog(DEMO_DISAPPROVE_SURVEY, false, form);
72          }
73  
74          String surveyResponse = disapproveSurvey.getResponse();
75  
76          GlobalVariables.getMessageMap().putInfoForSectionId("demoDialogEx9", "demo.dialogs.disapprove",
77                  disapproveExplanation, surveyResponse);
78  
79          return getModelAndView(form);
80      }
81  }