org.apache.wicket.ajax.attributes.AjaxCallListener Java Examples

The following examples show how to use org.apache.wicket.ajax.attributes.AjaxCallListener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: KeyPressBehavior.java    From the-app with Apache License 2.0 6 votes vote down vote up
@Override
protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
    super.updateAjaxAttributes(attributes);

    IAjaxCallListener listener = new AjaxCallListener() {
        @Override
        public CharSequence getPrecondition(Component component) {
            //this javascript code evaluates wether an ajaxcall is necessary.
            //Here only by keyocdes for F9 and F10
            return "var keycode = Wicket.Event.keyCode(attrs.event);" +
                    "if ((keycode == 112) || (keycode == 113) || (keycode == 114) || (keycode == 115))" +
                    "    return true;" +
                    "else" +
                    "    return false;";
        }
    };
    attributes.getAjaxCallListeners().add(listener);

    //Append the pressed keycode to the ajaxrequest
    attributes.getDynamicExtraParameters()
            .add("var eventKeycode = Wicket.Event.keyCode(attrs.event);" +
                    "return {keycode: eventKeycode};");

    //whithout setting, no keyboard events will reach any inputfield
    attributes.setPreventDefault(true);
}
 
Example #2
Source File: GbAjaxButton.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
@Override
protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
	super.updateAjaxAttributes(attributes);
	attributes.getAjaxCallListeners().add(new AjaxCallListener()
			// disable the button right away after clicking it
			// and mark on it if the window is unloading
			.onBefore(
					String.format(
							"$('#%s').prop('disabled', true);" +
									"$(window).on('beforeunload', function() {" +
									"$('#%s').data('unloading', true).prop('disabled', true)});",
							getMarkupId(), getMarkupId()))
			// if the page is unloading, keep it disabled, otherwise
			// add a slight delay in re-enabling it, just in case it succeeded
			// and there's a delay in closing a parent modal
			.onComplete(
					String.format("setTimeout(function() {" +
							"if (!$('#%s').data('unloading')) $('#%s').prop('disabled',false);" +
							"}, 1000)",
							getMarkupId(), getMarkupId())));
}
 
Example #3
Source File: KeyPressBehavior.java    From AppStash with Apache License 2.0 6 votes vote down vote up
@Override
protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
    super.updateAjaxAttributes(attributes);

    IAjaxCallListener listener = new AjaxCallListener() {
        @Override
        public CharSequence getPrecondition(Component component) {
            //this javascript code evaluates wether an ajaxcall is necessary.
            //Here only by keyocdes for F9 and F10
            return "var keycode = Wicket.Event.keyCode(attrs.event);" +
                    "if ((keycode == 112) || (keycode == 113) || (keycode == 114) || (keycode == 115))" +
                    "    return true;" +
                    "else" +
                    "    return false;";
        }
    };
    attributes.getAjaxCallListeners().add(listener);

    //Append the pressed keycode to the ajaxrequest
    attributes.getDynamicExtraParameters()
            .add("var eventKeycode = Wicket.Event.keyCode(attrs.event);" +
                    "return {keycode: eventKeycode};");

    //whithout setting, no keyboard events will reach any inputfield
    attributes.setPreventDefault(true);
}
 
Example #4
Source File: GbAjaxButton.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
@Override
protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
	super.updateAjaxAttributes(attributes);
	attributes.getAjaxCallListeners().add(new AjaxCallListener()
			// disable the button right away after clicking it
			// and mark on it if the window is unloading
			.onBefore(
					String.format(
							"$('#%s').prop('disabled', true);" +
									"$(window).on('beforeunload', function() {" +
									"$('#%s').data('unloading', true).prop('disabled', true)});",
							getMarkupId(), getMarkupId()))
			// if the page is unloading, keep it disabled, otherwise
			// add a slight delay in re-enabling it, just in case it succeeded
			// and there's a delay in closing a parent modal
			.onComplete(
					String.format("setTimeout(function() {" +
							"if (!$('#%s').data('unloading')) $('#%s').prop('disabled',false);" +
							"}, 1000)",
							getMarkupId(), getMarkupId())));
}
 
