Project

General

Profile

1 35644 stefania.m
package eu.dnetlib.client.fundingrequest.newrequest.summarystep;
2 35581 stefania.m
3 35660 stefania.m
import com.github.gwtbootstrap.client.ui.Alert;
4
import com.github.gwtbootstrap.client.ui.CheckBox;
5
import com.github.gwtbootstrap.client.ui.base.IconAnchor;
6
import com.github.gwtbootstrap.client.ui.constants.AlertType;
7
import com.google.gwt.core.client.GWT;
8
import com.google.gwt.event.dom.client.ClickEvent;
9
import com.google.gwt.event.dom.client.ClickHandler;
10
import com.google.gwt.user.client.rpc.AsyncCallback;
11 35581 stefania.m
import com.google.gwt.user.client.ui.FlowPanel;
12 35841 stefania.m
import com.google.gwt.user.client.ui.HTML;
13 35660 stefania.m
import com.google.gwt.user.client.ui.Label;
14 35581 stefania.m
import com.google.gwt.user.client.ui.Widget;
15 35660 stefania.m
import eu.dnetlib.client.fundingrequest.newrequest.EligibilityDisplayWidget;
16
import eu.dnetlib.client.fundingrequest.newrequest.EligibilityService;
17
import eu.dnetlib.client.fundingrequest.newrequest.EligibilityServiceAsync;
18 35644 stefania.m
import eu.dnetlib.client.fundingrequest.newrequest.FundingWizardStepWidget;
19 35660 stefania.m
import eu.dnetlib.goldoa.domain.Eligibility;
20 35581 stefania.m
import eu.dnetlib.shared.FundingWizardState;
21
22
/**
23
 * Created by stefania on 3/24/15.
24
 */
