1 |
35644
|
stefania.m
|
package eu.dnetlib.client.fundingrequest.newrequest.researcherstep;
|
2 |
35007
|
stefania.m
|
|
3 |
35292
|
stefania.m
|
import com.github.gwtbootstrap.client.ui.Alert;
|
4 |
36075
|
stefania.m
|
import com.github.gwtbootstrap.client.ui.Form;
|
5 |
|
|
import com.github.gwtbootstrap.client.ui.ListBox;
|
6 |
35292
|
stefania.m
|
import com.github.gwtbootstrap.client.ui.RadioButton;
|
7 |
|
|
import com.github.gwtbootstrap.client.ui.constants.AlertType;
|
8 |
36075
|
stefania.m
|
import com.github.gwtbootstrap.client.ui.constants.AlternateSize;
|
9 |
|
|
import com.github.gwtbootstrap.client.ui.constants.FormType;
|
10 |
36078
|
stefania.m
|
import com.google.gwt.core.client.GWT;
|
11 |
36079
|
stefania.m
|
import com.google.gwt.event.dom.client.ChangeEvent;
|
12 |
|
|
import com.google.gwt.event.dom.client.ChangeHandler;
|
13 |
35292
|
stefania.m
|
import com.google.gwt.event.logical.shared.ValueChangeEvent;
|
14 |
|
|
import com.google.gwt.event.logical.shared.ValueChangeHandler;
|
15 |
36078
|
stefania.m
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
16 |
36075
|
stefania.m
|
import com.google.gwt.user.client.ui.*;
|
17 |
46067
|
panagiotis
|
import eu.dnetlib.client.*;
|
18 |
36115
|
stefania.m
|
import eu.dnetlib.client.user.MyPersonalInfoWidget;
|
19 |
36078
|
stefania.m
|
import eu.dnetlib.client.fundingrequest.newrequest.EligibilityDisplayWidget;
|
20 |
|
|
import eu.dnetlib.client.fundingrequest.newrequest.EligibilityService;
|
21 |
|
|
import eu.dnetlib.client.fundingrequest.newrequest.EligibilityServiceAsync;
|
22 |
35644
|
stefania.m
|
import eu.dnetlib.client.fundingrequest.newrequest.FundingWizardStepWidget;
|
23 |
36075
|
stefania.m
|
import eu.dnetlib.client.widgets.FormFieldSet;
|
24 |
|
|
import eu.dnetlib.goldoa.domain.*;
|
25 |
35007
|
stefania.m
|
import eu.dnetlib.shared.FundingWizardState;
|
26 |
|
|
|
27 |
46067
|
panagiotis
|
import javax.xml.crypto.Data;
|
28 |
|
|
|
29 |
35007
|
stefania.m
|
/**
|
30 |
|
|
* Created by stefania on 2/25/15.
|
31 |
|
|
*/
|
32 |
|
|
public class ResearcherStepWidget extends FundingWizardStepWidget {
|
33 |
|
|
|
34 |
|
|
private FlowPanel researcherStepPanel = new FlowPanel();
|
35 |
35292
|
stefania.m
|
private Label researcherInfoLabel = new Label();
|
36 |
35007
|
stefania.m
|
|
37 |
35292
|
stefania.m
|
private Alert errorLabel = new Alert();
|
38 |
|
|
|
39 |
36078
|
stefania.m
|
private FlowPanel eligibilityPanel = new FlowPanel();
|
40 |
|
|
|
41 |
36075
|
stefania.m
|
private FlowPanel selectAffiliationPanel = new FlowPanel();
|
42 |
|
|
private Label institutionsFormLabel = new Label("Select an affiliation for this specific request");
|
43 |
|
|
private Form institutionsForm = new Form();
|
44 |
|
|
private ListBox institutions = new ListBox();
|
45 |
|
|
|
46 |
35292
|
stefania.m
|
private Label radioButtonLabel = new Label("Are you requesting funding for a researcher in your institution/project?");
|
47 |
|
|
private FlowPanel radioGroupPanel = new FlowPanel();
|
48 |
|
|
private RadioButton yesRadio = new RadioButton("researcherInfoRadioGroup", "yes", false);
|
49 |
|
|
private RadioButton noRadio = new RadioButton("researcherInfoRadioGroup", "no", false);
|
50 |
|
|
|
51 |
|
|
private FlowPanel researcherInfoPanel = new FlowPanel();
|
52 |
|
|
private ResearcherInfoForm researcherInfoForm = new ResearcherInfoForm();
|
53 |
|
|
|
54 |
35841
|
stefania.m
|
private HTML loadingWheel = new HTML("<div class=\"loader-big\"></div><div class=\"whiteFilm\"></div>");
|
55 |
|
|
|
56 |
45767
|
panagiotis
|
private User researcher = null;
|
57 |
35292
|
stefania.m
|
|
58 |
36078
|
stefania.m
|
private EligibilityServiceAsync eligibilityService = GWT.create(EligibilityService.class);
|
59 |
36946
|
stefania.m
|
private GoldOAConstants goldOAConstants = GWT.create(GoldOAConstants.class);
|
60 |
46067
|
panagiotis
|
private DataServiceAsync dataService = GWT.create(DataService.class);
|
61 |
36078
|
stefania.m
|
|
62 |
35347
|
stefania.m
|
private FundingWizardStepCompleteListener fundingWizardStepCompleteListener;
|
63 |
35292
|
stefania.m
|
|
64 |
35007
|
stefania.m
|
public ResearcherStepWidget(String title) {
|
65 |
35292
|
stefania.m
|
|
66 |
35007
|
stefania.m
|
super(title);
|
67 |
|
|
|
68 |
35700
|
stefania.m
|
researcherStepPanel.addStyleName("fundingWizardStep");
|
69 |
|
|
|
70 |
35292
|
stefania.m
|
errorLabel.addStyleName("alertLabel");
|
71 |
|
|
errorLabel.setType(AlertType.ERROR);
|
72 |
|
|
errorLabel.setVisible(false);
|
73 |
|
|
errorLabel.setClose(false);
|
74 |
|
|
|
75 |
|
|
researcherInfoLabel.addStyleName("stepWidgetLabel");
|
76 |
|
|
researcherInfoLabel.setText("Researcher Info");
|
77 |
|
|
|
78 |
36075
|
stefania.m
|
institutionsFormLabel.addStyleName("contentLabel");
|
79 |
|
|
|
80 |
|
|
institutionsForm.setType(FormType.HORIZONTAL);
|
81 |
|
|
for(Affiliation affiliation : GoldOAPortal.currentUser.getAffiliations()) {
|
82 |
45991
|
panagiotis
|
Organization organization = affiliation.getOrganization();
|
83 |
36075
|
stefania.m
|
if(organization!=null)
|
84 |
|
|
institutions.addItem(organization.getName(), organization.getId());
|
85 |
|
|
}
|
86 |
|
|
institutions.setAlternateSize(AlternateSize.XXLARGE);
|
87 |
|
|
institutions.setName("institution");
|
88 |
36079
|
stefania.m
|
institutions.addChangeHandler(new ChangeHandler() {
|
89 |
|
|
@Override
|
90 |
|
|
public void onChange(ChangeEvent changeEvent) {
|
91 |
|
|
|
92 |
|
|
Organization organization = new Organization();
|
93 |
|
|
organization.setId(institutions.getSelectedValue());
|
94 |
|
|
organization.setName(institutions.getSelectedItemText());
|
95 |
|
|
researcherInfoForm.setAffiliation(organization);
|
96 |
|
|
}
|
97 |
|
|
});
|
98 |
36075
|
stefania.m
|
institutionsForm.add(new FormFieldSet("Organization (*)", institutions));
|
99 |
|
|
|
100 |
|
|
selectAffiliationPanel.add(institutionsFormLabel);
|
101 |
|
|
selectAffiliationPanel.add(institutionsForm);
|
102 |
|
|
|
103 |
35292
|
stefania.m
|
radioButtonLabel.addStyleName("contentLabel");
|
104 |
|
|
|
105 |
|
|
radioGroupPanel.addStyleName("radioGroupPanel");
|
106 |
|
|
|
107 |
|
|
noRadio.addStyleName("inlineBlock");
|
108 |
|
|
yesRadio.addStyleName("inlineBlock");
|
109 |
|
|
yesRadio.setValue(true);
|
110 |
|
|
|
111 |
|
|
radioGroupPanel.add(yesRadio);
|
112 |
|
|
radioGroupPanel.add(noRadio);
|
113 |
|
|
|
114 |
|
|
yesRadio.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
|
115 |
|
|
@Override
|
116 |
|
|
public void onValueChange(ValueChangeEvent<Boolean> booleanValueChangeEvent) {
|
117 |
|
|
|
118 |
|
|
if(booleanValueChangeEvent.getValue()) {
|
119 |
35665
|
stefania.m
|
researcherInfoPanel.clear();
|
120 |
|
|
researcherInfoPanel.add(researcherInfoForm.asWidget());
|
121 |
35292
|
stefania.m
|
}
|
122 |
|
|
}
|
123 |
|
|
});
|
124 |
|
|
|
125 |
|
|
noRadio.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
|
126 |
|
|
@Override
|
127 |
|
|
public void onValueChange(ValueChangeEvent<Boolean> booleanValueChangeEvent) {
|
128 |
|
|
|
129 |
|
|
if(booleanValueChangeEvent.getValue()) {
|
130 |
35665
|
stefania.m
|
researcherInfoPanel.clear();
|
131 |
|
|
MyPersonalInfoWidget myPersonalInfoWidget = new MyPersonalInfoWidget();
|
132 |
|
|
researcherInfoPanel.add(myPersonalInfoWidget.asWidget());
|
133 |
35292
|
stefania.m
|
}
|
134 |
|
|
}
|
135 |
|
|
});
|
136 |
|
|
|
137 |
|
|
researcherInfoPanel.add(researcherInfoForm.asWidget());
|
138 |
|
|
|
139 |
|
|
ResearcherInfoForm.ResearcherFormListener researcherFormListener = new ResearcherInfoForm.ResearcherFormListener() {
|
140 |
|
|
|
141 |
|
|
@Override
|
142 |
45767
|
panagiotis
|
public void researcherSaved(User person, boolean saveSucceeded) {
|
143 |
35841
|
stefania.m
|
|
144 |
|
|
researcherStepPanel.removeStyleName("loading");
|
145 |
|
|
researcherStepPanel.remove(loadingWheel);
|
146 |
|
|
|
147 |
|
|
if(saveSucceeded) {
|
148 |
|
|
researcher = person;
|
149 |
|
|
if (fundingWizardStepCompleteListener != null) {
|
150 |
|
|
fundingWizardStepCompleteListener.setStepComplete(true);
|
151 |
|
|
}
|
152 |
35292
|
stefania.m
|
}
|
153 |
|
|
}
|
154 |
|
|
};
|
155 |
|
|
researcherInfoForm.setResearcherFormListener(researcherFormListener);
|
156 |
35510
|
stefania.m
|
|
157 |
35730
|
stefania.m
|
loadContent(new FundingWizardState());
|
158 |
35007
|
stefania.m
|
}
|
159 |
|
|
|
160 |
|
|
@Override
|
161 |
|
|
public void updateState(FundingWizardState fundingWizardState) {
|
162 |
|
|
|
163 |
46067
|
panagiotis
|
final Request request = fundingWizardState.getRequest();
|
164 |
35640
|
stefania.m
|
if(researcher !=null) {
|
165 |
45767
|
panagiotis
|
request.setResearcher(researcher);
|
166 |
35640
|
stefania.m
|
fundingWizardState.setResearcher(researcher);
|
167 |
|
|
}
|
168 |
|
|
else {
|
169 |
45767
|
panagiotis
|
request.setResearcher(GoldOAPortal.currentUser);
|
170 |
35640
|
stefania.m
|
fundingWizardState.setResearcher(GoldOAPortal.currentUser);
|
171 |
|
|
}
|
172 |
36075
|
stefania.m
|
|
173 |
44668
|
stefania.m
|
if(Utils.currentUserHasRoleApproved("moderator")) {
|
174 |
|
|
|
175 |
45991
|
panagiotis
|
request.setOrganization(researcher.getAffiliations().get(0).getOrganization());
|
176 |
44668
|
stefania.m
|
|
177 |
36432
|
stefania.m
|
} else {
|
178 |
44668
|
stefania.m
|
|
179 |
|
|
if (!GoldOAPortal.currentUser.getAffiliations().isEmpty()) {
|
180 |
46067
|
panagiotis
|
dataService.getOrganization(institutions.getSelectedValue(), new AsyncCallback<Organization>() {
|
181 |
|
|
@Override
|
182 |
|
|
public void onFailure(Throwable throwable) {
|
183 |
|
|
|
184 |
|
|
}
|
185 |
|
|
|
186 |
|
|
@Override
|
187 |
|
|
public void onSuccess(Organization organization) {
|
188 |
|
|
request.setOrganization(organization);
|
189 |
|
|
}
|
190 |
|
|
});
|
191 |
|
|
|
192 |
|
|
|
193 |
44668
|
stefania.m
|
} else {
|
194 |
45991
|
panagiotis
|
request.setOrganization(researcher.getAffiliations().get(0).getOrganization());
|
195 |
44668
|
stefania.m
|
}
|
196 |
36432
|
stefania.m
|
}
|
197 |
|
|
|
198 |
35007
|
stefania.m
|
}
|
199 |
|
|
|
200 |
|
|
@Override
|
201 |
35347
|
stefania.m
|
public void save() {
|
202 |
|
|
|
203 |
36230
|
stefania.m
|
if(Utils.currentUserHasRoleApproved("library_staff") || Utils.currentUserHasRoleApproved("moderator") || Utils.currentUserHasRoleApproved("publisher")
|
204 |
|
|
|| Utils.currentUserHasRoleApproved("accounting") || Utils.currentUserHasRoleApproved("administrator") || Utils.currentUserHasRoleApproved("project_coordinator")) {
|
205 |
35510
|
stefania.m
|
|
206 |
36230
|
stefania.m
|
if(Utils.currentUserHasRoleApproved("researcher")) {
|
207 |
35510
|
stefania.m
|
if(noRadio.getValue()) {
|
208 |
|
|
if(fundingWizardStepCompleteListener!=null)
|
209 |
|
|
fundingWizardStepCompleteListener.setStepComplete(true);
|
210 |
|
|
} else {
|
211 |
35841
|
stefania.m
|
|
212 |
|
|
researcherStepPanel.addStyleName("loading");
|
213 |
|
|
researcherStepPanel.add(loadingWheel);
|
214 |
|
|
|
215 |
35510
|
stefania.m
|
researcherInfoForm.saveResearcherInfo();
|
216 |
|
|
}
|
217 |
|
|
} else {
|
218 |
35841
|
stefania.m
|
|
219 |
|
|
researcherStepPanel.addStyleName("loading");
|
220 |
|
|
researcherStepPanel.add(loadingWheel);
|
221 |
|
|
|
222 |
35510
|
stefania.m
|
researcherInfoForm.saveResearcherInfo();
|
223 |
|
|
}
|
224 |
36230
|
stefania.m
|
} else if(Utils.currentUserHasRoleApproved("researcher")) {
|
225 |
36078
|
stefania.m
|
|
226 |
46067
|
panagiotis
|
final Request request = new Request();
|
227 |
|
|
|
228 |
|
|
dataService.getOrganization(institutions.getSelectedValue(), new AsyncCallback<Organization>() {
|
229 |
|
|
@Override
|
230 |
|
|
public void onFailure(Throwable throwable) {
|
231 |
|
|
|
232 |
|
|
}
|
233 |
|
|
|
234 |
|
|
@Override
|
235 |
|
|
public void onSuccess(Organization organization) {
|
236 |
|
|
request.setOrganization(organization);
|
237 |
|
|
}
|
238 |
|
|
});
|
239 |
|
|
|
240 |
|
|
|
241 |
36078
|
stefania.m
|
eligibilityService.validate(request, new AsyncCallback<Eligibility>() {
|
242 |
|
|
|
243 |
|
|
@Override
|
244 |
|
|
public void onFailure(Throwable throwable) {
|
245 |
|
|
eligibilityPanel.clear();
|
246 |
|
|
EligibilityDisplayWidget eligibilityDisplayWidget = new EligibilityDisplayWidget(null);
|
247 |
|
|
eligibilityPanel.add(eligibilityDisplayWidget.asWidget());
|
248 |
|
|
}
|
249 |
|
|
|
250 |
|
|
@Override
|
251 |
|
|
public void onSuccess(Eligibility eligibility) {
|
252 |
|
|
|
253 |
|
|
if(eligibility.getStatus().equals(Eligibility.Status.NONO)) {
|
254 |
|
|
eligibilityPanel.clear();
|
255 |
|
|
EligibilityDisplayWidget eligibilityDisplayWidget = new EligibilityDisplayWidget(eligibility);
|
256 |
|
|
eligibilityPanel.add(eligibilityDisplayWidget.asWidget());
|
257 |
|
|
} else {
|
258 |
|
|
if (fundingWizardStepCompleteListener != null)
|
259 |
|
|
fundingWizardStepCompleteListener.setStepComplete(true);
|
260 |
|
|
}
|
261 |
|
|
}
|
262 |
|
|
});
|
263 |
|
|
|
264 |
35347
|
stefania.m
|
} else {
|
265 |
36946
|
stefania.m
|
errorLabel.setText(goldOAConstants.researcherStepErrorUserNotYetAuthorized());
|
266 |
35510
|
stefania.m
|
errorLabel.setVisible(true);
|
267 |
35347
|
stefania.m
|
}
|
268 |
|
|
}
|
269 |
|
|
|
270 |
|
|
@Override
|
271 |
35700
|
stefania.m
|
public void clear() {
|
272 |
|
|
|
273 |
35730
|
stefania.m
|
researcherStepPanel.clear();
|
274 |
|
|
errorLabel.setVisible(false);
|
275 |
35700
|
stefania.m
|
}
|
276 |
|
|
|
277 |
|
|
@Override
|
278 |
35515
|
stefania.m
|
public void loadContent(FundingWizardState fundingWizardState) {
|
279 |
|
|
|
280 |
35730
|
stefania.m
|
researcherStepPanel.add(researcherInfoLabel);
|
281 |
|
|
researcherStepPanel.add(errorLabel);
|
282 |
36078
|
stefania.m
|
researcherStepPanel.add(eligibilityPanel);
|
283 |
35730
|
stefania.m
|
|
284 |
36075
|
stefania.m
|
if(GoldOAPortal.currentUser.getAffiliations().size()>1)
|
285 |
|
|
researcherStepPanel.add(selectAffiliationPanel);
|
286 |
|
|
|
287 |
36230
|
stefania.m
|
if(Utils.currentUserHasRoleApproved("library_staff") || Utils.currentUserHasRoleApproved("moderator") || Utils.currentUserHasRoleApproved("publisher")
|
288 |
|
|
|| Utils.currentUserHasRoleApproved("accounting") || Utils.currentUserHasRoleApproved("administrator") || Utils.currentUserHasRoleApproved("project_coordinator")) {
|
289 |
35730
|
stefania.m
|
|
290 |
36230
|
stefania.m
|
if(Utils.currentUserHasRoleApproved("researcher")) {
|
291 |
35730
|
stefania.m
|
researcherStepPanel.add(radioButtonLabel);
|
292 |
|
|
researcherStepPanel.add(radioGroupPanel);
|
293 |
|
|
researcherStepPanel.add(researcherInfoPanel);
|
294 |
|
|
} else {
|
295 |
|
|
researcherStepPanel.add(researcherInfoPanel);
|
296 |
|
|
}
|
297 |
|
|
|
298 |
36432
|
stefania.m
|
if(!GoldOAPortal.currentUser.getAffiliations().isEmpty()) {
|
299 |
|
|
Organization organization = new Organization();
|
300 |
|
|
organization.setId(institutions.getSelectedValue());
|
301 |
|
|
organization.setName(institutions.getSelectedItemText());
|
302 |
|
|
researcherInfoForm.setAffiliation(organization);
|
303 |
|
|
}
|
304 |
36079
|
stefania.m
|
|
305 |
36230
|
stefania.m
|
} else if(Utils.currentUserHasRoleApproved("researcher")) {
|
306 |
35730
|
stefania.m
|
|
307 |
|
|
MyPersonalInfoWidget myPersonalInfoWidget = new MyPersonalInfoWidget();
|
308 |
|
|
researcherStepPanel.add(myPersonalInfoWidget.asWidget());
|
309 |
|
|
|
310 |
|
|
} else {
|
311 |
36946
|
stefania.m
|
errorLabel.setText(goldOAConstants.researcherStepErrorUserNotYetAuthorized());
|
312 |
35730
|
stefania.m
|
errorLabel.setVisible(true);
|
313 |
|
|
}
|
314 |
|
|
|
315 |
|
|
if(fundingWizardState.getResearcher()!=null && fundingWizardState.getRequest()!=null
|
316 |
|
|
&& fundingWizardState.getRequest().getUser()!=null) {
|
317 |
|
|
|
318 |
45767
|
panagiotis
|
User researcher = fundingWizardState.getResearcher();
|
319 |
|
|
String userId = fundingWizardState.getRequest().getUser().getId();
|
320 |
35752
|
stefania.m
|
if(researcher.getId().equals(userId)) {
|
321 |
35730
|
stefania.m
|
|
322 |
|
|
noRadio.setValue(true, true);
|
323 |
|
|
|
324 |
|
|
} else {
|
325 |
|
|
|
326 |
|
|
researcherInfoForm.loadResearcher(researcher);
|
327 |
|
|
}
|
328 |
|
|
}
|
329 |
35515
|
stefania.m
|
}
|
330 |
|
|
|
331 |
|
|
@Override
|
332 |
35292
|
stefania.m
|
public void setFundingWizardStepCompleteListener(FundingWizardStepCompleteListener fundingWizardStepCompleteListener) {
|
333 |
|
|
this.fundingWizardStepCompleteListener = fundingWizardStepCompleteListener;
|
334 |
|
|
}
|
335 |
|
|
|
336 |
|
|
@Override
|
337 |
35660
|
stefania.m
|
public void setFundingWizardJumpToStepListener(FundingWizardJumpToStepListener fundingWizardJumpToStepListener) {
|
338 |
|
|
|
339 |
|
|
}
|
340 |
|
|
|
341 |
|
|
@Override
|
342 |
35007
|
stefania.m
|
public Widget asWidget() {
|
343 |
|
|
return researcherStepPanel;
|
344 |
|
|
}
|
345 |
35510
|
stefania.m
|
|
346 |
35007
|
stefania.m
|
}
|