Search in sources :

Example 1 with AbstractDefaultAjaxBehavior

use of org.apache.wicket.ajax.AbstractDefaultAjaxBehavior in project midpoint by Evolveum.

the class PageBase method createModalWindow.

protected ModalWindow createModalWindow(final String id, IModel<String> title, int width, int height) {
    final ModalWindow modal = new ModalWindow(id);
    add(modal);
    modal.setResizable(false);
    modal.setTitle(title);
    modal.setCookieName(PageBase.class.getSimpleName() + ((int) (Math.random() * 100)));
    modal.setInitialWidth(width);
    modal.setWidthUnit("px");
    modal.setInitialHeight(height);
    modal.setHeightUnit("px");
    modal.setCloseButtonCallback(new ModalWindow.CloseButtonCallback() {

        @Override
        public boolean onCloseButtonClicked(AjaxRequestTarget target) {
            return true;
        }
    });
    modal.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() {

        @Override
        public void onClose(AjaxRequestTarget target) {
            modal.close(target);
        }
    });
    modal.add(new AbstractDefaultAjaxBehavior() {

        @Override
        public void renderHead(Component component, IHeaderResponse response) {
            response.render(OnDomReadyHeaderItem.forScript("Wicket.Window.unloadConfirmation = false;"));
            response.render(JavaScriptHeaderItem.forScript("$(document).ready(function() {\n" + "  $(document).bind('keyup', function(evt) {\n" + "    if (evt.keyCode == 27) {\n" + getCallbackScript() + "\n" + "        evt.preventDefault();\n" + "    }\n" + "  });\n" + "});", id));
        }

        @Override
        protected void respond(AjaxRequestTarget target) {
            modal.close(target);
        }
    });
    return modal;
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AbstractDefaultAjaxBehavior(org.apache.wicket.ajax.AbstractDefaultAjaxBehavior) IHeaderResponse(org.apache.wicket.markup.head.IHeaderResponse) ModalWindow(org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow)

Example 2 with AbstractDefaultAjaxBehavior

use of org.apache.wicket.ajax.AbstractDefaultAjaxBehavior in project midpoint by Evolveum.

the class MidPointApplication method init.

