Search in sources :

Example 91 with AjaxLink

use of org.apache.wicket.ajax.markup.html.AjaxLink in project midpoint by Evolveum.

the class ValidationErrorPanel method initHeader.

private void initHeader(WebMarkupContainer box) {
    WebMarkupContainer iconType = new WebMarkupContainer("iconType");
    iconType.setOutputMarkupId(true);
    iconType.add(new AttributeAppender("class", new IModel() {

        @Override
        public Object getObject() {
            FeedbackMessage result = getModelObject();
            if (result == null) {
                return " fa-info";
            }
            switch(result.getLevel()) {
                case FeedbackMessage.INFO:
                case FeedbackMessage.DEBUG:
                    return " fa-info";
                case FeedbackMessage.SUCCESS:
                    return " fa-check";
                case FeedbackMessage.ERROR:
                case FeedbackMessage.FATAL:
                    return " fa-ban";
                case FeedbackMessage.UNDEFINED:
                // TODO:
                case FeedbackMessage.WARNING:
                default:
                    return " fa-warning";
            }
        }
    }));
    box.add(iconType);
    Label message = new Label(ID_MESSAGE, new PropertyModel<Serializable>(getModel(), "message"));
    box.add(message);
    AjaxLink<Void> close = new AjaxLink<Void>("close") {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            close(target);
        }
    };
    box.add(close);
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) IModel(org.apache.wicket.model.IModel) Serializable(java.io.Serializable) Label(org.apache.wicket.markup.html.basic.Label) FeedbackMessage(org.apache.wicket.feedback.FeedbackMessage) AjaxLink(org.apache.wicket.ajax.markup.html.AjaxLink) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) AttributeAppender(org.apache.wicket.behavior.AttributeAppender)

Example 92 with AjaxLink

use of org.apache.wicket.ajax.markup.html.AjaxLink in project midpoint by Evolveum.

the class PasswordPanel method initLayout.

