Search in sources :

Example 1 with AjaxCallListener

use of org.apache.wicket.ajax.attributes.AjaxCallListener in project ocvn by devgateway.

the class BootstrapDeleteButton method updateAjaxAttributes.

@Override
protected void updateAjaxAttributes(final AjaxRequestAttributes attributes) {
    super.updateAjaxAttributes(attributes);
    AjaxCallListener ajaxCallListener = new AjaxCallListener();
    ajaxCallListener.onPrecondition("return confirm('Confirm Delete?');");
    attributes.getAjaxCallListeners().add(ajaxCallListener);
}
Also used : AjaxCallListener(org.apache.wicket.ajax.attributes.AjaxCallListener)

Example 2 with AjaxCallListener

use of org.apache.wicket.ajax.attributes.AjaxCallListener in project wicket by apache.

the class AbstractDefaultAjaxBehaviorTest method renderAjaxAttributes.

/**
 * Checks the generated JSON for Ajax's attributes
 */
@Test
public void renderAjaxAttributes() {
    AjaxRequestAttributes attributes = new AjaxRequestAttributes();
    attributes.getExtraParameters().put("param1", 123);
    attributes.getExtraParameters().put("param2", Locale.CANADA_FRENCH);
    AjaxCallListener listener = new AjaxCallListener();
    listener.onPrecondition("return somePrecondition();");
    listener.onBefore("alert('Before!');");
    listener.onAfter("alert('After!');");
    listener.onSuccess("alert('Success!');");
    listener.onFailure("alert('Failure!');");
    listener.onComplete("alert('Complete!');");
    attributes.getAjaxCallListeners().add(listener);
    Component component = Mockito.mock(Component.class);
    AbstractDefaultAjaxBehavior behavior = new AbstractDefaultAjaxBehavior() {

        @Override
        protected void respond(AjaxRequestTarget target) {
        }

        @Override
        public CharSequence getCallbackUrl() {
            return "some/url";
        }
    };
    behavior.bind(component);
    CharSequence json = behavior.renderAjaxAttributes(component, attributes);
    String expected = "{\"" + AjaxAttributeName.URL + "\":\"some/url\",\"" + AjaxAttributeName.BEFORE_HANDLER + "\":[function(attrs){alert('Before!');}],\"" + AjaxAttributeName.AFTER_HANDLER + "\":[function(attrs){alert('After!');}],\"" + AjaxAttributeName.SUCCESS_HANDLER + "\":[function(attrs, jqXHR, data, textStatus){alert('Success!');}],\"" + AjaxAttributeName.FAILURE_HANDLER + "\":[function(attrs, jqXHR, errorMessage, textStatus){alert('Failure!');}],\"" + AjaxAttributeName.COMPLETE_HANDLER + "\":[function(attrs, jqXHR, textStatus){alert('Complete!');}],\"" + AjaxAttributeName.PRECONDITION + "\":[function(attrs){return somePrecondition();}],\"" + AjaxAttributeName.EXTRA_PARAMETERS + "\":[{\"name\":\"param1\",\"value\":123},{\"name\":\"param2\",\"value\":\"fr_CA\"}]" + "}";
    assertEquals(expected, json);
}
Also used : AjaxRequestAttributes(org.apache.wicket.ajax.attributes.AjaxRequestAttributes) Component(org.apache.wicket.Component) AjaxCallListener(org.apache.wicket.ajax.attributes.AjaxCallListener) Test(org.junit.Test)

Example 3 with AjaxCallListener

use of org.apache.wicket.ajax.attributes.AjaxCallListener in project wicket by apache.

the class AjaxFileDropBehavior method updateAjaxAttributes.

@Override
protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
    super.updateAjaxAttributes(attributes);
    attributes.setMultipart(true);
    attributes.setMethod(Method.POST);
    // default must be prevented, otherwise browser will consume the dataTransfer
    attributes.setPreventDefault(true);
    attributes.getAjaxCallListeners().add(new AjaxCallListener() {

        @Override
        public CharSequence getPrecondition(Component component) {
            String css = getComponent().getString(DRAG_OVER_CLASS_KEY);
            return String.format("jQuery('#' + attrs.c).toggleClass('%s', attrs.event.type === 'dragover'); return (attrs.event.type === 'drop');", css);
        }
    });
    attributes.getDynamicExtraParameters().add(String.format("return Wicket.DataTransfer.getFilesAsParamArray(attrs.event.originalEvent, '%s');", parameterName));
}
Also used : Component(org.apache.wicket.Component) AjaxCallListener(org.apache.wicket.ajax.attributes.AjaxCallListener)

Example 4 with AjaxCallListener

use of org.apache.wicket.ajax.attributes.AjaxCallListener in project wicket by apache.

the class AjaxEditableChoiceLabel method newEditor.

/**
 * {@inheritDoc}
 */
