1
|
package eu.dnetlib.client;
|
2
|
|
3
|
import com.github.gwtbootstrap.client.ui.*;
|
4
|
import com.github.gwtbootstrap.client.ui.Button;
|
5
|
import com.github.gwtbootstrap.client.ui.ListBox;
|
6
|
import com.github.gwtbootstrap.client.ui.SubmitButton;
|
7
|
import com.github.gwtbootstrap.client.ui.base.IconAnchor;
|
8
|
import com.github.gwtbootstrap.client.ui.constants.*;
|
9
|
import com.github.gwtbootstrap.datepicker.client.ui.DateBox;
|
10
|
import com.google.gwt.core.client.GWT;
|
11
|
import com.google.gwt.event.dom.client.ClickEvent;
|
12
|
import com.google.gwt.event.dom.client.ClickHandler;
|
13
|
import com.google.gwt.user.client.Window;
|
14
|
import com.google.gwt.user.client.ui.*;
|
15
|
import com.google.gwt.user.client.ui.FileUpload;
|
16
|
import com.google.gwt.user.client.ui.Label;
|
17
|
import com.google.gwt.user.datepicker.client.CalendarUtil;
|
18
|
import eu.dnetlib.client.widgets.FormFieldSet;
|
19
|
import eu.dnetlib.client.widgets.TextBox;
|
20
|
import eu.dnetlib.goldoa.domain.Affiliation;
|
21
|
import eu.dnetlib.goldoa.domain.Organization;
|
22
|
|
23
|
import java.util.Date;
|
24
|
|
25
|
/**
|
26
|
* Created by stefania on 4/2/15.
|
27
|
*/
|
28
|
public class NewBudgetRequestWidget implements MyWidget {
|
29
|
|
30
|
private String token = "";
|
31
|
|
32
|
private FlowPanel newBudgetRequestPanel = new FlowPanel();
|
33
|
|
34
|
private Label titleLabel = new Label();
|
35
|
private Label informationLabel = new Label();
|
36
|
|
37
|
private Alert informationAlert = new Alert();
|
38
|
private Alert errorLabel = new Alert();
|
39
|
|
40
|
private FlowPanel budgetFormPanel = new FlowPanel();
|
41
|
|
42
|
private Form budgetForm = new Form();
|
43
|
private IconAnchor downloadTerms = new IconAnchor();
|
44
|
private ListBox institutions = new ListBox();
|
45
|
private TextBox budgetRequestedTextBox = new TextBox();
|
46
|
private DateBox startDateDateBox = new DateBox();
|
47
|
private DateBox endDateDateBox = new DateBox();
|
48
|
private FileUpload fileUpload = new FileUpload();
|
49
|
private TextBox userIdTextBox = new TextBox();
|
50
|
|
51
|
private Label bankInfoLabel = new Label();
|
52
|
private TextBox nameOfBank = new TextBox();
|
53
|
private TextBox addressOfBank = new TextBox();
|
54
|
private TextBox accountHolder = new TextBox();
|
55
|
private TextBox accountNumber = new TextBox();
|
56
|
private TextBox bankCode = new TextBox();
|
57
|
|
58
|
private Button submit = new Button("Submit");
|
59
|
|
60
|
private HTML loadingWheel = new HTML("<div class=\"loader\"></div><div class=\"whiteFilm\"></div>");
|
61
|
|
62
|
public NewBudgetRequestWidget() {
|
63
|
|
64
|
newBudgetRequestPanel.addStyleName("content");
|
65
|
|
66
|
titleLabel.setText("New Budget Request");
|
67
|
titleLabel.addStyleName("contentTitleLabel");
|
68
|
|
69
|
informationLabel.setText("Request a new budget for an institution that you are affiliated with.");
|
70
|
informationLabel.addStyleName("contentInfoLabel");
|
71
|
|
72
|
informationAlert.addStyleName("alertLabel");
|
73
|
informationAlert.setType(AlertType.SUCCESS);
|
74
|
informationAlert.setClose(false);
|
75
|
informationAlert.setVisible(false);
|
76
|
|
77
|
errorLabel.addStyleName("alertLabel");
|
78
|
errorLabel.setType(AlertType.ERROR);
|
79
|
errorLabel.setClose(false);
|
80
|
errorLabel.setVisible(false);
|
81
|
|
82
|
budgetForm.setType(FormType.HORIZONTAL);
|
83
|
budgetForm.addStyleName("budgetForm");
|
84
|
budgetForm.setAction(GWT.getModuleBaseURL() + "budget");
|
85
|
budgetForm.setEncoding(FormPanel.ENCODING_MULTIPART);
|
86
|
budgetForm.setMethod(FormPanel.METHOD_POST);
|
87
|
|
88
|
budgetFormPanel.add(budgetForm);
|
89
|
|
90
|
downloadTerms.setText("Click here to download the terms of agreement");
|
91
|
downloadTerms.setIcon(IconType.DOWNLOAD_ALT);
|
92
|
downloadTerms.setIconPosition(IconPosition.RIGHT);
|
93
|
downloadTerms.addClickHandler(new ClickHandler() {
|
94
|
@Override
|
95
|
public void onClick(ClickEvent clickEvent) {
|
96
|
Window.open(GWT.getHostPageBaseURL() + "pdf/test.pdf", "_blank", "status=0,toolbar=0,menubar=0,location=0");
|
97
|
}
|
98
|
});
|
99
|
budgetForm.add(new FormFieldSet(null, downloadTerms));
|
100
|
|
101
|
for(Affiliation affiliation : GoldOAPortal.currentUser.getAffiliations()) {
|
102
|
Organization organization = affiliation.getOrganization();
|
103
|
if(organization!=null)
|
104
|
institutions.addItem(organization.getName(), organization.getId());
|
105
|
}
|
106
|
institutions.setAlternateSize(AlternateSize.XXLARGE);
|
107
|
institutions.setName("institution");
|
108
|
budgetForm.add(new FormFieldSet("Organization (*)", institutions));
|
109
|
|
110
|
Label budgetLabel = new Label("Euros");
|
111
|
budgetLabel.addStyleName("inlineBlock");
|
112
|
|
113
|
budgetRequestedTextBox.setAlternateSize(AlternateSize.XLARGE);
|
114
|
budgetRequestedTextBox.addStyleName("inlineBlock");
|
115
|
budgetRequestedTextBox.setName("amountRequested");
|
116
|
budgetForm.add(new FormFieldSet("Budget Requested (*)", budgetRequestedTextBox, budgetLabel));
|
117
|
|
118
|
startDateDateBox.setValue(new Date());
|
119
|
startDateDateBox.setName("startDate");
|
120
|
startDateDateBox.setFormat("yyyy/mm/dd");
|
121
|
budgetForm.add(new FormFieldSet("Start Date (*)", startDateDateBox));
|
122
|
|
123
|
Date endDate = new Date();
|
124
|
CalendarUtil.addMonthsToDate(endDate, 6);
|
125
|
endDateDateBox.setValue(endDate);
|
126
|
endDateDateBox.setName("endDate");
|
127
|
endDateDateBox.setFormat("yyyy/mm/dd");
|
128
|
budgetForm.add(new FormFieldSet("End Date (*)", endDateDateBox));
|
129
|
|
130
|
fileUpload.setName("termsFile");
|
131
|
fileUpload.addStyleName("input-xxlarge");
|
132
|
budgetForm.add(new FormFieldSet("Signed terms of agreement (*)", fileUpload));
|
133
|
|
134
|
userIdTextBox.setName("userId");
|
135
|
userIdTextBox.setValue(GoldOAPortal.currentUser.getId());
|
136
|
userIdTextBox.setVisible(false);
|
137
|
budgetForm.add(userIdTextBox);
|
138
|
|
139
|
bankInfoLabel.setText("Bank Information");
|
140
|
bankInfoLabel.addStyleName("strong");
|
141
|
budgetForm.add(new FormFieldSet(null, bankInfoLabel));
|
142
|
|
143
|
nameOfBank.setAlternateSize(AlternateSize.XLARGE);
|
144
|
nameOfBank.setName("bankName");
|
145
|
budgetForm.add(new FormFieldSet("Name of bank (*)", nameOfBank));
|
146
|
|
147
|
addressOfBank.setAlternateSize(AlternateSize.XLARGE);
|
148
|
addressOfBank.setName("bankAddress");
|
149
|
budgetForm.add(new FormFieldSet("Address of bank (*)", addressOfBank));
|
150
|
|
151
|
accountHolder.setAlternateSize(AlternateSize.XLARGE);
|
152
|
accountHolder.setName("accountHolder");
|
153
|
budgetForm.add(new FormFieldSet("Account holder (*)", accountHolder));
|
154
|
|
155
|
accountNumber.setAlternateSize(AlternateSize.XLARGE);
|
156
|
accountNumber.setName("accountNumber");
|
157
|
budgetForm.add(new FormFieldSet("Account number (IBAN format) (*)", accountNumber));
|
158
|
|
159
|
bankCode.setAlternateSize(AlternateSize.XLARGE);
|
160
|
bankCode.setName("bankCode");
|
161
|
budgetForm.add(new FormFieldSet("Bank code (BIC) / SWIFT code (*)", bankCode));
|
162
|
|
163
|
submit.setType(ButtonType.PRIMARY);
|
164
|
submit.addClickHandler(new ClickHandler() {
|
165
|
|
166
|
@Override
|
167
|
public void onClick(ClickEvent clickEvent) {
|
168
|
|
169
|
errorLabel.setVisible(false);
|
170
|
informationAlert.setVisible(false);
|
171
|
|
172
|
if(isComplete()) {
|
173
|
|
174
|
if(isPositiveFloat(budgetRequestedTextBox.getValue().trim())) {
|
175
|
|
176
|
budgetFormPanel.addStyleName("loading-small");
|
177
|
budgetFormPanel.add(loadingWheel);
|
178
|
budgetForm.submit();
|
179
|
|
180
|
} else {
|
181
|
errorLabel.setText("Budget must be a number greater than 0.");
|
182
|
errorLabel.setVisible(true);
|
183
|
}
|
184
|
} else {
|
185
|
errorLabel.setText("All asterisk (*) fields are required.");
|
186
|
errorLabel.setVisible(true);
|
187
|
}
|
188
|
}
|
189
|
});
|
190
|
budgetForm.add(new FormFieldSet(null, submit));
|
191
|
|
192
|
budgetForm.addSubmitCompleteHandler(new Form.SubmitCompleteHandler() {
|
193
|
@Override
|
194
|
public void onSubmitComplete(Form.SubmitCompleteEvent submitCompleteEvent) {
|
195
|
|
196
|
budgetFormPanel.removeStyleName("loading-small");
|
197
|
budgetFormPanel.remove(loadingWheel);
|
198
|
|
199
|
String budgetId = submitCompleteEvent.getResults().replace("<pre>", "").replace("</pre>", "");
|
200
|
|
201
|
informationAlert.setText("Budget request was completed successfully");
|
202
|
informationAlert.setVisible(true);
|
203
|
}
|
204
|
});
|
205
|
|
206
|
newBudgetRequestPanel.add(titleLabel);
|
207
|
newBudgetRequestPanel.add(informationLabel);
|
208
|
newBudgetRequestPanel.add(informationAlert);
|
209
|
newBudgetRequestPanel.add(errorLabel);
|
210
|
newBudgetRequestPanel.add(budgetFormPanel);
|
211
|
}
|
212
|
|
213
|
@Override
|
214
|
public Widget asWidget() {
|
215
|
return newBudgetRequestPanel;
|
216
|
}
|
217
|
|
218
|
@Override
|
219
|
public void clear() {
|
220
|
|
221
|
errorLabel.setVisible(false);
|
222
|
informationAlert.setVisible(false);
|
223
|
|
224
|
budgetRequestedTextBox.setValue("");
|
225
|
institutions.clear();
|
226
|
|
227
|
budgetForm.reset();
|
228
|
}
|
229
|
|
230
|
@Override
|
231
|
public void reload() {
|
232
|
|
233
|
MyWidgetHelper.hideSidebar();
|
234
|
|
235
|
SidebarPanel helpPanel = new SidebarPanel("Help");
|
236
|
MyWidgetHelper.loadHelp(helpPanel, token.split("\\.")[0]);
|
237
|
|
238
|
for(Affiliation affiliation : GoldOAPortal.currentUser.getAffiliations()) {
|
239
|
Organization organization = affiliation.getOrganization();
|
240
|
if(organization!=null)
|
241
|
institutions.addItem(organization.getName(), organization.getId());
|
242
|
}
|
243
|
|
244
|
userIdTextBox.setValue(GoldOAPortal.currentUser.getId());
|
245
|
|
246
|
startDateDateBox.setValue(new Date());
|
247
|
Date endDate = new Date();
|
248
|
CalendarUtil.addMonthsToDate(endDate, 6);
|
249
|
endDateDateBox.setValue(endDate);
|
250
|
}
|
251
|
|
252
|
@Override
|
253
|
public void setToken(String token) {
|
254
|
this.token = token;
|
255
|
}
|
256
|
|
257
|
@Override
|
258
|
public void afterAdditionToRootPanel() {
|
259
|
|
260
|
}
|
261
|
|
262
|
private boolean isComplete() {
|
263
|
|
264
|
if(!budgetRequestedTextBox.getValue().trim().equals("") && (fileUpload.getFilename()!=null && !fileUpload.getFilename().equals(""))
|
265
|
&& !nameOfBank.getValue().trim().equals("") && !addressOfBank.getValue().trim().equals("")
|
266
|
&& !accountHolder.getValue().trim().equals("") && !accountNumber.getValue().trim().equals("")
|
267
|
&& !bankCode.getValue().trim().equals(""))
|
268
|
return true;
|
269
|
|
270
|
return false;
|
271
|
}
|
272
|
|
273
|
private boolean isPositiveFloat(String number) {
|
274
|
|
275
|
try {
|
276
|
Float numberValue = Float.parseFloat(number);
|
277
|
if(numberValue > 0)
|
278
|
return true;
|
279
|
} catch(NumberFormatException nfe) {
|
280
|
return false;
|
281
|
}
|
282
|
|
283
|
return false;
|
284
|
}
|
285
|
}
|