1
|
package eu.dnetlib.client;
|
2
|
|
3
|
import com.github.gwtbootstrap.client.ui.AccordionGroup;
|
4
|
import com.github.gwtbootstrap.client.ui.Alert;
|
5
|
import com.github.gwtbootstrap.client.ui.constants.AlertType;
|
6
|
import com.github.gwtbootstrap.client.ui.constants.IconType;
|
7
|
import com.github.gwtbootstrap.client.ui.event.HideEvent;
|
8
|
import com.github.gwtbootstrap.client.ui.event.HideHandler;
|
9
|
import com.github.gwtbootstrap.client.ui.event.ShowEvent;
|
10
|
import com.github.gwtbootstrap.client.ui.event.ShowHandler;
|
11
|
import com.google.gwt.core.client.GWT;
|
12
|
import com.google.gwt.dom.client.Document;
|
13
|
import com.google.gwt.dom.client.Style;
|
14
|
import com.google.gwt.i18n.client.DateTimeFormat;
|
15
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
16
|
import com.google.gwt.user.client.ui.*;
|
17
|
import eu.dnetlib.goldoa.domain.Request;
|
18
|
import eu.dnetlib.goldoa.domain.RequestInfo;
|
19
|
|
20
|
import java.util.List;
|
21
|
|
22
|
/**
|
23
|
* Created by stefania on 3/6/15.
|
24
|
*/
|
25
|
public class MonitorFundingRequestsWidget implements MyWidget {
|
26
|
|
27
|
private FlowPanel monitorFundingRequestsPagePanel = new FlowPanel();
|
28
|
private Label monitorFundingRequestsTitleLabel = new Label();
|
29
|
private Label monitorFundingRequestsInfoLabel = new Label();
|
30
|
|
31
|
private Alert errorLabel = new Alert();
|
32
|
private Alert warningLabel = new Alert();
|
33
|
|
34
|
private FlowPanel requestsForApprovalPanel = new FlowPanel();
|
35
|
|
36
|
private DateTimeFormat dtf = DateTimeFormat.getFormat("yyyy/MM/dd");
|
37
|
private DataServiceAsync dataService = GWT.create(DataService.class);
|
38
|
|
39
|
public MonitorFundingRequestsWidget() {
|
40
|
|
41
|
monitorFundingRequestsPagePanel.addStyleName("content");
|
42
|
|
43
|
monitorFundingRequestsTitleLabel.setText("Monitor Funding Requests");
|
44
|
monitorFundingRequestsTitleLabel.addStyleName("contentTitleLabel");
|
45
|
|
46
|
monitorFundingRequestsInfoLabel.setText("Monitor and change the status of funding requests that are pending approval");
|
47
|
monitorFundingRequestsInfoLabel.addStyleName("contentInfoLabel");
|
48
|
|
49
|
errorLabel.addStyleName("alertLabel");
|
50
|
errorLabel.addStyleName("width80");
|
51
|
errorLabel.setType(AlertType.ERROR);
|
52
|
errorLabel.setClose(false);
|
53
|
errorLabel.setVisible(false);
|
54
|
|
55
|
warningLabel.addStyleName("alertLabel");
|
56
|
warningLabel.addStyleName("width80");
|
57
|
warningLabel.setType(AlertType.WARNING);
|
58
|
warningLabel.setClose(false);
|
59
|
warningLabel.setVisible(false);
|
60
|
|
61
|
requestsForApprovalPanel.addStyleName("requestsListPanel");
|
62
|
|
63
|
monitorFundingRequestsPagePanel.add(monitorFundingRequestsTitleLabel);
|
64
|
monitorFundingRequestsPagePanel.add(monitorFundingRequestsInfoLabel);
|
65
|
monitorFundingRequestsPagePanel.add(errorLabel);
|
66
|
monitorFundingRequestsPagePanel.add(warningLabel);
|
67
|
monitorFundingRequestsPagePanel.add(requestsForApprovalPanel);
|
68
|
}
|
69
|
|
70
|
@Override
|
71
|
public Widget asWidget() {
|
72
|
return monitorFundingRequestsPagePanel;
|
73
|
}
|
74
|
|
75
|
@Override
|
76
|
public void clear() {
|
77
|
|
78
|
errorLabel.setVisible(false);
|
79
|
warningLabel.setVisible(false);
|
80
|
requestsForApprovalPanel.clear();
|
81
|
}
|
82
|
|
83
|
@Override
|
84
|
public void reload() {
|
85
|
|
86
|
Document.get().getElementById("content").removeClassName("uk-width-medium-1-1");
|
87
|
Document.get().getElementById("content").addClassName("uk-width-medium-3-4");
|
88
|
Document.get().getElementById("sidebar").getStyle().setDisplay(Style.Display.BLOCK);
|
89
|
|
90
|
SidebarPanel sidebarPanel = new SidebarPanel("Help");
|
91
|
RootPanel.get("sidebar").add(sidebarPanel.asWidget());
|
92
|
|
93
|
final HTML loadingWheel = new HTML("<div class=\"loader-big\"></div><div class=\"whiteFilm\"></div>");
|
94
|
requestsForApprovalPanel.addStyleName("loading");
|
95
|
requestsForApprovalPanel.add(loadingWheel);
|
96
|
|
97
|
dataService.getRequests(null, null, null, null, null, null, new AsyncCallback<List<RequestInfo>>() {
|
98
|
|
99
|
@Override
|
100
|
public void onFailure(Throwable throwable) {
|
101
|
|
102
|
requestsForApprovalPanel.removeStyleName("loading");
|
103
|
requestsForApprovalPanel.remove(loadingWheel);
|
104
|
|
105
|
errorLabel.setText("System error retrieving requests");
|
106
|
errorLabel.setVisible(true);
|
107
|
}
|
108
|
|
109
|
@Override
|
110
|
public void onSuccess(List<RequestInfo> requestInfoList) {
|
111
|
|
112
|
requestsForApprovalPanel.removeStyleName("loading");
|
113
|
requestsForApprovalPanel.remove(loadingWheel);
|
114
|
|
115
|
if(requestInfoList.isEmpty()) {
|
116
|
warningLabel.setText("No available requests at the moment.");
|
117
|
warningLabel.setVisible(true);
|
118
|
} else {
|
119
|
for(RequestInfo requestInfo : requestInfoList)
|
120
|
drawRequestInfo(requestInfo);
|
121
|
}
|
122
|
}
|
123
|
});
|
124
|
|
125
|
}
|
126
|
|
127
|
@Override
|
128
|
public void setToken(String token) {
|
129
|
|
130
|
}
|
131
|
|
132
|
private void drawRequestInfo(final RequestInfo requestInfo) {
|
133
|
|
134
|
final AccordionGroup dataRequestAccordionItem = new AccordionGroup();
|
135
|
|
136
|
String heading = "\"" + requestInfo.getPublication().getTitle() + "\"" + " (" + dtf.format(requestInfo.getDate()) + ")"
|
137
|
+ ", STATUS: " + requestInfo.getStatus().getValue();
|
138
|
|
139
|
dataRequestAccordionItem.setHeading(heading);
|
140
|
dataRequestAccordionItem.setIcon(IconType.ANGLE_DOWN);
|
141
|
|
142
|
dataRequestAccordionItem.addShowHandler(new ShowHandler() {
|
143
|
|
144
|
@Override
|
145
|
public void onShow(ShowEvent showEvent) {
|
146
|
|
147
|
dataRequestAccordionItem.setIcon(IconType.ANGLE_UP);
|
148
|
dataRequestAccordionItem.clear();
|
149
|
|
150
|
final HTML loadingWheel = new HTML("<div class=\"loader-big\"></div><div class=\"whiteFilm\"></div>");
|
151
|
FlowPanel accordionInner = new FlowPanel();
|
152
|
accordionInner.addStyleName("loading");
|
153
|
accordionInner.add(loadingWheel);
|
154
|
|
155
|
dataRequestAccordionItem.add(accordionInner);
|
156
|
|
157
|
dataService.getRequestById(requestInfo.getId(), new AsyncCallback<RequestInfo>() {
|
158
|
|
159
|
@Override
|
160
|
public void onFailure(Throwable throwable) {
|
161
|
|
162
|
dataRequestAccordionItem.clear();
|
163
|
|
164
|
Alert errorLabel = new Alert();
|
165
|
errorLabel.addStyleName("alertLabel");
|
166
|
errorLabel.setType(AlertType.ERROR);
|
167
|
errorLabel.setClose(false);
|
168
|
errorLabel.setText("System error getting request information");
|
169
|
|
170
|
dataRequestAccordionItem.add(errorLabel);
|
171
|
}
|
172
|
|
173
|
@Override
|
174
|
public void onSuccess(final RequestInfo requestInfo) {
|
175
|
|
176
|
dataRequestAccordionItem.clear();
|
177
|
|
178
|
RequestInfoElement requestInfoElement = new RequestInfoElement(requestInfo);
|
179
|
dataRequestAccordionItem.add(requestInfoElement.asWidget());
|
180
|
|
181
|
RequestInfoElement.ActionListener actionListener = new RequestInfoElement.ActionListener() {
|
182
|
|
183
|
@Override
|
184
|
public void actionHappened(boolean succeeded, Request.RequestStatus requestStatus) {
|
185
|
|
186
|
dataRequestAccordionItem.getHeading().getElement().scrollIntoView();
|
187
|
if(succeeded) {
|
188
|
String heading = "\"" + requestInfo.getPublication().getTitle() + "\"" + " (" + dtf.format(requestInfo.getDate()) + ")"
|
189
|
+ ", STATUS: " + requestStatus.getValue();
|
190
|
|
191
|
dataRequestAccordionItem.setHeading(heading);
|
192
|
}
|
193
|
}
|
194
|
};
|
195
|
requestInfoElement.setActionListener(actionListener);
|
196
|
}
|
197
|
});
|
198
|
}
|
199
|
});
|
200
|
dataRequestAccordionItem.addHideHandler(new HideHandler() {
|
201
|
|
202
|
@Override
|
203
|
public void onHide(HideEvent hideEvent) {
|
204
|
dataRequestAccordionItem.setIcon(IconType.ANGLE_DOWN);
|
205
|
}
|
206
|
});
|
207
|
|
208
|
requestsForApprovalPanel.add(dataRequestAccordionItem);
|
209
|
}
|
210
|
}
|