1
|
package eu.dnetlib.client.support;
|
2
|
|
3
|
import com.github.gwtbootstrap.client.ui.Alert;
|
4
|
import com.github.gwtbootstrap.client.ui.Form;
|
5
|
import com.github.gwtbootstrap.client.ui.constants.AlertType;
|
6
|
import com.github.gwtbootstrap.client.ui.constants.FormType;
|
7
|
import com.google.gwt.core.client.GWT;
|
8
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
9
|
import com.google.gwt.user.client.ui.FlowPanel;
|
10
|
import com.google.gwt.user.client.ui.HTML;
|
11
|
import com.google.gwt.user.client.ui.Label;
|
12
|
import com.google.gwt.user.client.ui.Widget;
|
13
|
import eu.dnetlib.client.*;
|
14
|
import eu.dnetlib.client.user.EligibleProjectsInfoWidget;
|
15
|
import eu.dnetlib.client.widgets.AutoCompleteWidget;
|
16
|
import eu.dnetlib.client.widgets.FormFieldSet;
|
17
|
import eu.dnetlib.goldoa.domain.Vocabulary;
|
18
|
import eu.dnetlib.shared.EligiblePresentAndFutureProjects;
|
19
|
|
20
|
/**
|
21
|
* Created by stefania on 5/4/15.
|
22
|
*/
|
23
|
public class EligibleProjectsWidget implements MyWidget {
|
24
|
|
25
|
private String token = "";
|
26
|
|
27
|
private FlowPanel eligibleProjectsPagePanel = new FlowPanel();
|
28
|
private Label eligibleProjectsTitleLabel = new Label();
|
29
|
private Label eligibleProjectsInfoLabel = new Label();
|
30
|
|
31
|
private Form institutionsForm = new Form();
|
32
|
private AutoCompleteWidget organizationAutoComplete = new AutoCompleteWidget("organisation", "Search...");
|
33
|
private Label commentLabel = new Label();
|
34
|
|
35
|
private Alert errorLabel = new Alert();
|
36
|
|
37
|
private FlowPanel eligibleProjectListPanel = new FlowPanel();
|
38
|
|
39
|
private DataServiceAsync dataService = GWT.create(DataService.class);
|
40
|
private GoldOAConstants goldOAConstants = GWT.create(GoldOAConstants.class);
|
41
|
|
42
|
public EligibleProjectsWidget() {
|
43
|
|
44
|
eligibleProjectsPagePanel.addStyleName("content");
|
45
|
eligibleProjectsPagePanel.addStyleName("eligibleProjectsPage");
|
46
|
|
47
|
eligibleProjectsTitleLabel.setText("Eligible Projects");
|
48
|
eligibleProjectsTitleLabel.addStyleName("contentTitleLabel");
|
49
|
|
50
|
eligibleProjectsInfoLabel.setText("Find the eligible projects by organization ");
|
51
|
eligibleProjectsInfoLabel.addStyleName("contentInfoLabel");
|
52
|
|
53
|
institutionsForm.setType(FormType.HORIZONTAL);
|
54
|
|
55
|
AutoCompleteWidget.AutoCompleteListener organizationAutoCompleteListener = new AutoCompleteWidget.AutoCompleteListener() {
|
56
|
@Override
|
57
|
public void valueSelected(Vocabulary vocabulary) {
|
58
|
|
59
|
getEligibleProjects(vocabulary.getId());
|
60
|
}
|
61
|
};
|
62
|
organizationAutoComplete.setAutoCompleteListener(organizationAutoCompleteListener);
|
63
|
|
64
|
commentLabel.setText("Search using the name as it appears in CORDA");
|
65
|
commentLabel.addStyleName("comment");
|
66
|
commentLabel.addStyleName("fontItalic");
|
67
|
|
68
|
institutionsForm.add(new FormFieldSet("Organization", organizationAutoComplete.asWidget(), commentLabel));
|
69
|
|
70
|
errorLabel.addStyleName("alertLabel");
|
71
|
errorLabel.setType(AlertType.ERROR);
|
72
|
errorLabel.setVisible(false);
|
73
|
errorLabel.setClose(false);
|
74
|
|
75
|
eligibleProjectsPagePanel.add(eligibleProjectsTitleLabel);
|
76
|
eligibleProjectsPagePanel.add(eligibleProjectsInfoLabel);
|
77
|
eligibleProjectsPagePanel.add(institutionsForm);
|
78
|
eligibleProjectsPagePanel.add(errorLabel);
|
79
|
eligibleProjectsPagePanel.add(eligibleProjectListPanel);
|
80
|
}
|
81
|
|
82
|
@Override
|
83
|
public Widget asWidget() {
|
84
|
return eligibleProjectsPagePanel;
|
85
|
}
|
86
|
|
87
|
@Override
|
88
|
public void clear() {
|
89
|
|
90
|
errorLabel.setVisible(false);
|
91
|
eligibleProjectListPanel.clear();
|
92
|
organizationAutoComplete.setValue("");
|
93
|
}
|
94
|
|
95
|
@Override
|
96
|
public void reload() {
|
97
|
|
98
|
MyWidgetHelper.hideSidebar();
|
99
|
|
100
|
SidebarPanel helpPanel = new SidebarPanel("Help");
|
101
|
MyWidgetHelper.loadHelp(helpPanel, token.split("\\.")[0]);
|
102
|
}
|
103
|
|
104
|
@Override
|
105
|
public void setToken(String token) {
|
106
|
this.token = token;
|
107
|
}
|
108
|
|
109
|
@Override
|
110
|
public void afterAdditionToRootPanel() {
|
111
|
|
112
|
}
|
113
|
|
114
|
private void getEligibleProjects(String organizationId) {
|
115
|
|
116
|
errorLabel.setVisible(false);
|
117
|
|
118
|
final HTML loadingWheel = new HTML("<div class=\"loader-big\"></div><div class=\"whiteFilm\"></div>");
|
119
|
eligibleProjectListPanel.addStyleName("loading");
|
120
|
eligibleProjectListPanel.add(loadingWheel);
|
121
|
|
122
|
dataService.getEligibleProjectsForOrganization(organizationId,
|
123
|
new AsyncCallback<EligiblePresentAndFutureProjects>() {
|
124
|
|
125
|
@Override
|
126
|
public void onFailure(Throwable throwable) {
|
127
|
|
128
|
eligibleProjectListPanel.clear();
|
129
|
eligibleProjectListPanel.removeStyleName("loading");
|
130
|
|
131
|
errorLabel.setText(goldOAConstants.errorGettingEligibleProjectsByOrganization());
|
132
|
errorLabel.setVisible(true);
|
133
|
}
|
134
|
|
135
|
@Override
|
136
|
public void onSuccess(EligiblePresentAndFutureProjects eligiblePresentAndFutureProjects) {
|
137
|
|
138
|
eligibleProjectListPanel.clear();
|
139
|
eligibleProjectListPanel.removeStyleName("loading");
|
140
|
|
141
|
if(eligiblePresentAndFutureProjects!=null) {
|
142
|
EligibleProjectsInfoWidget eligibleProjectsInfoWidget = new EligibleProjectsInfoWidget(eligiblePresentAndFutureProjects);
|
143
|
eligibleProjectListPanel.add(eligibleProjectsInfoWidget.asWidget());
|
144
|
}
|
145
|
}
|
146
|
});
|
147
|
}
|
148
|
}
|