Project

General

Profile

1 43258 stefania.m
package eu.dnetlib.client.monitor;
2
3
import com.github.gwtbootstrap.client.ui.Alert;
4
import com.github.gwtbootstrap.client.ui.Button;
5
import com.github.gwtbootstrap.client.ui.Modal;
6
import com.github.gwtbootstrap.client.ui.constants.AlertType;
7
import com.github.gwtbootstrap.client.ui.constants.BackdropType;
8
import com.github.gwtbootstrap.client.ui.constants.ButtonType;
9
import com.google.gwt.core.client.GWT;
10
import com.google.gwt.event.dom.client.ClickEvent;
11
import com.google.gwt.event.dom.client.ClickHandler;
12
import com.google.gwt.user.client.rpc.AsyncCallback;
13
import com.google.gwt.user.client.ui.FlowPanel;
14
import com.google.gwt.user.client.ui.HTML;
15
import com.google.gwt.user.client.ui.IsWidget;
16
import com.google.gwt.user.client.ui.Widget;
17
import eu.dnetlib.client.DOIAndRepositoryForm;
18
import eu.dnetlib.client.DataService;
19
import eu.dnetlib.client.DataServiceAsync;
20
import eu.dnetlib.client.GoldOAPortal;
21
import eu.dnetlib.client.fundingrequest.stepinfo.*;
22
import eu.dnetlib.client.widgets.ConfirmActionModal;
23
import eu.dnetlib.goldoa.domain.Budget;
24
import eu.dnetlib.goldoa.domain.Comment;
25 46067 panagiotis
import eu.dnetlib.goldoa.domain.CommentTemplate;
26 46634 panagiotis
import eu.dnetlib.goldoa.domain.Organization;
27 43258 stefania.m
28 46067 panagiotis
import java.sql.Timestamp;
29 43258 stefania.m
import java.util.Date;
30
31
/**
32
 * Created by stefania on 5/5/16.
33
 */