private <F extends FocusType> void initLayout(final boolean isReadOnly, PrismObject<F> object) {
    setOutputMarkupId(true);
    final WebMarkupContainer inputContainer = new WebMarkupContainer(ID_INPUT_CONTAINER) {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            return passwordInputVisible;
        }
    };
    inputContainer.setOutputMarkupId(true);
    add(inputContainer);
    ValuePolicyType valuePolicy = getValuePolicy(object);
    LoadableModel<List<StringLimitationResult>> limitationsModel = new LoadableModel<>() {

        @Override
        protected List<StringLimitationResult> load() {
            return getLimitationsForActualPassword(valuePolicy, object);
        }
    };
    final PasswordLimitationsPanel validationPanel = new PasswordLimitationsPanel(ID_VALIDATION_PANEL, limitationsModel);
    validationPanel.setOutputMarkupId(true);
    inputContainer.add(validationPanel);
    final PasswordTextField password1 = new SecureModelPasswordTextField(ID_PASSWORD_ONE, new PasswordModel(model)) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onComponentTag(ComponentTag tag) {
            super.onComponentTag(tag);
            if (clearPasswordInput) {
                tag.remove("value");
            }
        }
    };
    password1.add(AttributeAppender.append("onfocus", "initPasswordValidation({\n" + "container: $('#progress-bar-container'),\n" + "hierarchy: {\n" + "    '0': ['progress-bar-danger', '" + PageBase.createStringResourceStatic(null, "PasswordPanel.strength.veryWeak").getString() + "'],\n" + "    '25': ['progress-bar-danger', '" + PageBase.createStringResourceStatic(null, "PasswordPanel.strength.weak").getString() + "'],\n" + "    '50': ['progress-bar-warning', '" + PageBase.createStringResourceStatic(null, "PasswordPanel.strength.good").getString() + "'],\n" + "    '75': ['progress-bar-success', '" + PageBase.createStringResourceStatic(null, "PasswordPanel.strength.strong").getString() + "'],\n" + "    '100': ['progress-bar-success', '" + PageBase.createStringResourceStatic(null, "PasswordPanel.strength.veryStrong").getString() + "']\n" + "}\n" + "})"));
    password1.setRequired(false);
    password1.setOutputMarkupId(true);
    password1.add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
    inputContainer.add(password1);
    final PasswordTextField password2 = new SecureModelPasswordTextField(ID_PASSWORD_TWO, new PasswordModel(Model.of(new ProtectedStringType())));
    password2.setRequired(false);
    password2.setOutputMarkupId(true);
    inputContainer.add(password2);
    password1.add(new AjaxFormComponentUpdatingBehavior("change") {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            boolean required = !StringUtils.isEmpty(password1.getModelObject());
            password2.setRequired(required);
            changePasswordPerformed();
        }
    });
    IModel<String> password2ValidationModel = (IModel<String>) () -> {
        String s1 = password1.getModelObject();
        String s2 = password2.getValue();
        if (StringUtils.isEmpty(s1) || StringUtils.isEmpty(s2)) {
            return "";
        }
        if (!Objects.equals(s1, s2)) {
            return PageBase.createStringResourceStatic(null, "passwordPanel.error").getString();
        }
        return "";
    };
    Label password2ValidationMessage = new Label(ID_PASSWORD_TWO_VALIDATION_MESSAGE, password2ValidationModel);
    password2ValidationMessage.setOutputMarkupId(true);
    inputContainer.add(password2ValidationMessage);
    password1.add(new AjaxFormComponentUpdatingBehavior("keyup input") {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            limitationsModel.reset();
            validationPanel.refreshItems(target);
            updatePasswordValidation(target);
            target.add(password2ValidationMessage);
        }

        @Override
        protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
            super.updateAjaxAttributes(attributes);
            attributes.setThrottlingSettings(new ThrottlingSettings(Duration.ofMillis(500), true));
            attributes.setChannel(new AjaxChannel("Drop", AjaxChannel.Type.DROP));
        }
    });
    PasswordValidator pass2Validator = new PasswordValidator(password1);
    password2.add(pass2Validator);
    password2.add(new AjaxFormComponentUpdatingBehavior("keyup input") {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            target.add(password2ValidationMessage);
        }

        @Override
        protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
            super.updateAjaxAttributes(attributes);
            attributes.setThrottlingSettings(new ThrottlingSettings(Duration.ofMillis(500), true));
            attributes.setChannel(new AjaxChannel("Drop", AjaxChannel.Type.DROP));
        }
    });
    final WebMarkupContainer linkContainer = new WebMarkupContainer(ID_LINK_CONTAINER) {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            return !passwordInputVisible;
        }
    };
    inputContainer.setOutputMarkupId(true);
    linkContainer.setOutputMarkupId(true);
    add(linkContainer);
    final Label passwordSetLabel = new Label(ID_PASSWORD_SET, new ResourceModel("passwordPanel.passwordSet"));
    linkContainer.add(passwordSetLabel);
    final Label passwordRemoveLabel = new Label(ID_PASSWORD_REMOVE, new ResourceModel("passwordPanel.passwordRemoveLabel"));
    passwordRemoveLabel.setVisible(false);
    linkContainer.add(passwordRemoveLabel);
    AjaxLink<Void> link = new AjaxLink<Void>(ID_CHANGE_PASSWORD_LINK) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            clearPasswordInput = true;
            setPasswordInput = false;
            onLinkClick(target);
        }

        @Override
        public boolean isVisible() {
            return !passwordInputVisible && model != null && model.getObject() != null;
        }
    };
    link.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            return !isReadOnly;
        }
    });
    link.setBody(new ResourceModel("passwordPanel.passwordChange"));
    link.setOutputMarkupId(true);
    linkContainer.add(link);
    final WebMarkupContainer removeButtonContainer = new WebMarkupContainer(ID_REMOVE_BUTTON_CONTAINER);
    AjaxLink<Void> removePassword = new AjaxLink<Void>(ID_REMOVE_PASSWORD_LINK) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            onRemovePassword(model, target);
        }
    };
    removePassword.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            PageBase pageBase = getPageBase();
            if (pageBase == null) {
                return false;
            }
            if (pageBase instanceof PageUserSelfProfile || pageBase instanceof PageOrgSelfProfile || pageBase instanceof PageRoleSelfProfile || pageBase instanceof PageServiceSelfProfile) {
                return false;
            }
            if (pageBase instanceof PageAdminFocus && !((PageAdminFocus) pageBase).isLoggedInFocusPage() && model.getObject() != null) {
                return true;
            }
            return false;
        }
    });
    removePassword.setBody(new ResourceModel("passwordPanel.passwordRemove"));
    removePassword.setOutputMarkupId(true);
    removeButtonContainer.add(removePassword);
    add(removeButtonContainer);
}
Also used : ThrottlingSettings(org.apache.wicket.ajax.attributes.ThrottlingSettings) ValuePolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.ValuePolicyType) PageAdminFocus(com.evolveum.midpoint.web.page.admin.PageAdminFocus) StringLimitationResult(com.evolveum.midpoint.model.api.validator.StringLimitationResult) Label(org.apache.wicket.markup.html.basic.Label) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) PageRoleSelfProfile(com.evolveum.midpoint.web.page.self.PageRoleSelfProfile) ResourceModel(org.apache.wicket.model.ResourceModel) List(java.util.List) ArrayList(java.util.ArrayList) AjaxChannel(org.apache.wicket.ajax.AjaxChannel) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) AjaxLink(org.apache.wicket.ajax.markup.html.AjaxLink) AjaxFormComponentUpdatingBehavior(org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior) IModel(org.apache.wicket.model.IModel) PageServiceSelfProfile(com.evolveum.midpoint.web.page.self.PageServiceSelfProfile) PasswordTextField(org.apache.wicket.markup.html.form.PasswordTextField) PageBase(com.evolveum.midpoint.gui.api.page.PageBase) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AjaxRequestAttributes(org.apache.wicket.ajax.attributes.AjaxRequestAttributes) PageUserSelfProfile(com.evolveum.midpoint.web.page.self.PageUserSelfProfile) ComponentTag(org.apache.wicket.markup.ComponentTag) LoadableModel(com.evolveum.midpoint.gui.api.model.LoadableModel) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType) PageOrgSelfProfile(com.evolveum.midpoint.web.page.self.PageOrgSelfProfile)

