View Javadoc

1   package org.kuali.student.lum.lu.ui.course.client.controllers;
2   
3   import org.kuali.student.common.ui.client.application.Application;
4   import org.kuali.student.common.ui.client.application.ViewContext;
5   import org.kuali.student.common.ui.client.event.ActionEvent;
6   import org.kuali.student.common.ui.client.event.SaveActionEvent;
7   import org.kuali.student.common.ui.client.mvc.ActionCompleteCallback;
8   import org.kuali.student.common.ui.client.mvc.Callback;
9   import org.kuali.student.common.ui.client.mvc.DataModel;
10  import org.kuali.student.common.ui.client.service.BaseDataOrchestrationRpcServiceAsync;
11  import org.kuali.student.common.ui.client.util.WindowTitleUtils;
12  import org.kuali.student.common.ui.client.widgets.KSButton;
13  import org.kuali.student.common.ui.client.widgets.notification.KSNotification;
14  import org.kuali.student.common.ui.client.widgets.notification.KSNotifier;
15  import org.kuali.student.common.ui.shared.IdAttributes.IdType;
16  import org.kuali.student.lum.common.client.widgets.AppLocations;
17  import org.kuali.student.lum.lu.assembly.data.client.constants.orch.CreditCourseConstants;
18  import org.kuali.student.lum.lu.ui.course.client.configuration.CourseAdminRetireConfigurer;
19  import org.kuali.student.lum.lu.ui.course.client.widgets.CourseWorkflowActionList;
20  import org.kuali.student.r2.common.dto.DtoConstants;
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   * Controller for retire screen
28   * 
29   * @author Will
30   *
31   */
32  public class CourseAdminRetireController extends CourseAdminWithoutVersionController{
33  		
34  	/**
35  	 * Override the intitailzeController method to use CourseAdminConfigurer 
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  	 * Override the getSaveButton to provide a new set of buttons for the admin screens
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  	 * This processes the save or activate button clicks
75  	 * 
76  	 * @param state The state to set on the course when saving course data.
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      * Override the setHeaderTitle to display proper header title for admin screens
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     	//There is no start section for retire screen
131     	return false;
132     }
133 
134     @Override
135 	public boolean isAuthorizationRequired() {
136 		//FIXME: Need to add proper authorization checks for admin modify.
137 		return false;
138 	}
139 
140 	@Override
141 	protected void progressiveEnableFields() {
142 		//Does nothing, there are no progressive enabled fields on retire screens.
143 	}
144 	
145 	/**
146 	 * Override the getStateforSaveAction since the save action for retire course will change state to 
147 	 * retired.  
148 	 */
149 	@Override
150     protected String getStateforSaveAction(DataModel model){
151     	return cfg.getState();
152     }
153     
154 }