34
public class BudgetInfoElement implements IsWidget {
35
36
    private FlowPanel budgetInfoPanel = new FlowPanel();
37
38
    private Alert errorLabel = new Alert();
39
    private Alert successLabel = new Alert();
40
41
    private FlowPanel budgetSummaryPanel = new FlowPanel();
42
    private FlowPanel firstDivider = new FlowPanel();
43
44
    private FlowPanel actionButtons = new FlowPanel();
45
    private Button initialApprove = new Button("Initial Approve");
46
    private Button approve = new Button("Approve");
47
    private Button reject = new Button("Reject");
48
49
    private Button editRequest = new Button("Edit request");
50
    private Button uploadContract = new Button("Upload Contract");
51
52
    private FlowPanel secondDivider = new FlowPanel();
53
54
    private ActionListener actionListener;
55
    private DataServiceAsync dataService = GWT.create(DataService.class);
56
57 45991 panagiotis
    public BudgetInfoElement(final Budget budget) {
58 43258 stefania.m
59
        budgetInfoPanel.addStyleName("requestInfoPanel");
60
61
        successLabel.addStyleName("alertLabel");
62
        successLabel.setType(AlertType.SUCCESS);
63
        successLabel.setVisible(false);
64
        successLabel.setClose(false);
65
66
        errorLabel.addStyleName("alertLabel");
67
        errorLabel.setType(AlertType.ERROR);
68
        errorLabel.setVisible(false);
69
        errorLabel.setClose(false);
70
71
        budgetSummaryPanel.addStyleName("requestDetailedInfoPanel");
72
73 45991 panagiotis
        if(budget.getUser()!=null) {
74
            ResearcherInlineInfo researcherInlineInfo = new ResearcherInlineInfo(budget.getUser());
75 43258 stefania.m
            budgetSummaryPanel.add(researcherInlineInfo.asWidget());
76
        }
77
78 45991 panagiotis
        if(budget.getPublisher()!=null) {
79
            PublisherInlineInfo publisherInlineInfo = new PublisherInlineInfo(budget.getPublisher());
80 43258 stefania.m
            budgetSummaryPanel.add(publisherInlineInfo.asWidget());
81
        }
82
83 46634 panagiotis
        /*dataService.getOrganizationForBudget(budget.getId(), new AsyncCallback<Organization>() {
84
            @Override
85
            public void onFailure(Throwable throwable) {
86
87
            }
88
89
            @Override
90
            public void onSuccess(Organization organization) {
91
                if(organization!=null) {
92
                    OrganisationInlineInfo organisationInlineInfo = new OrganisationInlineInfo(organization);
93
                    budgetSummaryPanel.add(organisationInlineInfo.asWidget());
94
                }
95
            }
96
        });*/
97
98
        if(budget.getOrganizations().get(0)!=null) {
99
            OrganisationInlineInfo organisationInlineInfo = new OrganisationInlineInfo(budget.getOrganizations().get(0));
100 43258 stefania.m
            budgetSummaryPanel.add(organisationInlineInfo.asWidget());
101
        }
102
103 45991 panagiotis
        BudgetDetailsInlineInfo budgetDetailsInlineInfo = new BudgetDetailsInlineInfo(budget);
104 43258 stefania.m
        budgetSummaryPanel.add(budgetDetailsInlineInfo.asWidget());
105
106 45991 panagiotis
        if(budget.getBankAccount()!=null &&
107
                ((budget.getBankAccount().getBankName()!=null && !budget.getBankAccount().getBankName().equals(""))
108
                        || (budget.getBankAccount().getBankAddress()!=null && !budget.getBankAccount().getBankAddress().equals(""))
109
                        || (budget.getBankAccount().getAccountHolder()!=null && !budget.getBankAccount().getAccountHolder().equals(""))
110
                        || (budget.getBankAccount().getIban()!=null && !budget.getBankAccount().getIban().equals(""))
111
                        || (budget.getBankAccount().getBankCode()!=null && !budget.getBankAccount().getBankCode().equals("")))) {
112
            BankAccountInlineInfo bankAccountInlineInfo = new BankAccountInlineInfo(budget.getBankAccount());
113 43258 stefania.m
            budgetSummaryPanel.add(bankAccountInlineInfo.asWidget());
114
        }
115
116
117
118
        //        if(budgetInfo.getInvoice()!=null) {
119
//            InvoiceInlineInfo invoiceInlineInfo = new InvoiceInlineInfo(budgetInfo.getInvoice());
120
//            budgetSummaryPanel.add(invoiceInlineInfo.asWidget());
121
//        }
122
123
//        if (budgetInfo.getStatus().equals(Budget.Status.ACCOUNTING_PAID) && budgetInfo.getAmountGranted()!=null
124
//                && budgetInfo.getTransferCost()!=null && budgetInfo.getDatePaid()!=null) {
125
//            BankTransferInlineInfo bankTransferInlineInfo = new BankTransferInlineInfo(budgetInfo);
126
//            budgetSummaryPanel.add(bankTransferInlineInfo.asWidget());
127
//        }
128
129
        actionButtons.addStyleName("requestInfoActionButtons");
130
131
        initialApprove.addStyleName("requestInfoActionButton");
132
        initialApprove.setType(ButtonType.DEFAULT);
133
        initialApprove.addClickHandler(new ClickHandler() {
134
135
            @Override
136
            public void onClick(ClickEvent event) {
137
138
                errorLabel.setVisible(false);
139
                successLabel.setVisible(false);
140
141
                ConfirmActionModal confirmActionModal = new ConfirmActionModal("Initial Approve", null);
142
                ConfirmActionModal.ActionConfirmedListener actionConfirmedListener = new ConfirmActionModal.ActionConfirmedListener() {
143
                    @Override
144
                    public void actionConfirmed(final String comment, final String templateId) {
145
146
                        final HTML loadingWheel = new HTML("<div class=\"loader-big\"></div><div class=\"whiteFilm\"></div>");
147
                        budgetInfoPanel.addStyleName("loading");
148
                        budgetInfoPanel.add(loadingWheel);
149
150 45991 panagiotis
                        dataService.initiallyApproveBudgetRequest(budget.getId(), comment, GoldOAPortal.currentUser.getId(),
151 43258 stefania.m
                                new AsyncCallback<Void>() {
152
153
                            @Override
154
                            public void onFailure(Throwable caught) {
155
156
                                budgetInfoPanel.removeStyleName("loading");
157
                                budgetInfoPanel.remove(loadingWheel);
158
159
                                errorLabel.setText("System error initial approving this budget request");
160
                                errorLabel.setVisible(true);
161
                                if(actionListener!=null) {
162 46067 panagiotis
                                    //TODO fix comment template
163
                                    CommentTemplate ct = new CommentTemplate();
164
                                    /*ct.setId(templateId);
165
                                    ct.setComment(comment);*/
166
                                    Comment newComment = new Comment(GoldOAPortal.currentUser, new Timestamp(new Date().getTime()), comment, ct);
167 43258 stefania.m
                                    actionListener.actionHappened(false, Budget.Status.INITIALLY_APPROVED, newComment);
168
                                }
169
                            }
170
171
                            @Override
172
                            public void onSuccess(Void result) {
173
174
                                budgetInfoPanel.removeStyleName("loading");
175
                                budgetInfoPanel.remove(loadingWheel);
176
177
                                successLabel.setText("Budget request initially approved successfully");
178
                                successLabel.setVisible(true);
179
180
                                //TODO remove initial approve button and add approve button
181
                                actionButtons.clear();
182
                                actionButtons.add(approve);
183
                                actionButtons.add(reject);
184
                                actionButtons.add(uploadContract);
185
186
                                if(actionListener!=null) {
187 46067 panagiotis
                                    //TODO fix comment template
188
                                    CommentTemplate ct = new CommentTemplate();
189
                                    /*ct.setId(templateId);
190
                                    ct.setComment(comment);*/
191
                                    Comment newComment = new Comment(GoldOAPortal.currentUser, new Timestamp(new Date().getTime()), comment, ct);
192 43258 stefania.m
                                    actionListener.actionHappened(true, Budget.Status.INITIALLY_APPROVED, newComment);
193
                                }
194
                            }
195
                        });
196
                    }
197
                };
198
                confirmActionModal.setActionConfirmedListener(actionConfirmedListener);
199
                confirmActionModal.show();
200
            }
201
        });
202
203
        approve.addStyleName("requestInfoActionButton");
204
        approve.setType(ButtonType.DEFAULT);
205
        approve.addClickHandler(new ClickHandler() {
206
207
            @Override
208
            public void onClick(ClickEvent event) {
209
210
            }
211
        });
212
213
        reject.addStyleName("requestInfoActionButton");
214
        reject.setType(ButtonType.DEFAULT);
215
        reject.addClickHandler(new ClickHandler() {
216
217
            @Override
218
            public void onClick(ClickEvent event) {
219
220
                errorLabel.setVisible(false);
221
                successLabel.setVisible(false);
222
223
                ConfirmActionModal confirmActionModal = new ConfirmActionModal("Reject", null);
224
                ConfirmActionModal.ActionConfirmedListener actionConfirmedListener = new ConfirmActionModal.ActionConfirmedListener() {
225
                    @Override
226
                    public void actionConfirmed(final String comment, final String templateId) {
227
228
                        final HTML loadingWheel = new HTML("<div class=\"loader-big\"></div><div class=\"whiteFilm\"></div>");
229
                        budgetInfoPanel.addStyleName("loading");
230
                        budgetInfoPanel.add(loadingWheel);
231
232 45991 panagiotis
                        dataService.rejectBudgetRequest(budget.getId(), comment, GoldOAPortal.currentUser.getId(),
233 43258 stefania.m
                                new AsyncCallback<Void>() {
234
235
                                    @Override
236
                                    public void onFailure(Throwable caught) {
237
238
                                        budgetInfoPanel.removeStyleName("loading");
239
                                        budgetInfoPanel.remove(loadingWheel);
240
241
                                        errorLabel.setText("System error rejecting this budget request");
242
                                        errorLabel.setVisible(true);
243
                                        if(actionListener!=null) {
244 46067 panagiotis
                                            //TODO fix comment template
245
                                            CommentTemplate ct = new CommentTemplate();
246
                                            /*ct.setId(templateId);
247
                                            ct.setComment(comment);*/
248
                                            Comment newComment = new Comment(GoldOAPortal.currentUser, new Timestamp(new Date().getTime()), comment, ct);
249 43258 stefania.m
                                            actionListener.actionHappened(false, Budget.Status.REJECTED, newComment);
250
                                        }
251
                                    }
252
253
                                    @Override
254
                                    public void onSuccess(Void result) {
255
256
                                        budgetInfoPanel.removeStyleName("loading");
257
                                        budgetInfoPanel.remove(loadingWheel);
258
259
                                        successLabel.setText("Budget request rejected successfully");
260
                                        successLabel.setVisible(true);
261
                                        budgetInfoPanel.remove(actionButtons);
262
                                        if(actionListener!=null) {
263 46067 panagiotis
                                            //TODO fix comment template
264
                                            CommentTemplate ct = new CommentTemplate();
265
                                            /*ct.setId(templateId);
266
                                            ct.setComment(comment);*/
267
                                            Comment newComment = new Comment(GoldOAPortal.currentUser, new Timestamp(new Date().getTime()), comment, ct);
268 43258 stefania.m
                                            actionListener.actionHappened(true, Budget.Status.REJECTED, newComment);
269
                                        }
270
                                    }
271
                                });
272
                    }
273
                };
274
                confirmActionModal.setActionConfirmedListener(actionConfirmedListener);
275
                confirmActionModal.show();
276
            }
277
        });
278
279
        uploadContract.addStyleName("float-right");
280
        uploadContract.addStyleName("marginLeft10");
281
        uploadContract.setType(ButtonType.PRIMARY);
282
        uploadContract.addClickHandler(new ClickHandler() {
283
            @Override
284
            public void onClick(ClickEvent event) {
285
286
//                final Modal addDOIAndRepositoryModal = new Modal();
287
//
288
//                addDOIAndRepositoryModal.addStyleName("contactModal");
289
//                addDOIAndRepositoryModal.setTitle("Add DOI and Repository");
290
//                addDOIAndRepositoryModal.setAnimation(true);
291
//                addDOIAndRepositoryModal.setBackdrop(BackdropType.STATIC);
292
//                addDOIAndRepositoryModal.setDynamicSafe(true);
293
//
294
//                DOIAndRepositoryForm doiAndRepositoryForm = new DOIAndRepositoryForm(requestInfo.getPublication());
295
//                DOIAndRepositoryForm.DOIAndRepositorySubmittedListener doiAndRepositorySubmittedListener =
296
//                        new DOIAndRepositoryForm.DOIAndRepositorySubmittedListener() {
297
//                            @Override
298
//                            public void doiAndRepositorySubmitted() {
299
//                                addDOIAndRepositoryModal.hide();
300
//                                if(publicationUpdatedListener!=null)
301
//                                    publicationUpdatedListener.publicationUpdated();
302
//                            }
303
//                        };
304
//                doiAndRepositoryForm.setDoiAndRepositorySubmittedListener(doiAndRepositorySubmittedListener);
305
//
306
//                addDOIAndRepositoryModal.add(doiAndRepositoryForm.asWidget());
307
//
308
//                addDOIAndRepositoryModal.show();
309
            }
310
        });
311
312
        firstDivider.addStyleName("uk-grid-divider");
313
        secondDivider.addStyleName("uk-grid-divider");
314
315
        budgetInfoPanel.add(successLabel);
316
        budgetInfoPanel.add(errorLabel);
317
        budgetInfoPanel.add(firstDivider);
318
        budgetInfoPanel.add(budgetSummaryPanel);
319
320
        budgetInfoPanel.add(secondDivider);
321 45991 panagiotis
        if(budget.getComments()!=null && !budget.getComments().isEmpty()) {
322
            CommentsInfo commentsInfo = new CommentsInfo(budget.getComments());
323 43258 stefania.m
            commentsInfo.addStyleName("requestComments");
324
            budgetInfoPanel.add(commentsInfo.asWidget());
325
        }
326
327 45991 panagiotis
        if(budget.getStatus().equals(Budget.Status.SUBMITTED)) {
328 43258 stefania.m
            actionButtons.add(initialApprove);
329
            actionButtons.add(reject);
330 45991 panagiotis
        } else if(budget.getStatus().equals(Budget.Status.INITIALLY_APPROVED)) {
331 43258 stefania.m
            actionButtons.add(approve);
332
            actionButtons.add(reject);
333
        }
334
335 45991 panagiotis
        if(budget.getStatus().equals(Budget.Status.INITIALLY_APPROVED) || budget.getStatus().equals(Budget.Status.APPROVED)
336
                || budget.getStatus().equals(Budget.Status.ACCOUNTING_ONHOLD)) {
337 43258 stefania.m
            actionButtons.add(uploadContract);
338
        }
339
//        if(!budgetInfo.getStatus().equals(Budget.Status.APPROVED) && !budgetInfo.getStatus().equals(Budget.Status.REJECTED)
340
//                && !budgetInfo.getStatus().equals(Budget.Status.ACCOUNTING_PAID)) {
341
//            actionButtons.add(approve);
342
//            actionButtons.add(reject);
343
//        }
344
345
        budgetInfoPanel.add(actionButtons);
346
    }
347
348
    @Override
349
    public Widget asWidget() {
350
        return budgetInfoPanel;
351
    }
352
353
    public interface ActionListener {
354
        public void actionHappened(boolean succeeded, Budget.Status status, Comment comment);
355
    }
356
357
    public void setActionListener(ActionListener actionListener) {
358
        this.actionListener = actionListener;
359
    }
360
}