Project

General

Profile

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 journal = null;
60
    private Journal journalFromAutoComplete = null;
61
    private Currency journalCurrency = Currency.EUR;
62
    private Publisher journalPublisher = null;
63

    
64

    
65
    private String journalIdFromDB = null;
66

    
67
    private Label apcEurosLabel = new Label(" " + journalCurrency.getName());
68

    
69
    private DataServiceAsync dataService = GWT.create(DataService.class);
70
    private GoldOAConstants goldOAConstants = GWT.create(GoldOAConstants.class);
71

    
72
    public JournalInfoStep() {
73

    
74
        errorLabel.addStyleName("alertLabel");
75
        errorLabel.setType(AlertType.ERROR);
76
        errorLabel.setVisible(false);
77
        errorLabel.setClose(false);
78

    
79
        journalAutoCompleteForm.setType(FormType.HORIZONTAL);
80
        journalAutoCompleteForm.addStyleName("journalAutoCompleteForm");
81

    
82
        journalInfoStepPanel.add(errorLabel);
83
        journalInfoStepPanel.add(journalAutoCompleteForm);
84

    
85
        cannotFindJournal.setText("If you cannot find your journal, check to complete its information");
86
        cannotFindJournal.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
87
            @Override
88
            public void onValueChange(ValueChangeEvent<Boolean> booleanValueChangeEvent) {
89

    
90
                if (cannotFindJournal.getValue()) {
91
                    journalInfoStepPanel.remove(journalDisplayInfoPanel);
92
                    journalInfoStepPanel.add(journalInfoPanel);
93
                    journalAutoComplete.setValue("");
94
                } else {
95
                    journalInfoStepPanel.remove(journalInfoPanel);
96
                }
97
            }
98
        });
99

    
100
        AutoCompleteWidget.AutoCompleteListener autoCompleteListener = new AutoCompleteWidget.AutoCompleteListener() {
101
            @Override
102
            public void valueSelected(Vocabulary vocabulary) {
103

    
104
                journal = vocabulary;
105
                cannotFindJournal.setValue(false);
106

    
107
                dataService.getJournal(vocabulary.getId(), new AsyncCallback<Journal>() {
108

    
109
                    @Override
110
                    public void onFailure(Throwable throwable) {
111
                        journalDisplayInfoPanel.clear();
112
                        JournalDisplayInfo journalDisplayInfo = new JournalDisplayInfo(null);
113
                        journalDisplayInfoPanel.add(journalDisplayInfo.asWidget());
114
                        journalInfoStepPanel.remove(journalInfoPanel);
115
                        journalInfoStepPanel.add(journalDisplayInfoPanel);
116
                    }
117

    
118
                    @Override
119
                    public void onSuccess(Journal journal) {
120

    
121
                        journalFromAutoComplete = journal;
122

    
123
                        journalDisplayInfoPanel.clear();
124
                        JournalDisplayInfo journalDisplayInfo = new JournalDisplayInfo(journal);
125
                        journalDisplayInfoPanel.add(journalDisplayInfo.asWidget());
126
                        journalInfoStepPanel.remove(journalInfoPanel);
127
                        journalInfoStepPanel.add(journalDisplayInfoPanel);
128
                    }
129
                });
130
            }
131
        };
132
        journalAutoComplete.setAutoCompleteListener(autoCompleteListener);
133

    
134
        journalAutoCompleteForm.add(new FormFieldSet("Journal Title (*)", journalAutoComplete.asWidget(), cannotFindJournal));
135

    
136
        //journal info form
137
        journalInfoPanel.addStyleName("journalInfoPanel");
138

    
139
        journalFormErrorLabel.addStyleName("alertLabel");
140
        journalFormErrorLabel.setType(AlertType.ERROR);
141
        journalFormErrorLabel.setVisible(false);
142
        journalFormErrorLabel.setClose(false);
143

    
144
        journalInfoForm.setType(FormType.HORIZONTAL);
145
        journalInfoForm.addStyleName("journalInfoForm");
146
        journalInfoPanel.add(journalInfoForm);
147

    
148
        title.setAlternateSize(AlternateSize.XXLARGE);
149

    
150
        alternativeTitle.setAlternateSize(AlternateSize.XXLARGE);
151

    
152
        url.setAlternateSize(AlternateSize.XXLARGE);
153

    
154
        languages.setAlternateSize(AlternateSize.XXLARGE);
155
        languages.setPlaceholder(" languages as a comma-separated list");
156

    
157
        issnAndEissn.setAlternateSize(AlternateSize.XXLARGE);
158
        issnAndEissn.setPlaceholder(" values as a comma-seperated list");
159

    
160
        country.setAlternateSize(AlternateSize.XXLARGE);
161

    
162
        subjects.setAlternateSize(AlternateSize.XXLARGE);
163
        subjects.setPlaceholder(" subjects as a comma-separated list");
164

    
165
        licence.setAlternateSize(AlternateSize.XXLARGE);
166

    
167
        apcEurosLabel.setStyleName("inlineBlock");
168

    
169
        apc.setAlternateSize(AlternateSize.XXLARGE);
170
        apc.addStyleName("inlineBlock");
171
        apc.setEnabled(false);
172

    
173
        Label goldDiscountPercentageLabel = new Label("  %");
