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.configurable.mvc.FieldDescriptor;
6   import org.kuali.student.common.ui.client.configurable.mvc.sections.BaseSection;
7   import org.kuali.student.common.ui.client.event.ActionEvent;
8   import org.kuali.student.common.ui.client.event.SaveActionEvent;
9   import org.kuali.student.common.ui.client.mvc.ActionCompleteCallback;
10  import org.kuali.student.common.ui.client.mvc.Callback;
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.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.CourseAdminWithoutVersionConfigurer;
19  import org.kuali.student.r2.common.dto.DtoConstants;
20  import org.kuali.student.r2.common.dto.DtoConstants.DtoState;
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 create/modify admin screens
28   * 
29   * @author Will
30   *
31   */
32  public class CourseAdminWithoutVersionController extends CourseAdminController{
33  		
34  	/**
35  	 * Override the intitailzeController method to use CourseAdminConfigurer 
36  	 */
37  	@Override
38  	protected void initializeController() {
39     		
40  		super.cfg = GWT.create(CourseAdminWithoutVersionConfigurer.class);
41  		
42  		//FIXME: This may not be what we want to do
43     		cfg.setState(DtoConstants.STATE_APPROVED.toUpperCase());
44     		cfg.setNextState(DtoConstants.STATE_ACTIVE.toUpperCase());
45     		super.setDefaultModelId(cfg.getModelId());
46     		super.registerModelsAndHandlers();
47     		super.addStyleName("ks-course-admin");  	   		   		
48      }
49  	
50  	/**
51  	 * Override the progressive enable fields to only allow edit of end term and retire fields when pilot box checked and course is not active
52  	 */
53  	@Override
54  	protected void progressiveEnableFields() {
55  		super.progressiveEnableFields();
56          final FieldDescriptor retireRationale = Application.getApplicationContext().getPathToFieldMapping(null,CreditCourseConstants.RETIREMENT_RATIONALE); 
57          final FieldDescriptor lastTermOffered = Application.getApplicationContext().getPathToFieldMapping(null,CreditCourseConstants.LAST_TERM_OFFERED);
58          final FieldDescriptor lastPublicationYear = Application.getApplicationContext().getPathToFieldMapping(null,CreditCourseConstants.LAST_PUBLICATION_YEAR);
59          final FieldDescriptor specialCircumstances = Application.getApplicationContext().getPathToFieldMapping(null,CreditCourseConstants.SPECIAL_CIRCUMSTANCES);
60          	
61  		String courseState = cluProposalModel.get(CreditCourseConstants.STATE);
62  		Boolean pilotValue = cluProposalModel.get(CreditCourseConstants.PILOT_COURSE);
63  		
64  		Boolean enableRetireFields = !DtoState.ACTIVE.equalsString(courseState) && (pilotValue == null || !pilotValue);
65  		
66  		BaseSection.progressiveEnableFields(enableRetireFields, retireRationale, lastTermOffered, lastPublicationYear, specialCircumstances);
67  	}
68  
69  	/**
70  	 * Override the getSaveButton to provide a new set of buttons for the admin screens
71  	 */
72  	@Override
73  	public KSButton getSaveButton(){
74  		KSButton saveButton =  new KSButton("Save", new ClickHandler(){
75              public void onClick(ClickEvent event) {
76              	handleButtonClick(DtoConstants.STATE_APPROVED);            	
77              }
78          });
79  		
80  		return saveButton;
81  	}
82  		
83  	
84  	public KSButton getCancelButton(){
85  		KSButton button = new KSButton("Cancel", new ClickHandler(){
86              public void onClick(ClickEvent event) {       
87              	Application.navigate(AppLocations.Locations.CURRICULUM_MANAGEMENT.getLocation());
88              }
89          });
90  	
91  		button.addStyleName("ks-button-spacing");
92  		return button;
93      }
94  	
95  	/**
96  	 * This processes the save or activate button clicks
97  	 * 
98  	 * @param state The state to set on the course when saving course data.
99  	 */
100 	protected void handleButtonClick(final String state){
101 		final SaveActionEvent saveActionEvent = new SaveActionEvent(false);
102 
103     	saveActionEvent.setActionCompleteCallback(new ActionCompleteCallback(){
104 			@Override
105 			public void onActionComplete(ActionEvent actionEvent) {
106 				if (saveActionEvent.isSaveSuccessful()){
107 	                final ViewContext viewContext = new ViewContext();
108 	                viewContext.setId((String)cluProposalModel.get(CreditCourseConstants.ID));
109 	                viewContext.setIdType(IdType.OBJECT_ID);											
110 					if (DtoConstants.STATE_ACTIVE.equalsIgnoreCase(state) || DtoConstants.STATE_APPROVED.equalsIgnoreCase(state)){
111 						KSNotifier.show("Course saved.");
112 						Application.navigate(AppLocations.Locations.VIEW_COURSE.getLocation(), viewContext);						
113 					}
114 				}      
115 			}
116     	});
117     	
118     	//Store the rules if save was called
119     	if((String)cluProposalModel.get(CreditCourseConstants.ID)!=null && cfg instanceof CourseAdminWithoutVersionConfigurer){
120     		((CourseAdminWithoutVersionConfigurer)cfg).getRequisitesSection().storeRules(new Callback<Boolean>(){
121     			public void exec(Boolean result) {
122 					if(result){
123 						CourseAdminWithoutVersionController.this.fireApplicationEvent(saveActionEvent); 
124 					}else{
125 						KSNotifier.show("Error saving rules.");
126 					}
127 				}
128     		});
129     	}else{
130     		CourseAdminWithoutVersionController.this.fireApplicationEvent(saveActionEvent);    		
131     	}
132 	}
133 	
134 	
135 	/**
136      * Override the setHeaderTitle to display proper header title for admin screens
137      */
138 	@Override
139 	protected void setHeaderTitle(){
140 		StringBuilder sb = new StringBuilder();
141 		sb.append("Modify: ");
142 		sb.append(cluProposalModel.get(cfg.getCourseTitlePath()));
143 		sb.append(" (Admin)");
144 				
145 		currentTitle = sb.toString();
146 		
147 		this.setContentTitle(currentTitle);
148     	this.setName(currentTitle);
149     	WindowTitleUtils.setContextTitle(currentTitle);		
150     }
151 	
152 	@Override
153 	protected Callback<Boolean> previousEndTermConfigurationCallback(Callback<Boolean> onReadyCallback) {
154 		//No need to display previous end term when modifying without version, just return original callback.
155 		return onReadyCallback;
156 	}
157 
158 	protected  BaseDataOrchestrationRpcServiceAsync getCourseProposalRpcService(){
159     	return courseServiceAsync;
160     }
161     	
162     public boolean startSectionRequired(){
163     	return false;
164     }
165 	@Override
166 	public boolean isAuthorizationRequired() {
167 		//FIXME: Need to add proper authorization checks for admin modify.
168 		return false;
169 	}
170 
171 }