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.TextBox;
7
import com.github.gwtbootstrap.client.ui.constants.AlertType;
8
import com.github.gwtbootstrap.client.ui.constants.AlternateSize;
9
import com.github.gwtbootstrap.client.ui.constants.FormType;
10
import com.google.gwt.core.client.GWT;
11
import com.google.gwt.event.logical.shared.ValueChangeEvent;
12
import com.google.gwt.event.logical.shared.ValueChangeHandler;
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.Widget;
17
import eu.dnetlib.client.DataService;
18
import eu.dnetlib.client.DataServiceAsync;
19
import eu.dnetlib.client.widgets.AutoCompleteWidget;
20
import eu.dnetlib.client.widgets.FormFieldSet;
21
import eu.dnetlib.goldoa.domain.Journal;
22
import eu.dnetlib.goldoa.domain.Vocabulary;
23

    
24
/**
25
 * Created by stefania on 3/11/15.
26
 */
27
public class JournalInfoStep implements IsWidget {
28

    
29
    private FlowPanel journalInfoStepPanel = new FlowPanel();
30

    
31
    private Alert errorLabel = new Alert();
32

    
33
    private Form journalAutoCompleteForm = new Form();
34
    private AutoCompleteWidget journalAutoComplete = new AutoCompleteWidget("journal", "Search...");
35

    
36
    private CheckBox cannotFindJournal = new CheckBox();
37

    
38
    // journal info form
39
    private FlowPanel journalInfoPanel = new FlowPanel();
40

    
41
    private Alert journalFormErrorLabel = new Alert();
42

    
43
    private Form journalInfoForm = new Form();
44
    private TextBox title = new TextBox();
45
    private TextBox alternativeTitle = new TextBox();
46
    private TextBox url = new TextBox();
47
    private TextBox languages = new TextBox();
48
    private TextBox issnAndEissn = new TextBox();
49
    private TextBox country = new TextBox();
50
    private TextBox subjects = new TextBox();
51
    private TextBox licence = new TextBox();
52

    
53
    private FlowPanel journalDisplayInfoPanel = new FlowPanel();
54

    
55
    private Vocabulary journal = null;
56

    
57
    private DataServiceAsync dataService = GWT.create(DataService.class);
58

    
59
    public JournalInfoStep() {
60

    
61
        errorLabel.addStyleName("alertLabel");
62
        errorLabel.addStyleName("width80");
63
        errorLabel.setType(AlertType.ERROR);
64
        errorLabel.setVisible(false);
65
        errorLabel.setClose(false);
66

    
67
        journalAutoCompleteForm.setType(FormType.HORIZONTAL);
68
        journalAutoCompleteForm.addStyleName("journalAutoCompleteForm");
69

    
70
        journalInfoStepPanel.add(errorLabel);
71
        journalInfoStepPanel.add(journalAutoCompleteForm);
72

    
73
        cannotFindJournal.setText("If you cannot find your journal, check to complete its information");
74
        cannotFindJournal.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
75
            @Override
76
            public void onValueChange(ValueChangeEvent<Boolean> booleanValueChangeEvent) {
77

    
78
                if (cannotFindJournal.getValue()) {
79
                    journalInfoStepPanel.remove(journalDisplayInfoPanel);
80
                    journalInfoStepPanel.add(journalInfoPanel);
81
                    journalAutoComplete.setValue("");
82
                } else {
83
                    journalInfoStepPanel.remove(journalInfoPanel);
84
                }
85
            }
86
        });
87

    
88
        AutoCompleteWidget.AutoCompleteListener autoCompleteListener = new AutoCompleteWidget.AutoCompleteListener() {
89
            @Override
90
            public void valueSelected(Vocabulary vocabulary) {
91

    
92
                journal = vocabulary;
93
                cannotFindJournal.setValue(false);
94

    
95
                dataService.getJournal(vocabulary.getId(), new AsyncCallback<Journal>() {
96

    
97
                    @Override
98
                    public void onFailure(Throwable throwable) {
99
                        journalDisplayInfoPanel.clear();
100
                        JournalDisplayInfo journalDisplayInfo = new JournalDisplayInfo(null);
101
                        journalDisplayInfoPanel.add(journalDisplayInfo.asWidget());
102
                        journalInfoStepPanel.remove(journalInfoPanel);
103
                        journalInfoStepPanel.add(journalDisplayInfoPanel);
104
                    }
105

    
106
                    @Override
107
                    public void onSuccess(Journal journal) {
108
                        journalDisplayInfoPanel.clear();
109
                        JournalDisplayInfo journalDisplayInfo = new JournalDisplayInfo(journal);
110
                        journalDisplayInfoPanel.add(journalDisplayInfo.asWidget());
111
                        journalInfoStepPanel.remove(journalInfoPanel);
112
                        journalInfoStepPanel.add(journalDisplayInfoPanel);
113
                    }
114
                });
115
            }
116
        };
117
        journalAutoComplete.setAutoCompleteListener(autoCompleteListener);
118

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

    
121
        //journal info form
122
        journalInfoPanel.addStyleName("journalInfoPanel");
123

    
124
        journalFormErrorLabel.addStyleName("alertLabel");
