001/** 002 * Copyright 2005-2015 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 */ 016package org.kuali.rice.krad.demo.uif.controller; 017 018import org.kuali.rice.krad.util.GlobalVariables; 019import org.kuali.rice.krad.web.form.DialogResponse; 020import org.kuali.rice.krad.web.form.UifFormBase; 021import org.springframework.stereotype.Controller; 022import org.springframework.web.bind.annotation.ModelAttribute; 023import org.springframework.web.bind.annotation.RequestMapping; 024import org.springframework.web.servlet.ModelAndView; 025 026/** 027 * Controller for the dialog demo view. 028 * 029 * @author Kuali Rice Team (rice.collab@kuali.org) 030 */ 031@Controller 032@RequestMapping(value = "/dialog") 033public class DemoDialogController extends KradSampleAppController { 034 035 protected static final String DEMO_DUPLICATE_DIALOG = "Demo-DialogGroup-ServerResponse1"; 036 protected static final String DEMO_DISAPPROVE_CONFIRM = "Demo-DialogGroup-ServerResponse2"; 037 protected static final String DEMO_DISAPPROVE_SURVEY = "Demo-DialogGroup-ServerResponse3"; 038 039 @RequestMapping(params = "methodToCall=save") 040 @Override 041 public ModelAndView save(@ModelAttribute("KualiForm") UifFormBase form) throws Exception { 042 // typically there would be conditional logic that triggers the dialog 043 DialogResponse duplicateDialogResponse = form.getDialogResponse(DEMO_DUPLICATE_DIALOG); 044 if (duplicateDialogResponse == null) { 045 return showDialog(DEMO_DUPLICATE_DIALOG, true, form); 046 } 047 048 boolean verifiedDuplicate = duplicateDialogResponse.getResponseAsBoolean(); 049 if (verifiedDuplicate) { 050 // continue with save 051 GlobalVariables.getMessageMap().putInfoForSectionId("demoDialogEx8", "demo.dialogs.saveConfirmation"); 052 } 053 054 return getModelAndView(form); 055 } 056 057 @RequestMapping(params = "methodToCall=disapprove") 058 public ModelAndView disapprove(@ModelAttribute("KualiForm") UifFormBase form) throws Exception { 059 // typically there would be conditional logic that triggers the dialog 060 DialogResponse disapproveConfirm = form.getDialogResponse(DEMO_DISAPPROVE_CONFIRM); 061 if (disapproveConfirm == null) { 062 return showDialog(DEMO_DISAPPROVE_CONFIRM, true, form); 063 } 064 065 // since the dialog was a confirmation, we don't need to check the answer, if they selected no the 066 // request will not be resent 067 String disapproveExplanation = disapproveConfirm.getExplanation(); 068 069 DialogResponse disapproveSurvey = form.getDialogResponse(DEMO_DISAPPROVE_SURVEY); 070 if (disapproveSurvey == null) { 071 return showDialog(DEMO_DISAPPROVE_SURVEY, false, form); 072 } 073 074 String surveyResponse = disapproveSurvey.getResponse(); 075 076 GlobalVariables.getMessageMap().putInfoForSectionId("demoDialogEx9", "demo.dialogs.disapprove", 077 disapproveExplanation, surveyResponse); 078 079 return getModelAndView(form); 080 } 081}