Example 93 with AjaxLink

use of org.apache.wicket.ajax.markup.html.AjaxLink in project midpoint by Evolveum.

the class UserSelectionButton method initLayout.

private void initLayout() {
    AjaxLink<String> userSelectionButton = new AjaxLink<String>(ID_USER_SELECTION_BUTTON) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
            super.updateAjaxAttributes(attributes);
            attributes.setEventPropagation(AjaxRequestAttributes.EventPropagation.BUBBLE);
        }

        @Override
        public void onClick(AjaxRequestTarget target) {
            if (showUserSelectionPopup) {
                initUserSelectionPopup(target);
            }
            showUserSelectionPopup = true;
        }
    };
    userSelectionButton.add(AttributeModifier.append("class", getTargetUserButtonClass()));
    userSelectionButton.setOutputMarkupId(true);
    userSelectionButton.add(new AttributeAppender("title", new IModel<String>() {

        private static final long serialVersionUID = 1L;

        @Override
        public String getObject() {
            return getUserSelectionButtonTitle();
        }
    }));
    add(userSelectionButton);
    Label label = new Label(ID_USER_SELECTION_BUTTON_LABEL, new IModel<String>() {

        private static final long serialVersionUID = 1L;

        @Override
        public String getObject() {
            return getUserButtonLabel();
        }
    });
    label.setRenderBodyOnly(true);
    userSelectionButton.add(label);
    AjaxLink<Void> deleteButton = new AjaxLink<Void>(ID_DELETE_SELECTED_USER_BUTTON) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            UserSelectionButton.this.onDeleteSelectedUsersPerformed(target);
        }
    };
    deleteButton.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            return isDeleteButtonVisible();
        }
    });
    userSelectionButton.add(deleteButton);
}
Also used : IModel(org.apache.wicket.model.IModel) Label(org.apache.wicket.markup.html.basic.Label) AjaxRequestAttributes(org.apache.wicket.ajax.attributes.AjaxRequestAttributes) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) AjaxLink(org.apache.wicket.ajax.markup.html.AjaxLink) AttributeAppender(org.apache.wicket.behavior.AttributeAppender)

Example 94 with AjaxLink

use of org.apache.wicket.ajax.markup.html.AjaxLink in project midpoint by Evolveum.

the class RoleCatalogItemButton method initLayout.