Example #5
Source File: FilterPanel.java    From Orienteer with Apache License 2.0 6 votes vote down vote up
private AjaxFormSubmitBehavior newOnEnterPressBehavior(final WebMarkupContainer container) {
    return new AjaxFormSubmitBehavior("keypress") {

        @Override
        protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
            super.updateAjaxAttributes(attributes);
            attributes.getAjaxCallListeners().add(new AjaxCallListener() {
                @Override
                public CharSequence getPrecondition(Component component) {
                    return "return Wicket.Event.keyCode(attrs.event) === 13;";
                }
            });
        }

        @Override
        protected void onSubmit(AjaxRequestTarget target) {
            super.onSubmit(target);
            onOkSubmit(target, container);
        }
    };
}
 
Example #6
Source File: FeatureEditor.java    From webanno with Apache License 2.0 5 votes vote down vote up
protected void addDelay(AjaxRequestAttributes aAttributes, int aDelay)
{
    // When focus is on a feature editor and the user selects a new annotation,
    // there is a race condition between the saving the value of the feature
    // editor and the loading of the new annotation. Delay the feature editor
    // save to give preference to loading the new annotation.
    aAttributes.setThrottlingSettings(new ThrottlingSettings(milliseconds(aDelay), true));
    aAttributes.getAjaxCallListeners().add(new AjaxCallListener()
    {
        private static final long serialVersionUID = 3157811089824093324L;
        
        @Override
        public CharSequence getPrecondition(Component aComponent)
        {
            // If the panel refreshes because the user selects a new annotation,
            // the annotation editor panel is updated for the new annotation
            // first (before saving values) because of the delay set above. When
            // the delay is over, we can no longer save the value because the
            // old component is no longer there. We use the markup id of the
            // editor fragments to check if the old component is still there
            // (i.e. if the user has just tabbed to a new field) or if the old
            // component is gone (i.e. the user selected/created another
            // annotation). If the old component is no longer there, we abort
            // the delayed save action.
            return "return $('#" + getMarkupId() + "').length > 0;";
        }
    });
}
 
Example #7
Source File: SakaiSpinningSelectOnChangeBehavior.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
@Override
protected void updateAjaxAttributes(AjaxRequestAttributes attributes)
{
	super.updateAjaxAttributes(attributes);
	attributes.setChannel(new AjaxChannel("blocking", AjaxChannel.Type.ACTIVE));

	AjaxCallListener listener = new SakaiSpinningSelectAjaxCallListener(getComponent().getMarkupId(), false);
	attributes.getAjaxCallListeners().add(listener);
}
 
Example #8
Source File: SakaiAjaxButton.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
@Override
protected void updateAjaxAttributes(AjaxRequestAttributes attributes)
{
	super.updateAjaxAttributes(attributes);
	attributes.setChannel(new AjaxChannel("blocking", AjaxChannel.Type.ACTIVE));

	AjaxCallListener listener = new SakaiSpinnerAjaxCallListener(getMarkupId(), willRenderOnClick);
	attributes.getAjaxCallListeners().add(listener);
}
 
Example #9
Source File: SakaiSpinningSelectOnChangeBehavior.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
@Override
protected void updateAjaxAttributes(AjaxRequestAttributes attributes)
{
	super.updateAjaxAttributes(attributes);
	attributes.setChannel(new AjaxChannel("blocking", AjaxChannel.Type.ACTIVE));

	AjaxCallListener listener = new SakaiSpinningSelectAjaxCallListener(getComponent().getMarkupId(), false);
	attributes.getAjaxCallListeners().add(listener);
}
 
Example #10
Source File: SakaiAjaxButton.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
@Override
protected void updateAjaxAttributes(AjaxRequestAttributes attributes)
{
	super.updateAjaxAttributes(attributes);
	attributes.setChannel(new AjaxChannel("blocking", AjaxChannel.Type.ACTIVE));

	AjaxCallListener listener = new SakaiSpinnerAjaxCallListener(getMarkupId(), willRenderOnClick);
	attributes.getAjaxCallListeners().add(listener);
}
 
Example #11
Source File: AjaxConfirmLink.java    From nextreports-server with Apache License 2.0 5 votes vote down vote up
@Override
protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
	super.updateAjaxAttributes(attributes);
	
	if (StringUtils.isNotEmpty(getMessage()) && showDialog()) {
		String message = getMessage().replaceAll("'", "\"");
		StringBuilder precondition = new StringBuilder("if(!confirm('").append(message).append("')) { hideBusy(); return false; };");
		
		AjaxCallListener listener = new AjaxCallListener();
		listener.onPrecondition(precondition);
		
		attributes.getAjaxCallListeners().add(listener);
	}
}
 
