1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.kpme.pm.controller;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.kpme.pm.position.PositionBo;
20 import org.kuali.rice.krad.kpme.controller.EffectiveDateMaintenanceController;
21 import org.kuali.rice.krad.maintenance.MaintenanceDocument;
22 import org.kuali.rice.krad.uif.UifParameters;
23 import org.kuali.rice.krad.uif.view.DialogManager;
24 import org.kuali.rice.krad.util.KRADConstants;
25 import org.kuali.rice.krad.web.form.DocumentFormBase;
26 import org.kuali.rice.krad.web.form.MaintenanceDocumentForm;
27 import org.kuali.rice.krad.web.form.UifFormBase;
28 import org.springframework.stereotype.Controller;
29 import org.springframework.validation.BindingResult;
30 import org.springframework.web.bind.annotation.ModelAttribute;
31 import org.springframework.web.bind.annotation.RequestMapping;
32 import org.springframework.web.servlet.ModelAndView;
33
34 import javax.servlet.http.HttpServletRequest;
35 import javax.servlet.http.HttpServletResponse;
36 import java.util.Properties;
37 import java.util.concurrent.Callable;
38
39
40 @Controller
41 @RequestMapping(value = "/kpme/positionMaintenance")
42 public class PositionMaintenanceController extends EffectiveDateMaintenanceController {
43
44 private static final String KPME_PROCESS_CHANGE_WARNING_DIALOG = "ProcessChangeWarning-Dialog";
45
46 @Override
47 @RequestMapping(params = "methodToCall=returnFromLightbox")
48 public ModelAndView returnFromLightbox(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
49 HttpServletRequest request, HttpServletResponse response) {
50 String newMethodToCall = "";
51
52
53 DialogManager dm = form.getDialogManager();
54 String dialogId = dm.getCurrentDialogId();
55 if (dialogId == null) {
56
57
58
59 newMethodToCall = "start";
60 } else {
61 dm.setDialogAnswer(dialogId, form.getDialogResponse());
62 dm.setDialogExplanation(dialogId, form.getDialogExplanation());
63 newMethodToCall = dm.getDialogReturnMethod(dialogId);
64 dm.setCurrentDialogId(null);
65 }
66
67
68 PositionBo aPositionBo = (PositionBo) ((MaintenanceDocumentForm) form).getDocument().getNewMaintainableObject().getDataObject();
69
70 Properties props = new Properties();
71 props.put(UifParameters.METHOD_TO_CALL, newMethodToCall);
72 props.put(UifParameters.VIEW_ID, form.getViewId());
73 props.put(UifParameters.FORM_KEY, form.getFormKey());
74 props.put(UifParameters.AJAX_REQUEST, "false");
75 props.put("hrPositionId",aPositionBo.getHrPositionId());
76 props.put("oldProcess",request.getParameter("oldProcess"));
77 props.put("newProcess",request.getParameter("newProcess"));
78 return performRedirect(form, form.getFormPostUrl(), props);
79 }
80
81 @RequestMapping(params = "methodToCall=changeProcess")
82 public ModelAndView changeProcess(@ModelAttribute("KualiForm") final MaintenanceDocumentForm form, final BindingResult result,
83 final HttpServletRequest request, final HttpServletResponse response) throws Exception {
84 return showProcessChangeWarningIfNeeded(form, result, request, response, new Callable<ModelAndView>() {
85 @Override
86 public ModelAndView call() throws Exception {
87
88 setupMaintenance(form, request, KRADConstants.MAINTENANCE_EDIT_ACTION);
89 String newProcess = request.getParameter("newProcess");
90
91 MaintenanceDocument maintenanceDocument = (MaintenanceDocument) form.getDocument();
92 ((PositionBo)maintenanceDocument.getNewMaintainableObject().getDataObject()).setProcess(newProcess);
93 return getUIFModelAndView(form);
94 }
95 });
96 }
97
98
99
100
101
102
103 protected ModelAndView showProcessChangeWarningIfNeeded(@ModelAttribute("KualiForm") DocumentFormBase form,
104 BindingResult result,
105 HttpServletRequest request,
106 HttpServletResponse response,
107 Callable<ModelAndView> callable) throws Exception {
108
109 ModelAndView retVal = null;
110 String oldProcess = request.getParameter("oldProcess");
111
112 if (!hasDialogBeenAnswered(KPME_PROCESS_CHANGE_WARNING_DIALOG, form)) {
113 if (StringUtils.isEmpty(oldProcess)) {
114 retVal = getUIFModelAndView(form);
115 } else {
116
117 retVal = showDialog(KPME_PROCESS_CHANGE_WARNING_DIALOG, form, request, response);
118 }
119 } else {
120 boolean areYouSure = getBooleanDialogResponse(KPME_PROCESS_CHANGE_WARNING_DIALOG, form, request, response);
121
122 form.getDialogManager().removeAllDialogs();
123 if (areYouSure) {
124
125 retVal = callable.call();
126 }
127 else {
128
129
130 MaintenanceDocument maintenanceDocument = (MaintenanceDocument) form.getDocument();
131 ((PositionBo)maintenanceDocument.getNewMaintainableObject().getDataObject()).setProcess(oldProcess);
132 retVal = getUIFModelAndView(form);
133 }
134 }
135 return retVal;
136 }
137
138 }