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.google.gwt.core.client.GWT;
|
9
|
import com.google.gwt.dom.client.Document;
|
10
|
import com.google.gwt.dom.client.Style;
|
11
|
import com.google.gwt.event.dom.client.ClickEvent;
|
12
|
import com.google.gwt.event.dom.client.ClickHandler;
|
13
|
import com.google.gwt.i18n.client.DateTimeFormat;
|
14
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
15
|
import com.google.gwt.user.client.ui.*;
|
16
|
import com.google.gwt.user.client.ui.Label;
|
17
|
import com.google.gwt.user.client.ui.TextArea;
|
18
|
import eu.dnetlib.client.*;
|
19
|
import eu.dnetlib.client.widgets.FormFieldSet;
|
20
|
import eu.dnetlib.goldoa.domain.Budget;
|
21
|
import eu.dnetlib.goldoa.domain.BudgetInfo;
|
22
|
import eu.dnetlib.goldoa.domain.Request;
|
23
|
|
24
|
import java.util.List;
|
25
|
|
26
|
/**
|
27
|
* Created by stefania on 4/2/15.
|
28
|
*/
|
29
|
public class MonitorBudgetsWidget implements MyWidget {
|
30
|
|
31
|
private String token = "";
|
32
|
|
33
|
private FlowPanel monitorBudgetsPagePanel = new FlowPanel();
|
34
|
private Label monitorBudgetsTitleLabel = new Label();
|
35
|
private Label monitorBudgetsInfoLabel = new Label();
|
36
|
|
37
|
private Alert errorLabel = new Alert();
|
38
|
private Alert warningLabel = new Alert();
|
39
|
|
40
|
private FlowPanel budgetsForApprovalPanel = new FlowPanel();
|
41
|
|
42
|
private DateTimeFormat dtf = DateTimeFormat.getFormat("yyyy/MM/dd");
|
43
|
private DataServiceAsync dataService = GWT.create(DataService.class);
|
44
|
|
45
|
public MonitorBudgetsWidget() {
|
46
|
|
47
|
monitorBudgetsPagePanel.addStyleName("content");
|
48
|
|
49
|
monitorBudgetsTitleLabel.setText("Monitor Budgets");
|
50
|
monitorBudgetsTitleLabel.addStyleName("contentTitleLabel");
|
51
|
|
52
|
monitorBudgetsInfoLabel.setText("Monitor and change the status of budget requests that are pending approval");
|
53
|
monitorBudgetsInfoLabel.addStyleName("contentInfoLabel");
|
54
|
|
55
|
errorLabel.addStyleName("alertLabel");
|
56
|
errorLabel.setType(AlertType.ERROR);
|
57
|
errorLabel.setClose(false);
|
58
|
errorLabel.setVisible(false);
|
59
|
|
60
|
warningLabel.addStyleName("alertLabel");
|
61
|
warningLabel.setType(AlertType.WARNING);
|
62
|
warningLabel.setClose(false);
|
63
|
warningLabel.setVisible(false);
|
64
|
|
65
|
budgetsForApprovalPanel.addStyleName("budgetsListPanel");
|
66
|
|
67
|
monitorBudgetsPagePanel.add(monitorBudgetsTitleLabel);
|
68
|
monitorBudgetsPagePanel.add(monitorBudgetsInfoLabel);
|
69
|
monitorBudgetsPagePanel.add(errorLabel);
|
70
|
monitorBudgetsPagePanel.add(warningLabel);
|
71
|
monitorBudgetsPagePanel.add(budgetsForApprovalPanel);
|
72
|
}
|
73
|
|
74
|
@Override
|
75
|
public void clear() {
|
76
|
|
77
|
errorLabel.setVisible(false);
|
78
|
warningLabel.setVisible(false);
|
79
|
budgetsForApprovalPanel.clear();
|
80
|
}
|
81
|
|
82
|
@Override
|
83
|
public void reload() {
|
84
|
|
85
|
MyWidgetHelper.hideSidebar();
|
86
|
|
87
|
SidebarPanel helpPanel = new SidebarPanel("Help");
|
88
|
MyWidgetHelper.loadHelp(helpPanel, token.split("\\.")[0]);
|
89
|
|
90
|
loadBudgets();
|
91
|
}
|
92
|
|
93
|
@Override
|
94
|
public void setToken(String token) {
|
95
|
this.token = token;
|
96
|
}
|
97
|
|
98
|
@Override
|
99
|
public void afterAdditionToRootPanel() {
|
100
|
|
101
|
}
|
102
|
|
103
|
@Override
|
104
|
public Widget asWidget() {
|
105
|
return monitorBudgetsPagePanel;
|
106
|
}
|
107
|
|
108
|
private void loadBudgets() {
|
109
|
|
110
|
errorLabel.setVisible(false);
|
111
|
warningLabel.setVisible(false);
|
112
|
|
113
|
final HTML loadingWheel = new HTML("<div class=\"loader-big\"></div><div class=\"whiteFilm\"></div>");
|
114
|
budgetsForApprovalPanel.addStyleName("loading");
|
115
|
budgetsForApprovalPanel.add(loadingWheel);
|
116
|
|
117
|
dataService.getBudgets(new AsyncCallback<List<BudgetInfo>>() {
|
118
|
|
119
|
@Override
|
120
|
public void onFailure(Throwable throwable) {
|
121
|
|
122
|
budgetsForApprovalPanel.clear();
|
123
|
budgetsForApprovalPanel.removeStyleName("loading");
|
124
|
|
125
|
errorLabel.setText("System error retrieving budgets");
|
126
|
errorLabel.setVisible(true);
|
127
|
}
|
128
|
|
129
|
@Override
|
130
|
public void onSuccess(List<BudgetInfo> budgetInfoList) {
|
131
|
|
132
|
budgetsForApprovalPanel.clear();
|
133
|
budgetsForApprovalPanel.removeStyleName("loading");
|
134
|
|
135
|
if (budgetInfoList.isEmpty()) {
|
136
|
warningLabel.setText("No available budgets at the moment.");
|
137
|
warningLabel.setVisible(true);
|
138
|
} else {
|
139
|
for (int i = 0; i < budgetInfoList.size(); i++)
|
140
|
drawBudgetInfo(budgetInfoList.get(i), i);
|
141
|
}
|
142
|
}
|
143
|
});
|
144
|
}
|
145
|
|
146
|
private void drawBudgetInfo(final BudgetInfo budgetInfo, int i) {
|
147
|
|
148
|
final FlowPanel budgetElement = new FlowPanel();
|
149
|
budgetElement.addStyleName("budgetRequest");
|
150
|
if(((i+1)%2)==1)
|
151
|
budgetElement.addStyleName("odd");
|
152
|
|
153
|
final Alert errorLabel = new Alert();
|
154
|
errorLabel.addStyleName("alertLabel");
|
155
|
errorLabel.setType(AlertType.ERROR);
|
156
|
errorLabel.setVisible(false);
|
157
|
errorLabel.setClose(false);
|
158
|
|
159
|
BudgetInfoElement budgetInfoElement = new BudgetInfoElement(budgetInfo);
|
160
|
|
161
|
FlowPanel actionButtons = new FlowPanel();
|
162
|
Button approve = new Button("Approve");
|
163
|
Button reject = new Button("Reject");
|
164
|
|
165
|
final FlowPanel divider = new FlowPanel();
|
166
|
|
167
|
final Form commentsForm = new Form();
|
168
|
final TextArea comments = new TextArea();
|
169
|
|
170
|
commentsForm.setType(FormType.VERTICAL);
|
171
|
comments.setEnabled(false);
|
172
|
if(budgetInfo.getComment()!=null)
|
173
|
comments.setValue(budgetInfo.getComment());
|
174
|
commentsForm.add(new FormFieldSet("Comments", comments));
|
175
|
|
176
|
actionButtons.addStyleName("requestInfoActionButtons");
|
177
|
|
178
|
approve.addStyleName("requestInfoActionButton");
|
179
|
approve.setType(ButtonType.SUCCESS);
|
180
|
approve.addClickHandler(new ClickHandler() {
|
181
|
@Override
|
182
|
public void onClick(ClickEvent clickEvent) {
|
183
|
|
184
|
errorLabel.setVisible(false);
|
185
|
|
186
|
dataService.approveBudget(budgetInfo.getId(), comments.getValue().trim(), new AsyncCallback<Void>() {
|
187
|
|
188
|
@Override
|
189
|
public void onFailure(Throwable throwable) {
|
190
|
|
191
|
errorLabel.setText("System error approving budget");
|
192
|
errorLabel.setVisible(true);
|
193
|
}
|
194
|
|
195
|
@Override
|
196
|
public void onSuccess(Void aVoid) {
|
197
|
|
198
|
budgetInfo.setStatus(Budget.Status.APPROVED);
|
199
|
BudgetInfoElement budgetInfoElement = new BudgetInfoElement(budgetInfo);
|
200
|
|
201
|
budgetElement.clear();
|
202
|
budgetElement.add(errorLabel);
|
203
|
budgetElement.add(budgetInfoElement.asWidget());
|
204
|
budgetElement.add(divider);
|
205
|
budgetElement.add(commentsForm);
|
206
|
|
207
|
comments.setEnabled(false);
|
208
|
}
|
209
|
});
|
210
|
}
|
211
|
});
|
212
|
actionButtons.add(approve);
|
213
|
|
214
|
reject.addStyleName("requestInfoActionButton");
|
215
|
reject.setType(ButtonType.DANGER);
|
216
|
reject.addClickHandler(new ClickHandler() {
|
217
|
@Override
|
218
|
public void onClick(ClickEvent clickEvent) {
|
219
|
|
220
|
errorLabel.setVisible(false);
|
221
|
|
222
|
dataService.rejectBudget(budgetInfo.getId(), comments.getValue().trim(), new AsyncCallback<Void>() {
|
223
|
|
224
|
@Override
|
225
|
public void onFailure(Throwable throwable) {
|
226
|
|
227
|
errorLabel.setText("System error rejecting budget");
|
228
|
errorLabel.setVisible(true);
|
229
|
}
|
230
|
|
231
|
@Override
|
232
|
public void onSuccess(Void aVoid) {
|
233
|
|
234
|
budgetInfo.setStatus(Budget.Status.REJECTED);
|
235
|
BudgetInfoElement budgetInfoElement = new BudgetInfoElement(budgetInfo);
|
236
|
|
237
|
budgetElement.clear();
|
238
|
budgetElement.add(errorLabel);
|
239
|
budgetElement.add(budgetInfoElement.asWidget());
|
240
|
budgetElement.add(divider);
|
241
|
budgetElement.add(commentsForm);
|
242
|
|
243
|
comments.setEnabled(false);
|
244
|
}
|
245
|
});
|
246
|
}
|
247
|
});
|
248
|
actionButtons.add(reject);
|
249
|
|
250
|
divider.addStyleName("uk-grid-divider");
|
251
|
|
252
|
budgetElement.add(errorLabel);
|
253
|
budgetElement.add(budgetInfoElement.asWidget());
|
254
|
budgetElement.add(divider);
|
255
|
budgetElement.add(commentsForm);
|
256
|
|
257
|
|
258
|
if(!budgetInfo.getStatus().equals(Budget.Status.APPROVED) && !budgetInfo.getStatus().equals(Budget.Status.REJECTED)) {
|
259
|
comments.setEnabled(true);
|
260
|
budgetElement.add(actionButtons);
|
261
|
}
|
262
|
|
263
|
budgetsForApprovalPanel.add(budgetElement);
|
264
|
}
|
265
|
}
|