1
|
package eu.dnetlib.client.monitor;
|
2
|
|
3
|
import com.github.gwtbootstrap.client.ui.*;
|
4
|
import com.github.gwtbootstrap.client.ui.Button;
|
5
|
import com.github.gwtbootstrap.client.ui.constants.AlertType;
|
6
|
import com.github.gwtbootstrap.client.ui.constants.ButtonType;
|
7
|
import com.github.gwtbootstrap.client.ui.constants.FormType;
|
8
|
import com.github.gwtbootstrap.client.ui.constants.IconType;
|
9
|
import com.github.gwtbootstrap.client.ui.event.HideEvent;
|
10
|
import com.github.gwtbootstrap.client.ui.event.HideHandler;
|
11
|
import com.github.gwtbootstrap.client.ui.event.ShowEvent;
|
12
|
import com.github.gwtbootstrap.client.ui.event.ShowHandler;
|
13
|
import com.google.gwt.core.client.GWT;
|
14
|
import com.google.gwt.dom.client.Document;
|
15
|
import com.google.gwt.dom.client.Style;
|
16
|
import com.google.gwt.event.dom.client.ClickEvent;
|
17
|
import com.google.gwt.event.dom.client.ClickHandler;
|
18
|
import com.google.gwt.i18n.client.DateTimeFormat;
|
19
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
20
|
import com.google.gwt.user.client.ui.*;
|
21
|
import com.google.gwt.user.client.ui.Label;
|
22
|
import com.google.gwt.user.client.ui.TextArea;
|
23
|
import eu.dnetlib.client.*;
|
24
|
import eu.dnetlib.client.widgets.FormFieldSet;
|
25
|
import eu.dnetlib.goldoa.domain.*;
|
26
|
|
27
|
import java.util.List;
|
28
|
|
29
|
/**
|
30
|
* Created by stefania on 4/2/15.
|
31
|
*/
|
32
|
public class MonitorBudgetsWidget implements MyWidget {
|
33
|
|
34
|
private String token = "";
|
35
|
|
36
|
private FlowPanel monitorBudgetsPagePanel = new FlowPanel();
|
37
|
private Label monitorBudgetsTitleLabel = new Label();
|
38
|
private Label monitorBudgetsInfoLabel = new Label();
|
39
|
|
40
|
private Alert errorLabel = new Alert();
|
41
|
private Alert warningLabel = new Alert();
|
42
|
|
43
|
private FlowPanel budgetsForApprovalPanel = new FlowPanel();
|
44
|
|
45
|
private DateTimeFormat dtf = DateTimeFormat.getFormat("yyyy/MM/dd");
|
46
|
private DataServiceAsync dataService = GWT.create(DataService.class);
|
47
|
|
48
|
private GoldOAConstants goldOAConstants = GWT.create(GoldOAConstants.class);
|
49
|
|
50
|
public MonitorBudgetsWidget() {
|
51
|
|
52
|
monitorBudgetsPagePanel.addStyleName("content");
|
53
|
|
54
|
monitorBudgetsTitleLabel.setText("Monitor Budgets");
|
55
|
monitorBudgetsTitleLabel.addStyleName("contentTitleLabel");
|
56
|
|
57
|
monitorBudgetsInfoLabel.setText("Monitor and change the status of budget requests that are pending approval");
|
58
|
monitorBudgetsInfoLabel.addStyleName("contentInfoLabel");
|
59
|
|
60
|
errorLabel.addStyleName("alertLabel");
|
61
|
errorLabel.setType(AlertType.ERROR);
|
62
|
errorLabel.setClose(false);
|
63
|
errorLabel.setVisible(false);
|
64
|
|
65
|
warningLabel.addStyleName("alertLabel");
|
66
|
warningLabel.setType(AlertType.WARNING);
|
67
|
warningLabel.setClose(false);
|
68
|
warningLabel.setVisible(false);
|
69
|
|
70
|
budgetsForApprovalPanel.addStyleName("budgetsListPanel");
|
71
|
|
72
|
monitorBudgetsPagePanel.add(monitorBudgetsTitleLabel);
|
73
|
monitorBudgetsPagePanel.add(monitorBudgetsInfoLabel);
|
74
|
monitorBudgetsPagePanel.add(errorLabel);
|
75
|
monitorBudgetsPagePanel.add(warningLabel);
|
76
|
monitorBudgetsPagePanel.add(budgetsForApprovalPanel);
|
77
|
}
|
78
|
|
79
|
@Override
|
80
|
public void clear() {
|
81
|
|
82
|
errorLabel.setVisible(false);
|
83
|
warningLabel.setVisible(false);
|
84
|
budgetsForApprovalPanel.clear();
|
85
|
}
|
86
|
|
87
|
@Override
|
88
|
public void reload() {
|
89
|
|
90
|
MyWidgetHelper.hideSidebar();
|
91
|
|
92
|
SidebarPanel helpPanel = new SidebarPanel("Help");
|
93
|
MyWidgetHelper.loadHelp(helpPanel, token.split("\\.")[0]);
|
94
|
|
95
|
loadBudgets();
|
96
|
}
|
97
|
|
98
|
@Override
|
99
|
public void setToken(String token) {
|
100
|
this.token = token;
|
101
|
}
|
102
|
|
103
|
@Override
|
104
|
public void afterAdditionToRootPanel() {
|
105
|
|
106
|
}
|
107
|
|
108
|
@Override
|
109
|
public Widget asWidget() {
|
110
|
return monitorBudgetsPagePanel;
|
111
|
}
|
112
|
|
113
|
private void loadBudgets() {
|
114
|
|
115
|
errorLabel.setVisible(false);
|
116
|
warningLabel.setVisible(false);
|
117
|
|
118
|
final HTML loadingWheel = new HTML("<div class=\"loader-big\"></div><div class=\"whiteFilm\"></div>");
|
119
|
budgetsForApprovalPanel.addStyleName("loading");
|
120
|
budgetsForApprovalPanel.add(loadingWheel);
|
121
|
|
122
|
dataService.getBudgets(new AsyncCallback<List<Budget>>() {
|
123
|
|
124
|
@Override
|
125
|
public void onFailure(Throwable throwable) {
|
126
|
|
127
|
budgetsForApprovalPanel.clear();
|
128
|
budgetsForApprovalPanel.removeStyleName("loading");
|
129
|
|
130
|
errorLabel.setText(goldOAConstants.errorGettingListOfBudgets());
|
131
|
errorLabel.setVisible(true);
|
132
|
}
|
133
|
|
134
|
@Override
|
135
|
public void onSuccess(List<Budget> budgetInfoList) {
|
136
|
|
137
|
budgetsForApprovalPanel.clear();
|
138
|
budgetsForApprovalPanel.removeStyleName("loading");
|
139
|
|
140
|
if (budgetInfoList.isEmpty()) {
|
141
|
warningLabel.setText(goldOAConstants.warningNoBudgetsAvailable());
|
142
|
warningLabel.setVisible(true);
|
143
|
} else {
|
144
|
for (int i = 0; i < budgetInfoList.size(); i++)
|
145
|
drawBudgetInfo(budgetInfoList.get(i), i);
|
146
|
}
|
147
|
}
|
148
|
});
|
149
|
}
|
150
|
|
151
|
private void drawBudgetInfo(final Budget budget, int i) {
|
152
|
|
153
|
final AccordionGroup budgetRequestAccordionItem = new AccordionGroup();
|
154
|
// if(((i+1)%2)==1)
|
155
|
// budgetRequestAccordionItem.addStyleName("odd");
|
156
|
|
157
|
HTML statusHeading = new HTML();
|
158
|
statusHeading.setHTML("<span class=\"status\">" + budget.getStatus().getValue().toUpperCase() + "</span>");
|
159
|
statusHeading.addStyleName("float-right");
|
160
|
statusHeading.addStyleName("statusHeading");
|
161
|
|
162
|
budgetRequestAccordionItem.getHeading().add(statusHeading);
|
163
|
|
164
|
HTML extraInfo = new HTML();
|
165
|
String extraInfoContents = "<div style=\"width: 8%\" class=\"inlineBlock\"><span>" + dtf.format(budget.getDate()) +
|
166
|
"</span></div>";
|
167
|
|
168
|
extraInfoContents += "<div style=\"width: 30%\" class=\"inlineBlock\"><span style=\"padding-right:10px; padding-left:10px\">|</span><span>";
|
169
|
|
170
|
extraInfoContents += "Valid from " + dtf.format(budget.getStartdate()) + " to " + dtf.format(budget.getEnddate());
|
171
|
|
172
|
extraInfoContents += "</span></div><div style=\"width: 32%\" class=\"inlineBlock\"><span style=\"padding-right:10px; " +
|
173
|
"padding-left:10px\">|</span><span>";
|
174
|
|
175
|
if(budget.getInvoice()!=null)
|
176
|
extraInfoContents += budget.getInvoice().getNumber();
|
177
|
else
|
178
|
extraInfoContents += "---";
|
179
|
extraInfoContents += "</span></div></div><div style=\"width: 30%\" class=\"inlineBlock\"><span style=\"padding-right:10px; " +
|
180
|
"padding-left:10px\">|</span><span>";
|
181
|
|
182
|
if(budget.getAmountRequested()!=null && budget.getCurrency()!=null)
|
183
|
extraInfoContents += Math.round(budget.getAmountRequested()*100) / 100.0 + " " + budget.getCurrency().toString();
|
184
|
else
|
185
|
extraInfoContents += "---";
|
186
|
extraInfoContents += "</span></div>";
|
187
|
|
188
|
extraInfo.setHTML(extraInfoContents);
|
189
|
extraInfo.addStyleName("headingExtraInfo");
|
190
|
|
191
|
budgetRequestAccordionItem.getHeading().add(extraInfo);
|
192
|
|
193
|
String heading = "(ID: " + budget.getId() + ") ";
|
194
|
if(budget.getPublisher()!=null)
|
195
|
heading += budget.getPublisher().getName();
|
196
|
else if(budget.getOrganizations().get(0)!=null)
|
197
|
heading += budget.getOrganizations().get(0).getName();
|
198
|
|
199
|
budgetRequestAccordionItem.setHeading(heading);
|
200
|
budgetRequestAccordionItem.setIcon(IconType.ANGLE_DOWN);
|
201
|
|
202
|
budgetRequestAccordionItem.addShowHandler(new ShowHandler() {
|
203
|
|
204
|
@Override
|
205
|
public void onShow(ShowEvent showEvent) {
|
206
|
|
207
|
budgetRequestAccordionItem.setIcon(IconType.ANGLE_UP);
|
208
|
budgetRequestAccordionItem.clear();
|
209
|
|
210
|
final HTML loadingWheel = new HTML("<div class=\"loader-big\"></div><div class=\"whiteFilm\"></div>");
|
211
|
FlowPanel accordionInner = new FlowPanel();
|
212
|
accordionInner.addStyleName("loading");
|
213
|
accordionInner.add(loadingWheel);
|
214
|
|
215
|
budgetRequestAccordionItem.add(accordionInner);
|
216
|
|
217
|
dataService.getBudgetById(budget.getId(), new AsyncCallback<Budget>() {
|
218
|
|
219
|
@Override
|
220
|
public void onFailure(Throwable caught) {
|
221
|
|
222
|
budgetRequestAccordionItem.clear();
|
223
|
|
224
|
Alert errorLabel = new Alert();
|
225
|
errorLabel.addStyleName("alertLabel");
|
226
|
errorLabel.setType(AlertType.ERROR);
|
227
|
errorLabel.setClose(false);
|
228
|
errorLabel.setText(goldOAConstants.errorGettingSpecificRequestInfo());
|
229
|
|
230
|
budgetRequestAccordionItem.add(errorLabel);
|
231
|
}
|
232
|
|
233
|
@Override
|
234
|
public void onSuccess(Budget budget) {
|
235
|
|
236
|
addNewBudgetInfo(budgetRequestAccordionItem, budget);
|
237
|
}
|
238
|
});
|
239
|
}
|
240
|
});
|
241
|
budgetRequestAccordionItem.addHideHandler(new HideHandler() {
|
242
|
|
243
|
@Override
|
244
|
public void onHide(HideEvent hideEvent) {
|
245
|
budgetRequestAccordionItem.setIcon(IconType.ANGLE_DOWN);
|
246
|
}
|
247
|
});
|
248
|
|
249
|
budgetsForApprovalPanel.add(budgetRequestAccordionItem);
|
250
|
// requestsList.add(budgetRequestAccordionItem);
|
251
|
}
|
252
|
|
253
|
private void addNewBudgetInfo(final AccordionGroup accordion, final Budget budget) {
|
254
|
|
255
|
accordion.clear();
|
256
|
|
257
|
BudgetInfoElement budgetInfoElement = new BudgetInfoElement(budget);
|
258
|
accordion.add(budgetInfoElement.asWidget());
|
259
|
|
260
|
BudgetInfoElement.ActionListener actionListener = new BudgetInfoElement.ActionListener() {
|
261
|
@Override
|
262
|
public void actionHappened(boolean succeeded, Budget.Status status, Comment comment) {
|
263
|
|
264
|
accordion.getHeading().getElement().scrollIntoView();
|
265
|
if(succeeded) {
|
266
|
|
267
|
HTML statusHeading = new HTML();
|
268
|
statusHeading.setHTML("<span class=\"status\">" + status.getValue().toUpperCase() + "</span>");
|
269
|
statusHeading.addStyleName("float-right");
|
270
|
statusHeading.addStyleName("statusHeading");
|
271
|
|
272
|
accordion.getHeading().remove(1);
|
273
|
accordion.getHeading().insert(statusHeading, 1);
|
274
|
|
275
|
String heading = "(ID: " + budget.getId() + ") ";
|
276
|
if(budget.getPublisher()!=null)
|
277
|
heading += budget.getPublisher().getName();
|
278
|
else if(budget.getOrganizations().get(0)!=null)
|
279
|
heading += budget.getOrganizations().get(0).getName();
|
280
|
|
281
|
accordion.setHeading(heading);
|
282
|
|
283
|
budget.setStatus(status);
|
284
|
|
285
|
if(comment!=null)
|
286
|
budget.getComments().add(comment);
|
287
|
|
288
|
addNewBudgetInfo(accordion, budget);
|
289
|
}
|
290
|
}
|
291
|
};
|
292
|
budgetInfoElement.setActionListener(actionListener);
|
293
|
}
|
294
|
|
295
|
// private void drawBudgetInfo(final BudgetInfo budgetInfo, int i) {
|
296
|
//
|
297
|
// final FlowPanel budgetElement = new FlowPanel();
|
298
|
// budgetElement.addStyleName("budgetRequest");
|
299
|
// if(((i+1)%2)==1)
|
300
|
// budgetElement.addStyleName("odd");
|
301
|
//
|
302
|
// final Alert errorLabel = new Alert();
|
303
|
// errorLabel.addStyleName("alertLabel");
|
304
|
// errorLabel.setType(AlertType.ERROR);
|
305
|
// errorLabel.setVisible(false);
|
306
|
// errorLabel.setClose(false);
|
307
|
//
|
308
|
// BudgetInfoElement budgetInfoElement = new BudgetInfoElement(budgetInfo);
|
309
|
//
|
310
|
// FlowPanel actionButtons = new FlowPanel();
|
311
|
// Button approve = new Button("Approve");
|
312
|
// Button reject = new Button("Reject");
|
313
|
//
|
314
|
// final FlowPanel divider = new FlowPanel();
|
315
|
//
|
316
|
// final Form commentsForm = new Form();
|
317
|
// final TextArea comments = new TextArea();
|
318
|
//
|
319
|
// commentsForm.setType(FormType.VERTICAL);
|
320
|
// comments.setEnabled(false);
|
321
|
//
|
322
|
// //TODO what was this?
|
323
|
//// if(budgetInfo.getComment()!=null)
|
324
|
//// comments.setValue(budgetInfo.getComment());
|
325
|
//
|
326
|
// commentsForm.add(new FormFieldSet("Comments", comments));
|
327
|
//
|
328
|
// actionButtons.addStyleName("requestInfoActionButtons");
|
329
|
//
|
330
|
// approve.addStyleName("requestInfoActionButton");
|
331
|
// approve.setType(ButtonType.SUCCESS);
|
332
|
// approve.addClickHandler(new ClickHandler() {
|
333
|
// @Override
|
334
|
// public void onClick(ClickEvent clickEvent) {
|
335
|
//
|
336
|
// errorLabel.setVisible(false);
|
337
|
//
|
338
|
// dataService.approveBudget(budgetInfo.getId(), comments.getValue().trim(), new AsyncCallback<Void>() {
|
339
|
//
|
340
|
// @Override
|
341
|
// public void onFailure(Throwable throwable) {
|
342
|
//
|
343
|
// errorLabel.setText(goldOAConstants.monitorErrorApprovingBudget());
|
344
|
// errorLabel.setVisible(true);
|
345
|
// }
|
346
|
//
|
347
|
// @Override
|
348
|
// public void onSuccess(Void aVoid) {
|
349
|
//
|
350
|
// budgetInfo.setStatus(Budget.Status.APPROVED);
|
351
|
// BudgetInfoElement budgetInfoElement = new BudgetInfoElement(budgetInfo);
|
352
|
//
|
353
|
// budgetElement.clear();
|
354
|
// budgetElement.add(errorLabel);
|
355
|
// budgetElement.add(budgetInfoElement.asWidget());
|
356
|
// budgetElement.add(divider);
|
357
|
// budgetElement.add(commentsForm);
|
358
|
//
|
359
|
// comments.setEnabled(false);
|
360
|
// }
|
361
|
// });
|
362
|
// }
|
363
|
// });
|
364
|
// actionButtons.add(approve);
|
365
|
//
|
366
|
// reject.addStyleName("requestInfoActionButton");
|
367
|
// reject.setType(ButtonType.DANGER);
|
368
|
// reject.addClickHandler(new ClickHandler() {
|
369
|
// @Override
|
370
|
// public void onClick(ClickEvent clickEvent) {
|
371
|
//
|
372
|
// errorLabel.setVisible(false);
|
373
|
//
|
374
|
// dataService.rejectBudget(budgetInfo.getId(), comments.getValue().trim(), new AsyncCallback<Void>() {
|
375
|
//
|
376
|
// @Override
|
377
|
// public void onFailure(Throwable throwable) {
|
378
|
//
|
379
|
// errorLabel.setText(goldOAConstants.monitorErrorRejectingBudget());
|
380
|
// errorLabel.setVisible(true);
|
381
|
// }
|
382
|
//
|
383
|
// @Override
|
384
|
// public void onSuccess(Void aVoid) {
|
385
|
//
|
386
|
// budgetInfo.setStatus(Budget.Status.REJECTED);
|
387
|
// BudgetInfoElement budgetInfoElement = new BudgetInfoElement(budgetInfo);
|
388
|
//
|
389
|
// budgetElement.clear();
|
390
|
// budgetElement.add(errorLabel);
|
391
|
// budgetElement.add(budgetInfoElement.asWidget());
|
392
|
// budgetElement.add(divider);
|
393
|
// budgetElement.add(commentsForm);
|
394
|
//
|
395
|
// comments.setEnabled(false);
|
396
|
// }
|
397
|
// });
|
398
|
// }
|
399
|
// });
|
400
|
// actionButtons.add(reject);
|
401
|
//
|
402
|
// divider.addStyleName("uk-grid-divider");
|
403
|
//
|
404
|
// budgetElement.add(errorLabel);
|
405
|
// budgetElement.add(budgetInfoElement.asWidget());
|
406
|
// budgetElement.add(divider);
|
407
|
// budgetElement.add(commentsForm);
|
408
|
//
|
409
|
//
|
410
|
// if(!budgetInfo.getStatus().equals(Budget.Status.APPROVED) && !budgetInfo.getStatus().equals(Budget.Status.REJECTED)) {
|
411
|
// comments.setEnabled(true);
|
412
|
// budgetElement.add(actionButtons);
|
413
|
// }
|
414
|
//
|
415
|
// budgetsForApprovalPanel.add(budgetElement);
|
416
|
// }
|
417
|
}
|