Example usage for org.apache.wicket.extensions.ajax.markup.html.modal ModalWindow setVisibilityAllowed

List of usage examples for org.apache.wicket.extensions.ajax.markup.html.modal ModalWindow setVisibilityAllowed

Introduction

In this page you can find the example usage for org.apache.wicket.extensions.ajax.markup.html.modal ModalWindow setVisibilityAllowed.

Prototype

public final Component setVisibilityAllowed(boolean allowed) 

Source Link

Document

Sets whether or not this component is allowed to be visible.

Usage

From source file:cz.zcu.kiv.eegdatabase.wui.ui.order.OrderItemPanel.java

License:Apache License

private ModalWindow addPromoCodePopup(final OrderItem parent, WebMarkupContainer membershipPlanContainer) {
    final ModalWindow popup = new ModalWindow("promoCodePopup");
    popup.setAutoSize(true);//from   ww w  . j  a  va 2 s  .c  o m
    popup.setResizable(false);
    popup.setMinimalWidth(500);
    popup.setWidthUnit("px");
    popup.showUnloadConfirmation(false);

    PromoCodePopupForm popupForm = new PromoCodePopupForm(popup.getContentId(),
            new Model<StringWrapper>(new StringWrapper())) {

        @Override
        protected void onSubmitAction(IModel<StringWrapper> strWrapper, AjaxRequestTarget target,
                Form<?> form) {
            String code = strWrapper.getObject().getValue();
            if (parent.getMembershipPlan() != null) {
                if (parent.getResearchGroup() == null) {
                    if (promoFacade.isValidPersonalPlanCode(code)) {
                        PromoCode promoCode = promoFacade.getPromoCodeByKeyword(code);
                        parent.setPromoCode(promoCode);
                        double price = parent.getMembershipPlan().getPrice().doubleValue()
                                * (1d - ((double) promoCode.getDiscount() / 100d));
                        parent.setPrice(new BigDecimal(price));
                    }
                } else {
                    if (promoFacade.isValidGroupPlanCode(code)) {
                        PromoCode promoCode = promoFacade.getPromoCodeByKeyword(code);
                        parent.setPromoCode(promoCode);
                        double price = parent.getMembershipPlan().getPrice().doubleValue()
                                * (1d - ((double) promoCode.getDiscount() / 100d));
                        parent.setPrice(new BigDecimal(price));
                    }
                }
            }
            ModalWindow.closeCurrent(target);
            setResponsePage(ShoppingCartPage.class);
        }

        @Override
        protected void onCancelAction(IModel<StringWrapper> strWrapper, AjaxRequestTarget target,
                Form<?> form) {
            ModalWindow.closeCurrent(target);
        }

    };
    popup.setContent(popupForm);
    membershipPlanContainer.add(popup);
    AjaxLink popupLink = new AjaxLink<Object>("applyPromoCode") {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            //License l = this.getModelObject();
            //if (l!=null) System.out.println(l.getTitle());
            popup.show(target);
        }

    };
    popup.setOutputMarkupPlaceholderTag(true);
    popup.setVisibilityAllowed(true);
    String promoCode = "";
    if (parent.getPromoCode() != null) {
        promoCode = "Applied code: " + parent.getPromoCode().getKeyword() + " ("
                + parent.getPromoCode().getDiscount() + "% off)";
    }
    membershipPlanContainer.add(new Label("promoCodeText", promoCode));
    membershipPlanContainer.add(popupLink);
    popupLink.setVisible(malleable);
    return popup;
}