private void initLayout() {
    setOutputMarkupId(true);
    WebMarkupContainer itemButtonContainer = new WebMarkupContainer(ID_ITEM_BUTTON_CONTAINER);
    itemButtonContainer.setOutputMarkupId(true);
    itemButtonContainer.add(new AttributeAppender("class", getBackgroundClass(getModelObject())));
    add(itemButtonContainer);
    AjaxLink<Void> inner = new AjaxLink<Void>(ID_INNER) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget ajaxRequestTarget) {
            targetObjectDetailsPerformed(RoleCatalogItemButton.this.getModelObject(), ajaxRequestTarget);
        }
    };
    inner.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isEnabled() {
            return isAuthorizedForTargetObjectDetailsPage(getModelObject()) && (isMultiUserRequest() || canAssign(RoleCatalogItemButton.this.getModelObject()));
        }
    });
    inner.add(new AttributeAppender("title", getModelObject().getName()));
    itemButtonContainer.add(inner);
    Label nameLabel = new Label(ID_INNER_LABEL, getModelObject().getName());
    inner.add(nameLabel);
    Label descriptionLabel = new Label(ID_INNER_DESCRIPTION, getModelObject().getTargetRef() != null ? getModelObject().getTargetRef().getDescription() : "");
    descriptionLabel.setOutputMarkupId(true);
    inner.add(descriptionLabel);
    AjaxLink<Void> detailsLink = new AjaxLink<Void>(ID_DETAILS_LINK) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget ajaxRequestTarget) {
            assignmentDetailsPerformed(RoleCatalogItemButton.this.getModelObject(), ajaxRequestTarget);
        }
    };
    detailsLink.add(getAssignmentDetailsLinkVisibleBehavior());
    detailsLink.add(AttributeAppender.append("title", AssignmentsUtil.getShoppingCartAssignmentsLimitReachedTitleModel(getPageBase())));
    detailsLink.add(AttributeAppender.append("class", new LoadableModel<String>() {

        @Override
        protected String load() {
            return detailsLink.isEnabled() ? "shopping-cart-item-button-details" : "shopping-cart-item-button-details-disabled";
        }
    }));
    itemButtonContainer.add(detailsLink);
    Label detailsLinkLabel = new Label(ID_DETAILS_LINK_LABEL, createStringResource("MultiButtonPanel.detailsLink"));
    detailsLinkLabel.setRenderBodyOnly(true);
    detailsLink.add(detailsLinkLabel);
    AjaxLink<Void> detailsLinkIcon = new AjaxLink<Void>(ID_DETAILS_LINK_ICON) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
        }
    };
    detailsLinkIcon.add(getAssignmentDetailsLinkVisibleBehavior());
    detailsLink.add(detailsLinkIcon);
    AjaxLink<Void> addToCartLink = new AjaxLink<Void>(ID_ADD_TO_CART_LINK) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget ajaxRequestTarget) {
            addAssignmentPerformed(RoleCatalogItemButton.this.getModelObject(), ajaxRequestTarget);
        }
    };
    addToCartLink.add(getFooterLinksEnableBehaviour());
    addToCartLink.add(AttributeAppender.append("title", AssignmentsUtil.getShoppingCartAssignmentsLimitReachedTitleModel(getPageBase())));
    addToCartLink.add(AttributeAppender.append("class", new LoadableModel<String>() {

        @Override
        protected String load() {
            return addToCartLink.isEnabled() ? "shopping-cart-item-button-add" : "shopping-cart-item-button-add-disabled";
        }
    }));
    itemButtonContainer.add(addToCartLink);
    AjaxLink<Void> addToCartLinkIcon = new AjaxLink<Void>(ID_ADD_TO_CART_LINK_ICON) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
        }
    };
    addToCartLinkIcon.add(getFooterLinksEnableBehaviour());
    addToCartLink.add(addToCartLinkIcon);
    WebMarkupContainer icon = new WebMarkupContainer(ID_TYPE_ICON);
    icon.add(new AttributeAppender("class", WebComponentUtil.createDefaultBlackIcon(getModelObject().getType().getQname())));
    itemButtonContainer.add(icon);
    WebMarkupContainer alreadyAssignedIcon = new WebMarkupContainer(ID_ALREADY_ASSIGNED_ICON);
    alreadyAssignedIcon.add(new AttributeAppender("title", getAlreadyAssignedIconTitleModel(getModelObject())));
    alreadyAssignedIcon.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            return !isMultiUserRequest() && getModelObject().isAlreadyAssigned();
        }
    });
    itemButtonContainer.add(alreadyAssignedIcon);
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) Label(org.apache.wicket.markup.html.basic.Label) LoadableModel(com.evolveum.midpoint.gui.api.model.LoadableModel) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) AjaxLink(org.apache.wicket.ajax.markup.html.AjaxLink) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) AttributeAppender(org.apache.wicket.behavior.AttributeAppender)

