Project

General

Profile

1
package eu.dnetlib.client.fundingrequest.newrequest.summarystep;
2

    
3
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
import com.google.gwt.user.client.ui.FlowPanel;
12
import com.google.gwt.user.client.ui.HTML;
13
import com.google.gwt.user.client.ui.Label;
14
import com.google.gwt.user.client.ui.Widget;
15
import eu.dnetlib.client.fundingrequest.newrequest.EligibilityDisplayWidget;
16
import eu.dnetlib.client.fundingrequest.newrequest.EligibilityService;
17
import eu.dnetlib.client.fundingrequest.newrequest.EligibilityServiceAsync;
18
import eu.dnetlib.client.fundingrequest.newrequest.FundingWizardStepWidget;
19
import eu.dnetlib.goldoa.domain.Eligibility;
20
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
    private Label summaryInfoLabel = new Label();
29
    private Alert errorLabel = new Alert();
30

    
31
    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
    private HTML loadingWheel = new HTML("<div class=\"loader-big\"></div><div class=\"whiteFilm\"></div>");
40

    
41
    private FundingWizardJumpToStepListener fundingWizardJumpToStepListener;
42
    private FundingWizardStepCompleteListener fundingWizardStepCompleteListener;
43

    
44
    private FundingWizardState currentFundingWizardState;
45

    
46
    private EligibilityServiceAsync eligibilityService = GWT.create(EligibilityService.class);
47

    
48
    public SummaryStepWidget(String title) {
49

    
50
        super(title);
51

    
52
        summaryInfoLabel.addStyleName("stepWidgetLabel");
53
        summaryInfoLabel.setText("Review your funding request so far and edit if needed before submitting");
54

    
55
        errorLabel.addStyleName("alertLabel");
56
        errorLabel.setType(AlertType.ERROR);
57
        errorLabel.setVisible(false);
58
        errorLabel.setClose(false);
59

    
60
        summaryWidgetsPanel.addStyleName("summaryWidgetsPanel");
61

    
62
        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
        summaryStepPanel.add(summaryInfoLabel);
77
        summaryStepPanel.add(errorLabel);
78
        summaryStepPanel.add(eligibilityPanel);
79
        summaryStepPanel.add(summaryWidgetsPanel);
80
        summaryStepPanel.add(agreeToTermsPanel);
81
    }
82

    
83
    @Override
84
    public void updateState(FundingWizardState fundingWizardState) {
85

    
86
    }
87

    
88
    @Override
89
    public void save() {
90

    
91
        errorLabel.setVisible(false);
92
        eligibilityPanel.clear();
93

    
94
        summaryStepPanel.addStyleName("loading");
95
        summaryStepPanel.add(loadingWheel);
96

    
97
        eligibilityService.validate(currentFundingWizardState.getRequest(), new AsyncCallback<Eligibility>() {
98

    
99
            @Override
100
            public void onFailure(Throwable throwable) {
101

    
102
                summaryStepPanel.removeStyleName("loading");
103
                summaryStepPanel.remove(loadingWheel);
104

    
105
                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
                summaryStepPanel.removeStyleName("loading");
113
                summaryStepPanel.remove(loadingWheel);
114

    
115
                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
    }
132

    
133
    @Override
134
    public void clear() {
135

    
136
    }
137

    
138
    @Override
139
    public void loadContent(FundingWizardState fundingWizardState) {
140

    
141
        currentFundingWizardState = fundingWizardState;
142

    
143
        errorLabel.setVisible(false);
144
        eligibilityPanel.clear();
145
        summaryWidgetsPanel.clear();
146

    
147
        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
            @Override
155
            public void editClicked(int stepNumber) {
156
                if(fundingWizardJumpToStepListener!=null)
157
                    fundingWizardJumpToStepListener.jumpTo(stepNumber);
158
            }
159
        };
160
        researcherSummaryWidget.setEditResearcherListener(editResearcherListener);
161

    
162
        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
            @Override
167
            public void editClicked(int stepNumber) {
168
                if(fundingWizardJumpToStepListener!=null)
169
                    fundingWizardJumpToStepListener.jumpTo(stepNumber);
170
            }
171
        };
172
        projectSummaryWidget.setEditProjectListener(editProjectListener);
173

    
174
        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
            @Override
185
            public void editClicked(int stepNumber) {
186
                if(fundingWizardJumpToStepListener!=null)
187
                    fundingWizardJumpToStepListener.jumpTo(stepNumber);
188
            }
189
        };
190
        publicationSummaryWidget.setEditPublicationListener(editPublicationListener);
191

    
192
        AccountingSummaryPanel accountingSummaryPanel = new AccountingSummaryPanel(fundingWizardState);
193
        accountingSummaryPanel.addStyleName("uk-width-medium-1-2");
194
        secondGrid.add(accountingSummaryPanel.asWidget());
195
        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

    
204
        summaryWidgetsPanel.add(secondGrid);
205
    }
206

    
207
    @Override
208
    public void setFundingWizardStepCompleteListener(FundingWizardStepCompleteListener fundingWizardStepCompleteListener) {
209
        this.fundingWizardStepCompleteListener = fundingWizardStepCompleteListener;
210
    }
211

    
212
    @Override
213
    public void setFundingWizardJumpToStepListener(FundingWizardJumpToStepListener fundingWizardJumpToStepListener) {
214
        this.fundingWizardJumpToStepListener = fundingWizardJumpToStepListener;
215
    }
216

    
217
    @Override
218
    public Widget asWidget() {
219
        return summaryStepPanel;
220
    }
221
}
(5-5/5)