25
public class SummaryStepWidget extends FundingWizardStepWidget {
26
27
    private FlowPanel summaryStepPanel = new FlowPanel();
28 35841 stefania.m
    private Label summaryInfoLabel = new Label();
29 35660 stefania.m
    private Alert errorLabel = new Alert();
30 35581 stefania.m
31 35660 stefania.m
    private FlowPanel eligibilityPanel = new FlowPanel();
32
33
    private FlowPanel summaryWidgetsPanel = new FlowPanel();
34
35
    private FlowPanel agreeToTermsPanel = new FlowPanel();
36
    private CheckBox agreeToTerms = new CheckBox("I have read and agreed to the ");
37
    private IconAnchor termsLink = new IconAnchor();
38
39 35841 stefania.m
    private HTML loadingWheel = new HTML("<div class=\"loader-big\"></div><div class=\"whiteFilm\"></div>");
40
41 35660 stefania.m
    private FundingWizardJumpToStepListener fundingWizardJumpToStepListener;
42
    private FundingWizardStepCompleteListener fundingWizardStepCompleteListener;
43
44
    private FundingWizardState currentFundingWizardState;
45
46
    private EligibilityServiceAsync eligibilityService = GWT.create(EligibilityService.class);
47
48 35581 stefania.m
    public SummaryStepWidget(String title) {
49
50
        super(title);
51 35660 stefania.m
52 35841 stefania.m
        summaryInfoLabel.addStyleName("stepWidgetLabel");
53
        summaryInfoLabel.setText("Review your funding request so far and edit if needed before submitting");
54 35660 stefania.m
55
        errorLabel.addStyleName("alertLabel");
56
        errorLabel.setType(AlertType.ERROR);
57
        errorLabel.setVisible(false);
58
        errorLabel.setClose(false);
59
60 35747 stefania.m
        summaryWidgetsPanel.addStyleName("summaryWidgetsPanel");
61
62 35660 stefania.m
        agreeToTermsPanel.addStyleName("agreeToTerms");
63
        agreeToTerms.addStyleName("inlineBlock");
64
        termsLink.setText("Terms and Conditions");
65
        termsLink.addStyleName("inlineBlock");
66
        termsLink.addClickHandler(new ClickHandler() {
67
            @Override
68
            public void onClick(ClickEvent clickEvent) {
69
70
            }
71
        });
72
73
        agreeToTermsPanel.add(agreeToTerms);
74
        agreeToTermsPanel.add(termsLink);
75
76 35841 stefania.m
        summaryStepPanel.add(summaryInfoLabel);
77 35660 stefania.m
        summaryStepPanel.add(errorLabel);
78
        summaryStepPanel.add(eligibilityPanel);
79
        summaryStepPanel.add(summaryWidgetsPanel);
80
        summaryStepPanel.add(agreeToTermsPanel);
81 35581 stefania.m
    }
82
83
    @Override
84
    public void updateState(FundingWizardState fundingWizardState) {
85
86
    }
87
88
    @Override
89
    public void save() {
90
91 35660 stefania.m
        errorLabel.setVisible(false);
92
        eligibilityPanel.clear();
93
94 35841 stefania.m
        summaryStepPanel.addStyleName("loading");
95
        summaryStepPanel.add(loadingWheel);
96
97 35660 stefania.m
        eligibilityService.validate(currentFundingWizardState.getRequest(), new AsyncCallback<Eligibility>() {
98
99
            @Override
100
            public void onFailure(Throwable throwable) {
101 35841 stefania.m
102
                summaryStepPanel.removeStyleName("loading");
103
                summaryStepPanel.remove(loadingWheel);
104
105 35660 stefania.m
                errorLabel.setText("System error retrieving eligibility for this request.");
106
                errorLabel.setVisible(true);
107
            }
108
109
            @Override
110
            public void onSuccess(Eligibility eligibility) {
111
112 35841 stefania.m
                summaryStepPanel.removeStyleName("loading");
113
                summaryStepPanel.remove(loadingWheel);
114
115 35660 stefania.m
                if(eligibility.getStatus().equals(Eligibility.Status.OK) || eligibility.getStatus().equals(Eligibility.Status.IFFY)) {
116
117
                    if(agreeToTerms.getValue()) {
118
                        if(fundingWizardStepCompleteListener!=null)
119
                            fundingWizardStepCompleteListener.setStepComplete(true);
120
                    } else {
121
                        errorLabel.setText("You need to agree first to our Terms and Conditions.");
122
                        errorLabel.setVisible(true);
123
                    }
124
125
                } else {
126
                    EligibilityDisplayWidget eligibilityDisplayWidget = new EligibilityDisplayWidget(eligibility);
127
                    eligibilityPanel.add(eligibilityDisplayWidget.asWidget());
128
                }
129
            }
130
        });
131 35581 stefania.m
    }
132
133
    @Override
134 35700 stefania.m
    public void clear() {
135
136
    }
137
138
    @Override
139 35581 stefania.m
    public void loadContent(FundingWizardState fundingWizardState) {
140
141 35660 stefania.m
        currentFundingWizardState = fundingWizardState;
142
143
        errorLabel.setVisible(false);
144 35668 stefania.m
        eligibilityPanel.clear();
145 35660 stefania.m
        summaryWidgetsPanel.clear();
146
147 35747 stefania.m
        FlowPanel firstGrid = new FlowPanel();
148
        firstGrid.addStyleName("uk-grid");
149
150
        ResearcherSummaryWidget researcherSummaryWidget = new ResearcherSummaryWidget(fundingWizardState.getResearcher());
151
        researcherSummaryWidget.addStyleName("uk-width-medium-1-2");
152
        firstGrid.add(researcherSummaryWidget.asWidget());
153
        ResearcherSummaryWidget.EditResearcherListener editResearcherListener = new ResearcherSummaryWidget.EditResearcherListener() {
154 35660 stefania.m
            @Override
155
            public void editClicked(int stepNumber) {
156
                if(fundingWizardJumpToStepListener!=null)
157
                    fundingWizardJumpToStepListener.jumpTo(stepNumber);
158
            }
159
        };
160 35747 stefania.m
        researcherSummaryWidget.setEditResearcherListener(editResearcherListener);
161 35660 stefania.m
162 35747 stefania.m
        ProjectSummaryWidget projectSummaryWidget = new ProjectSummaryWidget(fundingWizardState.getProject());
163
        projectSummaryWidget.addStyleName("uk-width-medium-1-2");
164
        firstGrid.add(projectSummaryWidget.asWidget());
165
        ProjectSummaryWidget.EditProjectListener editProjectListener = new ProjectSummaryWidget.EditProjectListener() {
166 35660 stefania.m
            @Override
167
            public void editClicked(int stepNumber) {
168
                if(fundingWizardJumpToStepListener!=null)
169
                    fundingWizardJumpToStepListener.jumpTo(stepNumber);
170
            }
171
        };
172 35747 stefania.m
        projectSummaryWidget.setEditProjectListener(editProjectListener);
173 35660 stefania.m
174 35747 stefania.m
        summaryWidgetsPanel.add(firstGrid);
175
176
177
        FlowPanel secondGrid = new FlowPanel();
178
        secondGrid.addStyleName("uk-grid");
179
180
        PublicationSummaryWidget publicationSummaryWidget = new PublicationSummaryWidget(fundingWizardState.getPublication());
181
        publicationSummaryWidget.addStyleName("uk-width-medium-1-2");
182
        secondGrid.add(publicationSummaryWidget.asWidget());
183
        PublicationSummaryWidget.EditPublicationListener editPublicationListener = new PublicationSummaryWidget.EditPublicationListener() {
184 35660 stefania.m
            @Override
185
            public void editClicked(int stepNumber) {
186
                if(fundingWizardJumpToStepListener!=null)
187
                    fundingWizardJumpToStepListener.jumpTo(stepNumber);
188
            }
189
        };
190 35747 stefania.m
        publicationSummaryWidget.setEditPublicationListener(editPublicationListener);
191 35660 stefania.m
192 35747 stefania.m
        AccountingSummaryPanel accountingSummaryPanel = new AccountingSummaryPanel(fundingWizardState);
193
        accountingSummaryPanel.addStyleName("uk-width-medium-1-2");
194
        secondGrid.add(accountingSummaryPanel.asWidget());
195 35660 stefania.m
        AccountingSummaryPanel.EditAccountingListener editAccountingListener = new AccountingSummaryPanel.EditAccountingListener() {
196
            @Override
197
            public void editClicked(int stepNumber) {
198
                if(fundingWizardJumpToStepListener!=null)
199
                    fundingWizardJumpToStepListener.jumpTo(stepNumber);
200
            }
201
        };
202
        accountingSummaryPanel.setEditAccountingListener(editAccountingListener);
203 35747 stefania.m
204
        summaryWidgetsPanel.add(secondGrid);
205 35581 stefania.m
    }
206
207
    @Override
208
    public void setFundingWizardStepCompleteListener(FundingWizardStepCompleteListener fundingWizardStepCompleteListener) {
209 35660 stefania.m
        this.fundingWizardStepCompleteListener = fundingWizardStepCompleteListener;
210
    }
211 35581 stefania.m
212 35660 stefania.m
    @Override
213
    public void setFundingWizardJumpToStepListener(FundingWizardJumpToStepListener fundingWizardJumpToStepListener) {
214
        this.fundingWizardJumpToStepListener = fundingWizardJumpToStepListener;
215 35581 stefania.m
    }
216
217
    @Override
218
    public Widget asWidget() {
219
        return summaryStepPanel;
220
    }
221
}