View Javadoc

1   /**
2    * Copyright 2005-2015 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.demo.uif.form.KradSampleAppForm;
19  import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
20  import org.kuali.rice.krad.uif.view.ViewTheme;
21  import org.kuali.rice.krad.util.GlobalVariables;
22  import org.kuali.rice.krad.web.controller.UifControllerBase;
23  import org.kuali.rice.krad.web.form.UifFormBase;
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.servlet.ModelAndView;
30  
31  import javax.servlet.http.HttpServletRequest;
32  import javax.servlet.http.HttpServletResponse;
33  
34  /**
35   * Basic controller for the KRAD sample application
36   *
37   * @author Kuali Rice Team (rice.collab@kuali.org)
38   */
39  @Controller
40  @RequestMapping(value = "/kradsampleapp")
41  public class KradSampleAppController extends UifControllerBase {
42  
43      @Override
44      protected KradSampleAppForm createInitialForm(HttpServletRequest request) {
45          return new KradSampleAppForm();
46      }
47  
48      @Override
49      @RequestMapping(params = "methodToCall=start")
50      public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
51              HttpServletRequest request, HttpServletResponse response) {
52          //TODO tbd
53          return super.start(form, result, request, response);
54      }
55  
56      @RequestMapping(method = RequestMethod.POST, params = "methodToCall=changeTheme")
57      public ModelAndView changeTheme(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
58              HttpServletRequest request, HttpServletResponse response) {
59          changeTheme(form);
60          return getUIFModelAndView(form);
61      }
62  
63      @RequestMapping(method = RequestMethod.POST, params = "methodToCall=validateView")
64      public ModelAndView validateView(@ModelAttribute("KualiForm") UifFormBase uiTestForm, BindingResult result,
65              HttpServletRequest request, HttpServletResponse response) {
66          KRADServiceLocatorWeb.getViewValidationService().validateView(uiTestForm);
67          return getUIFModelAndView(uiTestForm);
68      }
69  
70      @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addGrowl")
71      public ModelAndView addGrowl(@ModelAttribute("KualiForm") UifFormBase uiTestForm, BindingResult result,
72              HttpServletRequest request, HttpServletResponse response) {
73          String extraInfo = (String)request.getParameter("extraInfo");
74          if(extraInfo == null){
75              extraInfo = "none";
76          }
77          GlobalVariables.getMessageMap().addGrowlMessage("Growl Message", "demo.fakeGrowl", extraInfo);
78          return getUIFModelAndView(uiTestForm);
79      }
80  
81      private void changeTheme(UifFormBase form) {
82          String theme = ((KradSampleAppForm) form).getThemeName();
83          if (theme != null) {
84              ViewTheme newTheme = (ViewTheme) (KRADServiceLocatorWeb.getDataDictionaryService().getDictionaryObject(
85                      theme));
86              if (newTheme != null) {
87                  form.getPostedView().setTheme(newTheme);
88                  form.getView().setTheme(newTheme);
89              }
90          }
91      }
92  }