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.labs;
017
018import org.kuali.rice.krad.util.GlobalVariables;
019import org.kuali.rice.krad.web.controller.MethodAccessible;
020import org.kuali.rice.krad.web.controller.UifControllerBase;
021import org.kuali.rice.krad.web.form.UifFormBase;
022import org.kuali.rice.krad.web.service.FileControllerService;
023import org.springframework.beans.factory.annotation.Autowired;
024import org.springframework.beans.factory.annotation.Qualifier;
025import org.springframework.stereotype.Controller;
026import org.springframework.validation.BindingResult;
027import org.springframework.web.bind.annotation.ModelAttribute;
028import org.springframework.web.bind.annotation.RequestMapping;
029import org.springframework.web.bind.annotation.RequestMethod;
030import org.springframework.web.servlet.ModelAndView;
031
032import javax.servlet.http.HttpServletRequest;
033import javax.servlet.http.HttpServletResponse;
034
035/**
036 * Basic controller for the lab views
037 *
038 * @author Kuali Rice Team (rice.collab@kuali.org)
039 */
040@Controller
041@RequestMapping(value = "/labs")
042public class KradLabsController extends UifControllerBase {
043
044    @Override
045    @RequestMapping(params = "methodToCall=start")
046    public ModelAndView start(UifFormBase form) {
047
048        if (form.getViewId().equals("Labs-BootstrapMultiSelect")) {
049            GlobalVariables.getMessageMap().putWarning("multiSelectField2", "validation.equals");
050        }
051            return super.start(form);
052     }
053
054    @Override
055    protected KradLabsForm createInitialForm() {
056        return new KradLabsForm();
057    }
058
059    @RequestMapping(params = "methodToCall=jsonExample")
060    public ModelAndView jsonExample(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
061            HttpServletRequest request, HttpServletResponse response) {
062
063        form.setRequestJsonTemplate("/templates/jsonSample.ftl");
064
065        return getModelAndView(form);
066    }
067
068    @Autowired
069    @Qualifier("demoFileControllerService")
070    @Override
071    public void setFileControllerService(FileControllerService fileControllerService) {
072        super.setFileControllerService(fileControllerService);
073    }
074
075    @Override
076    @RequestMapping(method = RequestMethod.POST, params = "methodToCall=saveField")
077    public ModelAndView saveField(UifFormBase uifForm) throws Exception {
078        GlobalVariables.getMessageMap().putError("dataField3", "serverTestError");
079        // Hook method for saving individual fields
080        return refresh(uifForm);
081    }
082
083    @MethodAccessible
084    @RequestMapping(params = "methodToCall=dialogMessage")
085    public ModelAndView dialogMessage(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
086                HttpServletRequest request, HttpServletResponse response)  throws Exception {
087        GlobalVariables.getMessageMap().putError("HierarchyMessages", "serverTestError");
088        GlobalVariables.getMessageMap().putError("inputField1", "serverTestError");
089        // Hook method for saving individual fields
090        return getModelAndView(form);
091    }
092}