1
|
package eu.dnetlib.client.fundingrequest.newrequest.researcherstep;
|
2
|
|
3
|
import com.github.gwtbootstrap.client.ui.Alert;
|
4
|
import com.github.gwtbootstrap.client.ui.Form;
|
5
|
import com.github.gwtbootstrap.client.ui.ListBox;
|
6
|
import com.github.gwtbootstrap.client.ui.RadioButton;
|
7
|
import com.github.gwtbootstrap.client.ui.constants.AlertType;
|
8
|
import com.github.gwtbootstrap.client.ui.constants.AlternateSize;
|
9
|
import com.github.gwtbootstrap.client.ui.constants.FormType;
|
10
|
import com.google.gwt.core.client.GWT;
|
11
|
import com.google.gwt.event.dom.client.ChangeEvent;
|
12
|
import com.google.gwt.event.dom.client.ChangeHandler;
|
13
|
import com.google.gwt.event.logical.shared.ValueChangeEvent;
|
14
|
import com.google.gwt.event.logical.shared.ValueChangeHandler;
|
15
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
16
|
import com.google.gwt.user.client.ui.*;
|
17
|
import eu.dnetlib.client.*;
|
18
|
import eu.dnetlib.client.user.MyPersonalInfoWidget;
|
19
|
import eu.dnetlib.client.fundingrequest.newrequest.EligibilityDisplayWidget;
|
20
|
import eu.dnetlib.client.fundingrequest.newrequest.EligibilityService;
|
21
|
import eu.dnetlib.client.fundingrequest.newrequest.EligibilityServiceAsync;
|
22
|
import eu.dnetlib.client.fundingrequest.newrequest.FundingWizardStepWidget;
|
23
|
import eu.dnetlib.client.widgets.FormFieldSet;
|
24
|
import eu.dnetlib.goldoa.domain.*;
|
25
|
import eu.dnetlib.shared.FundingWizardState;
|
26
|
|
27
|
import javax.xml.crypto.Data;
|
28
|
|
29
|
/**
|
30
|
* Created by stefania on 2/25/15.
|
31
|
*/
|
32
|
public class ResearcherStepWidget extends FundingWizardStepWidget {
|
33
|
|
34
|
private FlowPanel researcherStepPanel = new FlowPanel();
|
35
|
private Label researcherInfoLabel = new Label();
|
36
|
|
37
|
private Alert errorLabel = new Alert();
|
38
|
|
39
|
private FlowPanel eligibilityPanel = new FlowPanel();
|
40
|
|
41
|
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
|
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
|
private HTML loadingWheel = new HTML("<div class=\"loader-big\"></div><div class=\"whiteFilm\"></div>");
|
55
|
|
56
|
private User researcher = null;
|
57
|
|
58
|
private EligibilityServiceAsync eligibilityService = GWT.create(EligibilityService.class);
|
59
|
private GoldOAConstants goldOAConstants = GWT.create(GoldOAConstants.class);
|
60
|
private DataServiceAsync dataService = GWT.create(DataService.class);
|
61
|
|
62
|
private FundingWizardStepCompleteListener fundingWizardStepCompleteListener;
|
63
|
|
64
|
public ResearcherStepWidget(String title) {
|
65
|
|
66
|
super(title);
|
67
|
|
68
|
researcherStepPanel.addStyleName("fundingWizardStep");
|
69
|
|
70
|
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
|
institutionsFormLabel.addStyleName("contentLabel");
|
79
|
|
80
|
institutionsForm.setType(FormType.HORIZONTAL);
|
81
|
for(Affiliation affiliation : GoldOAPortal.currentUser.getAffiliations()) {
|
82
|
Organization organization = affiliation.getOrganization();
|
83
|
if(organization!=null)
|
84
|
institutions.addItem(organization.getName(), organization.getId());
|
85
|
}
|
86
|
institutions.setAlternateSize(AlternateSize.XXLARGE);
|
87
|
institutions.setName("institution");
|
88
|
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
|
institutionsForm.add(new FormFieldSet("Organization (*)", institutions));
|
99
|
|
100
|
selectAffiliationPanel.add(institutionsFormLabel);
|
101
|
selectAffiliationPanel.add(institutionsForm);
|
102
|
|
103
|
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
|
researcherInfoPanel.clear();
|
120
|
researcherInfoPanel.add(researcherInfoForm.asWidget());
|
121
|
}
|
122
|
}
|
123
|
});
|
124
|
|
125
|
noRadio.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
|
126
|
@Override
|
127
|
public void onValueChange(ValueChangeEvent<Boolean> booleanValueChangeEvent) {
|
128
|
|
129
|
if(booleanValueChangeEvent.getValue()) {
|
130
|
researcherInfoPanel.clear();
|
131
|
MyPersonalInfoWidget myPersonalInfoWidget = new MyPersonalInfoWidget();
|
132
|
researcherInfoPanel.add(myPersonalInfoWidget.asWidget());
|
133
|
}
|
134
|
}
|
135
|
});
|
136
|
|
137
|
researcherInfoPanel.add(researcherInfoForm.asWidget());
|
138
|
|
139
|
ResearcherInfoForm.ResearcherFormListener researcherFormListener = new ResearcherInfoForm.ResearcherFormListener() {
|
140
|
|
141
|
@Override
|
142
|
public void researcherSaved(User person, boolean saveSucceeded) {
|
143
|
|
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
|
}
|
153
|
}
|
154
|
};
|
155
|
researcherInfoForm.setResearcherFormListener(researcherFormListener);
|
156
|
|
157
|
loadContent(new FundingWizardState());
|
158
|
}
|
159
|
|
160
|
@Override
|
161
|
public void updateState(FundingWizardState fundingWizardState) {
|
162
|
|
163
|
final Request request = fundingWizardState.getRequest();
|
164
|
if(researcher !=null) {
|
165
|
request.setResearcher(researcher);
|
166
|
fundingWizardState.setResearcher(researcher);
|
167
|
}
|
168
|
else {
|
169
|
request.setResearcher(GoldOAPortal.currentUser);
|
170
|
fundingWizardState.setResearcher(GoldOAPortal.currentUser);
|
171
|
}
|
172
|
|
173
|
if(Utils.currentUserHasRoleApproved("moderator")) {
|
174
|
|
175
|
request.setOrganization(researcher.getAffiliations().get(0).getOrganization());
|
176
|
|
177
|
} else {
|
178
|
|
179
|
if (!GoldOAPortal.currentUser.getAffiliations().isEmpty()) {
|
180
|
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
|
} else {
|
194
|
request.setOrganization(researcher.getAffiliations().get(0).getOrganization());
|
195
|
}
|
196
|
}
|
197
|
|
198
|
}
|
199
|
|
200
|
@Override
|
201
|
public void save() {
|
202
|
|
203
|
if(Utils.currentUserHasRoleApproved("library_staff") || Utils.currentUserHasRoleApproved("moderator") || Utils.currentUserHasRoleApproved("publisher")
|
204
|
|| Utils.currentUserHasRoleApproved("accounting") || Utils.currentUserHasRoleApproved("administrator") || Utils.currentUserHasRoleApproved("project_coordinator")) {
|
205
|
|
206
|
if(Utils.currentUserHasRoleApproved("researcher")) {
|
207
|
if(noRadio.getValue()) {
|
208
|
if(fundingWizardStepCompleteListener!=null)
|
209
|
fundingWizardStepCompleteListener.setStepComplete(true);
|
210
|
} else {
|
211
|
|
212
|
researcherStepPanel.addStyleName("loading");
|
213
|
researcherStepPanel.add(loadingWheel);
|
214
|
|
215
|
researcherInfoForm.saveResearcherInfo();
|
216
|
}
|
217
|
} else {
|
218
|
|
219
|
researcherStepPanel.addStyleName("loading");
|
220
|
researcherStepPanel.add(loadingWheel);
|
221
|
|
222
|
researcherInfoForm.saveResearcherInfo();
|
223
|
}
|
224
|
} else if(Utils.currentUserHasRoleApproved("researcher")) {
|
225
|
|
226
|
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
|
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
|
} else {
|
265
|
errorLabel.setText(goldOAConstants.researcherStepErrorUserNotYetAuthorized());
|
266
|
errorLabel.setVisible(true);
|
267
|
}
|
268
|
}
|
269
|
|
270
|
@Override
|
271
|
public void clear() {
|
272
|
|
273
|
researcherStepPanel.clear();
|
274
|
errorLabel.setVisible(false);
|
275
|
}
|
276
|
|
277
|
@Override
|
278
|
public void loadContent(FundingWizardState fundingWizardState) {
|
279
|
|
280
|
researcherStepPanel.add(researcherInfoLabel);
|
281
|
researcherStepPanel.add(errorLabel);
|
282
|
researcherStepPanel.add(eligibilityPanel);
|
283
|
|
284
|
if(GoldOAPortal.currentUser.getAffiliations().size()>1)
|
285
|
researcherStepPanel.add(selectAffiliationPanel);
|
286
|
|
287
|
if(Utils.currentUserHasRoleApproved("library_staff") || Utils.currentUserHasRoleApproved("moderator") || Utils.currentUserHasRoleApproved("publisher")
|
288
|
|| Utils.currentUserHasRoleApproved("accounting") || Utils.currentUserHasRoleApproved("administrator") || Utils.currentUserHasRoleApproved("project_coordinator")) {
|
289
|
|
290
|
if(Utils.currentUserHasRoleApproved("researcher")) {
|
291
|
researcherStepPanel.add(radioButtonLabel);
|
292
|
researcherStepPanel.add(radioGroupPanel);
|
293
|
researcherStepPanel.add(researcherInfoPanel);
|
294
|
} else {
|
295
|
researcherStepPanel.add(researcherInfoPanel);
|
296
|
}
|
297
|
|
298
|
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
|
|
305
|
} else if(Utils.currentUserHasRoleApproved("researcher")) {
|
306
|
|
307
|
MyPersonalInfoWidget myPersonalInfoWidget = new MyPersonalInfoWidget();
|
308
|
researcherStepPanel.add(myPersonalInfoWidget.asWidget());
|
309
|
|
310
|
} else {
|
311
|
errorLabel.setText(goldOAConstants.researcherStepErrorUserNotYetAuthorized());
|
312
|
errorLabel.setVisible(true);
|
313
|
}
|
314
|
|
315
|
if(fundingWizardState.getResearcher()!=null && fundingWizardState.getRequest()!=null
|
316
|
&& fundingWizardState.getRequest().getUser()!=null) {
|
317
|
|
318
|
User researcher = fundingWizardState.getResearcher();
|
319
|
String userId = fundingWizardState.getRequest().getUser().getId();
|
320
|
if(researcher.getId().equals(userId)) {
|
321
|
|
322
|
noRadio.setValue(true, true);
|
323
|
|
324
|
} else {
|
325
|
|
326
|
researcherInfoForm.loadResearcher(researcher);
|
327
|
}
|
328
|
}
|
329
|
}
|
330
|
|
331
|
@Override
|
332
|
public void setFundingWizardStepCompleteListener(FundingWizardStepCompleteListener fundingWizardStepCompleteListener) {
|
333
|
this.fundingWizardStepCompleteListener = fundingWizardStepCompleteListener;
|
334
|
}
|
335
|
|
336
|
@Override
|
337
|
public void setFundingWizardJumpToStepListener(FundingWizardJumpToStepListener fundingWizardJumpToStepListener) {
|
338
|
|
339
|
}
|
340
|
|
341
|
@Override
|
342
|
public Widget asWidget() {
|
343
|
return researcherStepPanel;
|
344
|
}
|
345
|
|
346
|
}
|