@Override
protected FormComponent<T> newEditor(final MarkupContainer parent, final String componentId, final IModel<T> model) {
    IModel<List<? extends T>> choiceModel = new IModel<List<? extends T>>() {

        private static final long serialVersionUID = 1L;

        @Override
        public List<? extends T> getObject() {
            return choices.getObject();
        }
    };
    DropDownChoice<T> editor = new DropDownChoice<T>(componentId, model, choiceModel, renderer) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onModelChanged() {
            AjaxEditableChoiceLabel.this.onModelChanged();
        }

        @Override
        protected void onModelChanging() {
            AjaxEditableChoiceLabel.this.onModelChanging();
        }
    };
    editor.setOutputMarkupId(true);
    editor.setVisible(false);
    editor.add(new EditorAjaxBehavior() {

        private static final long serialVersionUID = 1L;

        @Override
        protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
            super.updateAjaxAttributes(attributes);
            attributes.setEventNames("change", "blur", "keyup");
            CharSequence dynamicExtraParameters = "var result = [], " + "kc=Wicket.Event.keyCode(attrs.event)," + "evtType=attrs.event.type;" + "if (evtType === 'blur' || (evtType === 'keyup' && kc===27)) {" + "  result.push( { name: 'save', value: false } );" + "}" + "else {" + "  result = Wicket.Form.serializeElement(attrs.c);" + "  result.push( { name: 'save', value: true } );" + "}" + "return result;";
            attributes.getDynamicExtraParameters().add(dynamicExtraParameters);
            CharSequence precondition = "var kc=Wicket.Event.keyCode(attrs.event)," + "evtType=attrs.event.type," + "ret=false;" + "if(evtType==='blur' || evtType==='change' || (evtType==='keyup' && kc===27)) ret = true;" + "return ret;";
            AjaxCallListener ajaxCallListener = new AjaxCallListener();
            ajaxCallListener.onPrecondition(precondition);
            attributes.getAjaxCallListeners().add(ajaxCallListener);
        }
    });
    return editor;
}
Also used : AjaxRequestAttributes(org.apache.wicket.ajax.attributes.AjaxRequestAttributes) IModel(org.apache.wicket.model.IModel) DropDownChoice(org.apache.wicket.markup.html.form.DropDownChoice) List(java.util.List) AjaxCallListener(org.apache.wicket.ajax.attributes.AjaxCallListener)

Example 5 with AjaxCallListener

use of org.apache.wicket.ajax.attributes.AjaxCallListener in project wicket by apache.

the class AjaxEditableLabel method newEditor.

/**
 * Create a new form component instance to serve as editor.
 *
 * @param parent
 *            The parent component
 * @param componentId
 *            Id that should be used by the component
 * @param model
 *            The model
 * @return The editor
 */
protected FormComponent<T> newEditor(final MarkupContainer parent, final String componentId, final IModel<T> model) {
    TextField<T> editor = new TextField<T>(componentId, model) {

        private static final long serialVersionUID = 1L;

        @Override
        public <C> IConverter<C> getConverter(final Class<C> type) {
            IConverter<C> c = AjaxEditableLabel.this.getConverter(type);
            return c != null ? c : super.getConverter(type);
        }

        @Override
        protected void onModelChanged() {
            super.onModelChanged();
            AjaxEditableLabel.this.onModelChanged();
        }

        @Override
        protected void onModelChanging() {
            super.onModelChanging();
            AjaxEditableLabel.this.onModelChanging();
        }
    };
    editor.setOutputMarkupId(true);
    editor.setVisible(false);
    editor.add(new EditorAjaxBehavior() {

        @Override
        protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
            super.updateAjaxAttributes(attributes);
            attributes.setEventNames("blur", "keyup", "keydown");
            // Note: preventDefault is handled selectively below
            attributes.setPreventDefault(false);
            // Note: escape can be detected on keyup, enter can be detected on keyup
            CharSequence precondition = "var kc=Wicket.Event.keyCode(attrs.event)," + "evtType=attrs.event.type," + "ret=false;" + "if (evtType==='blur' || (evtType==='keyup' && kc===27) || (evtType==='keydown' && kc===13)) {attrs.event.preventDefault(); ret = true;}" + "return ret;";
            AjaxCallListener ajaxCallListener = new AjaxCallListener();
            ajaxCallListener.onPrecondition(precondition);
            CharSequence dynamicExtraParameters = "var result," + "evtType=attrs.event.type;" + "if (evtType === 'keyup') { result = { 'save': false }; }" + "else { result = { 'save': true }; }" + "return result;";
            attributes.getDynamicExtraParameters().add(dynamicExtraParameters);
            attributes.getAjaxCallListeners().add(ajaxCallListener);
        }
    });
    return editor;
}
Also used : AjaxRequestAttributes(org.apache.wicket.ajax.attributes.AjaxRequestAttributes) TextField(org.apache.wicket.markup.html.form.TextField) AjaxCallListener(org.apache.wicket.ajax.attributes.AjaxCallListener)

Aggregations

AjaxCallListener (org.apache.wicket.ajax.attributes.AjaxCallListener)14 Component (org.apache.wicket.Component)9 AjaxRequestAttributes (org.apache.wicket.ajax.attributes.AjaxRequestAttributes)7 List (java.util.List)3 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)3 FormComponent (org.apache.wicket.markup.html.form.FormComponent)3 IModel (org.apache.wicket.model.IModel)3 ArrayList (java.util.ArrayList)2 IndicatorAjaxEventBehavior (org.apache.syncope.client.console.wicket.ajax.form.IndicatorAjaxEventBehavior)2 IAjaxCallListener (org.apache.wicket.ajax.attributes.IAjaxCallListener)2 TextField (com.googlecode.wicket.kendo.ui.form.TextField)1 BootstrapToggle (de.agilecoders.wicket.extensions.markup.html.bootstrap.form.checkbox.bootstraptoggle.BootstrapToggle)1 BootstrapToggleConfig (de.agilecoders.wicket.extensions.markup.html.bootstrap.form.checkbox.bootstraptoggle.BootstrapToggleConfig)1 AnnotationException (de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException)1 AnnotationDetailEditorPanel.handleException (de.tudarmstadt.ukp.clarin.webanno.ui.annotation.detail.AnnotationDetailEditorPanel.handleException)1 IOException (java.io.IOException)1 Collection (java.util.Collection)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Transformer (org.apache.commons.collections4.Transformer)1