@Override
public void init() {
    super.init();
    getCspSettings().blocking().disabled();
    getJavaScriptLibrarySettings().setJQueryReference(new PackageResourceReference(MidPointApplication.class, // todo no jquery.js is found
    "../../../../../webjars/AdminLTE/2.4.18/bower_components/jquery/dist/jquery.min.js"));
    getComponentInstantiationListeners().add(new SpringComponentInjector(this, applicationContext, true));
    systemConfigurationChangeDispatcher.registerListener(new DeploymentInformationChangeListener(this));
    SystemConfigurationType config = getSystemConfigurationIfAvailable();
    if (config != null) {
        deploymentInfo = config.getDeploymentInformation();
    }
    ResourceSettings resourceSettings = getResourceSettings();
    resourceSettings.setParentFolderPlaceholder("$-$");
    resourceSettings.setHeaderItemComparator(new PriorityFirstComparator(true));
    SecurePackageResourceGuard guard = (SecurePackageResourceGuard) resourceSettings.getPackageResourceGuard();
    guard.addPattern("+*.woff2");
    List<IStringResourceLoader> resourceLoaders = resourceSettings.getStringResourceLoaders();
    resourceLoaders.add(0, new MidPointStringResourceLoader(localizationService));
    IResourceStreamLocator locator = new CachingResourceStreamLocator(new MidPointResourceStreamLocator(resourceSettings.getResourceFinders()));
    resourceSettings.setResourceStreamLocator(locator);
    resourceSettings.setThrowExceptionOnMissingResource(false);
    getMarkupSettings().setStripWicketTags(true);
    getMarkupSettings().setStripComments(true);
    if (RuntimeConfigurationType.DEVELOPMENT.equals(getConfigurationType())) {
        getDebugSettings().setAjaxDebugModeEnabled(true);
        getDebugSettings().setDevelopmentUtilitiesEnabled(true);
        initializeDevelopmentSerializers();
        mount(new MountedMapper("/inspector", InspectorPage.class, new PageParametersEncoder()));
        mount(new MountedMapper("/liveSession", LiveSessionsPage.class, new PageParametersEncoder()));
        mount(new MountedMapper("/pageStore", PageStorePage.class, new PageParametersEncoder()));
    }
    // pretty url for resources (e.g. images)
    mountFiles(ImgResources.BASE_PATH, ImgResources.class);
    // exception handling an error pages
    ApplicationSettings appSettings = getApplicationSettings();
    appSettings.setAccessDeniedPage(PageError401.class);
    appSettings.setInternalErrorPage(PageError.class);
    appSettings.setPageExpiredErrorPage(PageError.class);
    mount(new MountedMapper(MOUNT_INTERNAL_SERVER_ERROR, PageError.class, new PageParametersEncoder()));
    mount(new MountedMapper(MOUNT_UNAUTHORIZED_ERROR, PageError401.class, new PageParametersEncoder()));
    mount(new MountedMapper(MOUNT_FORBIDEN_ERROR, PageError403.class, new PageParametersEncoder()));
    mount(new MountedMapper(MOUNT_NOT_FOUND_ERROR, PageError404.class, new PageParametersEncoder()));
    mount(new MountedMapper(MOUNT_GONE_ERROR, PageError410.class, new PageParametersEncoder()));
    getRequestCycleListeners().add(new LoggingRequestCycleListener(this));
    getAjaxRequestTargetListeners().add(new AjaxRequestTarget.IListener() {

        @Override
        public void updateAjaxAttributes(AbstractDefaultAjaxBehavior behavior, AjaxRequestAttributes attributes) {
            // check whether behavior will use POST method, if not then don't put CSRF token there
            if (!isPostMethodTypeBehavior(behavior, attributes)) {
                return;
            }
            CsrfToken csrfToken = SecurityUtils.getCsrfToken();
            if (csrfToken == null) {
                return;
            }
            String parameterName = csrfToken.getParameterName();
            String value = csrfToken.getToken();
            attributes.getExtraParameters().put(parameterName, value);
        }
    });
    getSessionListeners().add((ISessionListener) asyncWebProcessManager);
    // descriptor loader, used for customization
    new PageMounter().loadData(this);
    descriptorLoader.loadData();
    if (applicationContext != null) {
        Map<String, MidPointApplicationConfiguration> map = applicationContext.getBeansOfType(MidPointApplicationConfiguration.class);
        if (map != null) {
            map.forEach((key, value) -> value.init(this));
        }
    }
    // for schrodinger selenide library
    initializeSchrodinger();
    ServletContext servletContext = getServletContext();
    if (servletContext != null) {
        taskManager.setWebContextPath(servletContext.getContextPath());
    }
}
Also used : CachingResourceStreamLocator(org.apache.wicket.core.util.resource.locator.caching.CachingResourceStreamLocator) MountedMapper(org.apache.wicket.core.request.mapper.MountedMapper) MidPointResourceStreamLocator(com.evolveum.midpoint.web.util.MidPointResourceStreamLocator) IResourceStreamLocator(org.apache.wicket.core.util.resource.locator.IResourceStreamLocator) InspectorPage(org.apache.wicket.devutils.inspector.InspectorPage) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PriorityFirstComparator(org.apache.wicket.markup.head.PriorityFirstComparator) MidPointStringResourceLoader(com.evolveum.midpoint.web.util.MidPointStringResourceLoader) AbstractDefaultAjaxBehavior(org.apache.wicket.ajax.AbstractDefaultAjaxBehavior) PackageResourceReference(org.apache.wicket.request.resource.PackageResourceReference) IStringResourceLoader(org.apache.wicket.resource.loader.IStringResourceLoader) ServletContext(javax.servlet.ServletContext) LiveSessionsPage(org.apache.wicket.devutils.inspector.LiveSessionsPage) MidPointApplicationConfiguration(com.evolveum.midpoint.gui.api.util.MidPointApplicationConfiguration) PageStorePage(org.apache.wicket.devutils.pagestore.PageStorePage) CsrfToken(org.springframework.security.web.csrf.CsrfToken) PageMounter(com.evolveum.midpoint.web.application.PageMounter) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AjaxRequestAttributes(org.apache.wicket.ajax.attributes.AjaxRequestAttributes) ApplicationSettings(org.apache.wicket.settings.ApplicationSettings) SecurePackageResourceGuard(org.apache.wicket.markup.html.SecurePackageResourceGuard) ResourceSettings(org.apache.wicket.settings.ResourceSettings) SystemConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType) PageParametersEncoder(org.apache.wicket.request.mapper.parameter.PageParametersEncoder) SpringComponentInjector(org.apache.wicket.spring.injection.annot.SpringComponentInjector)

