/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package ro.nextreports.server.web.dashboard.chart;

import org.apache.wicket.ajax.AbstractDefaultAjaxBehavior;
import org.apache.wicket.ajax.AjaxRequestTarget;

import ro.nextreports.engine.chart.JsonExporter;

/**
 * @author Decebal Suiu
 */
public class OnClickChartAjaxBehavior extends AbstractDefaultAjaxBehavior {

	private static final long serialVersionUID = 1L;
	
	/** Value identifiant into the request */
	private static final String X_VALUE = "value";

	public OnClickChartAjaxBehavior() {
		super();
	}

	public String getOnClickJavaScript() {		
		return "Wicket.Ajax.get('" + getCallbackUrl() 
			+ "&" + X_VALUE + "=" + JsonExporter.X_VALUE 
			+ "', null, null, function() { return true; })";
	}
	
	@Override
	protected void respond(AjaxRequestTarget target) {
		String value = this.getComponent().getRequest().getRequestParameters().getParameterValue(X_VALUE).toString();		
		onClickChart(target, value);
	}

	public void onClickChart(AjaxRequestTarget target, String value) {
		System.out.println("!!!!!!!!!!!!!!!! Click on " + value);
	}

}

@@ -1174,51 +1174,8 @@
 ;%0A%09%0A
-%09/** Value identifiant into the request */%0A
 %09pri
@@ -1206,16 +1206,27 @@
  X_VALUE
+_PARAM_NAME
  = %22valu
@@ -1325,42 +1325,126 @@
 () %7B
-%09%09
 %0A%09%09
-return %22Wicket.Ajax.get('%22 + 
+StringBuilder javaScript = new StringBuilder();%0A%09%09javaScript.append(%22Wicket.Ajax.get(%7B u: '%22);%0A%09%09javaScript.append(
 getC
@@ -1459,110 +1459,211 @@
 rl()
- %0A%09%09%09+ %22&%22 + X_VALUE + %22=%22 + JsonExporter.X_VALUE %0A%09%09%09+ %22', null, null, function() %7B return true; %7D)%22;
+);%0A%09%09javaScript.append(%22&%22);%0A%09%09javaScript.append(X_VALUE_PARAM_NAME);%0A%09%09javaScript.append(%22=%22);%0A%09%09javaScript.append(JsonExporter.X_VALUE);%0A%09%09javaScript.append(%22'%7D)%22);%0A%09%09%0A%09%09return javaScript.toString();%09%09
 %0A%09%7D%0A
@@ -1748,13 +1748,8 @@
 e = 
-this.
 getC
@@ -1820,16 +1820,27 @@
 (X_VALUE
+_PARAM_NAME
 ).toStri
@@ -1844,19 +1844,54 @@
 tring();
+%0A
 %09%09
-%0A
+if (value != null) %7B // defensive%0A%09
 %09%09onClic
@@ -1908,24 +1908,33 @@
 get, value);
+%09%09%09%0A%09%09%7D%09%09
 %0A%09%7D%0A%0A%09public

fix drill down