125
        journalFormErrorLabel.setType(AlertType.ERROR);
126
        journalFormErrorLabel.setVisible(false);
127
        journalFormErrorLabel.setClose(false);
128

    
129
        journalInfoForm.setType(FormType.HORIZONTAL);
130
        journalInfoForm.addStyleName("journalInfoForm");
131
        journalInfoPanel.add(journalInfoForm);
132

    
133
        title.setAlternateSize(AlternateSize.XXLARGE);
134

    
135
        alternativeTitle.setAlternateSize(AlternateSize.XXLARGE);
136

    
137
        url.setAlternateSize(AlternateSize.XXLARGE);
138

    
139
        languages.setAlternateSize(AlternateSize.XXLARGE);
140
        languages.setPlaceholder(" languages as a comma-separated list");
141

    
142
        issnAndEissn.setAlternateSize(AlternateSize.XXLARGE);
143
        issnAndEissn.setPlaceholder(" values as a comma-seperated list");
144

    
145
        country.setAlternateSize(AlternateSize.XXLARGE);
146

    
147
        subjects.setAlternateSize(AlternateSize.XXLARGE);
148
        subjects.setPlaceholder(" subjects as a comma-separated list");
149

    
150
        licence.setAlternateSize(AlternateSize.XXLARGE);
151

    
152
        journalInfoForm.add(journalFormErrorLabel);
153
        journalInfoForm.add(new FormFieldSet("Title (*)", title));
154
        journalInfoForm.add(new FormFieldSet("Alternative Title", alternativeTitle));
155
        journalInfoForm.add(new FormFieldSet("URL", url));
156
        journalInfoForm.add(new FormFieldSet("Languages", languages));
157
        journalInfoForm.add(new FormFieldSet("ISSN / EISSN", issnAndEissn));
158
        journalInfoForm.add(new FormFieldSet("Country", country));
159
        journalInfoForm.add(new FormFieldSet("Subjects", subjects));
160
        journalInfoForm.add(new FormFieldSet("Licence (*)", licence));
161
    }
162

    
163
    @Override
164
    public Widget asWidget() {
165
        return journalInfoStepPanel;
166
    }
167

    
168
    public boolean isComplete() {
169

    
170
        if(!title.getValue().trim().equals("") && !licence.getValue().trim().equals(""))
171
            return true;
172

    
173
        return false;
174
    }
175

    
176
    public Journal getJournal() {
177

    
178
        journalFormErrorLabel.setVisible(false);
179
        errorLabel.setVisible(false);
180

    
181
        if(cannotFindJournal.getValue()) {
182
            if (isComplete()) {
183

    
184
                Journal journal = new Journal();
185
                journal.setTitle(title.getValue().trim());
186
                journal.setAlternativeTitle(alternativeTitle.getValue().trim());
187
                journal.setUrl(url.getValue().trim());
188
                journal.setLanguages(languages.getValue().trim());
189
                journal.setIssn(issnAndEissn.getValue().trim());
190
                journal.setCountry(country.getValue().trim());
191
                journal.setSubjects(subjects.getValue().trim());
192
                journal.setLicence(licence.getValue().trim());
193
                return journal;
194
            } else {
195
                journalFormErrorLabel.setText("All asterisk (*) fields are required.");
196
                journalFormErrorLabel.setVisible(true);
197
            }
198
        } else {
199
            if(journal!=null) {
200

    
201
                Journal journal = new Journal();
202
                journal.setId(this.journal.getId());
203
                return journal;
204
            } else {
205
                errorLabel.setText("You need to select a journal.");
206
                errorLabel.setVisible(true);
207
            }
208
        }
209

    
210
        return null;
211
    }
212

    
213
    public void clear() {
214

    
215
        journalFormErrorLabel.setVisible(false);
216
        errorLabel.setVisible(false);
217

    
218
        journal = null;
219
        journalAutoComplete.setValue("");
220

    
221
        cannotFindJournal.setValue(false);
222

    
223
        title.setValue("");
224
        alternativeTitle.setValue("");
225
        url.setValue("");
226
        languages.setValue("");
227
        issnAndEissn.setValue("");
228
        country.setValue("");
229
        subjects.setValue("");
230
        licence.setValue("");
231

    
232
        journalInfoStepPanel.remove(journalInfoPanel);
233
    }
234

    
235
    public void loadJournalInfo(Journal journal) {
236

    
237
        this.journal = null;
238

    
239
        cannotFindJournal.setValue(true);
240

    
241
        journalInfoStepPanel.remove(journalDisplayInfoPanel);
242
        journalInfoStepPanel.add(journalInfoPanel);
243
        journalAutoComplete.setValue("");
244

    
245
        title.setValue(journal.getTitle());
246
        alternativeTitle.setValue(journal.getAlternativeTitle());
247
        url.setValue(journal.getUrl());
248
        languages.setValue(journal.getLanguages());
249
        issnAndEissn.setValue(journal.getIssn());
250
        country.setValue(journal.getCountry());
251
        subjects.setValue(journal.getSubjects());
252
        licence.setValue(journal.getLicence());
253
    }
254
}
(2-2/5)