Example #12
Source File: AjaxSubmitConfirmLink.java    From nextreports-server with Apache License 2.0 5 votes vote down vote up
@Override
protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
	super.updateAjaxAttributes(attributes);
	
	if (StringUtils.isNotEmpty(getMessage()) && showDialog()) {
		String message = getMessage().replaceAll("'", "\"");
		StringBuilder precondition = new StringBuilder("if(!confirm('").append(message).append("')) { return false; };");
		
		AjaxCallListener listener = new AjaxCallListener();
		listener.onPrecondition(precondition);
		
		attributes.getAjaxCallListeners().add(listener);
	}
}
 
Example #13
Source File: WidgetPopupMenuModel.java    From nextreports-server with Apache License 2.0 4 votes vote down vote up
private AjaxConfirmLink createDeleteLink(final IModel<Widget> model) {
	AjaxConfirmLink<Void> deleteLink = new AjaxConfirmLink<Void>(MenuPanel.LINK_ID, 
			new StringResourceModel("WidgetPopupMenu.deleteWidget", null).getString() + " " + model.getObject().getTitle() + "?") {

		@Override
		public void onClick(AjaxRequestTarget target) {
			int column = dashboardService.getWidgetColumn(model.getObject().getId());
			try {
				dashboardService.removeWidget(getDashboardId(model.getObject().getId()), model.getObject().getId());
			} catch (NotFoundException e) {
				// never happening
				throw new RuntimeException(e);
			}				
			// the widget is removed with javascript (with a IAjaxCallDecorator) -> see getAjaxCallDecorator()
			
			// dashboard may become empty (hide global settings)
			findParent(DashboardPanel.class).refreshGlobalSettings(target);
		}
		
		@Override
           public boolean isVisible() {            
			return hasWritePermission(model.getObject());
		}  
		
		@Override
		protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
			super.updateAjaxAttributes(attributes);
			
			attributes.getAjaxCallListeners().add(new AjaxCallListener() {

				private static final long serialVersionUID = 1L;

				@Override
				public CharSequence getSuccessHandler(Component component) {
					return "$('#widget-" + model.getObject().getId() + "').remove();";
				}
				
			});
		}

	};				
	
	return deleteLink;
}
 
Example #14
Source File: AnalysisPanel.java    From nextreports-server with Apache License 2.0 4 votes vote down vote up
private AjaxSubmitLink getFreezeLink() {
 	return new AjaxSubmitLink("freeze") {

 		@Override
 		public void onSubmit(AjaxRequestTarget target, Form form) {
 			Analysis analysis = AnalysisPanel.this.getModel().getObject();    			
 			
 			Analysis newAnalysis = ObjectCloner.silenceDeepCopy(analysis);
 			newAnalysis.setName(analysis.getName() + " " + UUID.randomUUID());
 			newAnalysis.setFreezed(true);
 			String addedId = analysisService.addAnalysis(newAnalysis);    	
 			
 			AnalysisPanel.this.getModel().setObject(newAnalysis);
 			
 			AnalysisBrowserPanel browserPanel = findParent(AnalysisBrowserPanel.class);
	SectionContext sectionContext = NextServerSession.get().getSectionContext(AnalysisSection.ID);
	sectionContext.getData().put(SectionContextConstants.SELECTED_ANALYSIS_ID, addedId);
	browserPanel.getAnalysisPanel().changeDataProvider(new SelectedAnalysisModel(), target);							
	target.add(browserPanel);				
 			    		
 			getSession().getFeedbackMessages().add(new FeedbackMessage(null, getString("freeze.start"), JGrowlAjaxBehavior.INFO_FADE));    			
 	        setResponsePage(HomePage.class);    	            	        
 	        
 	        analysisService.freeze(newAnalysis);
 		}
 		
 		@Override
public boolean isVisible() {				
	if (dataProvider.isEmpty() || AnalysisPanel.this.getModel().getObject().isFreezed()) {
		return false;
	}
	if (!SecurityUtil.hasPermission(securityService, PermissionUtil.getWrite(), getModelObject().getId())) {
 				return false;
 			}
 			return true;
}	 
 		
 		@Override
 		protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
 		    super.updateAjaxAttributes(attributes);
 		    attributes.getAjaxCallListeners().add(new AjaxCallListener() {
 		        @Override
 		        public CharSequence getBeforeHandler(Component cmpnt) {
 		            return "$(\"#" + cmpnt.getMarkupId() + "\").hide()";    		        	
 		        }
 		    });   
 		}
 		
 	};
 }