Example 3 with AbstractDefaultAjaxBehavior

use of org.apache.wicket.ajax.AbstractDefaultAjaxBehavior in project openmeetings by apache.

the class MainPanel method onInitialize.

@Override
protected void onInitialize() {
    menu = new MenuPanel("menu", getMainMenu());
    add(topControls.setOutputMarkupPlaceholderTag(true).setMarkupId("topControls"));
    add(contents.add(getClient() == null || panel == null ? EMPTY : panel).setOutputMarkupId(true).setMarkupId("contents"));
    topControls.add(menu.setVisible(false), topLinks.setVisible(false).setOutputMarkupPlaceholderTag(true).setMarkupId("topLinks"));
    topLinks.add(new AjaxLink<Void>("messages") {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            updateContents(PROFILE_MESSAGES, target);
        }
    });
    topLinks.add(new AjaxLink<Void>("profile") {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            updateContents(PROFILE_EDIT, target);
        }
    });
    final AboutDialog about = new AboutDialog("aboutDialog");
    topLinks.add(new AjaxLink<Void>("about") {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            about.open(target);
        }
    });
    if (getApplication().getDebugSettings().isDevelopmentUtilitiesEnabled()) {
        add(new DebugBar("dev").setOutputMarkupId(true));
    } else {
        add(new EmptyPanel("dev").setVisible(false));
    }
    add(new OmAjaxClientInfoBehavior());
    add(about, chat = new ChatPanel("chatPanel"));
    add(newMessage = new MessageDialog("newMessageDialog", new CompoundPropertyModel<>(new PrivateMessage())) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClose(IPartialPageRequestHandler handler, DialogButton button) {
            BasePanel bp = getCurrentPanel();
            if (send.equals(button) && bp != null) {
                bp.onNewMessageClose(handler);
            }
        }
    });
    add(userInfo = new UserInfoDialog("userInfoDialog", newMessage));
    add(new AbstractDefaultAjaxBehavior() {

        private static final long serialVersionUID = 1L;

        @Override
        protected void respond(AjaxRequestTarget target) {
            userInfo.open(target, getParam(getComponent(), PARAM_USER_ID).toLong());
        }

        @Override
        public void renderHead(Component component, IHeaderResponse response) {
            super.renderHead(component, response);
            response.render(new PriorityHeaderItem(getNamedFunction("showUserInfo", this, explicit(PARAM_USER_ID))));
        }
    });
    add(new AbstractDefaultAjaxBehavior() {

        private static final long serialVersionUID = 1L;

        @Override
        protected void respond(AjaxRequestTarget target) {
            ContactsHelper.addUserToContactList(getParam(getComponent(), PARAM_USER_ID).toLong());
        }

        @Override
        public void renderHead(Component component, IHeaderResponse response) {
            super.renderHead(component, response);
            response.render(new PriorityHeaderItem(getNamedFunction("addContact", this, explicit(PARAM_USER_ID))));
        }
    });
    add(new AbstractDefaultAjaxBehavior() {

        private static final long serialVersionUID = 1L;

        @Override
        protected void respond(AjaxRequestTarget target) {
            newMessage.reset(true).open(target, getParam(getComponent(), PARAM_USER_ID).toOptionalLong());
        }

        @Override
        public void renderHead(Component component, IHeaderResponse response) {
            super.renderHead(component, response);
            response.render(new PriorityHeaderItem(getNamedFunction("privateMessage", this, explicit(PARAM_USER_ID))));
        }
    });
    add(inviteUser = new InviteUserToRoomDialog("invite-to-room"));
    add(new AbstractDefaultAjaxBehavior() {

        private static final long serialVersionUID = 1L;

        @Override
        protected void respond(AjaxRequestTarget target) {
            inviteUser.open(target, getParam(getComponent(), PARAM_USER_ID).toLong());
        }

        @Override
        public void renderHead(Component component, IHeaderResponse response) {
            super.renderHead(component, response);
            response.render(new PriorityHeaderItem(getNamedFunction("inviteUser", this, explicit(PARAM_USER_ID))));
        }
    });
    topLinks.add(new ConfirmableAjaxBorder("logout", getString("310"), getString("634")) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target) {
            getSession().invalidate();
            setResponsePage(Application.get().getSignInPageClass());
        }
    });
    super.onInitialize();
}
Also used : DebugBar(org.apache.wicket.devutils.debugbar.DebugBar) DialogButton(com.googlecode.wicket.jquery.ui.widget.dialog.DialogButton) AboutDialog(org.apache.openmeetings.web.user.AboutDialog) EmptyPanel(org.apache.wicket.markup.html.panel.EmptyPanel) IPartialPageRequestHandler(org.apache.wicket.core.request.handler.IPartialPageRequestHandler) ChatPanel(org.apache.openmeetings.web.user.chat.ChatPanel) InviteUserToRoomDialog(org.apache.openmeetings.web.user.InviteUserToRoomDialog) MenuPanel(org.apache.openmeetings.web.common.menu.MenuPanel) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) UserInfoDialog(org.apache.openmeetings.web.user.UserInfoDialog) PriorityHeaderItem(org.apache.wicket.markup.head.PriorityHeaderItem) AbstractDefaultAjaxBehavior(org.apache.wicket.ajax.AbstractDefaultAjaxBehavior) IHeaderResponse(org.apache.wicket.markup.head.IHeaderResponse) MessageDialog(org.apache.openmeetings.web.user.MessageDialog) PrivateMessage(org.apache.openmeetings.db.entity.user.PrivateMessage) Component(org.apache.wicket.Component)

