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.constants.AlertType;
5
import com.google.gwt.core.client.GWT;
6
import com.google.gwt.user.client.rpc.AsyncCallback;
7
import com.google.gwt.user.client.ui.FlowPanel;
8
import com.google.gwt.user.client.ui.HTML;
9
import com.google.gwt.user.client.ui.Label;
10
import com.google.gwt.user.client.ui.Widget;
11
import eu.dnetlib.client.GoldOAConstants;
12
import eu.dnetlib.client.fundingrequest.newrequest.*;
13
import eu.dnetlib.goldoa.domain.Eligibility;
14
import eu.dnetlib.goldoa.domain.Request;
15
import eu.dnetlib.shared.FundingWizardState;
16

    
17
/**
18
 * Created by stefania on 3/24/15.
19
 */
20
public class SummaryStepWidget extends FundingWizardStepWidget {
21

    
22
    private FlowPanel summaryStepPanel = new FlowPanel();
23
    private Label summaryInfoLabel = new Label();
24
    private Alert errorLabel = new Alert();
25

    
26
    private FlowPanel eligibilityPanel = new FlowPanel();
27

    
28
    private FlowPanel summaryWidgetsPanel = new FlowPanel();
29

    
30
    private HTML loadingWheel = new HTML("<div class=\"loader-big\"></div><div class=\"whiteFilm\"></div>");
31

    
32
    private FundingWizardJumpToStepListener fundingWizardJumpToStepListener;
33
    private FundingWizardStepCompleteListener fundingWizardStepCompleteListener;
34

    
35
    private FundingWizardState currentFundingWizardState;
36

    
37
    private EligibilityServiceAsync eligibilityService = GWT.create(EligibilityService.class);
38
    private GoldOAConstants goldOAConstants = GWT.create(GoldOAConstants.class);
39

    
40
    public SummaryStepWidget(String title) {
41

    
42
        super(title);
43

    
44
        summaryInfoLabel.addStyleName("stepWidgetLabel");
45
        summaryInfoLabel.setText("Review your funding request so far and edit if needed before submitting");
46

    
47
        errorLabel.addStyleName("alertLabel");
48
        errorLabel.setType(AlertType.ERROR);
49
        errorLabel.setVisible(false);
50
        errorLabel.setClose(false);
51

    
52
        summaryWidgetsPanel.addStyleName("summaryWidgetsPanel");
53

    
54
        summaryStepPanel.add(summaryInfoLabel);
55
        summaryStepPanel.add(errorLabel);
56
        summaryStepPanel.add(eligibilityPanel);
57
        summaryStepPanel.add(summaryWidgetsPanel);
58
    }
59

    
60
    @Override
61
    public void updateState(FundingWizardState fundingWizardState) {
62

    
63
    }
64

    
65
    @Override
66
    public void save() {
67

    
68
        errorLabel.setVisible(false);
69
        eligibilityPanel.clear();
70

    
71
        summaryStepPanel.addStyleName("loading");
72
        summaryStepPanel.add(loadingWheel);
73
        currentFundingWizardState.getRequest().setStatus(Request.RequestStatus.INCOMPLETE);
74
        eligibilityService.validate(currentFundingWizardState.getRequest(), new AsyncCallback<Eligibility>() {
75

    
76
            @Override
77
            public void onFailure(Throwable throwable) {
78

    
79
                summaryStepPanel.removeStyleName("loading");
80
                summaryStepPanel.remove(loadingWheel);
81

    
82
                errorLabel.setText(goldOAConstants.errorRetrievingEligibility());
83
                errorLabel.setVisible(true);
84
            }
85

    
86
            @Override
87
            public void onSuccess(Eligibility eligibility) {
88

    
89
                summaryStepPanel.removeStyleName("loading");
90
                summaryStepPanel.remove(loadingWheel);
91

    
92
                if(eligibility.getStatus().equals(Eligibility.Status.OK) || eligibility.getStatus().equals(Eligibility.Status.IFFY)) {
93

    
94
                    final TermsOfAgreementModal termsOfAgreementModal = new TermsOfAgreementModal();
95
                    termsOfAgreementModal.show();
96

    
97
                    TermsOfAgreementModal.TermsOfAgreementListener termsOfAgreementListener = new TermsOfAgreementModal.TermsOfAgreementListener() {
98
                        @Override
99
                        public void termsAgreed(boolean termsAgreed) {
100
                            if(termsAgreed) {
101
                                termsOfAgreementModal.hide();
102
                                if(fundingWizardStepCompleteListener!=null)
103
                                    fundingWizardStepCompleteListener.setStepComplete(true);
104
                            } else {
105
                                termsOfAgreementModal.hide();
106
                                errorLabel.setText(goldOAConstants.needToAgreeToTermsOfAgreement());
107
                                errorLabel.setVisible(true);
108
                            }
109
                        }
110
                    };
111
                    termsOfAgreementModal.setTermsOfAgreementListener(termsOfAgreementListener);
112

    
113
                } else {
114
                    EligibilityDisplayWidget eligibilityDisplayWidget = new EligibilityDisplayWidget(eligibility);
115
                    eligibilityPanel.add(eligibilityDisplayWidget.asWidget());
116
                }
117
            }
118
        });
119
    }
120

    
121
    @Override
122
    public void clear() {
123

    
124
    }
125

    
126
    @Override
127
    public void loadContent(FundingWizardState fundingWizardState) {
128

    
129
        currentFundingWizardState = fundingWizardState;
130

    
131
        errorLabel.setVisible(false);
132
        eligibilityPanel.clear();
133
        summaryWidgetsPanel.clear();
134

    
135
        FlowPanel firstGrid = new FlowPanel();
136
        firstGrid.addStyleName("uk-grid");
137

    
138
        ResearcherSummaryWidget researcherSummaryWidget = new ResearcherSummaryWidget(fundingWizardState.getResearcher());
139
        researcherSummaryWidget.addStyleName("uk-width-medium-1-2");
140
        firstGrid.add(researcherSummaryWidget.asWidget());
141
        ResearcherSummaryWidget.EditResearcherListener editResearcherListener = new ResearcherSummaryWidget.EditResearcherListener() {
142
            @Override
143
            public void editClicked(int stepNumber) {
144
                if(fundingWizardJumpToStepListener!=null)
145
                    fundingWizardJumpToStepListener.jumpTo(stepNumber);
146
            }
147
        };
148
        researcherSummaryWidget.setEditResearcherListener(editResearcherListener);
149

    
150
        ProjectSummaryWidget projectSummaryWidget = new ProjectSummaryWidget(fundingWizardState.getProject());
151
        projectSummaryWidget.addStyleName("uk-width-medium-1-2");
152
        firstGrid.add(projectSummaryWidget.asWidget());
153
        ProjectSummaryWidget.EditProjectListener editProjectListener = new ProjectSummaryWidget.EditProjectListener() {
154
            @Override
155
            public void editClicked(int stepNumber) {
156
                if(fundingWizardJumpToStepListener!=null)
157
                    fundingWizardJumpToStepListener.jumpTo(stepNumber);
158
            }
159
        };
160
        projectSummaryWidget.setEditProjectListener(editProjectListener);
161

    
162
        summaryWidgetsPanel.add(firstGrid);
163

    
164

    
165
        FlowPanel secondGrid = new FlowPanel();
166
        secondGrid.addStyleName("uk-grid");
167

    
168
        PublicationSummaryWidget publicationSummaryWidget = new PublicationSummaryWidget(fundingWizardState.getPublication());
169
        publicationSummaryWidget.addStyleName("uk-width-medium-1-2");
170
        secondGrid.add(publicationSummaryWidget.asWidget());
171
        PublicationSummaryWidget.EditPublicationListener editPublicationListener = new PublicationSummaryWidget.EditPublicationListener() {
172
            @Override
173
            public void editClicked(int stepNumber) {
174
                if(fundingWizardJumpToStepListener!=null)
175
                    fundingWizardJumpToStepListener.jumpTo(stepNumber);
176
            }
177
        };
178
        publicationSummaryWidget.setEditPublicationListener(editPublicationListener);
179

    
180
        AccountingSummaryPanel accountingSummaryPanel = new AccountingSummaryPanel(fundingWizardState);
181
        accountingSummaryPanel.addStyleName("uk-width-medium-1-2");
182
        secondGrid.add(accountingSummaryPanel.asWidget());
183
        AccountingSummaryPanel.EditAccountingListener editAccountingListener = new AccountingSummaryPanel.EditAccountingListener() {
184
            @Override
185
            public void editClicked(int stepNumber) {
186
                if(fundingWizardJumpToStepListener!=null)
187
                    fundingWizardJumpToStepListener.jumpTo(stepNumber);
188
            }
189
        };
190
        accountingSummaryPanel.setEditAccountingListener(editAccountingListener);
191

    
192
        summaryWidgetsPanel.add(secondGrid);
193
    }
194

    
195
    @Override
196
    public void setFundingWizardStepCompleteListener(FundingWizardStepCompleteListener fundingWizardStepCompleteListener) {
197
        this.fundingWizardStepCompleteListener = fundingWizardStepCompleteListener;
198
    }
199

    
200
    @Override
201
    public void setFundingWizardJumpToStepListener(FundingWizardJumpToStepListener fundingWizardJumpToStepListener) {
202
        this.fundingWizardJumpToStepListener = fundingWizardJumpToStepListener;
203
    }
204

    
205
    @Override
206
    public Widget asWidget() {
207
        return summaryStepPanel;
208
    }
209
}
(5-5/5)