1   package org.kuali.student.lum.lu.ui.course.client.controllers;
2   
3   import org.kuali.student.common.dto.DtoConstants;
4   import org.kuali.student.common.ui.client.application.Application;
5   import org.kuali.student.common.ui.client.application.ViewContext;
6   import org.kuali.student.common.ui.client.event.ActionEvent;
7   import org.kuali.student.common.ui.client.event.SaveActionEvent;
8   import org.kuali.student.common.ui.client.mvc.ActionCompleteCallback;
9   import org.kuali.student.common.ui.client.mvc.Callback;
10  import org.kuali.student.common.ui.client.mvc.DataModel;
11  import org.kuali.student.common.ui.client.service.BaseDataOrchestrationRpcServiceAsync;
12  import org.kuali.student.common.ui.client.util.WindowTitleUtils;
13  import org.kuali.student.common.ui.client.widgets.KSButton;
14  import org.kuali.student.common.ui.client.widgets.notification.KSNotification;
15  import org.kuali.student.common.ui.client.widgets.notification.KSNotifier;
16  import org.kuali.student.common.ui.shared.IdAttributes.IdType;
17  import org.kuali.student.lum.common.client.widgets.AppLocations;
18  import org.kuali.student.lum.lu.assembly.data.client.constants.orch.CreditCourseConstants;
19  import org.kuali.student.lum.lu.ui.course.client.configuration.CourseAdminRetireConfigurer;
20  import org.kuali.student.lum.lu.ui.course.client.widgets.CourseWorkflowActionList;
21  
22  import com.google.gwt.core.client.GWT;
23  import com.google.gwt.event.dom.client.ClickEvent;
24  import com.google.gwt.event.dom.client.ClickHandler;
25  
26  
27  
28  
29  
30  
31  
32  public class CourseAdminRetireController extends CourseAdminWithoutVersionController{
33  		
34  	
35  
36  
37  	@Override
38  	protected void initializeController() {
39     		
40  		super.cfg = GWT.create(CourseAdminRetireConfigurer.class);
41  		
42     		cfg.setState(DtoConstants.STATE_RETIRED.toUpperCase());
43     		super.setDefaultModelId(cfg.getModelId());
44     		super.registerModelsAndHandlers();
45     		super.addStyleName("ks-course-admin");  	   		   		
46      }
47  	
48  	
49  
50  
51  	@Override
52  	public KSButton getSaveButton(){
53  		KSButton saveButton =  new KSButton("Retire", new ClickHandler(){
54              public void onClick(ClickEvent event) {
55              	handleButtonClick(DtoConstants.STATE_RETIRED);            	
56              }
57          });
58  		
59  		return saveButton;
60  	}
61  				
62  	public KSButton getCancelButton(){
63  		KSButton button = new KSButton("Cancel", new ClickHandler(){
64              public void onClick(ClickEvent event) {       
65              	Application.navigate(AppLocations.Locations.VIEW_COURSE.getLocation());
66              }
67          });
68  	
69  		button.addStyleName("ks-button-spacing");
70  		return button;
71      }
72  	
73  	
74  
75  
76  
77  
78  	protected void handleButtonClick(final String state){
79  		final SaveActionEvent saveActionEvent = new SaveActionEvent(false);
80  
81      	saveActionEvent.setActionCompleteCallback(new ActionCompleteCallback(){
82  			@Override
83  			public void onActionComplete(ActionEvent actionEvent) {
84  				if (saveActionEvent.isSaveSuccessful()){
85  	                final ViewContext viewContext = new ViewContext();
86  	                viewContext.setId((String)cluProposalModel.get(CreditCourseConstants.ID));
87  	                viewContext.setIdType(IdType.OBJECT_ID);											
88  
89  	                
90  					CourseWorkflowActionList.setCourseState(viewContext.getId(), DtoConstants.STATE_RETIRED, new Callback<String>(){
91  						@Override
92  						public void exec(String result) {
93  							if (result == null){
94  								KSNotifier.add(new KSNotification("Course saved, but unable to set retire state.", false, true, 5000));
95  							} else {
96  								KSNotifier.show("Course saved and retired.");									
97  								Application.navigate(AppLocations.Locations.VIEW_COURSE.getLocation(), viewContext);
98  							}							
99  						}
100 					});							
101 				}      
102 			}
103     	});
104     	
105    		CourseAdminRetireController.this.fireApplicationEvent(saveActionEvent);    		
106 	}
107 	
108 	
109 	
110 
111 
112 	@Override
113 	protected void setHeaderTitle(){
114 		StringBuffer sb = new StringBuffer();
115 		sb.append(cluProposalModel.get(cfg.getCourseTitlePath()));
116 		sb.append(" (Retirement)");
117 				
118 		currentTitle = sb.toString();
119 		
120 		this.setContentTitle(currentTitle);
121     	this.setName(currentTitle);
122     	WindowTitleUtils.setContextTitle(currentTitle);		
123     }
124 
125 	protected  BaseDataOrchestrationRpcServiceAsync getCourseProposalRpcService(){
126     	return courseServiceAsync;
127     }
128     	
129     public boolean startSectionRequired(){
130     	
131     	return false;
132     }
133 
134     @Override
135 	public boolean isAuthorizationRequired() {
136 		
137 		return false;
138 	}
139 
140 	@Override
141 	protected void progressiveEnableFields() {
142 		
143 	}
144 	
145 	
146 
147 
148 
149 	@Override
150     protected String getStateforSaveAction(DataModel model){
151     	return cfg.getState();
152     }
153     
154 }