1
|
package eu.dnetlib.client;
|
2
|
|
3
|
import com.github.gwtbootstrap.client.ui.Alert;
|
4
|
import com.github.gwtbootstrap.client.ui.constants.AlertType;
|
5
|
import com.google.gwt.core.client.GWT;
|
6
|
import com.google.gwt.dom.client.Document;
|
7
|
import com.google.gwt.dom.client.Style;
|
8
|
import com.google.gwt.i18n.client.DateTimeFormat;
|
9
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
10
|
import com.google.gwt.user.client.ui.*;
|
11
|
import eu.dnetlib.goldoa.domain.Affiliation;
|
12
|
import eu.dnetlib.goldoa.domain.BudgetInfo;
|
13
|
|
14
|
import java.util.ArrayList;
|
15
|
import java.util.List;
|
16
|
|
17
|
/**
|
18
|
* Created by stefania on 4/6/15.
|
19
|
*/
|
20
|
public class ExistingBudgetRequestsWidget implements MyWidget {
|
21
|
|
22
|
private String token = "";
|
23
|
|
24
|
private FlowPanel existingBudgetsPagePanel = new FlowPanel();
|
25
|
private Label existingBudgetsTitleLabel = new Label();
|
26
|
private Label existingBudgetsInfoLabel = new Label();
|
27
|
|
28
|
private Alert errorLabel = new Alert();
|
29
|
private Alert warningLabel = new Alert();
|
30
|
|
31
|
private FlowPanel budgetsForApprovalPanel = new FlowPanel();
|
32
|
|
33
|
private DateTimeFormat dtf = DateTimeFormat.getFormat("yyyy/MM/dd");
|
34
|
private DataServiceAsync dataService = GWT.create(DataService.class);
|
35
|
|
36
|
private GoldOAConstants goldOAConstants = GWT.create(GoldOAConstants.class);
|
37
|
|
38
|
public ExistingBudgetRequestsWidget() {
|
39
|
|
40
|
existingBudgetsPagePanel.addStyleName("content");
|
41
|
|
42
|
existingBudgetsTitleLabel.setText("Existing Budgets");
|
43
|
existingBudgetsTitleLabel.addStyleName("contentTitleLabel");
|
44
|
|
45
|
existingBudgetsInfoLabel.setText("View all your budget requests and the amount of money left in each one.");
|
46
|
existingBudgetsInfoLabel.addStyleName("contentInfoLabel");
|
47
|
|
48
|
errorLabel.addStyleName("alertLabel");
|
49
|
errorLabel.setType(AlertType.ERROR);
|
50
|
errorLabel.setClose(false);
|
51
|
errorLabel.setVisible(false);
|
52
|
|
53
|
warningLabel.addStyleName("alertLabel");
|
54
|
warningLabel.setType(AlertType.WARNING);
|
55
|
warningLabel.setClose(false);
|
56
|
warningLabel.setVisible(false);
|
57
|
|
58
|
budgetsForApprovalPanel.addStyleName("budgetsListPanel");
|
59
|
|
60
|
existingBudgetsPagePanel.add(existingBudgetsTitleLabel);
|
61
|
existingBudgetsPagePanel.add(existingBudgetsInfoLabel);
|
62
|
existingBudgetsPagePanel.add(errorLabel);
|
63
|
existingBudgetsPagePanel.add(warningLabel);
|
64
|
existingBudgetsPagePanel.add(budgetsForApprovalPanel);
|
65
|
}
|
66
|
|
67
|
@Override
|
68
|
public void clear() {
|
69
|
|
70
|
errorLabel.setVisible(false);
|
71
|
warningLabel.setVisible(false);
|
72
|
budgetsForApprovalPanel.clear();
|
73
|
}
|
74
|
|
75
|
@Override
|
76
|
public void reload() {
|
77
|
|
78
|
MyWidgetHelper.hideSidebar();
|
79
|
|
80
|
SidebarPanel helpPanel = new SidebarPanel("Help");
|
81
|
MyWidgetHelper.loadHelp(helpPanel, token.split("\\.")[0]);
|
82
|
|
83
|
loadBudgets();
|
84
|
}
|
85
|
|
86
|
@Override
|
87
|
public void setToken(String token) {
|
88
|
this.token = token;
|
89
|
}
|
90
|
|
91
|
@Override
|
92
|
public void afterAdditionToRootPanel() {
|
93
|
|
94
|
}
|
95
|
|
96
|
@Override
|
97
|
public Widget asWidget() {
|
98
|
return existingBudgetsPagePanel;
|
99
|
}
|
100
|
|
101
|
private void loadBudgets() {
|
102
|
|
103
|
errorLabel.setVisible(false);
|
104
|
warningLabel.setVisible(false);
|
105
|
|
106
|
final HTML loadingWheel = new HTML("<div class=\"loader-big\"></div><div class=\"whiteFilm\"></div>");
|
107
|
budgetsForApprovalPanel.addStyleName("loading");
|
108
|
budgetsForApprovalPanel.add(loadingWheel);
|
109
|
|
110
|
if(Utils.currentUserHasRole("library_staff")) {
|
111
|
|
112
|
List<String> organizationIds = new ArrayList<>();
|
113
|
for(Affiliation affiliation : GoldOAPortal.currentUser.getAffiliations()) {
|
114
|
if(affiliation.getOrganization()!=null)
|
115
|
organizationIds.add(affiliation.getOrganization().getId());
|
116
|
}
|
117
|
|
118
|
dataService.getBudgetsForOrganizations(organizationIds, new AsyncCallback<List<BudgetInfo>>() {
|
119
|
|
120
|
@Override
|
121
|
public void onFailure(Throwable throwable) {
|
122
|
|
123
|
budgetsForApprovalPanel.clear();
|
124
|
budgetsForApprovalPanel.removeStyleName("loading");
|
125
|
|
126
|
errorLabel.setText(goldOAConstants.errorGettingListOfBudgets());
|
127
|
errorLabel.setVisible(true);
|
128
|
}
|
129
|
|
130
|
@Override
|
131
|
public void onSuccess(List<BudgetInfo> budgetInfoList) {
|
132
|
|
133
|
budgetsForApprovalPanel.clear();
|
134
|
budgetsForApprovalPanel.removeStyleName("loading");
|
135
|
|
136
|
if (budgetInfoList.isEmpty()) {
|
137
|
warningLabel.setText(goldOAConstants.warningNoBudgetsAvailable());
|
138
|
warningLabel.setVisible(true);
|
139
|
} else {
|
140
|
for (int i = 0; i < budgetInfoList.size(); i++)
|
141
|
drawBudgetInfo(budgetInfoList.get(i), i);
|
142
|
}
|
143
|
}
|
144
|
});
|
145
|
|
146
|
} else {
|
147
|
|
148
|
dataService.getBudgetsForUser(GoldOAPortal.currentUser.getId(), new AsyncCallback<List<BudgetInfo>>() {
|
149
|
|
150
|
@Override
|
151
|
public void onFailure(Throwable throwable) {
|
152
|
|
153
|
budgetsForApprovalPanel.clear();
|
154
|
budgetsForApprovalPanel.removeStyleName("loading");
|
155
|
|
156
|
errorLabel.setText(goldOAConstants.errorGettingListOfBudgets());
|
157
|
errorLabel.setVisible(true);
|
158
|
}
|
159
|
|
160
|
@Override
|
161
|
public void onSuccess(List<BudgetInfo> budgetInfoList) {
|
162
|
|
163
|
budgetsForApprovalPanel.clear();
|
164
|
budgetsForApprovalPanel.removeStyleName("loading");
|
165
|
|
166
|
if (budgetInfoList.isEmpty()) {
|
167
|
warningLabel.setText(goldOAConstants.warningNoBudgetsAvailable());
|
168
|
warningLabel.setVisible(true);
|
169
|
} else {
|
170
|
for (int i = 0; i < budgetInfoList.size(); i++)
|
171
|
drawBudgetInfo(budgetInfoList.get(i), i);
|
172
|
}
|
173
|
}
|
174
|
});
|
175
|
}
|
176
|
}
|
177
|
|
178
|
private void drawBudgetInfo(BudgetInfo budgetInfo, int i) {
|
179
|
|
180
|
FlowPanel budgetElement = new FlowPanel();
|
181
|
budgetElement.addStyleName("budgetRequest");
|
182
|
if(((i+1)%2)==1)
|
183
|
budgetElement.addStyleName("odd");
|
184
|
|
185
|
BudgetInfoElement budgetInfoElement = new BudgetInfoElement(budgetInfo);
|
186
|
|
187
|
budgetElement.add(budgetInfoElement.asWidget());
|
188
|
budgetsForApprovalPanel.add(budgetElement);
|
189
|
}
|
190
|
}
|