<commit_before>package fr.openwide.core.wicket.more.markup.html.feedback;

import org.apache.wicket.MarkupContainer;
import org.apache.wicket.markup.head.IHeaderResponse;
import org.apache.wicket.markup.head.JavaScriptHeaderItem;
import org.apache.wicket.markup.head.OnDomReadyHeaderItem;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.odlabs.wiquery.core.events.Event;
import org.odlabs.wiquery.core.events.MouseEvent;
import org.odlabs.wiquery.core.events.WiQueryEventBehavior;
import org.odlabs.wiquery.core.javascript.JsScope;
import org.odlabs.wiquery.core.javascript.JsScopeEvent;
import org.odlabs.wiquery.core.javascript.JsStatement;

import fr.openwide.core.wicket.more.markup.html.template.js.jquery.plugins.alert.AlertJavascriptResourceReference;

public class AnimatedGlobalFeedbackPanel extends GlobalFeedbackPanel {

	private static final long serialVersionUID = 2213180445046166086L;

	public AnimatedGlobalFeedbackPanel(String id) {
		super(id);
		setOutputMarkupId(true);
		
		WebMarkupContainer closeTrigger = new WebMarkupContainer("closeTrigger");
		add(closeTrigger);
		closeTrigger.add(new CloseAlertBehavior());
	}

	@Override
	public void renderHead(IHeaderResponse response) {
		response.render(JavaScriptHeaderItem.forReference(AlertJavascriptResourceReference.get()));
		response.render(OnDomReadyHeaderItem.forScript(new JsStatement().append("$.fn.alert.reset('#")
				.append(getMarkupId()).append("')").render()));
		
		super.renderHead(response);
	}

	private static class CloseAlertBehavior extends WiQueryEventBehavior {
		private static final long serialVersionUID = -5585291224997829649L;
		
		public CloseAlertBehavior() {
			super(new Event(MouseEvent.CLICK) {
				private static final long serialVersionUID = 2160875652552472051L;
				
				@Override
				public JsScope callback() {
					return JsScopeEvent.quickScope("$.fn.alert.close(event);");
				}
			});
		}
	}

	@Override
	public FeedbackPanel getFeedbackPanel(String id, int level, MarkupContainer component) {
		return new ErrorLevelFeedbackPanel(id, level) {
			private static final long serialVersionUID = 4843857703266180362L;
			
			private boolean visible = false;
			
			@Override
			public boolean isVisible() {
				return visible;
			}
			
			@Override
			protected void onConfigure() {
				// cf WICKET-4536 : ceci dit, même après mise à jour, on a encore eu des cas avec le problème
				// du coup, on laisse comme ça
				super.onConfigure();
				
				visible = anyMessage(level);
			}
		};
	}
}<commit_msg>WiQueryEventBehavior est devenue stateful... du coup on le fait à la main comme des grands histoire que cet élément ne passe pas d'office les pages en stateful<commit_after>package fr.openwide.core.wicket.more.markup.html.feedback;

import org.apache.wicket.Component;
import org.apache.wicket.MarkupContainer;
import org.apache.wicket.behavior.Behavior;
import org.apache.wicket.markup.head.IHeaderResponse;
import org.apache.wicket.markup.head.JavaScriptHeaderItem;
import org.apache.wicket.markup.head.OnDomReadyHeaderItem;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.odlabs.wiquery.core.events.Event;
import org.odlabs.wiquery.core.events.MouseEvent;
import org.odlabs.wiquery.core.javascript.JsQuery;
import org.odlabs.wiquery.core.javascript.JsScope;
import org.odlabs.wiquery.core.javascript.JsScopeEvent;
import org.odlabs.wiquery.core.javascript.JsStatement;

import fr.openwide.core.wicket.more.markup.html.template.js.jquery.plugins.alert.AlertJavascriptResourceReference;

public class AnimatedGlobalFeedbackPanel extends GlobalFeedbackPanel {

	private static final long serialVersionUID = 2213180445046166086L;

	public AnimatedGlobalFeedbackPanel(String id) {
		super(id);
		setOutputMarkupId(true);
		
		WebMarkupContainer closeTrigger = new WebMarkupContainer("closeTrigger");
		add(closeTrigger);
		closeTrigger.add(new CloseAlertBehavior());
	}

	@Override
	public void renderHead(IHeaderResponse response) {
		response.render(JavaScriptHeaderItem.forReference(AlertJavascriptResourceReference.get()));
		response.render(OnDomReadyHeaderItem.forScript(new JsStatement().append("$.fn.alert.reset('#")
				.append(getMarkupId()).append("')").render()));
		
		super.renderHead(response);
	}

	private static class CloseAlertBehavior extends Behavior {
		private static final long serialVersionUID = -5585291224997829649L;

		@Override
		public void renderHead(Component component, IHeaderResponse response) {
			super.renderHead(component, response);
			
			Event event = new Event(MouseEvent.CLICK) {
				private static final long serialVersionUID = 2160875652552472051L;
				
				@Override
				public JsScope callback() {
					return JsScopeEvent.quickScope("$.fn.alert.close(event);");
				}
			};
			
			response.render(OnDomReadyHeaderItem.forScript(new JsQuery(component).$().chain(event).render()));
		}
	}

	@Override
	public FeedbackPanel getFeedbackPanel(String id, int level, MarkupContainer component) {
		return new ErrorLevelFeedbackPanel(id, level) {
			private static final long serialVersionUID = 4843857703266180362L;
			
			private boolean visible = false;
			
			@Override
			public boolean isVisible() {
				return visible;
			}
			
			@Override
			protected void onConfigure() {
				// cf WICKET-4536 : ceci dit, même après mise à jour, on a encore eu des cas avec le problème
				// du coup, on laisse comme ça
				super.onConfigure();
				
				visible = anyMessage(level);
			}
		};
	}
}
{'fraction_non_alphanumeric': 0.09996429846483398, 'fraction_numerical': 0.028561228132809712, 'mean_word_length': 4.941675503711559, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4676207', 'n_tokens_mistral': 2025, 'n_tokens_neox': 1706, 'n_words': 339}