1 |
36099
|
stefania.m
|
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 |
36230
|
stefania.m
|
import eu.dnetlib.goldoa.domain.Affiliation;
|
12 |
36099
|
stefania.m
|
import eu.dnetlib.goldoa.domain.BudgetInfo;
|
13 |
|
|
|
14 |
36230
|
stefania.m
|
import java.util.ArrayList;
|
15 |
36099
|
stefania.m
|
import java.util.List;
|
16 |
|
|
|
17 |
|
|
/**
|
18 |
|
|
* Created by stefania on 4/6/15.
|
19 |
|
|
*/
|
20 |
|
|
public class ExistingBudgetRequestsWidget implements MyWidget {
|
21 |
|
|
|
22 |
36467
|
stefania.m
|
private String token = "";
|
23 |
|
|
|
24 |
36099
|
stefania.m
|
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 |
36946
|
stefania.m
|
private GoldOAConstants goldOAConstants = GWT.create(GoldOAConstants.class);
|
37 |
|
|
|
38 |
36099
|
stefania.m
|
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 |
36624
|
stefania.m
|
MyWidgetHelper.hideSidebar();
|
79 |
36099
|
stefania.m
|
|
80 |
36467
|
stefania.m
|
SidebarPanel helpPanel = new SidebarPanel("Help");
|
81 |
|
|
MyWidgetHelper.loadHelp(helpPanel, token.split("\\.")[0]);
|
82 |
|
|
|
83 |
36099
|
stefania.m
|
loadBudgets();
|
84 |
|
|
}
|
85 |
|
|
|
86 |
|
|
@Override
|
87 |
|
|
public void setToken(String token) {
|
88 |
36467
|
stefania.m
|
this.token = token;
|
89 |
36099
|
stefania.m
|
}
|
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 |
36230
|
stefania.m
|
if(Utils.currentUserHasRole("library_staff")) {
|
111 |
36099
|
stefania.m
|
|
112 |
36230
|
stefania.m
|
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 |
36099
|
stefania.m
|
|
118 |
36230
|
stefania.m
|
dataService.getBudgetsForOrganizations(organizationIds, new AsyncCallback<List<BudgetInfo>>() {
|
119 |
36099
|
stefania.m
|
|
120 |
36230
|
stefania.m
|
@Override
|
121 |
|
|
public void onFailure(Throwable throwable) {
|
122 |
36099
|
stefania.m
|
|
123 |
36230
|
stefania.m
|
budgetsForApprovalPanel.clear();
|
124 |
|
|
budgetsForApprovalPanel.removeStyleName("loading");
|
125 |
36099
|
stefania.m
|
|
126 |
36946
|
stefania.m
|
errorLabel.setText(goldOAConstants.errorGettingListOfBudgets());
|
127 |
36230
|
stefania.m
|
errorLabel.setVisible(true);
|
128 |
|
|
}
|
129 |
36099
|
stefania.m
|
|
130 |
36230
|
stefania.m
|
@Override
|
131 |
|
|
public void onSuccess(List<BudgetInfo> budgetInfoList) {
|
132 |
|
|
|
133 |
|
|
budgetsForApprovalPanel.clear();
|
134 |
|
|
budgetsForApprovalPanel.removeStyleName("loading");
|
135 |
|
|
|
136 |
|
|
if (budgetInfoList.isEmpty()) {
|
137 |
36946
|
stefania.m
|
warningLabel.setText(goldOAConstants.warningNoBudgetsAvailable());
|
138 |
36230
|
stefania.m
|
warningLabel.setVisible(true);
|
139 |
|
|
} else {
|
140 |
|
|
for (int i = 0; i < budgetInfoList.size(); i++)
|
141 |
|
|
drawBudgetInfo(budgetInfoList.get(i), i);
|
142 |
|
|
}
|
143 |
36099
|
stefania.m
|
}
|
144 |
36230
|
stefania.m
|
});
|
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 |
36946
|
stefania.m
|
errorLabel.setText(goldOAConstants.errorGettingListOfBudgets());
|
157 |
36230
|
stefania.m
|
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 |
36946
|
stefania.m
|
warningLabel.setText(goldOAConstants.warningNoBudgetsAvailable());
|
168 |
36230
|
stefania.m
|
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 |
36099
|
stefania.m
|
}
|
177 |
|
|
|
178 |
|
|
private void drawBudgetInfo(BudgetInfo budgetInfo, int i) {
|
179 |
|
|
|
180 |
36110
|
stefania.m
|
FlowPanel budgetElement = new FlowPanel();
|
181 |
|
|
budgetElement.addStyleName("budgetRequest");
|
182 |
36099
|
stefania.m
|
if(((i+1)%2)==1)
|
183 |
36110
|
stefania.m
|
budgetElement.addStyleName("odd");
|
184 |
36099
|
stefania.m
|
|
185 |
36110
|
stefania.m
|
BudgetInfoElement budgetInfoElement = new BudgetInfoElement(budgetInfo);
|
186 |
36099
|
stefania.m
|
|
187 |
36110
|
stefania.m
|
budgetElement.add(budgetInfoElement.asWidget());
|
188 |
|
|
budgetsForApprovalPanel.add(budgetElement);
|
189 |
36099
|
stefania.m
|
}
|
190 |
|
|
}
|