package org.devocative.wickomp.html;

import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.markup.ComponentTag;
import org.apache.wicket.markup.MarkupStream;
import org.apache.wicket.model.IModel;

public abstract class WAjaxLink extends AjaxLink {
	private static final long serialVersionUID = 4596376143569260289L;

	private IModel<String> caption;
	private HTMLBase icon;

	public WAjaxLink(String id) {
		this(id, null, null);
	}

	public WAjaxLink(String id, IModel<String> caption) {
		this(id, caption, null);
	}

	// Main Constructor
	public WAjaxLink(String id, IModel<String> caption, HTMLBase icon) {
		super(id);
		this.caption = caption;
		this.icon = icon;
	}

	@Override
	public void onComponentTagBody(MarkupStream markupStream, ComponentTag openTag) {
		if ("button".equalsIgnoreCase(openTag.getName()) && (caption != null || icon != null)) {
			String cap = "";
			if (caption != null) {
				cap = caption.getObject();
			}
			if (icon != null) {
				cap += " " + icon.toString();
			}
			replaceComponentTagBody(markupStream, openTag, cap);
		} else {
			super.onComponentTagBody(markupStream, openTag);
		}
	}
}

@@ -31,16 +31,175 @@
 .html;%0A%0A
+import org.apache.wicket.Component;%0Aimport org.apache.wicket.ajax.attributes.AjaxCallListener;%0Aimport org.apache.wicket.ajax.attributes.AjaxRequestAttributes;%0A
 import o
@@ -242,16 +242,16 @@
 axLink;%0A
-
 import o
@@ -550,16 +550,97 @@
 se icon;
+%0A%09private IModel%3CString%3E confirmationMessage;%0A%0A%09// ------------------------------
 %0A%0A%09publi
@@ -932,16 +932,236 @@
 on;%0A%09%7D%0A%0A
+%09// ------------------------------%0A%0A%09public WAjaxLink setConfirmationMessage(IModel%3CString%3E confirmationMessage) %7B%0A%09%09this.confirmationMessage = confirmationMessage;%0A%09%09return this;%0A%09%7D%0A%0A%09// ------------------------------%0A%0A
 %09@Overri
@@ -1548,16 +1548,16 @@
  else %7B%0A
-
 %09%09%09super
@@ -1606,11 +1606,525 @@
 ;%0A%09%09%7D%0A%09%7D
+%0A%0A%09@Override%0A%09protected void updateAjaxAttributes(AjaxRequestAttributes attributes) %7B%0A%09%09if (confirmationMessage != null) %7B%0A%09%09%09AjaxCallListener myAjaxCallListener = new AjaxCallListener() %7B%0A%09%09%09%09private static final long serialVersionUID = 1915387331347087734L;%0A%0A%09%09%09%09@Override%0A%09%09%09%09public CharSequence getPrecondition(Component component) %7B%0A%09%09%09%09%09return String.format(%22if(!confirm('%25s')) return false;%22, confirmationMessage.getObject());%0A%09%09%09%09%7D%0A%09%09%09%7D;%0A%09%09%09attributes.getAjaxCallListeners().add(myAjaxCallListener);%0A%09%09%7D%0A%09%7D
 %0A%7D%0A

add confirmationMessage property