174
        goldDiscountPercentageLabel.setStyleName("inlineBlock");
175

    
176
        discount.setAlternateSize(AlternateSize.XXLARGE);
177
        discount.addStyleName("inlineBlock");
178
        discount.setEnabled(false);
179

    
180
        journalInfoForm.add(journalFormErrorLabel);
181
        journalInfoForm.add(new FormFieldSet("Title (*)", title));
182
        journalInfoForm.add(new FormFieldSet("Alternative Title", alternativeTitle));
183
        journalInfoForm.add(new FormFieldSet("URL", url));
184
        journalInfoForm.add(new FormFieldSet("Languages", languages));
185
        journalInfoForm.add(new FormFieldSet("ISSN / EISSN", issnAndEissn));
186
        journalInfoForm.add(new FormFieldSet("Country", country));
187
        journalInfoForm.add(new FormFieldSet("Subjects", subjects));
188
        journalInfoForm.add(new FormFieldSet("Licence", licence));
189
        journalInfoForm.add(new FormFieldSet("Listed APC fee", apc, apcEurosLabel));
190
        journalInfoForm.add(new FormFieldSet("Pilot Discount", discount, goldDiscountPercentageLabel));
191
    }
192

    
193
    @Override
194
    public Widget asWidget() {
195
        return journalInfoStepPanel;
196
    }
197

    
198
    public boolean isComplete() {
199

    
200
        if(!title.getValue().trim().equals(""))
201
            return true;
202

    
203
        return false;
204
    }
205

    
206
    public Journal getJournal() {
207

    
208
        journalFormErrorLabel.setVisible(false);
209
        errorLabel.setVisible(false);
210

    
211
        if(cannotFindJournal.getValue()) {
212
            if (isComplete()) {
213

    
214
                Journal journal = new Journal();
215
                if(journalIdFromDB!=null)
216
                    journal.setId(journalIdFromDB);
217
                journal.setTitle(title.getValue().trim());
218
                journal.setAlternativeTitle(alternativeTitle.getValue().trim());
219
                journal.setUrl(url.getValue().trim());
220
                journal.setLanguages(languages.getValue().trim());
221
                journal.setIssn(issnAndEissn.getValue().trim());
222
                journal.setCountry(country.getValue().trim());
223
                journal.setSubjects(subjects.getValue().trim());
224
                journal.setLicence(licence.getValue().trim());
225

    
226
                journal.setApccurrency(journalCurrency);
227

    
228
                journal.setPublisher(journalPublisher);
229

    
230
                return journal;
231

    
232
            } else {
233
                journalFormErrorLabel.setText(goldOAConstants.journalFormErrorAllFieldsRequired());
234
                journalFormErrorLabel.setVisible(true);
235
            }
236
        } else {
237
            if(journal!=null) {
238

    
239
                if(journalFromAutoComplete!=null)
240
                    return journalFromAutoComplete;
241

    
242
                Journal journal = new Journal();
243
                journal.setId(this.journal.getId());
244
                return journal;
245

    
246
            } else {
247
                errorLabel.setText(goldOAConstants.journalErrorNotSelected());
248
                errorLabel.setVisible(true);
249
            }
250
        }
251

    
252
        return null;
253
    }
254

    
255
    public void clear() {
256

    
257
        journalFormErrorLabel.setVisible(false);
258
        errorLabel.setVisible(false);
259

    
260
        journal = null;
261
        journalIdFromDB = null;
262
        journalAutoComplete.setValue("");
263

    
264
        journalCurrency = Currency.EUR;
265
        apcEurosLabel.setText(" " + journalCurrency.getName());
266

    
267
        cannotFindJournal.setValue(false);
268

    
269
        title.setValue("");
270
        alternativeTitle.setValue("");
271
        url.setValue("");
272
        languages.setValue("");
273
        issnAndEissn.setValue("");
274
        country.setValue("");
275
        subjects.setValue("");
276
        licence.setValue("");
277
        apc.setValue("");
278
        discount.setValue("");
279

    
280
        journalInfoStepPanel.remove(journalInfoPanel);
281
    }
282

    
283
    public void loadJournalInfo(Journal journal) {
284

    
285
        this.journal = null;
286
        journalIdFromDB = journal.getId();
287

    
288
        journalCurrency = journal.getApccurrency();
289
        apcEurosLabel.setText(" " + journalCurrency.getName());
290

    
291
        journalPublisher = journal.getPublisher();
292

    
293
        cannotFindJournal.setValue(true);
294

    
295
        journalInfoStepPanel.remove(journalDisplayInfoPanel);
296
        journalInfoStepPanel.add(journalInfoPanel);
297
        journalAutoComplete.setValue("");
298

    
299
        title.setValue(journal.getTitle());
300
        alternativeTitle.setValue(journal.getAlttitle());
301
        url.setValue(journal.getUrl());
302
        languages.setValue(journal.getLanguages());
303
        issnAndEissn.setValue(journal.getIssn());
304
        country.setValue(journal.getCountry());
305
        subjects.setValue(journal.getSubjects());
306
        licence.setValue(journal.getLicence());
307
        apc.setValue((Math.round(journal.getApc() * 100) / 100.0)+"");
308
        discount.setValue((Math.round(journal.getDiscount() * 100) / 100.0)+"");
309
    }
310
}
(2-2/5)