Aggregations

AbstractDefaultAjaxBehavior (org.apache.wicket.ajax.AbstractDefaultAjaxBehavior)3 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)3 IHeaderResponse (org.apache.wicket.markup.head.IHeaderResponse)2 MidPointApplicationConfiguration (com.evolveum.midpoint.gui.api.util.MidPointApplicationConfiguration)1 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)1 PageMounter (com.evolveum.midpoint.web.application.PageMounter)1 MidPointResourceStreamLocator (com.evolveum.midpoint.web.util.MidPointResourceStreamLocator)1 MidPointStringResourceLoader (com.evolveum.midpoint.web.util.MidPointStringResourceLoader)1 SystemConfigurationType (com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType)1 DialogButton (com.googlecode.wicket.jquery.ui.widget.dialog.DialogButton)1 ServletContext (javax.servlet.ServletContext)1 PrivateMessage (org.apache.openmeetings.db.entity.user.PrivateMessage)1 MenuPanel (org.apache.openmeetings.web.common.menu.MenuPanel)1 AboutDialog (org.apache.openmeetings.web.user.AboutDialog)1 InviteUserToRoomDialog (org.apache.openmeetings.web.user.InviteUserToRoomDialog)1 MessageDialog (org.apache.openmeetings.web.user.MessageDialog)1 UserInfoDialog (org.apache.openmeetings.web.user.UserInfoDialog)1 ChatPanel (org.apache.openmeetings.web.user.chat.ChatPanel)1 Component (org.apache.wicket.Component)1 AjaxRequestAttributes (org.apache.wicket.ajax.attributes.AjaxRequestAttributes)1