Example 95 with AjaxLink

use of org.apache.wicket.ajax.markup.html.AjaxLink in project midpoint by Evolveum.

the class LinkedReferencePanel method initLayout.

private void initLayout() {
    setOutputMarkupId(true);
    IModel<DisplayType> displayModel = new ReadOnlyModel<>(() -> {
        PrismReferenceValue ref = referenceModel.getObject();
        if (ref == null) {
            return null;
        }
        DisplayType displayType = GuiDisplayTypeUtil.getDisplayTypeForObject(ref.getObject(), null, getPageBase());
        if (displayType == null) {
            displayType = new DisplayType();
        }
        if (displayType.getIcon() == null) {
            displayType.setIcon(WebComponentUtil.createIconType(WebComponentUtil.createDefaultBlackIcon(ref.getTargetType())));
        }
        return displayType;
    });
    ImagePanel imagePanel = new ImagePanel(ID_ICON, displayModel);
    imagePanel.setOutputMarkupId(true);
    add(imagePanel);
    AjaxLink<PrismReferenceValue> nameLink = new AjaxLink<PrismReferenceValue>(ID_NAME, referenceModel) {

        @Override
        public void onClick(AjaxRequestTarget ajaxRequestTarget) {
            WebComponentUtil.dispatchToObjectDetailsPage(referenceModel.getObject(), LinkedReferencePanel.this, false);
        }
    };
    nameLink.add(new EnableBehaviour(() -> {
        PrismReferenceValue ref = referenceModel.getObject();
        if (ref == null) {
            return false;
        }
        return ref.getObject() != null;
    }));
    nameLink.setOutputMarkupId(true);
    add(nameLink);
    Label nameLinkText = new Label(ID_NAME_TEXT, new ReadOnlyModel<>(() -> {
        PrismReferenceValue ref = referenceModel.getObject();
        if (ref == null) {
            return "";
        }
        return WebComponentUtil.getReferencedObjectDisplayNameAndName(ref.asReferencable(), false, getPageBase());
    }));
    nameLinkText.setOutputMarkupId(true);
    nameLink.add(nameLinkText);
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) DisplayType(com.evolveum.midpoint.xml.ns._public.common.common_3.DisplayType) ReadOnlyModel(com.evolveum.midpoint.gui.api.model.ReadOnlyModel) Label(org.apache.wicket.markup.html.basic.Label) AjaxLink(org.apache.wicket.ajax.markup.html.AjaxLink) ImagePanel(com.evolveum.midpoint.web.component.data.column.ImagePanel) EnableBehaviour(com.evolveum.midpoint.web.component.util.EnableBehaviour)

Aggregations

AjaxLink (org.apache.wicket.ajax.markup.html.AjaxLink)115 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)111 Label (org.apache.wicket.markup.html.basic.Label)64 VisibleEnableBehaviour (com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)62 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)58 IModel (org.apache.wicket.model.IModel)38 ListItem (org.apache.wicket.markup.html.list.ListItem)25 ListView (org.apache.wicket.markup.html.list.ListView)21 AttributeAppender (org.apache.wicket.behavior.AttributeAppender)19 TextField (org.apache.wicket.markup.html.form.TextField)18 AjaxFormComponentUpdatingBehavior (org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior)16 ArrayList (java.util.ArrayList)13 AttributeModifier (org.apache.wicket.AttributeModifier)13 VisibleBehaviour (com.evolveum.midpoint.web.component.util.VisibleBehaviour)12 AjaxSubmitLink (org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink)11 AjaxRequestAttributes (org.apache.wicket.ajax.attributes.AjaxRequestAttributes)10 List (java.util.List)9 AjaxButton (com.evolveum.midpoint.web.component.AjaxButton)8 ComponentFeedbackMessageFilter (org.apache.wicket.feedback.ComponentFeedbackMessageFilter)8 Test (org.junit.Test)8