1
|
package eu.dnetlib.client.fundingrequest.newrequest.publicationstep;
|
2
|
|
3
|
import com.github.gwtbootstrap.client.ui.Alert;
|
4
|
import com.github.gwtbootstrap.client.ui.CheckBox;
|
5
|
import com.github.gwtbootstrap.client.ui.Form;
|
6
|
import com.github.gwtbootstrap.client.ui.constants.AlertType;
|
7
|
import com.github.gwtbootstrap.client.ui.constants.AlternateSize;
|
8
|
import com.github.gwtbootstrap.client.ui.constants.FormType;
|
9
|
import com.google.gwt.core.client.GWT;
|
10
|
import com.google.gwt.event.logical.shared.ValueChangeEvent;
|
11
|
import com.google.gwt.event.logical.shared.ValueChangeHandler;
|
12
|
import com.google.gwt.user.client.Window;
|
13
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
14
|
import com.google.gwt.user.client.ui.FlowPanel;
|
15
|
import com.google.gwt.user.client.ui.IsWidget;
|
16
|
import com.google.gwt.user.client.ui.Label;
|
17
|
import com.google.gwt.user.client.ui.Widget;
|
18
|
import eu.dnetlib.client.DataService;
|
19
|
import eu.dnetlib.client.DataServiceAsync;
|
20
|
import eu.dnetlib.client.GoldOAConstants;
|
21
|
import eu.dnetlib.client.widgets.AutoCompleteWidget;
|
22
|
import eu.dnetlib.client.widgets.FormFieldSet;
|
23
|
import eu.dnetlib.client.widgets.TextBox;
|
24
|
import eu.dnetlib.goldoa.domain.*;
|
25
|
|
26
|
/**
|
27
|
* Created by stefania on 3/11/15.
|
28
|
*/
|
29
|
public class JournalInfoStep implements IsWidget {
|
30
|
|
31
|
private FlowPanel journalInfoStepPanel = new FlowPanel();
|
32
|
|
33
|
private Alert errorLabel = new Alert();
|
34
|
|
35
|
private Form journalAutoCompleteForm = new Form();
|
36
|
private AutoCompleteWidget journalAutoComplete = new AutoCompleteWidget("journal", "Search...");
|
37
|
|
38
|
private CheckBox cannotFindJournal = new CheckBox();
|
39
|
|
40
|
// journal info form
|
41
|
private FlowPanel journalInfoPanel = new FlowPanel();
|
42
|
|
43
|
private Alert journalFormErrorLabel = new Alert();
|
44
|
|
45
|
private Form journalInfoForm = new Form();
|
46
|
private TextBox title = new TextBox();
|
47
|
private TextBox alternativeTitle = new TextBox();
|
48
|
private TextBox url = new TextBox();
|
49
|
private TextBox languages = new TextBox();
|
50
|
private TextBox issnAndEissn = new TextBox();
|
51
|
private TextBox country = new TextBox();
|
52
|
private TextBox subjects = new TextBox();
|
53
|
private TextBox licence = new TextBox();
|
54
|
private TextBox apc = new TextBox();
|
55
|
private TextBox discount = new TextBox();
|
56
|
|
57
|
private FlowPanel journalDisplayInfoPanel = new FlowPanel();
|
58
|
|
59
|
private Vocabulary voc = null;
|
60
|
private Journal journal = null;
|
61
|
private Journal journalFromAutoComplete = null;
|
62
|
private Currency journalCurrency = Currency.EUR;
|
63
|
private Publisher journalPublisher = null;
|
64
|
|
65
|
|
66
|
private String journalIdFromDB = null;
|
67
|
|
68
|
private Label apcEurosLabel = new Label(" " + journalCurrency.getName());
|
69
|
|
70
|
private DataServiceAsync dataService = GWT.create(DataService.class);
|
71
|
private GoldOAConstants goldOAConstants = GWT.create(GoldOAConstants.class);
|
72
|
|
73
|
public JournalInfoStep() {
|
74
|
|
75
|
errorLabel.addStyleName("alertLabel");
|
76
|
errorLabel.setType(AlertType.ERROR);
|
77
|
errorLabel.setVisible(false);
|
78
|
errorLabel.setClose(false);
|
79
|
|
80
|
journalAutoCompleteForm.setType(FormType.HORIZONTAL);
|
81
|
journalAutoCompleteForm.addStyleName("journalAutoCompleteForm");
|
82
|
|
83
|
journalInfoStepPanel.add(errorLabel);
|
84
|
journalInfoStepPanel.add(journalAutoCompleteForm);
|
85
|
|
86
|
cannotFindJournal.setText("If you cannot find your journal, check to complete its information");
|
87
|
cannotFindJournal.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
|
88
|
@Override
|
89
|
public void onValueChange(ValueChangeEvent<Boolean> booleanValueChangeEvent) {
|
90
|
|
91
|
if (cannotFindJournal.getValue()) {
|
92
|
journalInfoStepPanel.remove(journalDisplayInfoPanel);
|
93
|
journalInfoStepPanel.add(journalInfoPanel);
|
94
|
journalAutoComplete.setValue("");
|
95
|
} else {
|
96
|
journalInfoStepPanel.remove(journalInfoPanel);
|
97
|
}
|
98
|
}
|
99
|
});
|
100
|
|
101
|
AutoCompleteWidget.AutoCompleteListener autoCompleteListener = new AutoCompleteWidget.AutoCompleteListener() {
|
102
|
@Override
|
103
|
public void valueSelected(Vocabulary vocabulary) {
|
104
|
|
105
|
journal = vocabulary.getJournal();
|
106
|
cannotFindJournal.setValue(false);
|
107
|
|
108
|
if (journal == null) {
|
109
|
journalDisplayInfoPanel.clear();
|
110
|
JournalDisplayInfo journalDisplayInfo = new JournalDisplayInfo(null);
|
111
|
journalDisplayInfoPanel.add(journalDisplayInfo.asWidget());
|
112
|
journalInfoStepPanel.remove(journalInfoPanel);
|
113
|
journalInfoStepPanel.add(journalDisplayInfoPanel);
|
114
|
}else{
|
115
|
journalFromAutoComplete = journal;
|
116
|
|
117
|
journalDisplayInfoPanel.clear();
|
118
|
JournalDisplayInfo journalDisplayInfo = new JournalDisplayInfo(journal);
|
119
|
journalDisplayInfoPanel.add(journalDisplayInfo.asWidget());
|
120
|
journalInfoStepPanel.remove(journalInfoPanel);
|
121
|
journalInfoStepPanel.add(journalDisplayInfoPanel);
|
122
|
}
|
123
|
|
124
|
|
125
|
/*dataService.getJournal(vocabulary.getId(), new AsyncCallback<Journal>() {
|
126
|
|
127
|
@Override
|
128
|
public void onFailure(Throwable throwable) {
|
129
|
journalDisplayInfoPanel.clear();
|
130
|
JournalDisplayInfo journalDisplayInfo = new JournalDisplayInfo(null);
|
131
|
journalDisplayInfoPanel.add(journalDisplayInfo.asWidget());
|
132
|
journalInfoStepPanel.remove(journalInfoPanel);
|
133
|
journalInfoStepPanel.add(journalDisplayInfoPanel);
|
134
|
}
|
135
|
|
136
|
@Override
|
137
|
public void onSuccess(Journal journal) {
|
138
|
|
139
|
journalFromAutoComplete = journal;
|
140
|
|
141
|
journalDisplayInfoPanel.clear();
|
142
|
JournalDisplayInfo journalDisplayInfo = new JournalDisplayInfo(journal);
|
143
|
journalDisplayInfoPanel.add(journalDisplayInfo.asWidget());
|
144
|
journalInfoStepPanel.remove(journalInfoPanel);
|
145
|
journalInfoStepPanel.add(journalDisplayInfoPanel);
|
146
|
}
|
147
|
});*/
|
148
|
}
|
149
|
};
|
150
|
journalAutoComplete.setAutoCompleteListener(autoCompleteListener);
|
151
|
|
152
|
journalAutoCompleteForm.add(new FormFieldSet("Journal Title (*)", journalAutoComplete.asWidget(), cannotFindJournal));
|
153
|
|
154
|
//journal info form
|
155
|
journalInfoPanel.addStyleName("journalInfoPanel");
|
156
|
|
157
|
journalFormErrorLabel.addStyleName("alertLabel");
|
158
|
journalFormErrorLabel.setType(AlertType.ERROR);
|
159
|
journalFormErrorLabel.setVisible(false);
|
160
|
journalFormErrorLabel.setClose(false);
|
161
|
|
162
|
journalInfoForm.setType(FormType.HORIZONTAL);
|
163
|
journalInfoForm.addStyleName("journalInfoForm");
|
164
|
journalInfoPanel.add(journalInfoForm);
|
165
|
|
166
|
title.setAlternateSize(AlternateSize.XXLARGE);
|
167
|
|
168
|
alternativeTitle.setAlternateSize(AlternateSize.XXLARGE);
|
169
|
|
170
|
url.setAlternateSize(AlternateSize.XXLARGE);
|
171
|
|
172
|
languages.setAlternateSize(AlternateSize.XXLARGE);
|
173
|
languages.setPlaceholder(" languages as a comma-separated list");
|
174
|
|
175
|
issnAndEissn.setAlternateSize(AlternateSize.XXLARGE);
|
176
|
issnAndEissn.setPlaceholder(" values as a comma-seperated list");
|
177
|
|
178
|
country.setAlternateSize(AlternateSize.XXLARGE);
|
179
|
|
180
|
subjects.setAlternateSize(AlternateSize.XXLARGE);
|
181
|
subjects.setPlaceholder(" subjects as a comma-separated list");
|
182
|
|
183
|
licence.setAlternateSize(AlternateSize.XXLARGE);
|
184
|
|
185
|
apcEurosLabel.setStyleName("inlineBlock");
|
186
|
|
187
|
apc.setAlternateSize(AlternateSize.XXLARGE);
|
188
|
apc.addStyleName("inlineBlock");
|
189
|
apc.setEnabled(false);
|
190
|
|
191
|
Label goldDiscountPercentageLabel = new Label(" %");
|
192
|
goldDiscountPercentageLabel.setStyleName("inlineBlock");
|
193
|
|
194
|
discount.setAlternateSize(AlternateSize.XXLARGE);
|
195
|
discount.addStyleName("inlineBlock");
|
196
|
discount.setEnabled(false);
|
197
|
|
198
|
journalInfoForm.add(journalFormErrorLabel);
|
199
|
journalInfoForm.add(new FormFieldSet("Title (*)", title));
|
200
|
journalInfoForm.add(new FormFieldSet("Alternative Title", alternativeTitle));
|
201
|
journalInfoForm.add(new FormFieldSet("URL", url));
|
202
|
journalInfoForm.add(new FormFieldSet("Languages", languages));
|
203
|
journalInfoForm.add(new FormFieldSet("ISSN / EISSN", issnAndEissn));
|
204
|
journalInfoForm.add(new FormFieldSet("Country", country));
|
205
|
journalInfoForm.add(new FormFieldSet("Subjects", subjects));
|
206
|
journalInfoForm.add(new FormFieldSet("Licence", licence));
|
207
|
journalInfoForm.add(new FormFieldSet("Listed APC fee", apc, apcEurosLabel));
|
208
|
journalInfoForm.add(new FormFieldSet("Pilot Discount", discount, goldDiscountPercentageLabel));
|
209
|
}
|
210
|
|
211
|
@Override
|
212
|
public Widget asWidget() {
|
213
|
return journalInfoStepPanel;
|
214
|
}
|
215
|
|
216
|
public boolean isComplete() {
|
217
|
|
218
|
if(!title.getValue().trim().equals(""))
|
219
|
return true;
|
220
|
|
221
|
return false;
|
222
|
}
|
223
|
|
224
|
public Journal getJournal() {
|
225
|
|
226
|
journalFormErrorLabel.setVisible(false);
|
227
|
errorLabel.setVisible(false);
|
228
|
|
229
|
if(cannotFindJournal.getValue()) {
|
230
|
if (isComplete()) {
|
231
|
|
232
|
Journal journal = new Journal();
|
233
|
if(journalIdFromDB!=null)
|
234
|
journal.setId(journalIdFromDB);
|
235
|
journal.setTitle(title.getValue().trim());
|
236
|
journal.setAlternativeTitle(alternativeTitle.getValue().trim());
|
237
|
journal.setUrl(url.getValue().trim());
|
238
|
journal.setLanguages(languages.getValue().trim());
|
239
|
journal.setIssn(issnAndEissn.getValue().trim());
|
240
|
journal.setCountry(country.getValue().trim());
|
241
|
journal.setSubjects(subjects.getValue().trim());
|
242
|
journal.setLicence(licence.getValue().trim());
|
243
|
|
244
|
journal.setApccurrency(journalCurrency);
|
245
|
|
246
|
journal.setPublisher(journalPublisher);
|
247
|
|
248
|
return journal;
|
249
|
|
250
|
} else {
|
251
|
journalFormErrorLabel.setText(goldOAConstants.journalFormErrorAllFieldsRequired());
|
252
|
journalFormErrorLabel.setVisible(true);
|
253
|
}
|
254
|
} else {
|
255
|
if(journal!=null) {
|
256
|
|
257
|
if(journalFromAutoComplete!=null)
|
258
|
return journalFromAutoComplete;
|
259
|
|
260
|
Journal journal = new Journal();
|
261
|
journal.setId(this.journal.getId());
|
262
|
return journal;
|
263
|
|
264
|
} else {
|
265
|
errorLabel.setText(goldOAConstants.journalErrorNotSelected());
|
266
|
errorLabel.setVisible(true);
|
267
|
}
|
268
|
}
|
269
|
|
270
|
return null;
|
271
|
}
|
272
|
|
273
|
public void clear() {
|
274
|
|
275
|
journalFormErrorLabel.setVisible(false);
|
276
|
errorLabel.setVisible(false);
|
277
|
|
278
|
journal = null;
|
279
|
journalIdFromDB = null;
|
280
|
journalAutoComplete.setValue("");
|
281
|
|
282
|
journalCurrency = Currency.EUR;
|
283
|
apcEurosLabel.setText(" " + journalCurrency.getName());
|
284
|
|
285
|
cannotFindJournal.setValue(false);
|
286
|
|
287
|
title.setValue("");
|
288
|
alternativeTitle.setValue("");
|
289
|
url.setValue("");
|
290
|
languages.setValue("");
|
291
|
issnAndEissn.setValue("");
|
292
|
country.setValue("");
|
293
|
subjects.setValue("");
|
294
|
licence.setValue("");
|
295
|
apc.setValue("");
|
296
|
discount.setValue("");
|
297
|
|
298
|
journalInfoStepPanel.remove(journalInfoPanel);
|
299
|
}
|
300
|
|
301
|
public void loadJournalInfo(Journal journal) {
|
302
|
|
303
|
this.journal = null;
|
304
|
journalIdFromDB = journal.getId();
|
305
|
|
306
|
journalCurrency = journal.getApccurrency();
|
307
|
apcEurosLabel.setText(" " + journalCurrency.getName());
|
308
|
|
309
|
journalPublisher = journal.getPublisher();
|
310
|
|
311
|
cannotFindJournal.setValue(true);
|
312
|
|
313
|
journalInfoStepPanel.remove(journalDisplayInfoPanel);
|
314
|
journalInfoStepPanel.add(journalInfoPanel);
|
315
|
journalAutoComplete.setValue("");
|
316
|
|
317
|
title.setValue(journal.getTitle());
|
318
|
alternativeTitle.setValue(journal.getAlttitle());
|
319
|
url.setValue(journal.getUrl());
|
320
|
languages.setValue(journal.getLanguages());
|
321
|
issnAndEissn.setValue(journal.getIssn());
|
322
|
country.setValue(journal.getCountry());
|
323
|
subjects.setValue(journal.getSubjects());
|
324
|
licence.setValue(journal.getLicence());
|
325
|
apc.setValue((Math.round(journal.getApc() * 100) / 100.0)+"");
|
326
|
discount.setValue((Math.round(journal.getDiscount() * 100) / 100.0)+"");
|
327
|
}
|
328
|
}
|