1 |
35644
|
stefania.m
|
package eu.dnetlib.client.fundingrequest.existingrequests;
|
2 |
35292
|
stefania.m
|
|
3 |
35926
|
stefania.m
|
import com.github.gwtbootstrap.client.ui.*;
|
4 |
|
|
import com.github.gwtbootstrap.client.ui.ListBox;
|
5 |
|
|
import com.github.gwtbootstrap.client.ui.constants.*;
|
6 |
35691
|
stefania.m
|
import com.github.gwtbootstrap.client.ui.event.HideEvent;
|
7 |
|
|
import com.github.gwtbootstrap.client.ui.event.HideHandler;
|
8 |
|
|
import com.github.gwtbootstrap.client.ui.event.ShowEvent;
|
9 |
|
|
import com.github.gwtbootstrap.client.ui.event.ShowHandler;
|
10 |
|
|
import com.google.gwt.core.client.GWT;
|
11 |
35842
|
stefania.m
|
import com.google.gwt.dom.client.Document;
|
12 |
|
|
import com.google.gwt.dom.client.Style;
|
13 |
35926
|
stefania.m
|
import com.google.gwt.event.dom.client.ChangeEvent;
|
14 |
|
|
import com.google.gwt.event.dom.client.ChangeHandler;
|
15 |
|
|
import com.google.gwt.event.dom.client.ClickEvent;
|
16 |
|
|
import com.google.gwt.event.dom.client.ClickHandler;
|
17 |
35691
|
stefania.m
|
import com.google.gwt.i18n.client.DateTimeFormat;
|
18 |
35926
|
stefania.m
|
import com.google.gwt.user.client.Timer;
|
19 |
35691
|
stefania.m
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
20 |
35292
|
stefania.m
|
import com.google.gwt.user.client.ui.*;
|
21 |
35926
|
stefania.m
|
import com.google.gwt.user.client.ui.Label;
|
22 |
35691
|
stefania.m
|
import eu.dnetlib.client.*;
|
23 |
35926
|
stefania.m
|
import eu.dnetlib.client.widgets.FormFieldSet;
|
24 |
|
|
import eu.dnetlib.client.widgets.TextBox;
|
25 |
|
|
import eu.dnetlib.client.widgets.ValueChangeEvent;
|
26 |
|
|
import eu.dnetlib.client.widgets.ValueChangeHandler;
|
27 |
|
|
import eu.dnetlib.goldoa.domain.RequestFilter;
|
28 |
35691
|
stefania.m
|
import eu.dnetlib.goldoa.domain.RequestInfo;
|
29 |
35926
|
stefania.m
|
import eu.dnetlib.goldoa.domain.RequestSort;
|
30 |
|
|
import eu.dnetlib.goldoa.domain.RequestSortOrder;
|
31 |
35292
|
stefania.m
|
|
32 |
35926
|
stefania.m
|
import java.util.Date;
|
33 |
35691
|
stefania.m
|
import java.util.List;
|
34 |
|
|
|
35 |
35292
|
stefania.m
|
/**
|
36 |
|
|
* Created by stefania on 3/7/15.
|
37 |
|
|
*/
|
38 |
35507
|
stefania.m
|
public class ExistingFundingRequestsWidget implements MyWidget {
|
39 |
35292
|
stefania.m
|
|
40 |
|
|
private FlowPanel existingFundingRequestsPanel = new FlowPanel();
|
41 |
|
|
|
42 |
35691
|
stefania.m
|
private Label titleLabel = new Label();
|
43 |
|
|
private Label informationLabel = new Label();
|
44 |
|
|
|
45 |
|
|
private Alert errorLabel = new Alert();
|
46 |
|
|
private Alert warningLabel = new Alert();
|
47 |
|
|
|
48 |
35926
|
stefania.m
|
private FlowPanel sortAndFilterPanel = new FlowPanel();
|
49 |
|
|
private TextBox search = new TextBox();
|
50 |
|
|
private ListBox orderByTypes = new ListBox();
|
51 |
|
|
private ListBox sortByTypes = new ListBox();
|
52 |
|
|
|
53 |
35691
|
stefania.m
|
private FlowPanel requestsForApprovalPanel = new FlowPanel();
|
54 |
|
|
|
55 |
|
|
private DateTimeFormat dtf = DateTimeFormat.getFormat("yyyy/MM/dd");
|
56 |
|
|
private DataServiceAsync dataService = GWT.create(DataService.class);
|
57 |
|
|
|
58 |
35926
|
stefania.m
|
private Timer timer;
|
59 |
|
|
|
60 |
35292
|
stefania.m
|
public ExistingFundingRequestsWidget() {
|
61 |
|
|
|
62 |
35792
|
stefania.m
|
existingFundingRequestsPanel.addStyleName("content");
|
63 |
35691
|
stefania.m
|
|
64 |
|
|
titleLabel.setText("My Existing Requests");
|
65 |
|
|
titleLabel.addStyleName("contentTitleLabel");
|
66 |
|
|
|
67 |
|
|
informationLabel.setText("View all your existing requests. Click on each to go to the request funding wizard and " +
|
68 |
|
|
"continue from where you left off.");
|
69 |
|
|
informationLabel.addStyleName("contentInfoLabel");
|
70 |
|
|
|
71 |
|
|
errorLabel.addStyleName("alertLabel");
|
72 |
|
|
errorLabel.setType(AlertType.ERROR);
|
73 |
|
|
errorLabel.setClose(false);
|
74 |
|
|
errorLabel.setVisible(false);
|
75 |
|
|
|
76 |
|
|
warningLabel.addStyleName("alertLabel");
|
77 |
|
|
warningLabel.setType(AlertType.WARNING);
|
78 |
|
|
warningLabel.setClose(false);
|
79 |
|
|
warningLabel.setVisible(false);
|
80 |
|
|
|
81 |
35926
|
stefania.m
|
addUtilitiesBar();
|
82 |
|
|
|
83 |
35691
|
stefania.m
|
requestsForApprovalPanel.addStyleName("requestsListPanel");
|
84 |
|
|
|
85 |
|
|
existingFundingRequestsPanel.add(titleLabel);
|
86 |
|
|
existingFundingRequestsPanel.add(informationLabel);
|
87 |
35926
|
stefania.m
|
existingFundingRequestsPanel.add(sortAndFilterPanel);
|
88 |
35691
|
stefania.m
|
existingFundingRequestsPanel.add(errorLabel);
|
89 |
|
|
existingFundingRequestsPanel.add(warningLabel);
|
90 |
|
|
existingFundingRequestsPanel.add(requestsForApprovalPanel);
|
91 |
35292
|
stefania.m
|
}
|
92 |
|
|
|
93 |
|
|
@Override
|
94 |
|
|
public Widget asWidget() {
|
95 |
|
|
return existingFundingRequestsPanel;
|
96 |
|
|
}
|
97 |
35507
|
stefania.m
|
|
98 |
|
|
@Override
|
99 |
|
|
public void clear() {
|
100 |
35941
|
stefania.m
|
|
101 |
35691
|
stefania.m
|
errorLabel.setVisible(false);
|
102 |
|
|
warningLabel.setVisible(false);
|
103 |
35736
|
stefania.m
|
requestsForApprovalPanel.clear();
|
104 |
35507
|
stefania.m
|
}
|
105 |
|
|
|
106 |
|
|
@Override
|
107 |
35665
|
stefania.m
|
public void reload() {
|
108 |
|
|
|
109 |
35842
|
stefania.m
|
Document.get().getElementById("content").removeClassName("uk-width-medium-1-1");
|
110 |
|
|
Document.get().getElementById("content").addClassName("uk-width-medium-3-4");
|
111 |
|
|
Document.get().getElementById("sidebar").getStyle().setDisplay(Style.Display.BLOCK);
|
112 |
|
|
|
113 |
|
|
SidebarPanel sidebarPanel = new SidebarPanel("Help");
|
114 |
|
|
RootPanel.get("sidebar").add(sidebarPanel.asWidget());
|
115 |
|
|
|
116 |
35926
|
stefania.m
|
search.setValue("", false);
|
117 |
|
|
orderByTypes.setSelectedValue(RequestSortOrder.ASCENDING.name());
|
118 |
|
|
sortByTypes.setSelectedValue(RequestSort.DATE.name());
|
119 |
|
|
timer = null;
|
120 |
|
|
|
121 |
|
|
loadRequests(null, null, RequestSort.DATE, RequestSortOrder.ASCENDING, null, null);
|
122 |
|
|
}
|
123 |
|
|
|
124 |
|
|
@Override
|
125 |
|
|
public void setToken(String token) {
|
126 |
|
|
|
127 |
|
|
}
|
128 |
|
|
|
129 |
|
|
private void addUtilitiesBar() {
|
130 |
|
|
|
131 |
|
|
FlowPanel sortAndFilterBar = new FlowPanel();
|
132 |
|
|
sortAndFilterBar.addStyleName("sortAndFilterBar");
|
133 |
|
|
|
134 |
|
|
search.addStyleName("searchTextBox");
|
135 |
|
|
search.addStyleName("float-right");
|
136 |
|
|
search.setPlaceholder("Filter...");
|
137 |
|
|
search.setValueChangeHandler(new ValueChangeHandler() {
|
138 |
|
|
@Override
|
139 |
|
|
public void handle(ValueChangeEvent valueChangeEvent) {
|
140 |
|
|
sortAndFilter();
|
141 |
|
|
}
|
142 |
|
|
});
|
143 |
|
|
|
144 |
|
|
sortAndFilterBar.add(search);
|
145 |
|
|
|
146 |
|
|
orderByTypes.addItem("Ascending", RequestSortOrder.ASCENDING.name());
|
147 |
|
|
orderByTypes.addItem("Descending", RequestSortOrder.DESCENDING.name());
|
148 |
|
|
orderByTypes.setAlternateSize(AlternateSize.SMALL);
|
149 |
|
|
orderByTypes.addChangeHandler(new ChangeHandler() {
|
150 |
|
|
@Override
|
151 |
|
|
public void onChange(ChangeEvent changeEvent) {
|
152 |
|
|
sortAndFilter();
|
153 |
|
|
}
|
154 |
|
|
});
|
155 |
|
|
|
156 |
|
|
Form orderBy = new Form();
|
157 |
|
|
orderBy.setType(FormType.HORIZONTAL);
|
158 |
|
|
orderBy.addStyleName("inlineBlock");
|
159 |
|
|
orderBy.add(new FormFieldSet("Order by", orderByTypes));
|
160 |
|
|
|
161 |
|
|
sortByTypes.addItem("Date", RequestSort.DATE.name());
|
162 |
|
|
sortByTypes.addItem("Publication", RequestSort.PUBLICATION.name());
|
163 |
|
|
sortByTypes.addItem("Status", RequestSort.STATUS.name());
|
164 |
|
|
sortByTypes.setAlternateSize(AlternateSize.SMALL);
|
165 |
|
|
sortByTypes.addChangeHandler(new ChangeHandler() {
|
166 |
|
|
@Override
|
167 |
|
|
public void onChange(ChangeEvent changeEvent) {
|
168 |
|
|
sortAndFilter();
|
169 |
|
|
}
|
170 |
|
|
});
|
171 |
|
|
|
172 |
|
|
Form sortBy = new Form();
|
173 |
|
|
sortBy.setType(FormType.HORIZONTAL);
|
174 |
|
|
sortBy.addStyleName("inlineBlock");
|
175 |
|
|
sortBy.add(new FormFieldSet("Sort by", sortByTypes));
|
176 |
|
|
|
177 |
|
|
sortAndFilterBar.add(sortBy);
|
178 |
|
|
sortAndFilterBar.add(orderBy);
|
179 |
|
|
|
180 |
|
|
sortAndFilterPanel.add(sortAndFilterBar);
|
181 |
|
|
}
|
182 |
|
|
|
183 |
|
|
private void sortAndFilter() {
|
184 |
|
|
|
185 |
|
|
if(timer==null) {
|
186 |
|
|
|
187 |
|
|
timer = new Timer() {
|
188 |
|
|
|
189 |
|
|
@Override
|
190 |
|
|
public void run() {
|
191 |
|
|
|
192 |
|
|
RequestSort requestSort = RequestSort.valueOf(sortByTypes.getSelectedValue());
|
193 |
|
|
RequestSortOrder requestSortOrder = RequestSortOrder.valueOf(orderByTypes.getSelectedValue());
|
194 |
|
|
String term = null;
|
195 |
|
|
if(!search.getValue().trim().equals(""))
|
196 |
|
|
term = search.getValue().trim();
|
197 |
|
|
|
198 |
|
|
loadRequests(null, null, requestSort, requestSortOrder, null, term);
|
199 |
|
|
}
|
200 |
|
|
};
|
201 |
|
|
timer.schedule(300);
|
202 |
|
|
|
203 |
|
|
} else {
|
204 |
|
|
|
205 |
|
|
timer.cancel();
|
206 |
|
|
timer.schedule(300);
|
207 |
|
|
}
|
208 |
|
|
}
|
209 |
|
|
|
210 |
|
|
private void loadRequests(Date from, Date to, RequestSort requestSortBy, RequestSortOrder order, RequestFilter requestFilter, String term) {
|
211 |
|
|
|
212 |
35941
|
stefania.m
|
errorLabel.setVisible(false);
|
213 |
|
|
warningLabel.setVisible(false);
|
214 |
|
|
|
215 |
35757
|
stefania.m
|
final HTML loadingWheel = new HTML("<div class=\"loader-big\"></div><div class=\"whiteFilm\"></div>");
|
216 |
|
|
requestsForApprovalPanel.addStyleName("loading");
|
217 |
|
|
requestsForApprovalPanel.add(loadingWheel);
|
218 |
|
|
|
219 |
35926
|
stefania.m
|
dataService.getRequestsForUser(GoldOAPortal.currentUser.getId(), from, to, requestSortBy, order, requestFilter, term,
|
220 |
|
|
new AsyncCallback<List<RequestInfo>>() {
|
221 |
35691
|
stefania.m
|
|
222 |
|
|
@Override
|
223 |
|
|
public void onFailure(Throwable throwable) {
|
224 |
35757
|
stefania.m
|
|
225 |
35926
|
stefania.m
|
requestsForApprovalPanel.clear();
|
226 |
35757
|
stefania.m
|
requestsForApprovalPanel.removeStyleName("loading");
|
227 |
|
|
|
228 |
35691
|
stefania.m
|
errorLabel.setText("System error retrieving requests");
|
229 |
|
|
errorLabel.setVisible(true);
|
230 |
|
|
}
|
231 |
|
|
|
232 |
|
|
@Override
|
233 |
|
|
public void onSuccess(List<RequestInfo> requestInfoList) {
|
234 |
35757
|
stefania.m
|
|
235 |
35926
|
stefania.m
|
requestsForApprovalPanel.clear();
|
236 |
35757
|
stefania.m
|
requestsForApprovalPanel.removeStyleName("loading");
|
237 |
|
|
|
238 |
35691
|
stefania.m
|
if(requestInfoList.isEmpty()) {
|
239 |
|
|
warningLabel.setText("No available requests at the moment.");
|
240 |
|
|
warningLabel.setVisible(true);
|
241 |
|
|
} else {
|
242 |
|
|
for(RequestInfo requestInfo : requestInfoList)
|
243 |
|
|
drawRequestInfo(requestInfo);
|
244 |
|
|
}
|
245 |
|
|
}
|
246 |
|
|
});
|
247 |
35665
|
stefania.m
|
}
|
248 |
|
|
|
249 |
35691
|
stefania.m
|
private void drawRequestInfo(final RequestInfo requestInfo) {
|
250 |
|
|
|
251 |
|
|
final AccordionGroup dataRequestAccordionItem = new AccordionGroup();
|
252 |
|
|
|
253 |
35751
|
stefania.m
|
String heading = "\"" + requestInfo.getPublication().getTitle() + "\"" + " (" + dtf.format(requestInfo.getDate()) + ")"
|
254 |
35791
|
stefania.m
|
+ ", STATUS: " + requestInfo.getStatus().getValue();
|
255 |
35691
|
stefania.m
|
|
256 |
|
|
dataRequestAccordionItem.setHeading(heading);
|
257 |
|
|
dataRequestAccordionItem.setIcon(IconType.ANGLE_DOWN);
|
258 |
|
|
|
259 |
|
|
dataRequestAccordionItem.addShowHandler(new ShowHandler() {
|
260 |
|
|
|
261 |
|
|
@Override
|
262 |
|
|
public void onShow(ShowEvent showEvent) {
|
263 |
|
|
|
264 |
35856
|
stefania.m
|
dataRequestAccordionItem.setIcon(IconType.ANGLE_UP);
|
265 |
|
|
dataRequestAccordionItem.clear();
|
266 |
|
|
|
267 |
35788
|
stefania.m
|
final HTML loadingWheel = new HTML("<div class=\"loader-big\"></div><div class=\"whiteFilm\"></div>");
|
268 |
|
|
FlowPanel accordionInner = new FlowPanel();
|
269 |
|
|
accordionInner.addStyleName("loading");
|
270 |
|
|
accordionInner.add(loadingWheel);
|
271 |
|
|
|
272 |
|
|
dataRequestAccordionItem.add(accordionInner);
|
273 |
|
|
|
274 |
|
|
dataService.getRequestById(requestInfo.getId(), new AsyncCallback<RequestInfo>() {
|
275 |
|
|
|
276 |
|
|
@Override
|
277 |
|
|
public void onFailure(Throwable throwable) {
|
278 |
|
|
|
279 |
|
|
dataRequestAccordionItem.clear();
|
280 |
|
|
|
281 |
|
|
Alert errorLabel = new Alert();
|
282 |
|
|
errorLabel.addStyleName("alertLabel");
|
283 |
|
|
errorLabel.setType(AlertType.ERROR);
|
284 |
|
|
errorLabel.setClose(false);
|
285 |
|
|
errorLabel.setText("System error getting request information");
|
286 |
|
|
|
287 |
|
|
dataRequestAccordionItem.add(errorLabel);
|
288 |
|
|
}
|
289 |
|
|
|
290 |
|
|
@Override
|
291 |
|
|
public void onSuccess(RequestInfo requestInfo) {
|
292 |
|
|
|
293 |
|
|
dataRequestAccordionItem.clear();
|
294 |
35856
|
stefania.m
|
|
295 |
35788
|
stefania.m
|
ExistingRequestElement existingRequestElement = new ExistingRequestElement(requestInfo);
|
296 |
|
|
dataRequestAccordionItem.add(existingRequestElement.asWidget());
|
297 |
|
|
}
|
298 |
|
|
});
|
299 |
35691
|
stefania.m
|
}
|
300 |
|
|
});
|
301 |
|
|
dataRequestAccordionItem.addHideHandler(new HideHandler() {
|
302 |
|
|
|
303 |
|
|
@Override
|
304 |
|
|
public void onHide(HideEvent hideEvent) {
|
305 |
|
|
dataRequestAccordionItem.setIcon(IconType.ANGLE_DOWN);
|
306 |
|
|
}
|
307 |
|
|
});
|
308 |
|
|
|
309 |
35736
|
stefania.m
|
requestsForApprovalPanel.add(dataRequestAccordionItem);
|
310 |
35691
|
stefania.m
|
}
|
311 |
35292
|
stefania.m
|
}
|