Project

General

Profile

1
package eu.dnetlib.client;
2

    
3
import com.github.gwtbootstrap.client.ui.Button;
4
import com.github.gwtbootstrap.client.ui.base.IconAnchor;
5
import com.github.gwtbootstrap.client.ui.constants.ButtonType;
6
import com.google.gwt.core.client.GWT;
7
import com.google.gwt.dom.client.Document;
8
import com.google.gwt.dom.client.Style;
9
import com.google.gwt.event.dom.client.ClickEvent;
10
import com.google.gwt.event.dom.client.ClickHandler;
11
import com.google.gwt.user.client.History;
12
import com.google.gwt.user.client.rpc.AsyncCallback;
13
import com.google.gwt.user.client.ui.*;
14
import eu.dnetlib.client.fundingrequest.newrequest.EligibilityDisplayWidget;
15
import eu.dnetlib.client.fundingrequest.newrequest.EligibilityService;
16
import eu.dnetlib.client.fundingrequest.newrequest.EligibilityServiceAsync;
17
import eu.dnetlib.client.widgets.AutoCompleteWidget;
18
import eu.dnetlib.goldoa.domain.Eligibility;
19
import eu.dnetlib.goldoa.domain.Project;
20
import eu.dnetlib.goldoa.domain.Request;
21
import eu.dnetlib.goldoa.domain.Vocabulary;
22

    
23
/**
24
 * Created by stefania on 3/6/15.
25
 */
