1 | |
package org.kuali.student.lum.program.client.credential.view; |
2 | |
|
3 | |
import org.kuali.student.common.rice.authorization.PermissionType; |
4 | |
import org.kuali.student.common.ui.client.application.Application; |
5 | |
import org.kuali.student.common.ui.client.application.KSAsyncCallback; |
6 | |
import org.kuali.student.common.ui.client.application.ViewContext; |
7 | |
import org.kuali.student.common.ui.client.mvc.Callback; |
8 | |
import org.kuali.student.common.ui.client.mvc.DataModel; |
9 | |
import org.kuali.student.common.ui.client.mvc.history.HistoryManager; |
10 | |
import org.kuali.student.common.ui.client.security.AuthorizationCallback; |
11 | |
import org.kuali.student.common.ui.client.security.RequiresAuthorization; |
12 | |
import org.kuali.student.common.ui.shared.IdAttributes.IdType; |
13 | |
import org.kuali.student.lum.common.client.lu.LUUIPermissions; |
14 | |
import org.kuali.student.lum.common.client.widgets.AppLocations; |
15 | |
import org.kuali.student.lum.common.client.widgets.DropdownList; |
16 | |
import org.kuali.student.lum.program.client.ProgramConstants; |
17 | |
import org.kuali.student.lum.program.client.ProgramRegistry; |
18 | |
import org.kuali.student.lum.program.client.ProgramSections; |
19 | |
import org.kuali.student.lum.program.client.ProgramStatus; |
20 | |
import org.kuali.student.lum.program.client.credential.CredentialController; |
21 | |
import org.kuali.student.lum.program.client.events.ModelLoadedEvent; |
22 | |
import org.kuali.student.lum.program.client.events.ProgramViewEvent; |
23 | |
import org.kuali.student.lum.program.client.major.ActionType; |
24 | |
|
25 | |
import com.google.gwt.core.client.GWT; |
26 | |
import com.google.gwt.event.dom.client.ChangeEvent; |
27 | |
import com.google.gwt.event.dom.client.ChangeHandler; |
28 | |
import com.google.gwt.event.shared.HandlerManager; |
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | 0 | public class CredentialViewController extends CredentialController implements RequiresAuthorization{ |
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | 0 | private final DropdownList actionBox = new DropdownList(ActionType.getValuesForCredentialProgram(false)); |
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
public CredentialViewController(DataModel programModel, ViewContext viewContext, HandlerManager eventBus) { |
47 | 0 | super(programModel, viewContext, eventBus); |
48 | 0 | configurer = GWT.create(CredentialViewConfigurer.class); |
49 | 0 | bind(); |
50 | 0 | } |
51 | |
|
52 | |
private void bind() { |
53 | 0 | actionBox.addChangeHandler(new ChangeHandler() { |
54 | |
@Override |
55 | |
public void onChange(ChangeEvent event) { |
56 | 0 | ActionType actionType = ActionType.of(actionBox.getSelectedValue()); |
57 | 0 | ViewContext viewContext = getViewContext(); |
58 | 0 | if (actionType == ActionType.MODIFY) { |
59 | 0 | ProgramRegistry.setSection(ProgramSections.getEditSection(getCurrentViewEnum())); |
60 | 0 | HistoryManager.navigate(AppLocations.Locations.EDIT_BACC_PROGRAM.getLocation(), getViewContext()); |
61 | 0 | } else if (actionType == ActionType.MODIFY_VERSION) { |
62 | 0 | String versionIndId = getStringProperty(ProgramConstants.VERSION_IND_ID); |
63 | 0 | viewContext.setId(versionIndId); |
64 | 0 | viewContext.setIdType(IdType.COPY_OF_OBJECT_ID); |
65 | 0 | HistoryManager.navigate(AppLocations.Locations.EDIT_BACC_PROGRAM.getLocation(), viewContext); |
66 | |
} |
67 | 0 | } |
68 | |
}); |
69 | 0 | eventBus.addHandler(ProgramViewEvent.TYPE, new ProgramViewEvent.Handler() { |
70 | |
@Override |
71 | |
public void onEvent(ProgramViewEvent event) { |
72 | 0 | actionBox.setSelectedIndex(0); |
73 | 0 | } |
74 | |
}); |
75 | 0 | eventBus.addHandler(ModelLoadedEvent.TYPE, new ModelLoadedEvent.Handler() { |
76 | |
@Override |
77 | |
public void onEvent(ModelLoadedEvent event) { |
78 | 0 | resetActionList(); |
79 | 0 | } |
80 | |
}); |
81 | 0 | } |
82 | |
|
83 | |
@Override |
84 | |
protected void configureView() { |
85 | 0 | super.configureView(); |
86 | 0 | addContentWidget(actionBox); |
87 | 0 | initialized = true; |
88 | 0 | } |
89 | |
|
90 | |
protected void resetActionList() { |
91 | |
|
92 | 0 | ProgramStatus status = ProgramStatus.of(programModel); |
93 | 0 | String versionIndId = getStringProperty(ProgramConstants.VERSION_IND_ID); |
94 | 0 | Long sequenceNumber = programModel.get(ProgramConstants.VERSION_SEQUENCE_NUMBER); |
95 | |
|
96 | 0 | actionBox.clear(); |
97 | 0 | if (status == ProgramStatus.ACTIVE) { |
98 | 0 | programRemoteService.isLatestVersion(versionIndId, sequenceNumber, new KSAsyncCallback<Boolean>() { |
99 | |
public void onSuccess(Boolean isLatest) { |
100 | 0 | actionBox.setList(ActionType.getValuesForCredentialProgram(isLatest)); |
101 | 0 | } |
102 | |
}); |
103 | |
} else { |
104 | 0 | actionBox.setList(ActionType.getValuesForCredentialProgram(false)); |
105 | |
} |
106 | 0 | } |
107 | |
|
108 | |
@Override |
109 | |
public boolean isAuthorizationRequired() { |
110 | 0 | return true; |
111 | |
} |
112 | |
|
113 | |
@Override |
114 | |
public void setAuthorizationRequired(boolean required) { |
115 | 0 | throw new UnsupportedOperationException(); |
116 | |
} |
117 | |
|
118 | |
@Override |
119 | |
public void checkAuthorization(final AuthorizationCallback authCallback) { |
120 | 0 | Application.getApplicationContext().getSecurityContext().checkScreenPermission(LUUIPermissions.USE_VIEW_CREDENTIAL_PROGRAMS_SCREEN, new Callback<Boolean>() { |
121 | |
@Override |
122 | |
public void exec(Boolean result) { |
123 | |
|
124 | 0 | final boolean isAuthorized = result; |
125 | |
|
126 | 0 | if(isAuthorized){ |
127 | 0 | authCallback.isAuthorized(); |
128 | |
} |
129 | |
else |
130 | 0 | authCallback.isNotAuthorized("User is not authorized: " + LUUIPermissions.USE_VIEW_CREDENTIAL_PROGRAMS_SCREEN); |
131 | 0 | } |
132 | |
}); |
133 | 0 | } |
134 | |
} |