26
public class HomeWidget implements MyWidget {
27

    
28
    private FlowPanel homePagePanel = new FlowPanel();
29

    
30
    private FlowPanel mainBlock = new FlowPanel();
31
    private FlowPanel mainGrid = new FlowPanel();
32

    
33
    private FlowPanel pilotAbout = new FlowPanel();
34
    private Label pilotAboutTitleLabel = new Label();
35
    private HTML pilotAboutContent = new HTML();
36

    
37
    private Label needMoreInfoLabel = new Label();
38
    private HTML needMoreInfoContent = new HTML();
39

    
40
    private FlowPanel projectEligibleAndSignIn = new FlowPanel();
41
    private Label projectEligibleTitleLabel = new Label();
42
    private Label projectEligibleInfoLabel = new Label();
43
    private FlowPanel eligibilityPanel = new FlowPanel();
44
    private AutoCompleteWidget projectAutoComplete = new AutoCompleteWidget("project", "Search...");
45
    private HTML projectEligibleCommentLabel = new HTML();
46

    
47
    private FlowPanel viewEligibleProjectsPanel = new FlowPanel();
48
    private Anchor viewEligibleProjects = new Anchor();
49

    
50
    private FlowPanel signInAndRegister = new FlowPanel();
51
    private Button signIn = new Button();
52
    private HTML register = new HTML();
53

    
54
    private FlowPanel secondaryBlock = new FlowPanel();
55

    
56
    private FlowPanel researchersPanel = new FlowPanel();
57
    private Label researcherTitleLabel = new Label();
58
    private Label researcherSubTitleLabel = new Label();
59
    private HTML researcherInfoLabel = new HTML();
60

    
61
    private FlowPanel institutionsPanel = new FlowPanel();
62
    private Label institutionTitleLabel = new Label();
63
    private Label institutionSubTitleLabel = new Label();
64
    private HTML institutionInfoFirstLabel = new HTML();
65
    private IconAnchor viewAllInstitutions = new IconAnchor();
66
    private HTML institutionInfoSecondLabel = new HTML();
67

    
68
    private FlowPanel publishersPanel = new FlowPanel();
69
    private Label publisherTitleLabel = new Label();
70
    private Label publisherSubTitleLabel = new Label();
71
    private HTML publisherInfoFirstLabel = new HTML();
72
    private HTML publisherInfoSecondLabel = new HTML();
73

    
74
    private GoldOAConstants goldOAConstants = GWT.create(GoldOAConstants.class);
75

    
76
    private EligibilityServiceAsync eligibilityService = GWT.create(EligibilityService.class);
77
    private DataServiceAsync dataService = GWT.create(DataService.class);
78

    
79
    public HomeWidget() {
80

    
81
        homePagePanel.addStyleName("homePage");
82

    
83
        mainBlock.addStyleName("content");
84
        mainGrid.addStyleName("uk-grid");
85
        mainGrid.addStyleName("uk-grid-divider");
86

    
87
        pilotAbout.addStyleName("uk-width-medium-2-3");
88

    
89
        pilotAboutTitleLabel.addStyleName("contentTitleLabel");
90
        pilotAboutTitleLabel.setText("Requesting funds for post-grant FP7 publications?");
91

    
92
        pilotAboutContent.addStyleName("contentText");
93
        pilotAboutContent.setHTML(goldOAConstants.whatIsThisServiceAbout());
94

    
95
        needMoreInfoLabel.addStyleName("contentTitleLabel");
96
        needMoreInfoLabel.setText("Need more information?");
97

    
98
        needMoreInfoContent.addStyleName("contentText");
99
        needMoreInfoContent.setHTML(goldOAConstants.needMoreInfoOnThePilot());
100

    
101
        pilotAbout.add(pilotAboutTitleLabel);
102
        pilotAbout.add(pilotAboutContent);
103
        pilotAbout.add(needMoreInfoLabel);
104
        pilotAbout.add(needMoreInfoContent);
105

    
106
        projectEligibleAndSignIn.addStyleName("uk-width-medium-1-3");
107

    
108
        projectEligibleTitleLabel.addStyleName("contentTitleLabel");
109
        projectEligibleTitleLabel.setText("Is your project eligible?");
110

    
111
        projectEligibleInfoLabel.addStyleName("contentText");
112
        projectEligibleInfoLabel.setText("Type your FP7 acronym/granted or project name to see if you can request funding for your publication");
113

    
114
        AutoCompleteWidget.AutoCompleteListener projectAutoCompleteListener = new AutoCompleteWidget.AutoCompleteListener() {
115
            @Override
116
            public void valueSelected(Vocabulary vocabulary) {
117

    
118
                final HTML loadingWheel = new HTML("<div class=\"loader\"></div><div class=\"whiteFilm\"></div>");
119
                eligibilityPanel.addStyleName("loading-small");
120
                eligibilityPanel.add(loadingWheel);
121

    
122
                final Request request = new Request();
123

    
124
                dataService.getProject(vocabulary.getId(), new AsyncCallback<Project>() {
125
                    @Override
126
                    public void onFailure(Throwable throwable) {
127

    
128
                    }
129

    
130
                    @Override
131
                    public void onSuccess(Project project) {
132
                        request.setProject(project);
133
                    }
134
                });
135

    
136
                eligibilityService.validate(request, new AsyncCallback<Eligibility>() {
137

    
138
                    @Override
139
                    public void onFailure(Throwable throwable) {
140

    
141
                        eligibilityPanel.removeStyleName("loading-small");
142

    
143
                        eligibilityPanel.clear();
144
                        EligibilityDisplayWidget eligibilityDisplayWidget = new EligibilityDisplayWidget(null);
145
                        eligibilityPanel.add(eligibilityDisplayWidget.asWidget());
146
                    }
147

    
148
                    @Override
149
                    public void onSuccess(Eligibility eligibility) {
150

    
151
                        eligibilityPanel.removeStyleName("loading-small");
152

    
153
                        eligibilityPanel.clear();
154
                        EligibilityDisplayWidget eligibilityDisplayWidget = new EligibilityDisplayWidget(eligibility);
155
                        eligibilityPanel.add(eligibilityDisplayWidget.asWidget());
156
                    }
157
                });
158
            }
159
        };
160
        projectAutoComplete.setAutoCompleteListener(projectAutoCompleteListener);
161

    
162
        projectEligibleCommentLabel.addStyleName("comment");
163
        projectEligibleCommentLabel.addStyleName("fontItalic");
164
        projectEligibleCommentLabel.setHTML("If you cannot find your project in our database, do not hesitate to " +
165
                "<a class=\"contactUs\">contact us</a>");
166

    
167
        viewEligibleProjects.setText("View eligible projects by organization...");
168
        viewEligibleProjects.setHref("#eligibleProjects");
169
        viewEligibleProjects.addStyleName("emphasis");
170
        viewEligibleProjects.addClickHandler(new ClickHandler() {
171
            @Override
172
            public void onClick(ClickEvent clickEvent) {
173
                History.newItem("eligibleProjects");
174
            }
175
        });
176
        viewEligibleProjectsPanel.add(viewEligibleProjects);
177
        viewEligibleProjectsPanel.addStyleName("viewEligibleProjectsHomeLink");
178

    
179
        signIn.addStyleName("signIn");
180
        signIn.setText("Sign In");
181
        signIn.setType(ButtonType.PRIMARY);
182
        signIn.addClickHandler(new ClickHandler() {
183
            @Override
184
            public void onClick(ClickEvent clickEvent) {
185
                History.newItem("login");
186
            }
187
        });
188

    
189
        register.setHTML("<div class=\"register\">New User? <a href=\"#register\">Start here</a></div>");
190

    
191
        signInAndRegister.add(signIn);
192
        signInAndRegister.add(register);
193

    
194
        projectEligibleAndSignIn.add(projectEligibleTitleLabel);
195
        projectEligibleAndSignIn.add(projectEligibleInfoLabel);
196
        projectEligibleAndSignIn.add(projectAutoComplete);
197
        projectEligibleAndSignIn.add(projectEligibleCommentLabel);
198
        projectEligibleAndSignIn.add(eligibilityPanel);
199
        projectEligibleAndSignIn.add(viewEligibleProjectsPanel);
200

    
201
        mainGrid.add(pilotAbout);
202
        mainGrid.add(projectEligibleAndSignIn);
203

    
204
        mainBlock.add(mainGrid);
205
        
206

    
207
        researchersPanel.addStyleName("inlineBlock");
208
        researchersPanel.addStyleName("width25");
209
        researchersPanel.addStyleName("content");
210
        researchersPanel.addStyleName("smallContentPanel");
211

    
212
        researcherTitleLabel.addStyleName("contentTitleLabel");
213
        researcherTitleLabel.setText("Researchers");
214

    
215
        researcherSubTitleLabel.addStyleName("contentTitleLabel");
216
        researcherSubTitleLabel.setText("How to request APCs");
217

    
218
        researcherInfoLabel.addStyleName("contentText");
219
        researcherInfoLabel.setHTML(goldOAConstants.infoForResearchers());
220

    
221
        researchersPanel.add(researcherTitleLabel);
222
        researchersPanel.add(researcherSubTitleLabel);
223
        researchersPanel.add(researcherInfoLabel);
224

    
225

    
226
        institutionsPanel.addStyleName("inlineBlock");
227
        institutionsPanel.addStyleName("width25");
228
        institutionsPanel.addStyleName("content");
229
        institutionsPanel.addStyleName("smallContentPanel");
230

    
231
        institutionTitleLabel.addStyleName("contentTitleLabel");
232
        institutionTitleLabel.setText("Institutions");
233

    
234
        institutionSubTitleLabel.addStyleName("contentTitleLabel");
235
        institutionSubTitleLabel.setText("How to get involved");
236

    
237
        institutionInfoFirstLabel.addStyleName("contentText");
238
        institutionInfoFirstLabel.setHTML(goldOAConstants.infoForInstitutionsFirstText());
239

    
240
        viewAllInstitutions.setText("View all participating institutions...");
241
        viewAllInstitutions.setHref("https://www.openaire.eu/postgrantoapilot-participants");
242
        viewAllInstitutions.setTarget("_blank");
243

    
244
        institutionInfoSecondLabel.addStyleName("contentText");
245
        institutionInfoSecondLabel.setHTML(goldOAConstants.infoForInstitutionsSecondText());
246

    
247
        institutionsPanel.add(institutionTitleLabel);
248
        institutionsPanel.add(institutionSubTitleLabel);
249
        institutionsPanel.add(institutionInfoFirstLabel);
250
        institutionsPanel.add(viewAllInstitutions);
251
        institutionsPanel.add(institutionInfoSecondLabel);
252

    
253

    
254
        publishersPanel.addStyleName("inlineBlock");
255
        publishersPanel.addStyleName("width25");
256
        publishersPanel.addStyleName("content");
257
        publishersPanel.addStyleName("smallContentPanel");
258

    
259
        publisherTitleLabel.addStyleName("contentTitleLabel");
260
        publisherTitleLabel.setText("Publishers");
261

    
262
        publisherSubTitleLabel.addStyleName("contentTitleLabel");
263
        publisherSubTitleLabel.setText("Get in contact");
264

    
265
        publisherInfoFirstLabel.addStyleName("contentText");
266
        publisherInfoFirstLabel.setHTML(goldOAConstants.infoForPublishersFirstText());
267

    
268
        publisherInfoSecondLabel.addStyleName("contentText");
269
        publisherInfoSecondLabel.setHTML(goldOAConstants.infoForPublishersSecondText());
270

    
271
        publishersPanel.add(publisherTitleLabel);
272
        publishersPanel.add(publisherSubTitleLabel);
273
        publishersPanel.add(publisherInfoFirstLabel);
274
        publishersPanel.add(publisherInfoSecondLabel);
275

    
276

    
277
        secondaryBlock.addStyleName("secondaryBlock");
278
        secondaryBlock.add(researchersPanel);
279
        secondaryBlock.add(institutionsPanel);
280
        secondaryBlock.add(publishersPanel);
281

    
282

    
283
        homePagePanel.add(mainBlock);
284
        homePagePanel.add(secondaryBlock);
285
    }
286

    
287
    @Override
288
    public Widget asWidget() {
289
        return homePagePanel;
290
    }
291

    
292
    @Override
293
    public void clear() {
294

    
295
    }
296

    
297
    @Override
298
    public void reload() {
299

    
300
        Document.get().getElementById("content").removeClassName("uk-width-medium-3-4");
301
        Document.get().getElementById("content").addClassName("uk-width-medium-1-1");
302
        Document.get().getElementById("sidebar").getStyle().setDisplay(Style.Display.NONE);
303

    
304
        if(GoldOAPortal.currentUser==null) {
305
            projectEligibleAndSignIn.remove(viewEligibleProjectsPanel);
306
            projectEligibleAndSignIn.add(signInAndRegister);
307
            projectEligibleAndSignIn.add(viewEligibleProjectsPanel);
308
        } else {
309
            projectEligibleAndSignIn.remove(signInAndRegister);
310
        }
311
    }
312

    
313
    @Override
314
    public void setToken(String token) {
315

    
316
    }
317

    
318
    @Override
319
    public void afterAdditionToRootPanel() {
320

    
321
    }
322
}
(12-12/22)